Skip to content

Commit 87b5a1c

Browse files
FrostGodJoffref
andauthored
feat(supervisor): IPv6 policy DNS egress and NAT64-aware SSRF checks (#5793)
* feat(supervisor): make policy DNS IPv6 egress configurable Mediated policy DNS always answered AAAA queries with NOERROR/NODATA and resolved A queries upstream as A only. On IPv6-only hosts behind NAT64/DNS64 the trusted resolver returns no A records, so every policy-allowed name failed with policy_dns_upstream_no_data and native TCP egress was unusable. Add a driver-owned supervisor flag, --policy-dns-ipv6-egress {auto,enabled,disabled}. The default auto mode enables AAAA answers only when the supervisor network namespace has an IPv6 default route and no IPv4 default route, so dual-stack and IPv4-only hosts keep the current A-record fallback. AAAA answers use the existing epoch-scoped synthetic IPv6 pool and are pinned and dialed through the same resolved-endpoint store and destination validation as IPv4 answers. Signed-off-by: Joffref <mjoffre@blaxel.ai> * feat(supervisor): NAT64-aware SSRF checks and driver IPv6 egress settings A DNS64 answer like 64:ff9b::a00:5 is really 10.0.0.5, but the SSRF checks treated it as a public IPv6 address. Addresses inside a NAT64 prefix are now checked as the IPv4 address they embed, in policy DNS and in the CONNECT path. The well-known prefix is always known; other prefixes come from the new nat64_prefixes driver setting, or from ipv4only.arpa discovery when the supervisor starts. policy_dns_ipv6_egress and nat64_prefixes can now be set in the Docker, Podman, Kubernetes and VM driver configs. Before this, only auto was reachable in practice. The supervisor logs its IPv6 egress decision (requested mode, result, default routes, route state) and the NAT64 prefixes it uses as OCSF config events. Tests: route detection fixtures per backend, a start_mediated test with a fake mediation source and DNS64 upstream, driver arg tests, and an e2e check of the decision event. Signed-off-by: Joffref <mjoffre@blaxel.ai> * fix(supervisor): apply the IPv6 egress mode to the listener policy DNS runtime The listener-based runtime still started with IPv6 answers off, so an explicit mode only reached the mediated runtime. Resolve the mode once and use it for both. Signed-off-by: Joffref <mjoffre@blaxel.ai> * test(supervisor): IPv6 fail-closed cases and allowed_ips for NAT64 answers allowed_ips entries now match a NAT64 address through the IPv4 address it embeds, so 10.0.0.0/8 covers 64:ff9b::a00:5 the same way it covers 10.0.0.5. Loopback, link-local and metadata stay blocked first. The mediated IPv6 test now also checks that these are denied: the real upstream IPv6, an unallocated synthetic address, the right address on the wrong port, an open without a binary identity, and the old mapping after a policy reload. A second test covers an unreachable trusted resolver. The store gets the IPv6 version of the wrong port / stale generation / expiry test. Signed-off-by: Joffref <mjoffre@blaxel.ai> * fix(core): classify NAT64 addresses by the longest matching prefix embedded_ipv4 returned the first registered prefix that contained the address. With a configured 2001:db8::/32 and a later-discovered 2001:db8:8c52:7003::/96, 2001:db8:8c52:7003::7f00:1 was read through the /32 as 140.82.112.3 and passed the SSRF checks, while the /96 route translates it to 127.0.0.1. Pick the longest matching prefix, the well-known prefix included, the same way the route that carries the packet does. The tests register the broad prefix first and check loopback, metadata and private destinations under the nested one. They use RFC 9637 documentation space because the registry is process-wide and a 2001:db8::/32 would change how other tests classify their 2001:db8 addresses. Signed-off-by: Joffref <mjoffre@blaxel.ai> * style(supervisor): satisfy clippy duration_suboptimal_units in NAT64 test Signed-off-by: Joffref <mjoffre@blaxel.ai> * fix(supervisor): adapt IPv6 policy DNS egress to current main Use egress_emit for the supervisor-network config events, pass the new supervisor_pod and preauthorize_transparent_open arguments, and use the PolicyDnsService and pinned_addresses_for APIs in the IPv6 tests. Signed-off-by: divesh <dgude@nvidia.com> * fix(supervisor): honor policy DNS IPv6 settings in shared supervisors Shared supervisors gave every hosted instance auto mode and no NAT64 prefixes. They now take --policy-dns-ipv6-egress and --nat64-prefix like dedicated supervisors, and the Helm chart renders both from the Kubernetes driver settings. Signed-off-by: divesh <dgude@nvidia.com> --------- Signed-off-by: Joffref <mjoffre@blaxel.ai> Signed-off-by: divesh <dgude@nvidia.com> Co-authored-by: Joffref <mjoffre@blaxel.ai>
1 parent 4fe0103 commit 87b5a1c

35 files changed

Lines changed: 2770 additions & 31 deletions

File tree

‎crates/openshell-core/src/config.rs‎

Lines changed: 141 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,105 @@ impl UpstreamProxyConfig {
11611161
}
11621162
}
11631163

1164+
/// AAAA handling for the supervisor's mediated policy DNS.
1165+
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
1166+
#[serde(rename_all = "lowercase")]
1167+
pub enum PolicyDnsIpv6Egress {
1168+
/// Answer AAAA only when the supervisor network namespace has an IPv6
1169+
/// default route and no IPv4 default route.
1170+
#[default]
1171+
Auto,
1172+
/// Always resolve AAAA through the trusted resolver.
1173+
Enabled,
1174+
/// Never resolve AAAA; answer with NOERROR/NODATA.
1175+
Disabled,
1176+
}
1177+
1178+
impl PolicyDnsIpv6Egress {
1179+
/// The value used in configuration and on the supervisor command line.
1180+
#[must_use]
1181+
pub const fn as_str(self) -> &'static str {
1182+
match self {
1183+
Self::Auto => "auto",
1184+
Self::Enabled => "enabled",
1185+
Self::Disabled => "disabled",
1186+
}
1187+
}
1188+
}
1189+
1190+
impl fmt::Display for PolicyDnsIpv6Egress {
1191+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1192+
f.write_str(self.as_str())
1193+
}
1194+
}
1195+
1196+
impl FromStr for PolicyDnsIpv6Egress {
1197+
type Err = String;
1198+
1199+
fn from_str(value: &str) -> Result<Self, Self::Err> {
1200+
match value {
1201+
"auto" => Ok(Self::Auto),
1202+
"enabled" => Ok(Self::Enabled),
1203+
"disabled" => Ok(Self::Disabled),
1204+
other => Err(format!(
1205+
"unknown policy_dns_ipv6_egress '{other}'; expected 'auto', 'enabled' or 'disabled'"
1206+
)),
1207+
}
1208+
}
1209+
}
1210+
1211+
/// Supervisor IPv6 egress settings shared by compute drivers.
1212+
///
1213+
/// Like [`UpstreamProxyConfig`], this type is `flatten`ed by driver tables.
1214+
/// The values travel to the supervisor on argv, which sandbox environment
1215+
/// cannot influence.
1216+
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
1217+
#[serde(default, deny_unknown_fields)]
1218+
pub struct SupervisorIpv6EgressConfig {
1219+
/// AAAA handling for mediated policy DNS. Unset means the supervisor
1220+
/// default, `auto`.
1221+
pub policy_dns_ipv6_egress: Option<PolicyDnsIpv6Egress>,
1222+
/// NAT64 prefixes (RFC 6052) used by the sandbox network, for example
1223+
/// `64:ff9b:1::/96` or a network-specific `/96`. Addresses inside them
1224+
/// are classified by their embedded IPv4 address for SSRF checks. The
1225+
/// well-known prefix `64:ff9b::/96` is always recognized; the supervisor
1226+
/// also discovers the network's prefix through `ipv4only.arpa` (RFC 7050).
1227+
pub nat64_prefixes: Vec<String>,
1228+
}
1229+
1230+
impl SupervisorIpv6EgressConfig {
1231+
/// Validate prefix syntax and RFC 6052 lengths.
1232+
pub fn validate(&self) -> Result<(), String> {
1233+
self.parsed_nat64_prefixes().map(|_| ())
1234+
}
1235+
1236+
/// Parse the configured NAT64 prefixes.
1237+
pub fn parsed_nat64_prefixes(&self) -> Result<Vec<crate::net::nat64::Nat64Prefix>, String> {
1238+
self.nat64_prefixes
1239+
.iter()
1240+
.map(|raw| {
1241+
raw.parse::<crate::net::nat64::Nat64Prefix>()
1242+
.map_err(|error| format!("nat64_prefixes: {error}"))
1243+
})
1244+
.collect()
1245+
}
1246+
1247+
/// Supervisor arguments for these settings. Call [`Self::validate`]
1248+
/// first; invalid prefixes are passed through for the supervisor to
1249+
/// reject.
1250+
#[must_use]
1251+
pub fn supervisor_args(&self) -> Vec<String> {
1252+
let mut args = Vec::new();
1253+
if let Some(mode) = self.policy_dns_ipv6_egress {
1254+
args.extend(["--policy-dns-ipv6-egress".to_string(), mode.to_string()]);
1255+
}
1256+
for prefix in &self.nat64_prefixes {
1257+
args.extend(["--nat64-prefix".to_string(), prefix.trim().to_string()]);
1258+
}
1259+
args
1260+
}
1261+
}
1262+
11641263
/// Gateway-minted sandbox JWT configuration.
11651264
///
11661265
/// Points the gateway at the Ed25519 signing key (produced by `certgen`)
@@ -1585,8 +1684,9 @@ mod tests {
15851684
AppArmorProfile, Config, ConfigDeliveryMode, DEFAULT_SERVICE_ROUTING_DOMAIN,
15861685
GatewayInterceptorBindingPolicy, GatewayInterceptorConfig, GatewayInterceptorFailurePolicy,
15871686
GatewayJwtConfig, GatewayProviderProfileSourceConfig, ImagePullPolicy, MetricsTlsConfig,
1588-
PolicyValidationFailureMode, ServiceHostnameFormat, UpstreamProxyConfig,
1589-
default_sandbox_pids_limit, normalize_compute_driver_name,
1687+
PolicyDnsIpv6Egress, PolicyValidationFailureMode, ServiceHostnameFormat,
1688+
SupervisorIpv6EgressConfig, UpstreamProxyConfig, default_sandbox_pids_limit,
1689+
normalize_compute_driver_name,
15901690
};
15911691
use std::time::Duration;
15921692
use std::{net::SocketAddr, path::PathBuf};
@@ -1827,6 +1927,45 @@ mod tests {
18271927
}
18281928
}
18291929

1930+
#[test]
1931+
fn supervisor_ipv6_egress_config_parses_and_builds_supervisor_args() {
1932+
let config: SupervisorIpv6EgressConfig = serde_json::from_str(
1933+
r#"{"policy_dns_ipv6_egress":"enabled","nat64_prefixes":["64:ff9b:1::/96","2001:db8:122:344::/64"]}"#,
1934+
)
1935+
.unwrap();
1936+
config.validate().unwrap();
1937+
assert_eq!(
1938+
config.supervisor_args(),
1939+
[
1940+
"--policy-dns-ipv6-egress",
1941+
"enabled",
1942+
"--nat64-prefix",
1943+
"64:ff9b:1::/96",
1944+
"--nat64-prefix",
1945+
"2001:db8:122:344::/64",
1946+
]
1947+
);
1948+
assert!(
1949+
SupervisorIpv6EgressConfig::default()
1950+
.supervisor_args()
1951+
.is_empty()
1952+
);
1953+
for bad in ["10.0.0.0/8", "2001:db8::/80", "nonsense"] {
1954+
let config = SupervisorIpv6EgressConfig {
1955+
nat64_prefixes: vec![bad.to_string()],
1956+
..Default::default()
1957+
};
1958+
assert!(config.validate().is_err(), "{bad}");
1959+
}
1960+
assert!(
1961+
serde_json::from_str::<SupervisorIpv6EgressConfig>(
1962+
r#"{"policy_dns_ipv6_egress":"yes"}"#
1963+
)
1964+
.is_err()
1965+
);
1966+
assert_eq!("disabled".parse(), Ok(PolicyDnsIpv6Egress::Disabled));
1967+
}
1968+
18301969
#[test]
18311970
fn upstream_proxy_validation_enforces_cross_field_contract() {
18321971
let auth_file = Some("/run/secrets/proxy-auth".into());

‎crates/openshell-core/src/lib.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ pub use config::{
7777
GatewayInterceptorBindingOverride, GatewayInterceptorBindingPolicy, GatewayInterceptorConfig,
7878
GatewayInterceptorFailurePolicy, GatewayInterceptorPhaseConfig, GatewayJwtConfig,
7979
GatewayProviderProfileSourceConfig, ImagePullPolicy, MetricsTlsConfig, MtlsAuthConfig,
80-
OidcConfig, PolicyValidationFailureMode, TlsConfig, UpstreamProxyConfig,
80+
OidcConfig, PolicyDnsIpv6Egress, PolicyValidationFailureMode, SupervisorIpv6EgressConfig,
81+
TlsConfig, UpstreamProxyConfig,
8182
};
8283
pub use dynamic_string_allowlist::DynamicStringAllowlist;
8384
pub use error::{ComputeDriverError, Error, Result};

0 commit comments

Comments
 (0)