Skip to content

Commit f79878c

Browse files
committed
fix(auth): preserve disabled service routing behavior
Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
1 parent 00446a4 commit f79878c

3 files changed

Lines changed: 53 additions & 8 deletions

File tree

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,6 @@ fn endpoint_scheme(config: &openshell_core::Config) -> &'static str {
184184
if config.tls.is_none()
185185
|| (config.bind_address.ip().is_loopback()
186186
&& config.service_routing.enable_loopback_service_http
187-
&& !config.mtls_auth.enabled
188-
&& !config.mtls_auth.operator_enabled
189-
&& config.oidc.is_none()
190187
&& !config.service_routing.auth_enabled)
191188
{
192189
"http"
@@ -2065,6 +2062,38 @@ mod tests {
20652062
);
20662063
}
20672064

2065+
#[test]
2066+
fn configured_gateway_auth_does_not_change_the_disabled_service_auth_scheme() {
2067+
for mode in ["mtls", "operator", "oidc"] {
2068+
let mut cfg = openshell_core::Config::new(Some(tls_config()))
2069+
.with_bind_address("127.0.0.1:8080".parse().unwrap())
2070+
.with_server_sans(["*.dev.openshell.localhost"]);
2071+
match mode {
2072+
"mtls" => cfg.mtls_auth.enabled = true,
2073+
"operator" => cfg.mtls_auth.operator_enabled = true,
2074+
"oidc" => {
2075+
cfg.oidc = Some(
2076+
serde_json::from_value(serde_json::json!({
2077+
"issuer": "https://issuer.example.com",
2078+
"audience": "openshell"
2079+
}))
2080+
.unwrap(),
2081+
);
2082+
}
2083+
_ => unreachable!(),
2084+
}
2085+
assert_eq!(
2086+
endpoint_url(&cfg, "default", "my-sandbox", "web").as_deref(),
2087+
Some("http://default--my-sandbox--web.dev.openshell.localhost:8080/")
2088+
);
2089+
cfg.service_routing.auth_enabled = true;
2090+
assert_eq!(
2091+
endpoint_url(&cfg, "default", "my-sandbox", "web").as_deref(),
2092+
Some("https://default--my-sandbox--web.dev.openshell.localhost:8080/")
2093+
);
2094+
}
2095+
}
2096+
20682097
#[test]
20692098
fn endpoint_url_omits_service_label_for_empty_service_name() {
20702099
let cfg = openshell_core::Config::new(Some(tls_config()))

‎crates/openshell-supervisor/src/app_listener.rs‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,10 @@ fn sanitize_headers(headers: &mut http::HeaderMap, passthrough: bool, websocket:
902902
&& !name.trim().eq_ignore_ascii_case("cf-authorization")
903903
&& !name
904904
.trim()
905-
.to_ascii_lowercase()
906-
.starts_with("__host-openshell-")
905+
.eq_ignore_ascii_case("__Host-openshell-service-session")
906+
&& !name
907+
.trim()
908+
.eq_ignore_ascii_case("__Host-openshell-service-login")
907909
})
908910
})
909911
.map(str::trim)
@@ -1749,7 +1751,7 @@ mod tests {
17491751
let mut headers = http::HeaderMap::new();
17501752
headers.insert(
17511753
header::COOKIE,
1752-
"app=session; CF_Authorization=secret; __Host-openshell-service-session=secret; __Host-openshell-service-login=secret".parse().unwrap(),
1754+
"app=session; __Host-openshell-app=retained; CF_Authorization=secret; __Host-openshell-service-session=secret; __Host-openshell-service-login=secret".parse().unwrap(),
17531755
);
17541756
headers.insert("x-forwarded-client-cert", "secret".parse().unwrap());
17551757
headers.insert(
@@ -1769,11 +1771,17 @@ mod tests {
17691771
passthrough[header::AUTHORIZATION],
17701772
"Bearer application-token"
17711773
);
1772-
assert_eq!(passthrough[header::COOKIE], "app=session");
1774+
assert_eq!(
1775+
passthrough[header::COOKIE],
1776+
"app=session; __Host-openshell-app=retained"
1777+
);
17731778
assert!(!passthrough.contains_key("x-openshell-authorization"));
17741779
assert!(sanitize_headers(&mut headers, false, false));
17751780
assert!(!headers.contains_key(header::AUTHORIZATION));
1776-
assert_eq!(headers[header::COOKIE], "app=session");
1781+
assert_eq!(
1782+
headers[header::COOKIE],
1783+
"app=session; __Host-openshell-app=retained"
1784+
);
17771785
assert!(!headers.contains_key("x-forwarded-client-cert"));
17781786
assert!(!headers.contains_key("x-openshell-authorization"));
17791787
assert!(!headers.contains_key("x-openshell-auth-source"));

‎docs/how-it-works/gateways/authentication.mdx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ is `false`, which preserves existing service routing and its header, cookie,
1818
and path handling. The supervisor app-listener setting does not enable
1919
this authentication gate.
2020

21+
With gateway TLS configured, enabling service authentication advertises HTTPS
22+
service URLs on loopback too. Clients must trust the gateway certificate. With
23+
the flag disabled, configured mTLS or OIDC does not change the existing
24+
loopback HTTP URL behavior.
25+
2126
When enabled, gateway-mediated HTTP requests and WebSocket upgrades authenticate with the
2227
configured gateway identity and require workspace user access. OIDC users need
2328
the configured user or admin role and, when scope enforcement is enabled,
@@ -118,6 +123,9 @@ it admits at most 1,024 outstanding application credential revocations.
118123

119124
Direct supervisor app-listener access delegates authentication to the ingress
120125
provider. Gateway browser sessions and credentials do not authorize that path.
126+
The listener strips the gateway's `__Host-openshell-service-session` and
127+
`__Host-openshell-service-login` cookies, while preserving other application
128+
cookies, including names such as `__Host-openshell-app`.
121129

122130
## Gateway Resolution
123131

0 commit comments

Comments
 (0)