Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Self-assembling NTP Zone #2900

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions illumos-utils/src/running_zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ impl RunningZone {

/// Returns the filesystem path to the zone's root in the GZ.
pub fn root(&self) -> Utf8PathBuf {
self.inner.zonepath.join(Self::ROOT_FS_PATH)
self.inner.root()
}

pub fn control_interface(&self) -> AddrObject {
Expand Down Expand Up @@ -909,7 +909,7 @@ impl RunningZone {
}

pub fn links(&self) -> &Vec<Link> {
&self.inner.links
self.inner.links()
}

/// Return the running processes associated with all the SMF services this
Expand Down Expand Up @@ -1087,6 +1087,9 @@ pub struct InstalledZone {
}

impl InstalledZone {
/// The path to the zone's root filesystem (i.e., `/`), within zonepath.
pub const ROOT_FS_PATH: &'static str = "root";

/// Returns the name of a zone, based on the base zone name plus any unique
/// identifying info.
///
Expand All @@ -1109,10 +1112,19 @@ impl InstalledZone {
self.control_vnic.name()
}

pub fn links(&self) -> &Vec<Link> {
&self.links
}

pub fn name(&self) -> &str {
&self.name
}

/// Returns the filesystem path to the zone's root in the GZ.
pub fn root(&self) -> Utf8PathBuf {
self.zonepath.join(Self::ROOT_FS_PATH)
}

/// Returns the filesystem path to the zonepath
pub fn zonepath(&self) -> &Utf8Path {
&self.zonepath
Expand Down
209 changes: 111 additions & 98 deletions sled-agent/src/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ use crate::params::{
ZoneType,
};
use crate::profile::*;
use crate::smf_helper::Service;
use crate::smf_helper::SmfHelper;
use crate::zone_bundle::BundleError;
use crate::zone_bundle::ZoneBundler;
Expand Down Expand Up @@ -957,37 +956,22 @@ impl ServiceManager {

async fn configure_dns_client(
&self,
running_zone: &RunningZone,
zone: &InstalledZone,
dns_servers: &[IpAddr],
domain: &Option<String>,
) -> Result<(), Error> {
struct DnsClient {}

impl crate::smf_helper::Service for DnsClient {
fn service_name(&self) -> String {
"dns_client".to_string()
}
fn smf_name(&self) -> String {
"svc:/network/dns/client".to_string()
}
fn should_import(&self) -> bool {
false
}
}

let service = DnsClient {};
let smfh = SmfHelper::new(&running_zone, &service);

let etc = running_zone.root().join("etc");
let resolv_conf = etc.join("resolv.conf");
let nsswitch_conf = etc.join("nsswitch.conf");
let nsswitch_dns = etc.join("nsswitch.dns");

) -> Result<Option<ServiceBuilder>, Error> {
if dns_servers.is_empty() {
// Disable the dns/client service
smfh.disable()?;
Ok(None)
} else {
debug!(self.inner.log, "enabling {:?}", service.service_name());
let name = "network/dns/client";
let service = ServiceBuilder::new(name);
let etc = zone.root().join("etc");
let resolv_conf = etc.join("resolv.conf");
let nsswitch_conf = etc.join("nsswitch.conf");
let nsswitch_dns = etc.join("nsswitch.dns");

debug!(self.inner.log, "enabling {:?}", name);
let mut config = String::new();
if let Some(d) = domain {
config.push_str(&format!("domain {d}\n"));
Expand All @@ -1004,11 +988,8 @@ impl ServiceManager {
tokio::fs::copy(&nsswitch_dns, &nsswitch_conf)
.await
.map_err(|err| Error::io_path(&nsswitch_dns, err))?;

smfh.refresh()?;
smfh.enable()?;
Ok(Some(service))
}
Ok(())
}

async fn dns_install(
Expand Down Expand Up @@ -1309,8 +1290,99 @@ impl ServiceManager {
.add_to_zone(&self.inner.log, &installed_zone)
.await
.map_err(|err| Error::io("crucible pantry profile", err))?;
let running_zone = RunningZone::boot(installed_zone).await?;
return Ok(running_zone);
return Ok(RunningZone::boot(installed_zone).await?);
}
ZoneType::Ntp => {
let Some(info) = self.inner.sled_info.get() else {
return Err(Error::SledAgentNotReady);
};
let rack_net =
Ipv6Subnet::<RACK_PREFIX>::new(info.underlay_address).net();

let datalink = installed_zone.get_control_vnic_name();
let gateway = &info.underlay_address.to_string();
assert_eq!(request.zone.addresses.len(), 1);
let listen_addr = &request.zone.addresses[0].to_string();

assert_eq!(request.zone.services.len(), 1);
let (ntp_servers, dns_servers, domain, boundary) =
match request.zone.services[0].details.clone() {
ServiceType::InternalNtp {
ntp_servers,
dns_servers,
domain,
..
} => (ntp_servers, dns_servers, domain, false),
ServiceType::BoundaryNtp {
ntp_servers,
dns_servers,
domain,
..
} => (ntp_servers, dns_servers, domain, true),
_ => {
return Err(Error::BadServiceRequest {
service: request.zone.services[0]
.details
.to_string(),
message:
"Cannot set up this service in the NTP zone"
.to_string(),
});
}
};

info!(
self.inner.log,
"Set up NTP service boundary={}, Servers={:?}",
boundary,
ntp_servers
);

let config = PropertyGroupBuilder::new("config")
.add_property("gateway", "astring", gateway)
// TODO: Uncomment or delete after testing
// .add_property(
// "all_links",
// "astring",
// &installed_zone
// .links()
// .iter()
// .map(|l| l.name())
// .join(" "),
// )
.add_property("datalink", "astring", datalink)
.add_property("listen_addr", "astring", listen_addr)
.add_property("allow", "astring", &format!("{}", rack_net))
.add_property(
"boundary",
"astring",
if boundary { "true" } else { "false" },
)
.add_property("server", "astring", &ntp_servers.join(" "));

let profile = ProfileBuilder::new("omicron").add_service(
ServiceBuilder::new("system/illumos/ntp").add_instance(
ServiceInstanceBuilder::new("default")
.add_property_group(config),
),
);
let maybe_dns_client = self
.configure_dns_client(
&installed_zone,
&dns_servers,
&domain,
)
.await?;
let profile = if let Some(dns_client) = maybe_dns_client {
profile.add_service(dns_client)
} else {
profile
};
profile
.add_to_zone(&self.inner.log, &installed_zone)
.await
.map_err(|err| Error::io("NTP profile", err))?;
return Ok(RunningZone::boot(installed_zone).await?);
}
_ => {}
}
Expand Down Expand Up @@ -1912,67 +1984,6 @@ impl ServiceManager {

smfh.refresh()?;
}
ServiceType::BoundaryNtp {
ntp_servers,
dns_servers,
domain,
..
}
| ServiceType::InternalNtp {
ntp_servers,
dns_servers,
domain,
..
} => {
let boundary = matches!(
service.details,
ServiceType::BoundaryNtp { .. }
);
info!(
self.inner.log,
"Set up NTP service boundary={}, Servers={:?}",
boundary,
ntp_servers
);

let sled_info =
if let Some(info) = self.inner.sled_info.get() {
info
} else {
return Err(Error::SledAgentNotReady);
};

let rack_net = Ipv6Subnet::<RACK_PREFIX>::new(
sled_info.underlay_address,
)
.net();

smfh.setprop("config/allow", &format!("{}", rack_net))?;
smfh.setprop(
"config/boundary",
if boundary { "true" } else { "false" },
)?;

if boundary {
// Configure OPTE port for boundary NTP
running_zone
.ensure_address_for_port("public", 0)
.await?;
}

smfh.delpropvalue("config/server", "*")?;
for server in ntp_servers {
smfh.addpropvalue("config/server", server)?;
}
self.configure_dns_client(
&running_zone,
dns_servers,
&domain,
)
.await?;

smfh.refresh()?;
}
ServiceType::Uplink => {
// Nothing to do here - this service is special and
// configured in `ensure_switch_zone_uplinks_configured`
Expand Down Expand Up @@ -2053,11 +2064,13 @@ impl ServiceManager {

smfh.refresh()?;
}
ServiceType::Crucible { .. }
| ServiceType::CruciblePantry { .. }
| ServiceType::CockroachDb { .. }
ServiceType::BoundaryNtp { .. }
| ServiceType::Clickhouse { .. }
| ServiceType::ClickhouseKeeper { .. } => {
| ServiceType::ClickhouseKeeper { .. }
| ServiceType::CockroachDb { .. }
| ServiceType::Crucible { .. }
| ServiceType::CruciblePantry { .. }
| ServiceType::InternalNtp { .. } => {
panic!(
"{} is a service which exists as part of a self-assembling zone",
service.details,
Expand Down
15 changes: 0 additions & 15 deletions sled-agent/src/smf_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,19 +236,4 @@ impl<'t> SmfHelper<'t> {
})?;
Ok(())
}

pub fn disable(&self) -> Result<(), Error> {
self.running_zone
.run_cmd(&[
illumos_utils::zone::SVCADM,
"disable",
"-t",
&self.default_smf_name,
])
.map_err(|err| Error::ZoneCommand {
intent: format!("Disable {} service", self.default_smf_name),
err,
})?;
Ok(())
}
}
Loading
Loading