Skip to content

feat(auth): authenticate gateway-mediated application requests - #4963

Open
TaylorMutch wants to merge 15 commits into
mainfrom
feat/4722-gateway-service-auth/TaylorMutch
Open

TaylorMutch wants to merge 15 commits into
mainfrom
feat/4722-gateway-service-auth/TaylorMutch

Conversation

@TaylorMutch

@TaylorMutch TaylorMutch commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Opt in to authentication and authorization for gateway-mediated application HTTP requests and WebSocket upgrades using enable_gateway_service_auth = true in [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

  • Isolate durable session and revocation quotas per authenticated principal, rate-limit login admission, and periodically retire expired credential material across replicas.

  • Use verified certificate expiry for mTLS revocations and enforce expiry/shared revocation on existing WebSocket relays (five-second rechecks with a two-second check timeout).

  • Reserve exactly the two documented service-auth cookie names through a shared gateway/supervisor predicate; preserve unrelated application cookies.

  • Return safe authentication error categories and browser sign-in guidance; log when browser login has no configured origins.

  • 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_origins for 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/services only while gateway service routing is enabled. enable_gateway_service_routing = false disables the gateway application path regardless of enable_gateway_service_auth.

  • Add enable_gateway_service_auth (default false), --enable-gateway-service-auth true, OPENSHELL_ENABLE_GATEWAY_SERVICE_AUTH=true, and Helm gatewayConfig."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

Configuration surface Enable gateway application authentication
Gateway TOML [openshell.gateway] → enable_gateway_service_auth = true
Gateway CLI --enable-gateway-service-auth=true
Environment OPENSHELL_ENABLE_GATEWAY_SERVICE_AUTH=true
Helm values gatewayConfig."openshell.gateway".enable_gateway_service_auth: true

enable_gateway_service_auth defaults to false. Precedence is CLI > environment > TOML > default.

[openshell.gateway]
enable_gateway_service_routing = true
enable_gateway_service_auth = true
Gateway routing Service auth Gateway application behavior
Enabled (default) Disabled (default) Existing forwarding without gateway application authentication
Enabled Enabled Require configured gateway authentication and workspace authorization
Disabled Either Return 404; do not mount /auth/services

Browser login additionally requires an explicit trusted origin list:

[openshell.gateway]
service_auth_login_origins = ["https://gateway.example.com"]

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 (default false), 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

  • Auth independently: 2,950 server tests, 17 focused auth tests, and 28 supervisor app-listener tests passed.
  • Combined stack: 2,968 server tests passed; 52 ignored.
  • Strict server/supervisor Clippy and the real-Chrome sign-in regression passed.
  • 179 Helm gateway-configuration checks and Markdown lint passed.
  • SDK: 57 library and 77 client tests; CLI lifecycle: 91 passed, two ignored.

Non-required browser CI wiring is tracked in #6116. Current-head GitHub CI is running.

Fresh local k3d validation passed with rebuilt gateway/supervisor/proxy images: four hashed routes across two workspaces, single/finite/all discovery, verified application TLS, unknown SNI rejection, and withdrawal/re-exposure. Gateway application routing was disabled.

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. The example Kubernetes HTTPRoute controller remains a separate compatibility POC.

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)
  • Relevant implementation, configuration, and API documentation updated

PR dependency order: #4963 → #4964.

@copy-pr-bot

copy-pr-bot Bot commented Oct 27, 2026

Copy link
Copy Markdown

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.

@github-actions

Copy link
Copy Markdown

@TaylorMutch
TaylorMutch added this pull request to stack #4965 October 27, 2026 05:46
@TaylorMutch
TaylorMutch removed this pull request from stack #4965 October 27, 2026 05:47
@TaylorMutch
TaylorMutch force-pushed the feat/4722-gateway-service-auth/TaylorMutch branch from 18b394a to ce2a99e Compare October 27, 2026 06:24
@TaylorMutch
TaylorMutch force-pushed the feat/4953-authoritative-app-urls/TaylorMutch branch from 2574b9a to 70e365e Compare October 27, 2026 06:24
@TaylorMutch
TaylorMutch force-pushed the feat/4722-gateway-service-auth/TaylorMutch branch from ce2a99e to de94456 Compare October 27, 2026 06:25
@TaylorMutch
TaylorMutch force-pushed the feat/4953-authoritative-app-urls/TaylorMutch branch 2 times, most recently from 30cf9ce to 6b2fe9c Compare October 27, 2026 06:46
@TaylorMutch
TaylorMutch force-pushed the feat/4722-gateway-service-auth/TaylorMutch branch from de94456 to 3b08d4c Compare October 27, 2026 06:46
@TaylorMutch
TaylorMutch force-pushed the feat/4953-authoritative-app-urls/TaylorMutch branch from 6b2fe9c to dae4a9d Compare October 27, 2026 21:06
@TaylorMutch
TaylorMutch force-pushed the feat/4722-gateway-service-auth/TaylorMutch branch 2 times, most recently from c35e581 to caacd27 Compare October 28, 2026 17:05
@TaylorMutch
TaylorMutch force-pushed the feat/4953-authoritative-app-urls/TaylorMutch branch 2 times, most recently from 66220a7 to 3dc01d7 Compare October 28, 2026 22:52
@TaylorMutch
TaylorMutch force-pushed the feat/4722-gateway-service-auth/TaylorMutch branch 3 times, most recently from c37b455 to dd566cd Compare October 30, 2026 17:57
@TaylorMutch
TaylorMutch force-pushed the feat/4953-authoritative-app-urls/TaylorMutch branch 2 times, most recently from b71991c to ad8be4d Compare October 30, 2026 18:13
@TaylorMutch
TaylorMutch force-pushed the feat/4722-gateway-service-auth/TaylorMutch branch 2 times, most recently from 00061b6 to acc3754 Compare October 30, 2026 21:11
@TaylorMutch
TaylorMutch force-pushed the feat/4722-gateway-service-auth/TaylorMutch branch from e5927f4 to dfa898d Compare November 18, 2026 05:50
@TaylorMutch
TaylorMutch force-pushed the feat/4953-authoritative-app-urls/TaylorMutch branch from b7042a9 to 1e069a1 Compare November 18, 2026 05:51
@TaylorMutch
TaylorMutch force-pushed the feat/4722-gateway-service-auth/TaylorMutch branch from dfa898d to c02b593 Compare November 18, 2026 20:14
@TaylorMutch

Copy link
Copy Markdown
Contributor Author

/ok to test c02b593

@TaylorMutch

Copy link
Copy Markdown
Contributor Author

/ok to test 900920c

@TaylorMutch

Copy link
Copy Markdown
Contributor Author

/ok to test 240aa0f

@TaylorMutch

Copy link
Copy Markdown
Contributor Author

/ok to test 1f856fa

@github-actions

Copy link
Copy Markdown

Compatibility review (advisory)

New or updated breaking changes; see the full report for all findings.

1. api-behavior — No explicit risk acceptance found

The supervisor application listener previously forwarded __Host-openshell-service-session and __Host-openshell-service-login cookies but now strips both unconditionally.

  • Impact: Existing direct-ingress applications using either previously unreserved cookie name lose session or login state even with enable_gateway_service_auth=false.
  • Action: Preserve existing direct-ingress cookie forwarding in v0.1.10, and introduce these reserved names only through explicit opt-in with cookie-renaming migration guidance.
  • PR: feat(auth): authenticate gateway-mediated application requests #4963
Review details
  • Execution: complete
  • Candidate: PR #4963 (818b4bd895b96dbdf2e47f6e6ff6199609c98697)
  • Baseline: f8d1af1111c4aca5207127d501a11362865759d6 (f8d1af1111c4aca5207127d501a11362865759d6)
  • Reviewed: rust-sdk, python-sdk, typescript-sdk, api-behavior, cli, configuration, policy, helm, state

Advisory review; publication gates are unchanged.

Branch check run

@TaylorMutch

Copy link
Copy Markdown
Contributor Author

/ok to test adda68a

@TaylorMutch

Copy link
Copy Markdown
Contributor Author

/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>
@pimlock

pimlock commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

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 (active_token → service_access::authorize). I see why: cookie requests get exactly the same OIDC validation, role/scope mapping, workspace check and token revocation as API calls, and there's no shared signing key to manage across replicas.

The costs:

  • a credential-driver write (Vault/K8s Secret/DB) per login and a read per application request
  • a gateway-valid bearer token at rest for up to 10 minutes
  • session records, retire_session/cleanup, and the 1,024-session per-workspace cap (which also makes the login flood possible)

Two common alternatives used by authenticating proxies:

Stored session (this PR) Signed claims cookie Encrypted token cookie
Reuses authenticator chain unchanged yes no (new principal-from-cookie path) yes
New shared key across replicas no yes yes
Storage write per login record + driver secret none none
Read per request record + driver secret revocation list only revocation list only
Raw token at rest credential driver none browser, encrypted
Logout delete record tombstone in revocation list tombstone in revocation list
  • Signed claims cookie: e.g. a signed payload with sub, roles, workspace, host, exp (≤10 min), a session id and the token's revocation key. Cloudflare Access's CF_Authorization (which the gateway already recognizes) and Google IAP work this way. Revocation stays short TTL + denylist, which this PR already has.
  • Encrypted token cookie: encrypt the OIDC token into the cookie instead of storing it (oauth2-proxy's default cookie store). It keeps the "replay through the authenticator chain" property and drops the credential-driver dependency and session cap; it adds key management, the ~4 KB cookie limit, and an encrypted gateway-valid token in the browser.

Both need key distribution and rotation through openshell-crypto, so stored sessions are a reasonable choice. Was this trade-off considered? If stored sessions stay, it would help to record the rationale in RFC 0017. It also seems worth storing a minimal principal rather than the raw token, unless the per-request re-validation of the token is a requirement.

@pimlock pimlock left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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_token replaces the original error.
    • A Conflict on logout's put_if returns 503 without the cookie-clearing header, although the session is gone.
  2. 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.
  3. service_auth_login_origins is 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.
  4. The http to https switch. Enabling service auth switches loopback service URLs from http:// to https:// (endpoint_scheme). That makes sense for Secure cookies; please mention it in the --enable-gateway-service-auth help text and man page.
  5. Helm discoverability. Neither enable_gateway_service_auth nor service_auth_login_origins appears in values.yaml or the chart README, unlike enable_gateway_service_routing.
  6. 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_token sets no expiry. A periodic sweep, or deleting the secret when the session expires, would cap that at the 10-minute session lifetime.
  7. Tidy-ups:
    • Session.cookie_key is redundant, since the record id is already that digest.
    • 1024 appears five times as both the cap and the cleanup page size.
    • The pub items inside the private auth module could be pub(crate).
    • The ECDSA twin-signature test makes oidc::tests and three helpers pub; a unit test of token_revocation_key would cover the same property.
    • ServiceRoutingConfig.auth_enabled and auth_login_origins don't match the TOML names.
  8. 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.

Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
@TaylorMutch

Copy link
Copy Markdown
Contributor Author

The fixes are published in c8abe31. In addition to the inline threads, this addresses the smaller points from the review:

  • Admission limits are distinguished from backend failures. Compensating cleanup preserves the original failure; concurrent logout remains idempotent and clears the cookie.
  • HTTP errors expose safe, stable categories, with browser sign-in guidance when login is configured.
  • Empty service_auth_login_origins logs that browser login is disabled. TOML/Helm configuration, the HTTPS URL change, flag help, and the man page are updated; both auth settings are documented in Helm.
  • A bounded background sweep retires expired sessions and associated credential secrets without requiring another login, including when service auth is later disabled.
  • Removed Session.cookie_key, named capacity/page-size constants, aligned internal config names, and narrowed visibility where useful while keeping the auth module private. Existing OIDC fixture helpers remain shared where other tests use them; a focused revocation-key invariance test covers the key property.

For the stored-session design discussion, RFC 0017 now records the tradeoff: storing the token in the configured credential backend lets session requests reuse current token validation, role/scope mapping, and workspace checks across replicas, at the cost of credential reads/writes and cleanup. Signed-claims cookies require a separate principal-reconstruction path; encrypted-token cookies require shared key distribution/rotation and token-size handling. Those remain separate design options.

The auth branch passed independent server/supervisor checks and the real-Chrome regression. The combined stack passed 2,968 server tests, strict Clippy, and a fresh local k3d discovery/proxy routing matrix. Non-required browser CI is tracked in #6116.

Signed-off-by: Taylor Mutch <taylormutch@gmail.com>

@pimlock pimlock left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the fixes in c8abe31 address everything from my review: per-principal quotas and login rate limiting, the shared reserved-cookie predicate, WebSocket expiry and revocation rechecks, the browser test task (CI tracked in #6116), and the smaller points. Approving.

Non-blocking follow-up idea for WebSocket revocation: each authenticated socket currently polls the store every 5s, so reads scale with open sockets. If that grows, each replica could keep one revocation set fed by a cursor over the append-only revocation list (with logout writing a session tombstone into it) and close matching local sockets. The same set could replace the per-request revocation lookup on the HTTP path. Peer notification on revoke could cut latency further if 5s turns out to be too slow.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:enterprise Authentication, multitenancy, gateway interceptors, FIPS, and enterprise requirements. topic:authnz Authentication, authorization, identity, sessions, credential protection, and policy integrity. topic:security Vulnerability management, security analysis/auditing, bypass detection, and abuse prevention.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(auth): authenticate gateway-routed sandbox service requests

3 participants