Repository navigation
test: Add transparent inbound interception E2E suite - #2393
Conversation
ba082fa to
0e10fce
Compare
Green on a real cluster: 10 passed, 0 skippedFirst live run surfaced three problems — two in this suite, one in the platform. Retargeted at pre-onboarded namespaces ( Fixed an assertion that could not pass even on correct behavior. Removed two silent skips. The chain and egress-guard tests exec'd
The A/B that matters
Attributed to the sidecar, not a waypoint: Also verified an undeclared port :80 returns 401, so multi-port coverage is real, and health/stats/session (9091/9093/9094) return 200/200/404 — not gated. Assisted-By: Claude Code |
|
All seven addressed ( #1 The suite gated nothing — the important oneConfirmed exactly. Added to the shared target list in That is only safe because the suite now self-gates. It runs against whatever images a cluster happens to have, and an operator predating transparent inbound silently ignores the namespace flip and port-steals instead — which would fail the transparent assertions for a reason unrelated to the code under test. Detected from the injected pod (the sidecar declares #2 Stub Secret — two bugs, both realIt leaked. Teardown restored the namespace config and deleted the workload but never the placeholder Secret, so a fake credential outlived the run in a shared namespace. Now recorded on creation and removed on teardown — verified: today's run cleaned its own, and the three left in And the stdout/stderr point is exactly right. #3
|
Gates the inbound half of rossoctl/cortex#330. The load-bearing test is test_direct_pod_dial_is_validated: the reason the feature exists is that JWT validation must not be sidestepped by another pod dialing the agent's real port, and nothing in the existing suite covers that. Deploys two agents in separate namespaces — transparent and the default reverse-proxy — because a single-shape run cannot distinguish "validation works" from "nothing reached the agent at all". The reverse-proxy namespace is a control that deliberately documents the bypass as it exists today; if it starts failing because the bypass is gone, the default changed and the test should be retired with it. The probe always runs from a separate pod. Dialing from inside the agent pod would traverse loopback, which shares the network namespace and is inside the trust boundary by construction — deliberately not intercepted, so it would prove nothing. Beyond the boundary property the suite covers: - Shape: the agent keeps its own port and gets no PORT env var; the sidecar declares transparent-in and does not claim the agent's port; proxy-init has both INBOUND_TRANSPARENT_PORT and POD_IP (the latter from the downward API, without which the Istio ambient inbound path is uncaptured); AB_INBOUND is live in the pod's nat table, not merely configured. - Neighbours: :9091 is not JWT-gated (it would fail kubelet probes and crash-loop the pod), :9094 stays reachable for abctl, and AB_REDIRECT is still present so inbound capture did not disturb the egress guard. Namespace-scoped because inboundInterception is resolved from the namespace authbridge-runtime-config ConfigMap — the pod mutator has no access to the AgentRuntime CR — so each mechanism needs its own namespace. Requires the operator and authbridge images built from the corresponding rossoctl/cortex branch; skipped on non-Linux nodes. Refs: rossoctl/cortex#330 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Running the suite on Kind surfaced three platform constraints that each made the run silently meaningless rather than failing loudly: - The injection webhook's namespaceSelector requires `rossoctl-enabled=true` on the namespace. Without it the pod came up with no sidecar at all, so every assertion would have been measuring an unprotected workload. - `rossoctl.io/type` cannot be applied by hand: the agent-label-protection ValidatingAdmissionPolicy rejects it and directs you to use an AgentRuntime CR. Injection is now driven through the CR, which is also how agents are really deployed. - Readiness is not a usable gate. The AgentRuntime controller labels the pod template only after the Deployment exists, so the first ready pod predates injection. The wait now requires the authbridge-proxy container to be present. Also swaps the agent and probe images for one already cached on Kind nodes (nginx-unprivileged:alpine, whose busybox wget doubles as the probe), so the suite needs no registry pull, and has the stand-in honor PORT — without that the reverse-proxy control cannot be exercised at all, since an agent that ignores PORT collides with AuthBridge on the stolen port and never starts. Documents the onboarding prerequisite found while debugging: the injected sidecar mounts a per-agent Keycloak client-credentials Secret, and where the operator's client-registration path is broken (e.g. the Keycloak CRD is absent, as on a cluster installed with the community provider) every injected pod stays Pending on FailedMount regardless of this feature. That is what blocked the live traffic assertions on the dev cluster used here. Refs: rossoctl/cortex#330 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
First live run surfaced three problems — two in the suite, one in the platform. Retargets pre-onboarded namespaces (team1/team2, overridable) instead of creating its own. A fresh namespace lacks the platform's per-namespace plumbing (authbridge-config, and the Keycloak client registration that produces each agent's credentials Secret), so an injected pod there never starts — for reasons unrelated to this feature. Each fixture flips inboundInterception in place and restores the original body on teardown, since these namespaces are shared and a leftover flip would silently change every other agent in them. Fixes an assertion that could not pass even on correct behavior: test_agent_keeps_its_own_port asserted PORT was absent, but the stand-in agent declares PORT itself — it must, or the reverse-proxy control cannot be exercised. Now asserts the operator did not REWRITE it, which is the actual discriminator (port stealing overwrites it with originalPort+1). Removes two silent skips. The chain and egress-guard tests exec'd iptables-save in the sidecar, whose image has no iptables, so they could only ever skip — quietly dropping both assertions from a green run. They now assert on proxy-init's own report, which is portable and meaningful because that container runs require_jump guards that abort on a rule that did not land. The egress test additionally checks that egress setup completed BEFORE inbound setup began, since the ambient DNAT is installed at the head of the egress chain. Adds TI_STUB_CREDENTIALS=1 for clusters where Keycloak client registration is broken. Opt-in on purpose: stubbing by default would let the suite go green on a broken cluster. Sound for these assertions (the Secret is for outbound token-exchange; inbound rejects a request with no Authorization header before any IdP contact) but explicitly not for a test needing a valid token. Without the flag the suite skips with that cause named, rather than failing and pointing suspicion at the interception rules. Result on Kind: 10 passed, 0 skipped. Refs: rossoctl/cortex#330 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
CI's `ruff format --check` (pinned 0.15.12) flagged both new files. Formatting only — no logic change; suite still 10 passed on Kind. Refs: rossoctl/cortex#330 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
The most important one: this suite gated nothing. Every other e2e suite in the repo is reachable from a runner (openshell/ and token_exchange/ each have one); transparent_inbound/ was referenced by no workflow or script, so it ran only when a human typed the command — which is not what a regression gate is for. Added to the shared target list in 90-run-e2e-tests.sh, so it now runs wherever that runner does (Kind and HyperShift e2e, release validation). That is only safe because the suite self-gates: it runs against whatever images a cluster happens to have, and an operator that predates transparent inbound silently ignores the namespace flip and port-steals instead, which would fail the transparent assertions for a reason unrelated to the code under test. Detected from the injected pod (the sidecar declares transparent-in only when the feature is present) and skipped with the cause named. It becomes a real gate as soon as a cluster's operator and authbridge carry it. Two correctness fixes in the credential stub: - It leaked. Teardown restored the namespace config and deleted the workload but never the placeholder Secret, so a fake credential outlived the run in a shared namespace. Now recorded on creation and removed on teardown. - "already exists" was matched against stdout, but kubectl writes it to stderr, so the second poll onward always read as failure and re-attempted the create every 3s. Keyed on the exit code via a new kubectl_rc helper. _set_mechanism was not idempotent: it prepended the mechanism keys to the existing body, so with TI_KEEP=1 or after a killed run that skipped teardown, the next run produced duplicate top-level YAML keys. It now strips any it finds first. Removed _namespace_config, which was dead after the retarget to pre-onboarded namespaces — and which built exactly the synthetic config its sibling _set_mechanism's docstring argues against, so leaving it invited someone to use it. Three assertions that could pass while the thing they check is broken: - "9091" in logs matched the whole log, where that number appears in plenty of other contexts, so it never actually checked the exempt list. Now parses the "exempt sidecar ports=" field. - logs.index() raises ValueError when a marker is missing, so the ordering assertion's message could never print and the failure surfaced as an unrelated traceback. Uses find() with an explicit presence check. - The reverse-proxy control asserted status != 401, which would stay green if the bypass were closed with a 403 or the port stopped answering at all — the control would silently stop being a control. Now asserts 200. 10 passed on Kind after the changes, and the stub Secret is confirmed removed on teardown. Refs: rossoctl/cortex#330 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
3a828db to
c8bea74
Compare
cwiklik
left a comment
There was a problem hiding this comment.
Summary
Excellent, strict E2E suite for the transparent-inbound boundary (companion to operator#511 / cortex#776). The load-bearing test and its control are exactly right, and the design decisions in the body (two agents/two namespaces, probe from a separate pod not loopback, PORT-honoring stand-in) are all faithfully implemented. Approving — the tests are strong and this is test-only.
Verified strict:
test_direct_pod_dial_is_validated— dials the agent's realpodIP:portfrom a separate probe pod with no auth header and assertsstatus != 200andstatus in (401, 403)(specific codes, not a loose "not 5xx").test_reverse_proxy_control_bypass_is_reachable— a genuine contrasting control: asserts the relocated port!= AGENT_PORT(it really is port-stealing) andstatus == 200, with a comment on why a degrading control (!= 401) would be wrong.test_service_routed_request_is_validated—(401, 403). Fixtures clean up (restore shared-namespace config, delete stub Secret,--rmprobes), waits are deadline-bounded, and the only "secret" is an opt-in placeholder — good hygiene.
Main concern — gate robustness, not assertion quality (fast-follow): this suite is a security gate that can silently disarm itself on a cluster that is supposed to have the feature:
_require_platform_supportreads a missingtransparent-insidecar port as "platform predates the feature" and skips — but on a branch-built CI cluster that is a regression, and it would skip rather than fail. It can't distinguish feature-absent from feature-broken._wait_readyskips when the Keycloak-credentials Secret can't be created; if the CI cluster lacks working Keycloak registration, every injected pod stays Pending and the entire suite skips green — the boundary test never runs. Nothing in90-run-e2e-tests.shsetsTI_STUB_CREDENTIALS=1.
Neither can make the security test pass falsely — it becomes a named SKIP — but a SKIP reads as "not a failure," and nothing positively asserts the transparent path actually executed. The shell comment's "becomes a real gate as soon as they carry the feature" isn't enforced anywhere. Recommend a fast-follow: a CI flag (e.g. TI_REQUIRE_FEATURE=1) that converts these two skips into hard failures for branch-built images, and/or set TI_STUB_CREDENTIALS=1 in the runner if the CI cluster has no Keycloak CRD. (You reported 10 passed / 0 skipped on Kind, so the gate does execute in your env — this is about keeping it armed in shared CI over time.)
Minor:
test_health_port_not_gated/test_session_api_not_gatedassert onlynot in (401, 403), so a crash-looping 5xx passes — worth also asserting< 500._set_mechanism's empty-config skip can fire on a transientkubectlerror (check=False).- Stale module docstring says "scratch namespace," but the suite mutates the shared team1/team2 namespaces (contradicts the README and the teardown). Worth fixing so a reader doesn't think teardown nukes a scratch ns.
Author: huang195 (MEMBER — maintainer)
Areas reviewed: Python E2E tests, Shell (CI runner), test quality / skip-safety, fixtures & secrets
CI: 23 green; E2E HyperShift pending maintainer /run-e2e.
The suite was inert: all 13 tests skipped on every shared Kind e2e run, and had been since rossoctl#2393 merged. Root cause is not flakiness, as the earlier skip message claimed, but a deterministic and reproducible one. With SPIRE enabled, the operator's ClientRegistration controller derives the Keycloak client ID from the Deployment pod template's serviceAccountName and refuses on "default": "msg":"cannot resolve Keycloak client id yet" "reason":"SPIRE enabled: set spec.template.spec.serviceAccountName to a dedicated ServiceAccount (not default) on the workload for a stable SPIFFE client ID" It then requeues every 30s forever at Info level, so the per-agent credentials Secret is never created and the injected pod never leaves FailedMount. The fixtures' Deployment set no serviceAccountName, so they hit this every time; the platform's own agent deploy scripts create a dedicated SA for exactly this reason. Worth recording because it cost hours: the AuthBridge webhook DOES create a per-agent SA and set it on the pod, and pre-populates the annotation naming the Secret -- but it never touches the Deployment template the controller reads. So the two halves of one feature disagree, the pod is promised a Secret the controller has already declined to create, and nothing surfaces an error. That split is a platform defect, filed separately; setting the SA in the manifest is the half this suite controls. Verified on kind: 13 passed, 0 skipped, with NO TI_STUB_CREDENTIALS -- real controller-issued credentials, and the Secret hash matches the one the webhook had already pre-populated. Both shared namespaces restore clean. Also: - Teardown deletes the ServiceAccount. Nothing else does: the webhook creates per-agent SAs with no ownerReference, so they outlive the workload. Eight had leaked across team1/team2 during development. The credentials Secret needs no entry -- the controller owner-references it to the Deployment. - Rewrite the skip message and README. Both named causes that were wrong: "intermittent on Kind" and a missing k8s.keycloak.org CRD. The CRD is not in this path at all -- the controller uses Keycloak's admin REST API. They now point at the controller log, which prints the real reason verbatim. Signed-off-by: Hai Huang <[email protected]> Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
The suite was inert: all 13 tests skipped on every shared Kind e2e run, and had been since rossoctl#2393 merged. Root cause is not flakiness, as the earlier skip message claimed, but a deterministic and reproducible one. With SPIRE enabled, the operator's ClientRegistration controller derives the Keycloak client ID from the Deployment pod template's serviceAccountName and refuses on "default": "msg":"cannot resolve Keycloak client id yet" "reason":"SPIRE enabled: set spec.template.spec.serviceAccountName to a dedicated ServiceAccount (not default) on the workload for a stable SPIFFE client ID" It then requeues every 30s forever at Info level, so the per-agent credentials Secret is never created and the injected pod never leaves FailedMount. The fixtures' Deployment set no serviceAccountName, so they hit this every time; the platform's own agent deploy scripts create a dedicated SA for exactly this reason. Worth recording because it cost hours: the AuthBridge webhook DOES create a per-agent SA and set it on the pod, and pre-populates the annotation naming the Secret -- but it never touches the Deployment template the controller reads. So the two halves of one feature disagree, the pod is promised a Secret the controller has already declined to create, and nothing surfaces an error. That split is a platform defect, filed separately; setting the SA in the manifest is the half this suite controls. Verified on kind: 13 passed, 0 skipped, with NO TI_STUB_CREDENTIALS -- real controller-issued credentials, and the Secret hash matches the one the webhook had already pre-populated. Both shared namespaces restore clean. Also: - Teardown deletes the ServiceAccount. Nothing else does: the webhook creates per-agent SAs with no ownerReference, so they outlive the workload. Eight had leaked across team1/team2 during development. The credentials Secret needs no entry -- the controller owner-references it to the Deployment. - Rewrite the skip message and README. Both named causes that were wrong: "intermittent on Kind" and a missing k8s.keycloak.org CRD. The CRD is not in this path at all -- the controller uses Keycloak's admin REST API. They now point at the controller log, which prints the real reason verbatim. Signed-off-by: Hai Huang <[email protected]> Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Summary
E2E suite gating transparent inbound interception (rossoctl/cortex#330). Companions: rossoctl/cortex#776 (listener + iptables, merged), rossoctl/operator#511 (the switch).
The load-bearing test is
test_direct_pod_dial_is_validated. The reason the feature exists is that inbound JWT validation must not be sidestepped by another pod dialing the agent's real port, and nothing in the existing suite covers that.Design notes
Two agents, two namespaces. One
transparent, one defaultreverse-proxy. A single-shape run cannot distinguish "validation works" from "nothing reached the agent at all". The reverse-proxy namespace is a control that deliberately documents the bypass as it exists today — if it starts failing because the bypass is gone, the default changed and the test should be retired with it.The probe always runs from a separate pod. Dialing from inside the agent pod would traverse loopback, which shares the network namespace, is inside the trust boundary by construction, and is deliberately not intercepted — so it would prove nothing.
The stand-in agent honors
PORT. Without that the reverse-proxy control could not be exercised at all: an agent that ignoresPORTcollides with AuthBridge on the stolen port and never starts, which is itself one of the failure modes transparent interception removes.Coverage beyond the boundary property
PORTenv var; sidecar declarestransparent-inand does not claim the agent's port; proxy-init has bothINBOUND_TRANSPARENT_PORTandPOD_IP(from the downward API, without which the ambient inbound path is uncaptured);AB_INBOUNDis live in the pod's nat table, not merely configured.:9091is not JWT-gated (it would fail kubelet probes and crash-loop the pod),:9094stays reachable forabctl, andAB_REDIRECTis still present so inbound capture did not disturb the egress guard.Three platform constraints the fixtures satisfy
Each of these otherwise produces a silently meaningless run rather than a failure — found by running against a live cluster:
rossoctl-enabled=true, or the injection webhook'snamespaceSelectorskips it and the pod comes up with no sidecar at all.rossoctl.io/typecannot be applied by hand — theagent-label-protectionValidatingAdmissionPolicy rejects it. Injection is driven through an AgentRuntime CR, which is how agents are deployed for real.authbridge-proxycontainer.Images are ones already cached on Kind nodes (
nginx-unprivileged:alpine, whose busyboxwgetdoubles as the probe), so the suite needs no registry pull.Result: 10 passed, 0 skipped on Kind
The A/B that matters, verified live and attributed to the sidecar rather than to a waypoint (
Transparent inbound server listening addr=[::]:8083, thenjwt-validation … status=401 … reason="missing Authorization header"):reverse-proxy(default)reverse-proxy(default)transparentAlso confirmed: an undeclared port
:80returns 401 (multi-port coverage is real), and health/stats/session return 200/200/404 — not gated.Three things the first live run changed
Running this for real surfaced two bugs in the suite and one in the platform:
test_agent_keeps_its_own_portcould not pass even on correct behavior. It assertedPORTwas absent, but the stand-in agent declaresPORTitself — it must, or the reverse-proxy control cannot be exercised at all. Now asserts the operator did not rewrite it, which is the real discriminator.iptables-savein the sidecar, whose image has no iptables — quietly dropping both assertions from a green run. They now assert on proxy-init's own report, which is meaningful because that container runsrequire_jumpguards that abort on a rule that did not land.team1/team2, overridable). A fresh namespace lacks the per-namespace plumbing —authbridge-config, plus the Keycloak client registration that produces each agent's credentials Secret — so an injected pod there never starts, including default reverse-proxy ones. Fixtures flipinboundInterceptionin place and restore the original body on teardown, since these namespaces are shared.TI_STUB_CREDENTIALSOn clusters where Keycloak client registration is broken (no
k8s.keycloak.orgCRD, as on community-provider installs), every injected pod staysPendingonFailedMount. Without the flag the suite skips with that cause named, rather than failing and pointing suspicion at the interception rules.TI_STUB_CREDENTIALS=1creates a placeholder so the boundary can still be tested. Opt-in on purpose: stubbing by default would let this suite go green on a broken cluster. Sound for these assertions — the Secret is for outbound token-exchange, and inbound rejects a request with no Authorization header before any IdP contact — but explicitly not sound for any test needing a valid token.Not covered here
The ambient (HBONE) path. The cluster used runs only
istiod— no ztunnel — so there is no ambient data plane to exercise; counters confirm all traffic took plain PREROUTING. Adding an ambient case needs a cluster with ztunnel deployed.E2E HyperShiftispendingawaiting a maintainer/run-e2e.