Skip to content

Commit ee1528d

Browse files
committed
fix(upgrade): preserve pre.4 supervisor compatibility
Signed-off-by: Evan Lezar <[email protected]>
1 parent 50f274f commit ee1528d

9 files changed

Lines changed: 202 additions & 45 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ fn yaml_mcp_method(
486486
method.to_string()
487487
}
488488

489+
#[allow(deprecated)]
489490
fn to_proto(raw: PolicyFile) -> Result<SandboxPolicy> {
490491
for (policy_name, rule) in &raw.network_policies {
491492
for (endpoint_index, endpoint) in rule.endpoints.iter().enumerate() {
@@ -532,6 +533,9 @@ fn to_proto(raw: PolicyFile) -> Result<SandboxPolicy> {
532533
};
533534
NetworkEndpoint {
534535
host: e.host,
536+
legacy_tls: String::new(),
537+
legacy_enforcement: String::new(),
538+
legacy_access: String::new(),
535539
path: e.path,
536540
port: normalized_ports.first().copied().unwrap_or(0),
537541
ports: normalized_ports,

‎crates/openshell-providers/src/profiles.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,9 +1541,13 @@ fn discovery_to_proto(discovery: &DiscoveryProfile) -> ProviderProfileDiscovery
15411541
}
15421542
}
15431543

1544+
#[allow(deprecated)]
15441545
fn endpoint_to_proto(endpoint: &EndpointProfile) -> NetworkEndpoint {
15451546
NetworkEndpoint {
15461547
host: endpoint.host.clone(),
1548+
legacy_tls: String::new(),
1549+
legacy_enforcement: String::new(),
1550+
legacy_access: String::new(),
15471551
port: endpoint.port,
15481552
protocol: endpoint.protocol.clone(),
15491553
tls: network_tls_mode_from_str(&endpoint.tls).map_or(-1, |value| value as i32),

‎crates/openshell-server/src/grpc/policy.rs‎

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.

‎crates/openshell-server/src/grpc/sandbox.rs‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,11 @@ pub(super) async fn resolve_and_authorize_sandbox_name(
202202
.map_err(|e| Status::internal(format!("fetch sandbox failed: {e}")))?
203203
.filter(|sandbox| {
204204
sandbox.metadata.as_ref().is_some_and(|metadata| {
205-
metadata.name == sandbox_name
205+
// Supervisors released before sandbox names became the
206+
// canonical RPC reference send their authenticated sandbox
207+
// UUID in the same protobuf field. The principal is already
208+
// bound to that UUID, so accepting it cannot widen scope.
209+
(metadata.name == sandbox_name || sandbox_principal.sandbox_id == sandbox_name)
206210
&& (workspace.is_empty() || workspace == sandbox.object_workspace())
207211
})
208212
});
@@ -3832,6 +3836,7 @@ async fn run_exec_with_russh(
38323836
#[cfg(test)]
38333837
mod tests {
38343838
use super::*;
3839+
use crate::auth::principal::{Principal, SandboxIdentitySource, SandboxPrincipal};
38353840
use crate::compute::NoopTestDriver;
38363841
use crate::grpc::test_support::{
38373842
authed_request, test_server_state, test_server_state_with_compute_driver,
@@ -4294,6 +4299,33 @@ mod tests {
42944299
sandbox
42954300
}
42964301

4302+
#[tokio::test]
4303+
async fn sandbox_principal_accepts_legacy_id_reference_for_its_own_sandbox() {
4304+
let state = test_server_state().await;
4305+
let sandbox = test_sandbox("legacy-reference", Vec::new());
4306+
let sandbox_id = sandbox.object_id().to_string();
4307+
state.store.put_message(&sandbox).await.unwrap();
4308+
let principal = Principal::Sandbox(SandboxPrincipal {
4309+
sandbox_id: sandbox_id.clone(),
4310+
source: SandboxIdentitySource::BootstrapJwt {
4311+
issuer: "openshell-gateway:test".to_string(),
4312+
},
4313+
trust_domain: Some("openshell".to_string()),
4314+
});
4315+
4316+
let resolved = resolve_and_authorize_sandbox_name(
4317+
&state,
4318+
&principal,
4319+
&sandbox_id,
4320+
"",
4321+
MinWorkspaceRole::User,
4322+
)
4323+
.await
4324+
.unwrap();
4325+
4326+
assert_eq!(resolved.object_id(), sandbox_id);
4327+
}
4328+
42974329
fn test_workload_template(name: &str) -> SandboxWorkloadTemplate {
42984330
SandboxWorkloadTemplate {
42994331
metadata: Some(ObjectMeta {

‎crates/openshell-server/src/persistence/legacy_time_wire.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,13 @@ fn conversion(message: &str, field: u32) -> Option<Conversion> {
332332
Some(D { new_tag: 116 })
333333
}
334334
("openshell.sandbox.v1.MiddlewareBinding", 4) => Some(DS { new_tag: 104 }),
335-
("openshell.sandbox.v1.NetworkEndpoint", 4) => Some(E { tag: 4, kind: Tls }),
335+
("openshell.sandbox.v1.NetworkEndpoint", 4) => Some(E { tag: 27, kind: Tls }),
336336
("openshell.sandbox.v1.NetworkEndpoint", 5) => Some(E {
337-
tag: 5,
337+
tag: 28,
338338
kind: Enforcement,
339339
}),
340340
("openshell.sandbox.v1.NetworkEndpoint", 6) => Some(E {
341-
tag: 6,
341+
tag: 29,
342342
kind: Access,
343343
}),
344344
_ => None,

‎crates/openshell-server/src/storage_proto.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ mod tests {
125125
const PUBLIC_RPC_SCHEMA_SHA256: &str =
126126
"e9533b91b8ead17666c43b17ca5bca3bf84050346e4855e5e5a261cbb56a26bb";
127127
const DURABLE_SCHEMA_SHA256: &str =
128-
"9eeaa29dfba187bff69fb7bc4f9a13a0f1d7be3f7049a38c8f0e20ce77ec7d8b";
128+
"0430e14e8cc4ac5c41d7c6cdf41a5aafa7cb724b7d9026b593ddb9194ae58379";
129129
const PUBLIC_DURABLE_OVERLAP_SHA256: &str =
130130
"a6e97fdde30c439ffaa03c2952a43033f8ea338fed6b1456ebe2d7d8af14e834";
131131
// A persisted Sandbox without endpoint status retains its lifecycle fields;

‎crates/openshell-supervisor-network/src/policy_local.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,7 @@ fn network_rule_from_json(
11201120
})
11211121
}
11221122

1123+
#[allow(deprecated)]
11231124
fn network_endpoint_from_json(
11241125
endpoint: NetworkEndpointJson,
11251126
) -> std::result::Result<NetworkEndpoint, String> {
@@ -1192,6 +1193,9 @@ fn network_endpoint_from_json(
11921193

11931194
Ok(NetworkEndpoint {
11941195
host: endpoint.host,
1196+
legacy_tls: String::new(),
1197+
legacy_enforcement: String::new(),
1198+
legacy_access: String::new(),
11951199
port,
11961200
protocol: endpoint.protocol,
11971201
tls: openshell_policy::network_tls_mode_from_str(&endpoint.tls)

‎proto/sandbox.proto‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,11 @@ message NetworkEndpoint {
148148
// Endpoint protocol. "tcp" and "" select L4-only handling; "rest",
149149
// "websocket", "graphql", "sql", "json-rpc", and "mcp" select L7 inspection.
150150
string protocol = 3;
151-
// TLS handling. Unspecified enables automatic detection and termination.
152-
NetworkTlsMode tls = 4;
153-
// Enforcement mode. Unspecified preserves the audit default.
154-
NetworkEnforcementMode enforcement = 5;
155-
// Access preset shorthand. Unspecified means no preset.
156-
// Mutually exclusive with rules.
157-
NetworkAccessPreset access = 6;
151+
// Deprecated string representation retained for supervisors released before
152+
// endpoint security modes became typed enums.
153+
string legacy_tls = 4 [deprecated = true];
154+
string legacy_enforcement = 5 [deprecated = true];
155+
string legacy_access = 6 [deprecated = true];
158156
// Explicit L7 rules (mutually exclusive with access).
159157
repeated L7Rule rules = 7;
160158
// Allowed resolved IP addresses or CIDR ranges for this endpoint.
@@ -230,6 +228,13 @@ message NetworkEndpoint {
230228
// Internal gateway-derived marker indicating that this endpoint belongs to
231229
// an attached credentialed provider. User-authored values are ignored.
232230
bool provider_credentialed = 26;
231+
// TLS handling. Unspecified enables automatic detection and termination.
232+
NetworkTlsMode tls = 27;
233+
// Enforcement mode. Unspecified preserves the audit default.
234+
NetworkEnforcementMode enforcement = 28;
235+
// Access preset shorthand. Unspecified means no preset.
236+
// Mutually exclusive with rules.
237+
NetworkAccessPreset access = 29;
233238
}
234239

235240
// MCP options are grouped so MCP-specific policy can grow without adding more

0 commit comments

Comments
 (0)