Skip to content

Commit d37c126

Browse files
committed
feat(auth): authenticate gateway-mediated application requests
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>
1 parent 6903eaa commit d37c126

19 files changed

Lines changed: 2867 additions & 29 deletions

File tree

‎crates/openshell-credential-issuer/README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ This is the internal-refactoring increment of RFC phase 2, not remote readiness.
2424

2525
## Owners and compatibility
2626

27-
`SecretOwner` scopes each operation to a workspace and one of three kinds:
27+
`SecretOwner` scopes each operation to a workspace and one of four kinds:
2828

2929
- `Provider`: the existing provider UUID and name.
30+
- `ApplicationSession`: the gateway browser session storage identity (`service-session-<session ID>`), using the existing `gateway-service-session` driver scope.
3031
- `Sandbox`: the sandbox UUID for its SSH host identity.
3132
- `SupervisorInstance`: the sandbox UUID owning a launch-material assignment, not the shared supervisor route or host.
3233

‎crates/openshell-credential-issuer/src/owner.rs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ pub enum SecretOwnerKind<'a> {
2020
Sandbox {
2121
id: &'a str,
2222
},
23+
/// Gateway-owned browser application session storage identity.
24+
ApplicationSession {
25+
id: &'a str,
26+
},
2327
/// Launch material is owned by a sandbox assignment, not the host/route.
2428
SupervisorInstance {
2529
sandbox_id: &'a str,
@@ -54,9 +58,20 @@ impl<'a> SecretOwner<'a> {
5458
}
5559
}
5660

61+
/// `id` is the existing `service-session-<session ID>` storage identity.
62+
pub fn application_session(workspace: &'a str, id: &'a str) -> Self {
63+
Self {
64+
workspace,
65+
kind: SecretOwnerKind::ApplicationSession { id },
66+
}
67+
}
68+
5769
pub(crate) fn legacy_scope(self) -> LegacyScope<'a> {
5870
let (provider, id) = match self.kind {
5971
SecretOwnerKind::Provider { id, name } => (Cow::Borrowed(name), id),
72+
SecretOwnerKind::ApplicationSession { id } => {
73+
(Cow::Borrowed("gateway-service-session"), id)
74+
}
6075
SecretOwnerKind::Sandbox { id } => (Cow::Owned(format!("sandbox-ssh-{id}")), id),
6176
SecretOwnerKind::SupervisorInstance { sandbox_id } => (
6277
Cow::Owned(format!("sandbox-instance-{sandbox_id}")),
@@ -83,6 +98,11 @@ mod tests {
8398
"provider-name",
8499
"provider-id",
85100
),
101+
(
102+
SecretOwner::application_session("workspace-a", "service-session-session-id"),
103+
"gateway-service-session",
104+
"service-session-session-id",
105+
),
86106
(
87107
SecretOwner::sandbox("workspace-a", "sandbox-id"),
88108
"sandbox-ssh-sandbox-id",

‎crates/openshell-server/README.md‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,39 @@ must independently honor the advertised lease expiry.
340340
Reconnect and relist on stream termination; revisions are opaque
341341
equality tokens, not resumable cursors or an ordering across gateway replicas.
342342

343+
## Gateway application authentication
344+
345+
Gateway-mediated application HTTP requests and WebSocket upgrades authenticate
346+
through the gateway chain or verified TLS client identity before endpoint lookup,
347+
independently of app-listener enablement. User access requires TCP-forwarding
348+
role/scope policy (`sandbox:write` when enforced) and current workspace membership;
349+
operators retain their platform grant. Internal principals are rejected. Only
350+
explicit local-development unauthenticated access bypasses this gate.
351+
352+
`/auth/services` hosts browser login on the control-plane origin. The application
353+
origin receives a single-use bootstrap code bound to a browser login nonce, then
354+
a distinct host-only, Secure/HttpOnly session cookie. Shared metadata contains
355+
only credential-driver handles and hashes; the configured credential driver
356+
stores the access token. Login codes expire after two minutes, sessions after
357+
at most ten minutes or token expiry. Every request revalidates the token and
358+
workspace authorization. Session deletion, credential revocation, and redemption
359+
CAS use the shared database. Expired metadata cleanup and admission are bounded.
360+
The application path consumes standard gateway bearer headers, or authenticates
361+
through a separate `X-OpenShell-Authorization`, browser session, or mTLS identity
362+
while preserving application bearer passthrough and cookies. Gateway headers and
363+
reserved cookies never reach the workload, and workloads cannot set reserved
364+
browser auth cookies. Browser ambient credentials require origin checks for
365+
unsafe methods and WebSocket upgrades. Direct supervisor ingress delegates
366+
application authentication to its ingress provider.
367+
368+
The optional real-Chrome login test uses an isolated profile and local test
369+
credentials. Run it with `OPENSHELL_BROWSER_E2E_CHROME` pointing to Chrome:
370+
371+
```shell
372+
OPENSHELL_BROWSER_E2E_CHROME='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' \
373+
cargo test -p openshell-server --lib gateway_service_auth_real_browser_cross_site_login -- --ignored
374+
```
375+
343376
## Application URL publication
344377

345378
`supervisor.app_listener.public_url` is an optional HTTPS origin matching the

‎crates/openshell-server/src/auth/http.rs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ fn sanitize_callback_host(raw: &Option<String>) -> (String, String) {
9191
/// Create the auth router.
9292
pub fn router(state: Arc<ServerState>) -> Router {
9393
Router::new()
94+
.route(
95+
"/auth/services",
96+
get(service_browser_login).post(service_browser_login),
97+
)
9498
.route("/auth/connect", get(auth_connect))
9599
.route("/auth/oidc-config", get(oidc_config_handler))
96100
.route("/.well-known/jwks.json", get(gateway_jwks_handler))
@@ -101,6 +105,16 @@ pub fn router(state: Arc<ServerState>) -> Router {
101105
.with_state(state)
102106
}
103107

108+
async fn service_browser_login(
109+
State(state): State<Arc<ServerState>>,
110+
req: axum::extract::Request,
111+
) -> axum::response::Response {
112+
match super::service_session::control(&state, req).await {
113+
Ok(response) => response,
114+
Err(error) => super::service_session::error(&error),
115+
}
116+
}
117+
104118
/// Publish OIDC-shaped discovery metadata for extension services.
105119
///
106120
/// This lets an extension be configured with only the trusted gateway URL:

‎crates/openshell-server/src/auth/mod.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pub mod principal;
2525
pub mod sandbox_jwt;
2626
pub mod sandbox_methods;
2727
pub mod sandbox_session;
28+
pub mod service_access;
29+
pub mod service_session;
2830
pub mod supervisor_token;
2931
pub mod workspace_authz;
3032

‎crates/openshell-server/src/auth/oidc.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ impl Authenticator for OidcAuthenticator {
948948
}
949949

950950
#[cfg(test)]
951-
mod tests {
951+
pub mod tests {
952952
use super::*;
953953

954954
fn transport_test_config(issuer: impl Into<String>) -> OidcConfig {
@@ -1418,7 +1418,7 @@ mod tests {
14181418
}
14191419

14201420
/// Sign `claims` with the test key, tagging the header with `kid`.
1421-
fn mint_rs256(claims: &serde_json::Value, kid: &str) -> String {
1421+
pub fn mint_rs256(claims: &serde_json::Value, kid: &str) -> String {
14221422
crate::install_jsonwebtoken_crypto_provider();
14231423

14241424
let mut header = jsonwebtoken::Header::new(Algorithm::RS256);
@@ -1428,7 +1428,7 @@ mod tests {
14281428
openshell_crypto::jwt::encode(&header, claims, &key).expect("sign RS256 token")
14291429
}
14301430

1431-
fn claims_for(issuer: &str, audience: &str, exp: i64) -> serde_json::Value {
1431+
pub fn claims_for(issuer: &str, audience: &str, exp: i64) -> serde_json::Value {
14321432
serde_json::json!({
14331433
"sub": "user-42",
14341434
"preferred_username": "ada",
@@ -1442,7 +1442,7 @@ mod tests {
14421442

14431443
/// Serve an OIDC discovery document and a JWKS carrying the test key, then
14441444
/// build a cache against them the same way production does.
1445-
async fn cache_with_mock_issuer(server: &wiremock::MockServer) -> JwksCache {
1445+
pub async fn cache_with_mock_issuer(server: &wiremock::MockServer) -> JwksCache {
14461446
use wiremock::matchers::{method, path};
14471447
use wiremock::{Mock, ResponseTemplate};
14481448

0 commit comments

Comments
 (0)