From f541cab3176c035702df4ad3f89b3eb87c396587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karen=20C=C3=A1rcamo?= Date: Mon, 22 Apr 2024 11:31:09 +1200 Subject: [PATCH] [sled-agent] NTP zone config set up via zone-setup CLI (#5440) ## Overview This PR repurposes the zone-network CLI into a zone-setup CLI, in order to remove as many zone start-up scripts as possible. This is also in preparation to use this zone-setup CLI with the self assembling switch zone. Related: https://github.com/oxidecomputer/omicron/issues/1898 --------- Co-authored-by: Andy Fiddaman --- Cargo.lock | 13 +- Cargo.toml | 5 +- illumos-utils/src/lib.rs | 1 + illumos-utils/src/svcadm.rs | 21 + package-manifest.toml | 62 ++- sled-agent/src/services.rs | 12 +- .../etc/logadm.d/chrony.logadm.conf | 0 smf/chrony-setup/manifest.xml | 46 ++ smf/ntp/etc/inet/chrony.conf.boundary | 32 -- smf/ntp/etc/inet/chrony.conf.internal | 31 -- smf/ntp/manifest/manifest.xml | 22 +- smf/ntp/method/svc-site-ntp | 128 ----- smf/opte-interface-setup/manifest.xml | 2 +- smf/zone-network-setup/manifest.xml | 2 +- zone-network-setup/src/bin/zone-networking.rs | 202 -------- {zone-network-setup => zone-setup}/Cargo.toml | 3 +- zone-setup/src/bin/zone-setup.rs | 484 ++++++++++++++++++ 17 files changed, 618 insertions(+), 448 deletions(-) create mode 100644 illumos-utils/src/svcadm.rs rename smf/{ntp => chrony-setup}/etc/logadm.d/chrony.logadm.conf (100%) create mode 100644 smf/chrony-setup/manifest.xml delete mode 100644 smf/ntp/etc/inet/chrony.conf.boundary delete mode 100644 smf/ntp/etc/inet/chrony.conf.internal delete mode 100755 smf/ntp/method/svc-site-ntp delete mode 100644 zone-network-setup/src/bin/zone-networking.rs rename {zone-network-setup => zone-setup}/Cargo.toml (88%) create mode 100644 zone-setup/src/bin/zone-setup.rs diff --git a/Cargo.lock b/Cargo.lock index 9eeb22632e..0f5477f077 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10589,6 +10589,16 @@ dependencies = [ "serde", ] +[[package]] +name = "uzers" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76d283dc7e8c901e79e32d077866eaf599156cbf427fffa8289aecc52c5c3f63" +dependencies = [ + "libc", + "log", +] + [[package]] name = "vcpkg" version = "0.2.15" @@ -11393,7 +11403,7 @@ dependencies = [ ] [[package]] -name = "zone-network-setup" +name = "zone-setup" version = "0.1.0" dependencies = [ "anyhow", @@ -11404,6 +11414,7 @@ dependencies = [ "omicron-workspace-hack", "slog", "tokio", + "uzers", "zone 0.3.0", ] diff --git a/Cargo.toml b/Cargo.toml index fa1f548b56..b6b937614c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -79,7 +79,7 @@ members = [ "wicket", "wicketd", "workspace-hack", - "zone-network-setup", + "zone-setup", ] default-members = [ @@ -158,7 +158,7 @@ default-members = [ "wicket-dbg", "wicket", "wicketd", - "zone-network-setup", + "zone-setup", ] resolver = "2" @@ -442,6 +442,7 @@ update-common = { path = "update-common" } update-engine = { path = "update-engine" } usdt = "0.5.0" uuid = { version = "1.8.0", features = ["serde", "v4"] } +uzers = "0.11" walkdir = "2.5" whoami = "1.5" wicket = { path = "wicket" } diff --git a/illumos-utils/src/lib.rs b/illumos-utils/src/lib.rs index 550170b0f2..d041c866b0 100644 --- a/illumos-utils/src/lib.rs +++ b/illumos-utils/src/lib.rs @@ -24,6 +24,7 @@ pub mod route; pub mod running_zone; pub mod scf; pub mod svc; +pub mod svcadm; pub mod vmm_reservoir; pub mod zfs; pub mod zone; diff --git a/illumos-utils/src/svcadm.rs b/illumos-utils/src/svcadm.rs new file mode 100644 index 0000000000..0d472187df --- /dev/null +++ b/illumos-utils/src/svcadm.rs @@ -0,0 +1,21 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +//! Utilities for manipulating SMF services. + +use crate::zone::SVCADM; +use crate::{execute, ExecutionError, PFEXEC}; + +/// Wraps commands for interacting with svcadm. +pub struct Svcadm {} + +#[cfg_attr(any(test, feature = "testing"), mockall::automock)] +impl Svcadm { + pub fn refresh_logadm_upgrade() -> Result<(), ExecutionError> { + let mut cmd = std::process::Command::new(PFEXEC); + let cmd = cmd.args(&[SVCADM, "refresh", "logadm-upgrade"]); + execute(cmd)?; + Ok(()) + } +} diff --git a/package-manifest.toml b/package-manifest.toml index 7fed672271..8633255c7e 100644 --- a/package-manifest.toml +++ b/package-manifest.toml @@ -100,7 +100,7 @@ only_for_targets.image = "standard" source.type = "composite" source.packages = [ "omicron-nexus.tar.gz", - "zone-network-setup.tar.gz", + "zone-setup.tar.gz", "zone-network-install.tar.gz", "opte-interface-setup.tar.gz", ] @@ -130,11 +130,7 @@ output.intermediate_only = true service_name = "oximeter" only_for_targets.image = "standard" source.type = "composite" -source.packages = [ - "oximeter-collector.tar.gz", - "zone-network-setup.tar.gz", - "zone-network-install.tar.gz", -] +source.packages = [ "oximeter-collector.tar.gz", "zone-setup.tar.gz", "zone-network-install.tar.gz" ] output.type = "zone" [package.oximeter-collector] @@ -157,8 +153,8 @@ source.type = "composite" source.packages = [ "clickhouse_svc.tar.gz", "internal-dns-cli.tar.gz", - "zone-network-setup.tar.gz", - "zone-network-install.tar.gz", + "zone-setup.tar.gz", + "zone-network-install.tar.gz" ] output.type = "zone" @@ -183,8 +179,8 @@ source.type = "composite" source.packages = [ "clickhouse_keeper_svc.tar.gz", "internal-dns-cli.tar.gz", - "zone-network-setup.tar.gz", - "zone-network-install.tar.gz", + "zone-setup.tar.gz", + "zone-network-install.tar.gz" ] output.type = "zone" @@ -209,8 +205,8 @@ source.type = "composite" source.packages = [ "cockroachdb-service.tar.gz", "internal-dns-cli.tar.gz", - "zone-network-setup.tar.gz", - "zone-network-install.tar.gz", + "zone-setup.tar.gz", + "zone-network-install.tar.gz" ] output.type = "zone" @@ -245,8 +241,8 @@ source.type = "composite" source.packages = [ "dns-server.tar.gz", "internal-dns-customizations.tar.gz", - "zone-network-setup.tar.gz", - "zone-network-install.tar.gz", + "zone-setup.tar.gz", + "zone-network-install.tar.gz" ] output.type = "zone" @@ -257,7 +253,7 @@ source.type = "composite" source.packages = [ "dns-server.tar.gz", "external-dns-customizations.tar.gz", - "zone-network-setup.tar.gz", + "zone-setup.tar.gz", "zone-network-install.tar.gz", "opte-interface-setup.tar.gz", ] @@ -298,10 +294,11 @@ service_name = "ntp" only_for_targets.image = "standard" source.type = "composite" source.packages = [ + "chrony-setup.tar.gz", "ntp-svc.tar.gz", "opte-interface-setup.tar.gz", - "zone-network-setup.tar.gz", - "zone-network-install.tar.gz", + "zone-setup.tar.gz", + "zone-network-install.tar.gz" ] output.type = "zone" @@ -311,8 +308,17 @@ only_for_targets.image = "standard" source.type = "local" source.paths = [ { from = "smf/ntp/manifest", to = "/var/svc/manifest/site/ntp" }, - { from = "smf/ntp/method", to = "/var/svc/method" }, - { from = "smf/ntp/etc", to = "/etc" }, +] +output.intermediate_only = true +output.type = "zone" + +[package.chrony-setup] +service_name = "chrony-setup" +only_for_targets.image = "standard" +source.type = "local" +source.paths = [ + { from = "smf/chrony-setup/manifest.xml", to = "/var/svc/manifest/site/chrony-setup/manifest.xml" }, + { from = "smf/chrony-setup/etc", to = "/etc" }, ] output.intermediate_only = true output.type = "zone" @@ -457,11 +463,7 @@ output.intermediate_only = true service_name = "crucible" only_for_targets.image = "standard" source.type = "composite" -source.packages = [ - "crucible.tar.gz", - "zone-network-setup.tar.gz", - "zone-network-install.tar.gz", -] +source.packages = [ "crucible.tar.gz", "zone-setup.tar.gz", "zone-network-install.tar.gz" ] output.type = "zone" @@ -469,11 +471,7 @@ output.type = "zone" service_name = "crucible_pantry" only_for_targets.image = "standard" source.type = "composite" -source.packages = [ - "crucible-pantry.tar.gz", - "zone-network-setup.tar.gz", - "zone-network-install.tar.gz", -] +source.packages = [ "crucible-pantry.tar.gz", "zone-setup.tar.gz", "zone-network-install.tar.gz" ] output.type = "zone" # Packages not built within Omicron, but which must be imported. @@ -746,11 +744,11 @@ source.paths = [ output.type = "zone" output.intermediate_only = true -[package.zone-network-setup] -service_name = "zone-network-cli" +[package.zone-setup] +service_name = "zone-setup-cli" only_for_targets.image = "standard" source.type = "local" -source.rust.binary_names = ["zone-networking"] +source.rust.binary_names = ["zone-setup"] source.rust.release = true output.type = "zone" output.intermediate_only = true diff --git a/sled-agent/src/services.rs b/sled-agent/src/services.rs index 1ddb3f9b0a..e2e86e327e 100644 --- a/sled-agent/src/services.rs +++ b/sled-agent/src/services.rs @@ -2006,7 +2006,7 @@ impl ServiceManager { Self::dns_install(info, Some(dns_servers.to_vec()), domain) .await?; - let mut ntp_config = PropertyGroupBuilder::new("config") + let mut chrony_config = PropertyGroupBuilder::new("config") .add_property("allow", "astring", &rack_net) .add_property( "boundary", @@ -2015,7 +2015,7 @@ impl ServiceManager { ); for s in ntp_servers { - ntp_config = ntp_config.add_property( + chrony_config = chrony_config.add_property( "server", "astring", &s.to_string(), @@ -2030,13 +2030,17 @@ impl ServiceManager { } let ntp_service = ServiceBuilder::new("oxide/ntp") - .add_instance( + .add_instance(ServiceInstanceBuilder::new("default")); + + let chrony_setup_service = + ServiceBuilder::new("oxide/chrony-setup").add_instance( ServiceInstanceBuilder::new("default") - .add_property_group(ntp_config), + .add_property_group(chrony_config), ); let mut profile = ProfileBuilder::new("omicron") .add_service(nw_setup_service) + .add_service(chrony_setup_service) .add_service(disabled_ssh_service) .add_service(dns_install_service) .add_service(dns_client_service) diff --git a/smf/ntp/etc/logadm.d/chrony.logadm.conf b/smf/chrony-setup/etc/logadm.d/chrony.logadm.conf similarity index 100% rename from smf/ntp/etc/logadm.d/chrony.logadm.conf rename to smf/chrony-setup/etc/logadm.d/chrony.logadm.conf diff --git a/smf/chrony-setup/manifest.xml b/smf/chrony-setup/manifest.xml new file mode 100644 index 0000000000..f31f13a2ea --- /dev/null +++ b/smf/chrony-setup/manifest.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/smf/ntp/etc/inet/chrony.conf.boundary b/smf/ntp/etc/inet/chrony.conf.boundary deleted file mode 100644 index d13bc9c815..0000000000 --- a/smf/ntp/etc/inet/chrony.conf.boundary +++ /dev/null @@ -1,32 +0,0 @@ -# -# Configuration file for a boundary NTP server - one which communicates with -# NTP servers outside the rack. -# - -pool @SERVER@ iburst maxdelay 0.1 maxsources 16 - -driftfile /var/lib/chrony/drift -ntsdumpdir /var/lib/chrony -dumpdir /var/lib/chrony -pidfile /var/run/chrony/chronyd.pid -logdir /var/log/chrony - -log measurements statistics tracking - -allow fe80::/10 -allow @ALLOW@ - -# Enable local reference mode, which keeps us operating as an NTP server that -# appears synchronised even if there are currently no active upstreams. When -# in this mode, we report as stratum 10 to clients. -local stratum 10 - -# makestep -# We allow chrony to step the system clock during the first three time updates -# if we are more than 0.1 seconds out. -makestep 0.1 3 - -# When a leap second occurs we slew the clock over approximately 37 seconds. -leapsecmode slew -maxslewrate 2708.333 - diff --git a/smf/ntp/etc/inet/chrony.conf.internal b/smf/ntp/etc/inet/chrony.conf.internal deleted file mode 100644 index 9e9ff3ddea..0000000000 --- a/smf/ntp/etc/inet/chrony.conf.internal +++ /dev/null @@ -1,31 +0,0 @@ -# -# Configuration file for an internal NTP server - one which communicates with -# boundary NTP servers within the rack. -# - -server @SERVER@ iburst minpoll 0 maxpoll 4 - -driftfile /var/lib/chrony/drift -ntsdumpdir /var/lib/chrony -dumpdir /var/lib/chrony -pidfile /var/run/chrony/chronyd.pid -logdir /var/log/chrony - -log measurements statistics tracking - -# makestep -# We allow chrony to step the system clock if we are more than a day out, -# regardless of how many clock updates have occurred since boot. -# The boundary NTP servers are configured with local reference mode, which -# means that if they start up without external connectivity, they will appear -# as authoritative servers even if they are advertising January 1987 -# (which is the default system clock on a gimlet after boot). -# This configuration allows a one-off adjustment once RSS begins and the -# boundary servers are synchronised, after which the clock will advance -# monotonically forwards. -makestep 86400 -1 - -# When a leap second occurs we slew the clock over approximately 37 seconds. -leapsecmode slew -maxslewrate 2708.333 - diff --git a/smf/ntp/manifest/manifest.xml b/smf/ntp/manifest/manifest.xml index 7783bbe76c..df427a16a5 100644 --- a/smf/ntp/manifest/manifest.xml +++ b/smf/ntp/manifest/manifest.xml @@ -39,6 +39,11 @@ + + + + @@ -57,7 +62,9 @@ The service also always starts the binary with ASLR enabled, regardless of whether it was linked with -zaslr --> - - - - - - - - - - -