Skip to content

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

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

TaylorMutch wants to merge 13 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

  • 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

  • Rebased authentication branch: 2,942 server tests passed; 52 ignored.
  • Combined auth/discovery-reader stack: 2,953 server tests passed; 52 ignored.
  • Combined stack: 317 supervisor tests and 77 Rust SDK client-mock tests passed.
  • Supervisor coverage includes reserved-cookie filtering through native gRPC and HTTP/2-to-HTTP/1.1 forwarding, preserving ordinary application cookies.
  • All 148 gateway Helm configuration tests passed.
  • Strict server/supervisor all-target Clippy, Rust formatting, and whitespace checks passed.
  • Range-diff confirms runtime patches are unchanged; the discovery schema inventory fingerprint was refreshed for main.

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

  • 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 2bc4518 to f79878c Compare November 16, 2026 21:48
@TaylorMutch
TaylorMutch force-pushed the feat/4953-authoritative-app-urls/TaylorMutch branch from 35e2d05 to c503a94 Compare November 16, 2026 21:48
@TaylorMutch
TaylorMutch force-pushed the feat/4722-gateway-service-auth/TaylorMutch branch 4 times, most recently 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.

REVOKED,
&key,
&key,
REVOCATION_SCOPE,

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.

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 notAfter rather than u64::MAX.
  • Rate-limit /auth/services per 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-"))

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.

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 {

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.

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"]

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.

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 -- --ignored

No 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.

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