Skip to content

Commit cfe305e

Browse files
committed
feat(config): deliver gateway configuration over the supervisor session
Supervisors poll the gateway for configuration every 10 seconds. Add an opt-in push path: with config_delivery_mode = "push", the gateway delivers sandbox configuration and provider environments over the existing ConnectSupervisor session, and supervisors apply and acknowledge them. Poll stays the default, and older supervisors and gateways keep polling. The gateway builds a streamed bootstrap that the supervisor applies before starting the workload, then runs a per-session delivery task that coalesces publications, takes FIFO build permits sized from the database pool, retries failed components with backoff, and reconciles periodically. Both components build from one shared input load, and the bootstrap checks that they agree on provider revision, attachments, and effective policy. In HA, replicas notify the session owner, which rebuilds from shared state. Builds also get cheaper in poll mode: interceptor provider-profile sources are served from a snapshot refreshed every 10 seconds, and provider environment builds read refresh states once and load providers concurrently. The supervisor applies polled and streamed configuration through one runtime, now in its own module, and stops polling once a push session is applying configuration. New metrics cover builds, deliveries, apply results, bootstraps, and peer notifications. Part of #1731. Signed-off-by: Piotr Mlocek <pmlocek@nvidia.com>
1 parent d789ec6 commit cfe305e

60 files changed

Lines changed: 19457 additions & 4977 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/e2e-docker-test.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ on:
3333
required: false
3434
type: string
3535
default: >-
36-
[{"suite":"python","cmd":"mise run --no-deps --skip-deps e2e:python","apt_packages":"","python_proto":true,"mcp":false},{"suite":"oidc-python","cmd":"mise run --no-deps --skip-deps e2e:oidc-python:docker","apt_packages":"","python_proto":true,"mcp":false},{"suite":"oidc-pkce-docker","cmd":"mise run --no-deps --skip-deps e2e:oidc-pkce:docker","apt_packages":"openssh-client","python_proto":false,"mcp":false},{"suite":"rust-docker","cmd":"mise run --no-deps --skip-deps e2e:rust","apt_packages":"openssh-client","python_proto":false,"mcp":false},{"suite":"mcp","cmd":"mise run --no-deps --skip-deps e2e:mcp","apt_packages":"","python_proto":false,"mcp":true}]
36+
[{"suite":"python","cmd":"mise run --no-deps --skip-deps e2e:python","apt_packages":"","python_proto":true,"mcp":false},{"suite":"oidc-python","cmd":"mise run --no-deps --skip-deps e2e:oidc-python:docker","apt_packages":"","python_proto":true,"mcp":false},{"suite":"oidc-pkce-docker","cmd":"mise run --no-deps --skip-deps e2e:oidc-pkce:docker","apt_packages":"openssh-client","python_proto":false,"mcp":false},{"suite":"rust-docker","cmd":"mise run --no-deps --skip-deps e2e:rust","apt_packages":"openssh-client","python_proto":false,"mcp":false},{"suite":"rust-docker-push","cmd":"mise run --no-deps --skip-deps e2e:rust:push","apt_packages":"openssh-client","python_proto":false,"mcp":false},{"suite":"mcp","cmd":"mise run --no-deps --skip-deps e2e:mcp","apt_packages":"","python_proto":false,"mcp":true}]
3737
3838
permissions:
3939
actions: read

‎TESTING.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ Suites:
223223
the selected deployment.
224224
- Docker suite (`--features e2e-docker`) - includes Docker-only coverage such as Dockerfile image builds, Docker preflight checks, and managed Docker gateway start.
225225
- Docker GPU suite (`--features e2e-docker-gpu`) - Docker suite plus GPU sandbox smoke coverage.
226+
- Configuration push suite (`--features e2e-config-push`) - CLI conformance and the policy tests against a Docker gateway with `config_delivery_mode = "push"`. Run it with `mise run e2e:rust:push`.
226227
- VM suite (`--features e2e-vm`) - runs e2e tests on a VM.
227228
- Kubernetes credential-driver suite (`--features e2e-kubernetes-credential-drivers`) - targeted Kubernetes Secrets and Vault provider credential storage coverage.
228229

‎crates/openshell-cli/tests/ensure_providers_integration.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ impl TestOpenShell {
7979

8080
#[tonic::async_trait]
8181
impl OpenShell for TestOpenShell {
82+
async fn peer_notify_config_update(
83+
&self,
84+
_request: tonic::Request<openshell_core::proto::PeerNotifyConfigUpdateRequest>,
85+
) -> Result<Response<openshell_core::proto::PeerNotifyConfigUpdateResponse>, Status> {
86+
Err(Status::unimplemented("not used by this test server"))
87+
}
88+
8289
async fn peer_report_provider_readiness(
8390
&self,
8491
_request: tonic::Request<openshell_core::proto::ReportProviderReadinessRequest>,

‎crates/openshell-cli/tests/mtls_integration.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ struct TestOpenShell;
3232

3333
#[tonic::async_trait]
3434
impl OpenShell for TestOpenShell {
35+
async fn peer_notify_config_update(
36+
&self,
37+
_request: tonic::Request<openshell_core::proto::PeerNotifyConfigUpdateRequest>,
38+
) -> Result<Response<openshell_core::proto::PeerNotifyConfigUpdateResponse>, Status> {
39+
Err(Status::unimplemented("not used by this test server"))
40+
}
41+
3542
async fn peer_report_provider_readiness(
3643
&self,
3744
_request: tonic::Request<openshell_core::proto::ReportProviderReadinessRequest>,

‎crates/openshell-cli/tests/provider_commands_integration.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,13 @@ impl TestOpenShell {
232232

233233
#[tonic::async_trait]
234234
impl OpenShell for TestOpenShell {
235+
async fn peer_notify_config_update(
236+
&self,
237+
_request: tonic::Request<openshell_core::proto::PeerNotifyConfigUpdateRequest>,
238+
) -> Result<Response<openshell_core::proto::PeerNotifyConfigUpdateResponse>, Status> {
239+
Err(Status::unimplemented("not used by this test server"))
240+
}
241+
235242
async fn peer_report_provider_readiness(
236243
&self,
237244
_request: tonic::Request<openshell_core::proto::ReportProviderReadinessRequest>,

‎crates/openshell-cli/tests/sandbox_create_lifecycle_integration.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ struct TestOpenShell {
101101

102102
#[tonic::async_trait]
103103
impl OpenShell for TestOpenShell {
104+
async fn peer_notify_config_update(
105+
&self,
106+
_request: tonic::Request<openshell_core::proto::PeerNotifyConfigUpdateRequest>,
107+
) -> Result<Response<openshell_core::proto::PeerNotifyConfigUpdateResponse>, Status> {
108+
Err(Status::unimplemented("not used by this test server"))
109+
}
110+
104111
async fn peer_report_provider_readiness(
105112
&self,
106113
_request: tonic::Request<openshell_core::proto::ReportProviderReadinessRequest>,

‎crates/openshell-cli/tests/sandbox_exec_streaming_integration.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ mock_gateway! {
275275
peer_report_provider_readiness(proto::ReportProviderReadinessRequest) -> proto::ReportProviderReadinessResponse;
276276
peer_report_endpoint_status(proto::ReportEndpointStatusRequest) -> proto::ReportEndpointStatusResponse;
277277
peer_get_sandbox_provider_status(proto::GetSandboxProviderStatusRequest) -> proto::GetSandboxProviderStatusResponse;
278+
peer_notify_config_update(proto::PeerNotifyConfigUpdateRequest) -> proto::PeerNotifyConfigUpdateResponse;
278279
submit_policy_analysis(proto::SubmitPolicyAnalysisRequest) -> proto::SubmitPolicyAnalysisResponse;
279280
get_draft_policy(proto::GetDraftPolicyRequest) -> proto::GetDraftPolicyResponse;
280281
approve_draft_chunk(proto::ApproveDraftChunkRequest) -> proto::ApproveDraftChunkResponse;

‎crates/openshell-cli/tests/sandbox_name_fallback_integration.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ struct TestOpenShell {
4747

4848
#[tonic::async_trait]
4949
impl OpenShell for TestOpenShell {
50+
async fn peer_notify_config_update(
51+
&self,
52+
_request: tonic::Request<openshell_core::proto::PeerNotifyConfigUpdateRequest>,
53+
) -> Result<Response<openshell_core::proto::PeerNotifyConfigUpdateResponse>, Status> {
54+
Err(Status::unimplemented("not used by this test server"))
55+
}
56+
5057
async fn peer_report_provider_readiness(
5158
&self,
5259
_request: tonic::Request<openshell_core::proto::ReportProviderReadinessRequest>,

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

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,33 @@ pub const DEFAULT_DOCKER_NETWORK_NAME: &str = "openshell-docker";
4646
/// Default domain used for browser-facing sandbox service URLs.
4747
pub const DEFAULT_SERVICE_ROUTING_DOMAIN: &str = "openshell.localhost";
4848

49+
/// Gateway delivery path for supervisor configuration.
50+
///
51+
/// `Push` sends configuration over the supervisor session to supervisors that
52+
/// apply streamed configuration, which then stop polling. Other supervisors
53+
/// keep polling.
54+
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
55+
#[serde(rename_all = "snake_case")]
56+
pub enum ConfigDeliveryMode {
57+
#[default]
58+
Poll,
59+
Push,
60+
}
61+
62+
impl FromStr for ConfigDeliveryMode {
63+
type Err = String;
64+
65+
fn from_str(value: &str) -> Result<Self, Self::Err> {
66+
match value {
67+
"poll" => Ok(Self::Poll),
68+
"push" => Ok(Self::Push),
69+
_ => Err(format!(
70+
"invalid config delivery mode '{value}'; expected poll or push"
71+
)),
72+
}
73+
}
74+
}
75+
4976
/// Gateway posture when a sandbox rejects a candidate policy generation.
5077
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
5178
#[serde(rename_all = "snake_case")]
@@ -209,6 +236,9 @@ pub struct Config {
209236
/// Security posture for rejected sandbox policy generations.
210237
pub policy_validation_failure_mode: PolicyValidationFailureMode,
211238

239+
/// Whether supervisors poll for configuration or receive it over their session.
240+
pub config_delivery_mode: ConfigDeliveryMode,
241+
212242
/// TLS configuration. When `None`, the server listens on plaintext HTTP.
213243
pub tls: Option<TlsConfig>,
214244

@@ -883,6 +913,7 @@ impl Config {
883913
metrics_bind_address: None,
884914
log_level: default_log_level(),
885915
policy_validation_failure_mode: PolicyValidationFailureMode::default(),
916+
config_delivery_mode: ConfigDeliveryMode::default(),
886917
tls,
887918
oidc: None,
888919
auth: GatewayAuthConfig::default(),
@@ -1149,10 +1180,11 @@ const fn default_ssh_session_ttl_secs() -> u64 {
11491180
#[cfg(test)]
11501181
mod tests {
11511182
use super::{
1152-
AppArmorProfile, Config, DEFAULT_SERVICE_ROUTING_DOMAIN, GatewayInterceptorBindingPolicy,
1153-
GatewayInterceptorConfig, GatewayInterceptorFailurePolicy, GatewayJwtConfig,
1154-
GatewayProviderProfileSourceConfig, ImagePullPolicy, PolicyValidationFailureMode,
1155-
UpstreamProxyConfig, default_sandbox_pids_limit, normalize_compute_driver_name,
1183+
AppArmorProfile, Config, ConfigDeliveryMode, DEFAULT_SERVICE_ROUTING_DOMAIN,
1184+
GatewayInterceptorBindingPolicy, GatewayInterceptorConfig, GatewayInterceptorFailurePolicy,
1185+
GatewayJwtConfig, GatewayProviderProfileSourceConfig, ImagePullPolicy,
1186+
PolicyValidationFailureMode, UpstreamProxyConfig, default_sandbox_pids_limit,
1187+
normalize_compute_driver_name,
11561188
};
11571189
use std::net::SocketAddr;
11581190
use std::time::Duration;
@@ -1172,6 +1204,19 @@ mod tests {
11721204
assert!("keep_old".parse::<PolicyValidationFailureMode>().is_err());
11731205
}
11741206

1207+
#[test]
1208+
fn config_delivery_defaults_to_poll_and_rejects_unknown_modes() {
1209+
assert_eq!(
1210+
Config::new(None).config_delivery_mode,
1211+
ConfigDeliveryMode::Poll
1212+
);
1213+
assert_eq!(
1214+
"push".parse::<ConfigDeliveryMode>().unwrap(),
1215+
ConfigDeliveryMode::Push
1216+
);
1217+
assert!("enabled".parse::<ConfigDeliveryMode>().is_err());
1218+
}
1219+
11751220
#[test]
11761221
fn compute_driver_name_normalization_accepts_builtin_and_custom_names() {
11771222
assert_eq!(normalize_compute_driver_name(" VM ").unwrap(), "vm");

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

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,7 @@ pub struct SettingsPollResult {
13231323
pub version: u32,
13241324
pub policy_hash: String,
13251325
pub config_revision: u64,
1326+
pub settings_revision: u64,
13261327
pub policy_source: PolicySource,
13271328
/// Effective settings keyed by name.
13281329
pub settings: HashMap<String, crate::proto::EffectiveSetting>,
@@ -1349,6 +1350,7 @@ fn settings_poll_result(inner: crate::proto::GetSandboxConfigResponse) -> Settin
13491350
version: inner.version,
13501351
policy_hash: inner.policy_hash,
13511352
config_revision: inner.config_revision,
1353+
settings_revision: inner.settings_revision,
13521354
policy_source: PolicySource::try_from(inner.policy_source)
13531355
.unwrap_or(PolicySource::Unspecified),
13541356
settings: inner.settings,
@@ -1365,6 +1367,32 @@ fn settings_poll_result(inner: crate::proto::GetSandboxConfigResponse) -> Settin
13651367
}
13661368
}
13671369

1370+
/// Delivered snapshots go through the polling projection, so both paths
1371+
/// apply the same defaults and validation.
1372+
impl From<crate::proto::SandboxConfigSnapshot> for SettingsPollResult {
1373+
fn from(snapshot: crate::proto::SandboxConfigSnapshot) -> Self {
1374+
settings_poll_result(crate::proto::GetSandboxConfigResponse {
1375+
policy: snapshot.policy,
1376+
version: snapshot.version,
1377+
policy_hash: snapshot.policy_hash,
1378+
settings: snapshot.settings,
1379+
config_revision: snapshot.config_revision,
1380+
policy_source: snapshot.policy_source,
1381+
global_policy_version: snapshot.global_policy_version,
1382+
provider_env_revision: snapshot.provider_env_revision,
1383+
supervisor_middleware_services: snapshot.supervisor_middleware_services,
1384+
workspace: snapshot.workspace,
1385+
policy_validation_failure_mode: snapshot.policy_validation_failure_mode,
1386+
extension_authentication_enabled: snapshot.extension_authentication_enabled,
1387+
configuration_admitted: snapshot.configuration_admitted,
1388+
provider_attachment_epoch: snapshot.provider_attachment_epoch,
1389+
configuration_instance_id: snapshot.configuration_instance_id,
1390+
configuration_error: snapshot.configuration_error,
1391+
settings_revision: snapshot.settings_revision,
1392+
})
1393+
}
1394+
}
1395+
13681396
#[cfg(test)]
13691397
mod settings_poll_tests {
13701398
use super::{learned_workspace_selector, settings_poll_result};
@@ -1407,6 +1435,25 @@ mod settings_poll_tests {
14071435
assert!(!legacy.extension_authentication_enabled);
14081436
}
14091437

1438+
#[test]
1439+
fn delivered_sandbox_snapshot_uses_the_polling_projection() {
1440+
let result = super::SettingsPollResult::from(crate::proto::SandboxConfigSnapshot {
1441+
version: 7,
1442+
policy_hash: "hash-7".to_string(),
1443+
config_revision: 42,
1444+
provider_env_revision: 9,
1445+
workspace: "workspace-a".to_string(),
1446+
extension_authentication_enabled: true,
1447+
..Default::default()
1448+
});
1449+
assert_eq!(result.version, 7);
1450+
assert_eq!(result.policy_hash, "hash-7");
1451+
assert_eq!(result.config_revision, 42);
1452+
assert_eq!(result.provider_env_revision, 9);
1453+
assert_eq!(result.workspace, "workspace-a");
1454+
assert!(result.extension_authentication_enabled);
1455+
}
1456+
14101457
#[test]
14111458
fn workspace_selector_is_omitted_until_bootstrap_learns_the_workspace() {
14121459
assert!(learned_workspace_selector(None).is_none());
@@ -1438,6 +1485,130 @@ pub struct ProviderEnvironmentResult {
14381485
pub non_secret_environment_keys: Vec<String>,
14391486
}
14401487

1488+
/// Delivered snapshots go through the polling projection, so both paths
1489+
/// reject invalid expiration times and withhold on unknown readiness reasons.
1490+
impl TryFrom<crate::proto::ProviderEnvironmentSnapshot> for ProviderEnvironmentResult {
1491+
type Error = miette::Report;
1492+
1493+
fn try_from(snapshot: crate::proto::ProviderEnvironmentSnapshot) -> Result<Self> {
1494+
use crate::proto::ProviderEnvironmentValueClassification;
1495+
1496+
let mut response = GetSandboxProviderEnvironmentResponse {
1497+
provider_env_revision: snapshot.provider_env_revision,
1498+
dynamic_credentials: snapshot.dynamic_credentials,
1499+
provider_attachment_epoch: snapshot.provider_attachment_epoch,
1500+
policy_hash: snapshot.policy_hash,
1501+
readiness_reason: snapshot.readiness_reason,
1502+
files: snapshot.files,
1503+
..Default::default()
1504+
};
1505+
for value in snapshot.values {
1506+
if let Some(expiration_time) = value.expiration_time {
1507+
response
1508+
.credential_expiration_times
1509+
.insert(value.name.clone(), expiration_time);
1510+
}
1511+
match ProviderEnvironmentValueClassification::try_from(value.classification)
1512+
.unwrap_or_default()
1513+
{
1514+
ProviderEnvironmentValueClassification::NonSecret => {
1515+
response
1516+
.non_secret_environment_keys
1517+
.push(value.name.clone());
1518+
}
1519+
ProviderEnvironmentValueClassification::StaticCredential => {
1520+
if let Some(binding) = value.static_credential_binding {
1521+
response
1522+
.static_credential_bindings
1523+
.insert(value.name.clone(), binding);
1524+
}
1525+
}
1526+
ProviderEnvironmentValueClassification::Unspecified => {}
1527+
}
1528+
response.environment.insert(value.name, value.value);
1529+
}
1530+
provider_environment_result(response)
1531+
}
1532+
}
1533+
1534+
#[cfg(test)]
1535+
mod provider_snapshot_tests {
1536+
use super::ProviderEnvironmentResult;
1537+
use crate::proto::{
1538+
ProviderEnvironmentSnapshot, ProviderEnvironmentValue,
1539+
ProviderEnvironmentValueClassification, ProviderReadinessReason, StaticCredentialBinding,
1540+
};
1541+
1542+
#[test]
1543+
fn delivered_provider_snapshot_preserves_secret_classification_metadata() {
1544+
let result = ProviderEnvironmentResult::try_from(ProviderEnvironmentSnapshot {
1545+
provider_env_revision: 11,
1546+
values: vec![
1547+
ProviderEnvironmentValue {
1548+
name: "REGION".to_string(),
1549+
value: "west".to_string(),
1550+
classification: ProviderEnvironmentValueClassification::NonSecret.into(),
1551+
..Default::default()
1552+
},
1553+
ProviderEnvironmentValue {
1554+
name: "TOKEN".to_string(),
1555+
value: "redacted".to_string(),
1556+
classification: ProviderEnvironmentValueClassification::StaticCredential.into(),
1557+
static_credential_binding: Some(StaticCredentialBinding::default()),
1558+
expiration_time: Some(prost_types::Timestamp {
1559+
seconds: 1_900_000_000,
1560+
nanos: 123_000_000,
1561+
}),
1562+
},
1563+
],
1564+
..Default::default()
1565+
})
1566+
.expect("valid provider snapshot");
1567+
assert_eq!(result.provider_env_revision, 11);
1568+
assert_eq!(result.environment.len(), 2);
1569+
assert_eq!(result.non_secret_environment_keys, ["REGION"]);
1570+
assert!(result.static_credential_bindings.contains_key("TOKEN"));
1571+
assert_eq!(
1572+
result.credential_expires_at_ms.get("TOKEN"),
1573+
Some(&1_900_000_000_123)
1574+
);
1575+
assert_eq!(
1576+
result.readiness_reason,
1577+
ProviderReadinessReason::Unspecified
1578+
);
1579+
}
1580+
1581+
#[test]
1582+
fn delivered_provider_snapshot_withholds_unknown_readiness_reason() {
1583+
let result = ProviderEnvironmentResult::try_from(ProviderEnvironmentSnapshot {
1584+
readiness_reason: i32::MAX,
1585+
..Default::default()
1586+
})
1587+
.expect("valid provider snapshot");
1588+
assert_eq!(
1589+
result.readiness_reason,
1590+
ProviderReadinessReason::CredentialsWithheld
1591+
);
1592+
}
1593+
1594+
#[test]
1595+
fn delivered_provider_snapshot_rejects_invalid_credential_expiration() {
1596+
let result = ProviderEnvironmentResult::try_from(ProviderEnvironmentSnapshot {
1597+
values: vec![ProviderEnvironmentValue {
1598+
name: "TOKEN".to_string(),
1599+
value: "redacted".to_string(),
1600+
expiration_time: Some(prost_types::Timestamp {
1601+
seconds: 1_900_000_000,
1602+
nanos: -1,
1603+
}),
1604+
..Default::default()
1605+
}],
1606+
..Default::default()
1607+
});
1608+
assert!(result.is_err());
1609+
}
1610+
}
1611+
14411612
pub struct ProviderSubjectTokenExchangeResult {
14421613
pub access_token: String,
14431614
pub expires_in: i64,

0 commit comments

Comments
 (0)