Skip to content

Commit 9484db2

Browse files
committed
fix(auth): use valid default session token lifetime
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent ed64206 commit 9484db2

12 files changed

Lines changed: 16 additions & 41 deletions

File tree

‎architecture/gateway.md‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,7 @@ controllers and `agents.x-k8s.io/v1alpha1` ownerReferences from existing
246246
deployments. Supervisors renew gateway JWTs in memory before expiry only while
247247
the sandbox record still exists. Older tokens are not server-revoked; shared
248248
deployments bound replay exposure with short `gateway_jwt.ttl_secs` lifetimes.
249-
The config default is
250-
`gateway_jwt.ttl_secs = 0` for local single-player Docker, Podman, and VM
251-
gateways; those tokens carry `exp = 0` and do not expire. Kubernetes and other
252-
shared deployments should set a positive TTL.
249+
The value defaults to 3600 seconds and must be between 60 and 3600 seconds.
253250

254251
Gateway JWT signing-key rotation is currently an offline operator action. The
255252
runtime loads one active signing key and one matching public verification key

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -522,8 +522,7 @@ pub struct GatewayJwtConfig {
522522
/// `openshell`.
523523
#[serde(default = "default_gateway_id")]
524524
pub gateway_id: String,
525-
/// Token lifetime in seconds. A value of 0 disables expiration and is
526-
/// intended only for local single-player deployments.
525+
/// Token lifetime in seconds. Must be between 60 and 3600 seconds.
527526
#[serde(default = "default_sandbox_token_ttl_secs")]
528527
pub ttl_secs: u64,
529528
}
@@ -533,7 +532,7 @@ fn default_gateway_id() -> String {
533532
}
534533

535534
const fn default_sandbox_token_ttl_secs() -> u64 {
536-
0
535+
3600
537536
}
538537

539538
fn default_roles_claim() -> String {
@@ -914,15 +913,15 @@ mod tests {
914913
}
915914

916915
#[test]
917-
fn gateway_jwt_ttl_defaults_to_non_expiring() {
916+
fn gateway_jwt_ttl_defaults_to_one_hour() {
918917
let cfg: GatewayJwtConfig = serde_json::from_value(serde_json::json!({
919918
"signing_key_path": "/tmp/signing.pem",
920919
"public_key_path": "/tmp/public.pem",
921920
"kid_path": "/tmp/kid"
922921
}))
923922
.expect("gateway JWT config should deserialize with default ttl");
924923

925-
assert_eq!(cfg.ttl_secs, 0);
924+
assert_eq!(cfg.ttl_secs, 3600);
926925
}
927926

928927
#[test]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub fn complete_local_jwt_config() -> Result<Option<GatewayJwtConfig>> {
104104
public_key_path: paths.public_key,
105105
kid_path: paths.kid,
106106
gateway_id: "openshell".to_string(),
107-
ttl_secs: 0,
107+
ttl_secs: 3600,
108108
})),
109109
_ => Err(miette::miette!(
110110
"partial local sandbox JWT state in {}: expected jwt/signing.pem, jwt/public.pem, and jwt/kid",
@@ -237,6 +237,6 @@ mod tests {
237237
assert_eq!(config.public_key_path, tmp.path().join("jwt/public.pem"));
238238
assert_eq!(config.kid_path, tmp.path().join("jwt/kid"));
239239
assert_eq!(config.gateway_id, "openshell");
240-
assert_eq!(config.ttl_secs, 0);
240+
assert_eq!(config.ttl_secs, 3600);
241241
}
242242
}

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,17 +1406,6 @@ async fn build_compute_runtime(
14061406
let driver = resolve_configured_compute_driver(registry, selection.name(), driver_startup)?;
14071407
let telemetry_compute_driver = driver.telemetry_compute_driver(registry);
14081408
info!(driver = %driver.name(), "Using compute driver");
1409-
if config
1410-
.gateway_jwt
1411-
.as_ref()
1412-
.is_some_and(|jwt| jwt.ttl_secs == 0)
1413-
&& !driver.is_local_singleplayer(registry)
1414-
{
1415-
warn!(
1416-
"Gateway configured with non-expiring sandbox JWTs; set gateway_jwt.ttl_secs > 0 for shared deployments"
1417-
);
1418-
}
1419-
14201409
let runtime = match driver {
14211410
ConfiguredComputeDriver::Registered(registration) => {
14221411
let build_context = ComputeDriverBuildContext {
@@ -1502,15 +1491,6 @@ impl ConfiguredComputeDriver {
15021491
}
15031492
}
15041493

1505-
fn is_local_singleplayer(&self, registry: &ComputeDriverRegistry) -> bool {
1506-
match self {
1507-
Self::Registered(registration) => registration.is_local_singleplayer(),
1508-
Self::Remote { name } => registry
1509-
.get(name)
1510-
.is_some_and(ComputeDriverRegistration::is_local_singleplayer),
1511-
}
1512-
}
1513-
15141494
fn telemetry_compute_driver(&self, registry: &ComputeDriverRegistry) -> TelemetryComputeDriver {
15151495
match self {
15161496
Self::Registered(registration) => registration.telemetry_category,

‎docs/reference/gateway-config.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ Local Docker, Podman, and VM gateways can also set `[openshell.gateway.mtls_auth
211211

212212
`[openshell.gateway] policy_validation_failure_mode` controls what sandbox supervisors do when a complete candidate policy fails runtime validation. The default, `fail_closed`, deactivates the previous network policy, closes relays pinned to it, and denies new egress until a valid generation loads. `retain_last_valid` leaves the previous valid generation active. Both modes reject the candidate atomically; startup always fails closed when no previous valid generation exists. Gateway mutation paths that can preflight a known effective scope reject invalid candidates before persistence and leave the active policy unchanged regardless of this setting. Changing the value requires restarting the gateway so it can reload `gateway.toml` and distribute the new posture to sandbox supervisors.
213213

214-
`[openshell.gateway.gateway_jwt] ttl_secs` controls gateway-minted sandbox JWT lifetime. When omitted, it defaults to `0`: the token `exp` claim and `expires_at_ms` response field become `0`, and the sandbox JWT does not expire. Use that default only for local single-player Docker, Podman, or VM gateways. Kubernetes and other shared deployments should set a positive TTL; Helm renders `3600` seconds by default, and the gateway logs a warning when a Kubernetes gateway uses `0`.
214+
`[openshell.gateway.gateway_jwt] ttl_secs` controls gateway-minted sandbox JWT lifetime. It defaults to `3600` seconds and must be between `60` and `3600` seconds so sandbox sessions can rotate short-lived credentials safely.
215215

216216
`[openshell.gateway.auth] allow_unauthenticated_users = true` is an unsafe local-development and trusted-proxy escape hatch. It accepts user-facing CLI/API calls without OIDC or mTLS credentials while sandbox supervisors still authenticate with gateway-minted sandbox JWTs. Leave it false for shared and production gateways.
217217

‎e2e/configs/gateway/docker.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ signing_key_path = ".cache/openshell-e2e/gateway-jwt/signing.pem"
1818
public_key_path = ".cache/openshell-e2e/gateway-jwt/public.pem"
1919
kid_path = ".cache/openshell-e2e/gateway-jwt/kid"
2020
gateway_id = "openshell-e2e"
21-
ttl_secs = 0
21+
ttl_secs = 3600
2222

2323
[openshell.drivers.docker]
2424
default_image = "ghcr.io/nvidia/openshell-community/sandboxes/base:latest"

‎e2e/configs/gateway/podman.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ signing_key_path = ".cache/openshell-e2e/gateway-jwt/signing.pem"
1818
public_key_path = ".cache/openshell-e2e/gateway-jwt/public.pem"
1919
kid_path = ".cache/openshell-e2e/gateway-jwt/kid"
2020
gateway_id = "openshell-e2e"
21-
ttl_secs = 0
21+
ttl_secs = 3600
2222

2323
[openshell.drivers.podman]
2424
default_image = "ghcr.io/nvidia/openshell-community/sandboxes/base:latest"

‎e2e/rust/e2e-vm.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ kid_path = "${JWT_DIR}/kid"
277277
gateway_id = "${GATEWAY_NAME}"
278278
# Local VM e2e gateways exercise the single-player default: sandbox JWTs
279279
# identify the supervisor and do not expire.
280-
ttl_secs = 0
280+
ttl_secs = 3600
281281
282282
[openshell.drivers.vm]
283283
EOF

‎e2e/support/gateway-common.sh‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,8 @@ e2e_write_gateway_jwt_config() {
174174
printf 'public_key_path = %s\n' "$(e2e_toml_string "${jwt_dir}/public.pem")"
175175
printf 'kid_path = %s\n' "$(e2e_toml_string "${jwt_dir}/kid")"
176176
printf 'gateway_id = %s\n' "$(e2e_toml_string "${gateway_id}")"
177-
# Local Docker/Podman e2e gateways exercise the single-player default:
178-
# sandbox JWTs identify the supervisor and do not expire.
179-
printf 'ttl_secs = 0\n\n'
177+
# Session tokens use the maximum supported one-hour lifetime.
178+
printf 'ttl_secs = 3600\n\n'
180179
}
181180

182181
e2e_write_gateway_mtls_auth_config() {

‎examples/governance-interceptor/smoke.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ signing_key_path = "$JWT_DIR/signing.pem"
340340
public_key_path = "$JWT_DIR/public.pem"
341341
kid_path = "$JWT_DIR/kid"
342342
gateway_id = "$RUN_ID"
343-
ttl_secs = 0
343+
ttl_secs = 3600
344344
345345
[[openshell.gateway.interceptors]]
346346
name = "provider-governance"

0 commit comments

Comments
 (0)