@@ -2597,6 +2597,10 @@ async fn handle_get_sandbox_config_inner(
25972597) -> Result<Response<GetSandboxConfigResponse>, Status> {
25982598 let principal = super::extract_principal(&request)?;
25992599 let req = request.into_inner();
2600+ let legacy_supervisor = matches!(
2601+ &principal,
2602+ Principal::Sandbox(sandbox) if req.workspace_scope.is_none() && req.name == sandbox.sandbox_id
2603+ );
26002604 let workspace = match &principal {
26012605 Principal::Sandbox(_) if req.workspace_scope.is_none() => "",
26022606 _ => crate::auth::workspace_authz::selected_workspace_name(req.workspace_scope.as_ref())?,
@@ -2609,7 +2613,35 @@ async fn handle_get_sandbox_config_inner(
26092613 MinWorkspaceRole::User,
26102614 )
26112615 .await?;
2612- Ok(Response::new(load_sandbox_config(state, &sandbox).await?))
2616+ let mut config = load_sandbox_config(state, &sandbox).await?;
2617+ if legacy_supervisor && let Some(policy) = config.policy.as_mut() {
2618+ populate_legacy_endpoint_modes(policy)?;
2619+ }
2620+ Ok(Response::new(config))
2621+ }
2622+
2623+ #[allow(deprecated)]
2624+ fn populate_legacy_endpoint_modes(policy: &mut ProtoSandboxPolicy) -> Result<(), Status> {
2625+ for rule in policy.network_policies.values_mut() {
2626+ for endpoint in &mut rule.endpoints {
2627+ endpoint.legacy_tls = openshell_policy::network_tls_mode_to_str(endpoint.tls)
2628+ .ok_or_else(|| Status::internal("effective policy contains an unknown TLS mode"))?
2629+ .to_string();
2630+ endpoint.legacy_enforcement =
2631+ openshell_policy::network_enforcement_mode_to_str(endpoint.enforcement)
2632+ .ok_or_else(|| {
2633+ Status::internal("effective policy contains an unknown enforcement mode")
2634+ })?
2635+ .to_string();
2636+ endpoint.legacy_access =
2637+ openshell_policy::network_access_preset_to_str(endpoint.access)
2638+ .ok_or_else(|| {
2639+ Status::internal("effective policy contains an unknown access preset")
2640+ })?
2641+ .to_string();
2642+ }
2643+ }
2644+ Ok(())
26132645}
26142646
26152647/// Resolve the same effective configuration for authenticated RPCs and trusted
@@ -7523,6 +7555,45 @@ mod tests {
75237555 use std::sync::atomic::{AtomicUsize, Ordering};
75247556 use tonic::Code;
75257557
7558+ #[derive(Clone, PartialEq, prost::Message)]
7559+ struct LegacyNetworkEndpoint {
7560+ #[prost(string, tag = "4")]
7561+ tls: String,
7562+ #[prost(string, tag = "5")]
7563+ enforcement: String,
7564+ #[prost(string, tag = "6")]
7565+ access: String,
7566+ }
7567+
7568+ #[test]
7569+ fn legacy_endpoint_modes_remain_decodable_by_pre4_supervisors() {
7570+ use openshell_core::proto::{NetworkAccessPreset, NetworkEnforcementMode, NetworkTlsMode};
7571+
7572+ let mut policy = ProtoSandboxPolicy {
7573+ network_policies: HashMap::from([(
7574+ "api".to_string(),
7575+ NetworkPolicyRule {
7576+ endpoints: vec![NetworkEndpoint {
7577+ tls: NetworkTlsMode::Skip.into(),
7578+ enforcement: NetworkEnforcementMode::Enforce.into(),
7579+ access: NetworkAccessPreset::ReadWrite.into(),
7580+ ..Default::default()
7581+ }],
7582+ ..Default::default()
7583+ },
7584+ )]),
7585+ ..Default::default()
7586+ };
7587+
7588+ populate_legacy_endpoint_modes(&mut policy).unwrap();
7589+ let encoded = policy.network_policies["api"].endpoints[0].encode_to_vec();
7590+ let legacy = LegacyNetworkEndpoint::decode(encoded.as_slice()).unwrap();
7591+
7592+ assert_eq!(legacy.tls, "skip");
7593+ assert_eq!(legacy.enforcement, "enforce");
7594+ assert_eq!(legacy.access, "read-write");
7595+ }
7596+
75267597 /// Wrap a request with a user `Principal` so handler scope guards treat
75277598 /// the test caller as a CLI user. Most handler tests exercise
75287599 /// user-facing behavior and should not trip sandbox equality checks.
0 commit comments