Skip to content

Commit 0148b41

Browse files
committed
fix(network): order the CONNECT TLS-unavailable refusal after SSRF
Addresses the gator re-check on #2162. Ordering: the pre-200 fail-closed refusal ran before SSRF/allowed_ips validation, so during CA-init failure an internal-address CONNECT got a 503 tls_termination_unavailable instead of the normal 403 ssrf_denied, weakening operator visibility in degraded state. The SSRF branches now return validated addresses; the refusal runs after that validation (an internal address has already been denied with 403) but still before the upstream connect and before 200 Connection Established. effective_tls_skip is still resolved up front since the refusal consumes it. Tests: add connection-level regressions through the real handle_tcp_connection, driving a CONNECT from a child /bin/bash copy so the /proc process-identity binding resolves it against a permissive policy (the hot-swap test's identity pattern). They assert the first bytes are HTTP/1.1 503 for a terminating route with no TLS state, a 403 (not 503) for an internal address, and no refusal for a tls: skip route. These are gated to Linux at runtime (evaluate_opa_tcp needs /proc); a companion test verifies the OPA policy shape (glob allow, tls mode) on every platform so the precondition is locked where /proc is unavailable. rest.rs: tighten the fail-closed relay test to assert the forwarded buffer is_empty() rather than merely lacking the placeholder/secret. Signed-off-by: Tony Luo <[email protected]>
1 parent e736ee9 commit 0148b41

2 files changed

Lines changed: 330 additions & 67 deletions

File tree

‎crates/openshell-supervisor-network/src/l7/rest.rs‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4909,23 +4909,20 @@ mod tests {
49094909
"relay must fail closed when a placeholder cannot be resolved"
49104910
);
49114911

4912-
// Nothing must have reached upstream. Drop the proxy write half so the
4913-
// read observes EOF instead of blocking, then confirm neither the
4914-
// placeholder nor the secret leaked.
4912+
// The fail-closed scan rejects the request before any byte reaches
4913+
// upstream, so nothing at all must have been forwarded — a strictly
4914+
// stronger invariant than "the placeholder/secret did not appear". Drop
4915+
// the proxy write half so the read observes EOF instead of blocking.
49154916
drop(proxy_to_upstream);
49164917
let mut forwarded = Vec::new();
49174918
upstream_side
49184919
.read_to_end(&mut forwarded)
49194920
.await
49204921
.expect("upstream read should complete");
4921-
let forwarded = String::from_utf8_lossy(&forwarded);
49224922
assert!(
4923-
!forwarded.contains("openshell:resolve:env:"),
4924-
"placeholder must not leak to upstream: {forwarded}"
4925-
);
4926-
assert!(
4927-
!forwarded.contains("nvapi-secret"),
4928-
"secret must not leak to upstream: {forwarded}"
4923+
forwarded.is_empty(),
4924+
"no bytes may reach upstream when the placeholder cannot be resolved; got: {}",
4925+
String::from_utf8_lossy(&forwarded)
49294926
);
49304927
}
49314928

0 commit comments

Comments
 (0)