Repository navigation
feat(auth): authenticate gateway-mediated application requests - #4963
TaylorMutch wants to merge 13 commits into
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
|
🌿 Preview your docs: https://nvidia-preview-pr-4963.docs.buildwithfern.com/openshell |
18b394a to
ce2a99e
Compare
2574b9a to
70e365e
Compare
ce2a99e to
de94456
Compare
30cf9ce to
6b2fe9c
Compare
de94456 to
3b08d4c
Compare
6b2fe9c to
dae4a9d
Compare
c35e581 to
caacd27
Compare
66220a7 to
3dc01d7
Compare
c37b455 to
dd566cd
Compare
b71991c to
ad8be4d
Compare
00061b6 to
acc3754
Compare
2bc4518 to
f79878c
Compare
35e2d05 to
c503a94
Compare
e5927f4 to
dfa898d
Compare
b7042a9 to
1e069a1
Compare
dfa898d to
c02b593
Compare
|
/ok to test c02b593 |
|
/ok to test 900920c |
|
/ok to test 240aa0f |
|
/ok to test 1f856fa |
Compatibility review (advisory)New or updated breaking changes; see the full report for all findings. 1. api-behavior — No explicit risk acceptance foundThe supervisor application listener previously forwarded
Review details
Advisory review; publication gates are unchanged. |
|
/ok to test adda68a |
|
/ok to test e0db629 |
Require configured gateway authentication for application HTTP requests and WebSocket upgrades, with or without the independent app listener. Add browser sessions, application credential separation, shared revocation, request authorization, documentation, and browser coverage. Closes #4722 Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
|
Design consideration (non-blocking): browser session storage Today a browser session stores the user's raw OIDC token in the credential driver, and every cookie request reads it back and replays it through the unchanged authenticator chain ( The costs:
Two common alternatives used by authenticating proxies:
Both need key distribution and rotation through |
pimlock
left a comment
There was a problem hiding this comment.
Thanks for this. The core flow held up well in a local test with a TLS gateway, a mock OIDC issuer, and mTLS at this head:
- Unauthenticated requests and WebSocket upgrades are refused before reaching the app.
- Login codes are single-use, including under 20 concurrent redeems.
- The session cookie is
Secure; HttpOnly; SameSite=Strict, and logout invalidates it. - Origin and Fetch Metadata checks block cross-site, missing-Origin, and sibling-service requests.
- The gateway token is never forwarded to the app.
- With the flag off, routing, headers, and cookies are unchanged.
The inline comments cover the four things I'd like addressed or tracked: shared revocation and login quotas, reserved cookie names, WebSockets outliving logout, and the browser test. Smaller points:
- Error mapping. Concurrent duplicate revokes return 503 (covered in the quota comment). Also in
service_session.rs:- Any store error on session creation becomes
resource_exhausted. - A failed compensating
delete_application_tokenreplaces the original error. - A
Conflicton logout'sput_ifreturns 503 without the cookie-clearing header, although the session is gone.
- Any store error on session creation becomes
- Opaque errors. 403, 429, and 503 all return the body "Application authentication failed", which hides causes such as "revocation limit reached". An unauthenticated browser navigation gets a bare 401 with no pointer to the login page.
service_auth_login_originsis TOML/Helm-only. Its sibling has CLI and env forms. An empty list is a valid bearer/mTLS-only setup, so a startup info line ("browser login disabled: service_auth_login_origins is empty") and a note that it's TOML-only would be enough.- The http to https switch. Enabling service auth switches loopback service URLs from
http://tohttps://(endpoint_scheme). That makes sense forSecurecookies; please mention it in the--enable-gateway-service-authhelp text and man page. - Helm discoverability. Neither
enable_gateway_service_authnorservice_auth_login_originsappears invalues.yamlor the chart README, unlikeenable_gateway_service_routing. - Stored tokens outlive sessions. Expired browser sessions keep the user's still-valid gateway token in the credential driver until the next login or revoke in that workspace, since
store_application_tokensets no expiry. A periodic sweep, or deleting the secret when the session expires, would cap that at the 10-minute session lifetime. - Tidy-ups:
Session.cookie_keyis redundant, since the record id is already that digest.1024appears five times as both the cap and the cleanup page size.- The
pubitems inside the privateauthmodule could bepub(crate). - The ECDSA twin-signature test makes
oidc::testsand three helperspub; a unit test oftoken_revocation_keywould cover the same property. ServiceRoutingConfig.auth_enabledandauth_login_originsdon't match the TOML names.
- Design question. Was a signed, host-bound session cookie plus the existing revocation list considered instead of per-session records and credential-driver secrets? It would remove the secret storage and the cleanup lifecycle, and some of the quota and error-handling issues come from the stored model. It would help to note the reasoning in RFC 0017.
| REVOKED, | ||
| &key, | ||
| &key, | ||
| REVOCATION_SCOPE, |
There was a problem hiding this comment.
One workspace user can block revocation (and login) for everyone.
All revocations share one gateway-wide scope (REVOCATION_SCOPE) capped at 1,024, and mTLS entries are stored with u64::MAX, so cleanup never removes them.
Reproduced on a local gateway at this head: one User-role OIDC user revoked 1,030 distinct tokens of their own in about 6 s (1,020 × 204, then 429). After that, a different user's DELETE /.openshell/service-auth/credential for their client certificate returned 429 and the certificate kept working. The list is persisted, so it was still full after a gateway restart. Revoked mTLS entries make the cap permanent once 1,024 certificates have been revoked.
Login has the same shape (create_if_workspace_count_below(SESSION, …, 1024) above, no rate limit): 2,000 login POSTs from one user returned 977 × 429, and a second user's login right after was refused. That clears about 2 minutes after the flood stops, but it can be repeated.
Suggestions:
- Scope revocations per workspace or per principal rather than one gateway-wide bucket.
- Expire mTLS entries at the certificate's
notAfterrather thanu64::MAX. - Rate-limit
/auth/servicesper subject before writing to the credential driver. - Treat a duplicate-key insert as success: 20 concurrent revokes of the same credential returned one 204 and 15–19 × 503. The revocation still applied; sequential repeats return 401.
| .to_str() | ||
| .ok() | ||
| .and_then(|v| v.split_once('=')) | ||
| .is_some_and(|(name, _)| !name.trim().starts_with("__Host-openshell-")) |
There was a problem hiding this comment.
The gateway and the direct app listener disagree on which cookie names are reserved.
This response filter drops every Set-Cookie whose name starts with __Host-openshell-, case-sensitively. The request filter (is_gateway_auth_cookie in service_routing.rs) drops the same prefix case-insensitively. The direct listener (app_listener.rs gateway_cookie_name) strips only the two exact names, case-insensitively, and authentication.mdx says names such as __Host-openshell-app are preserved.
Observed through the gateway with service auth on: the app's __Host-openshell-app=x was dropped in both directions, while __HOST-OPENSHELL-SERVICE-SESSION=evil reached the client. The security impact is low because the gateway reads its cookie by exact name, but the same app behaves differently depending on the path.
These names aren't released yet, so this is the cheap moment to decide: reserve exactly __Host-openshell-service-session and __Host-openshell-service-login (case-insensitive), or reserve the whole prefix. Either way, one shared helper for the gateway and the listener, with docs to match.
|
|
||
| let (parts, _) = response.into_parts(); | ||
| let (mut parts, _) = response.into_parts(); | ||
| if state.config.service_routing.auth_enabled { |
There was a problem hiding this comment.
An open WebSocket outlives logout, revocation, and session expiry.
Authorization runs once before the upgrade. The relay a few lines above (copy_bidirectional) has no deadline and never rechecks the session or the revocation list.
Reproduced locally: opened a WebSocket with a session cookie, called DELETE /.openshell/service-auth/session (204), and confirmed the cookie then got 401. The open socket kept echoing. New upgrades were rejected correctly.
The docs say WebSockets are not continuously reauthenticated, but they also describe the credential endpoint as providing "immediate application cutoff", and terminals and notebooks are the long-lived WebSocket apps where that matters most. A cheap fix is to bound the relay by min(session expiry, token exp). A fuller one is a periodic revocation recheck. If neither fits this PR, please state in the logout and revocation section that live upgrades are not terminated.
| } | ||
|
|
||
| #[tokio::test] | ||
| #[ignore = "requires OPENSHELL_BROWSER_E2E_CHROME and Node.js"] |
There was a problem hiding this comment.
This browser test isn't run anywhere.
No CI job or mise task selects it. It's the only check of the part unit tests can't cover: that the Strict session cookie is sent after a cross-site login, because the redeem step returns a page on the service origin and starts a fresh navigation (browser_complete).
The test is self-contained (in-process TLS gateway, mock issuer, Chrome mapping hostnames to loopback), and the GitHub-hosted ubuntu-24.04 runners already have Chrome and Node. So it looks cheap to run in a non-required job outside the CI container, with something like:
OPENSHELL_BROWSER_E2E_CHROME=$(which google-chrome) cargo test -p openshell-server gateway_service_auth_real_browser_cross_site_login -- --ignoredNo need to block this PR on it. Could you open a follow-up issue for it and link it here? If that isn't worth it, a line in the server README on how to run it locally would cover the gap.
Summary
Opt in to authentication and authorization for gateway-mediated application HTTP requests and WebSocket upgrades using
enable_gateway_service_auth = truein[openshell.gateway]. The default is false, preserving existing application routing. This setting is independent of the supervisor app listener and compute driver.Based on main at
cb3e701b5.Related Issue
Closes #4722. Part of RFC 0017.
Changes
Identify revoked application tokens by authenticated signed contents and strip reserved gateway auth cookies from direct-listener responses over HTTP/1.1, HTTP/2, and WebSocket upgrades.
Require exact HTTPS control-plane origins in
[openshell.gateway].service_auth_login_originsfor browser login. The empty default disables browser login while retaining bearer and mTLS application access.Atomically promote pending browser sessions without an extra capacity slot, and fence cleanup with resource-version claims.
Log service authentication as enabled/disabled only when gateway-mediated service routing is enabled.
Apply service authentication and mount
/auth/servicesonly while gateway service routing is enabled.enable_gateway_service_routing = falsedisables the gateway application path regardless ofenable_gateway_service_auth.Add
enable_gateway_service_auth(default false),--enable-gateway-service-auth true,OPENSHELL_ENABLE_GATEWAY_SERVICE_AUTH=true, and HelmgatewayConfig."openshell.gateway".enable_gateway_service_auth. Explicit false overrides are supported.Preserve existing forwarding, application-owned paths, headers, and cookies when service authentication is disabled.
Store browser application-session tokens through the credential issuer using an explicit session owner, preserving existing backend scopes, opaque handles, and expiration checks.
Resolve browser login origins through the gateway route index for both readable and hashed service hosts, preserving workspace authorization and the control-plane login boundary.
Apply gateway identity, workspace access, and forwarding role/scope authorization before upstream connection.
Add browser login with single-use bootstrap codes and bounded Secure/HttpOnly/SameSite=Strict host-only sessions.
Use configured credential storage for sessions and shared revocation across gateway replicas.
Separate gateway credentials from application bearer tokens/cookies, strip reserved credentials, and enforce origin/Fetch Metadata protections.
Configuration
[openshell.gateway]→enable_gateway_service_auth = true--enable-gateway-service-auth=trueOPENSHELL_ENABLE_GATEWAY_SERVICE_AUTH=truegatewayConfig."openshell.gateway".enable_gateway_service_auth: trueenable_gateway_service_authdefaults tofalse. Precedence is CLI > environment > TOML > default.404; do not mount/auth/servicesBrowser login additionally requires an explicit trusted origin list:
The default empty list disables browser login. Include exact public origins and nonstandard ports on every replica. Wildcards, credentials, paths, queries, and fragments are rejected. Bearer and mTLS application access do not require this setting. Helm uses
gatewayConfig."openshell.gateway".service_auth_login_origins.These flags are independent of
supervisor.app_listener.enabled. Direct app-listener access delegates authentication to the ingress provider/application.Release Notes
Gateway-mediated application authentication is opt-in through
[openshell.gateway].enable_gateway_service_auth(defaultfalse), independently of the app listener.Compatibility
With service authentication disabled, configuring mTLS, operator auth, or OIDC preserves existing loopback HTTP URLs. Enabling service authentication selects HTTPS when gateway TLS is configured. Direct supervisor ingress strips the two gateway service session/login cookies from requests and responses; other application cookies retain their behavior.
Testing
Current-head GitHub CI is pending. Earlier GKE feature-stack validation has not been repeated for this rebase.
Qualification limits
Live Kubernetes qualification covers dedicated/shared supervisors, graceful shared-owner replacement, gateway outage, and policy isolation. Hashed URL/public-port behavior is covered by unit tests. Whole-node failure, real network partitions, metric-driven HPA, sustained production load, external ingress/DNS automation, and published release artifacts remain unqualified. Installation-status presentation (#4670) remains separate work. The example Kubernetes HTTPRoute controller remains a separate compatibility POC.
Checklist
PR dependency order: #4963 → #4964.