Skip to content

test(e2e): cover inbound mTLS and the ambient/HBONE path in transparent inbound - #2404

Merged
huang195 merged 6 commits into
rossoctl:mainfrom
huang195:feat/transparent-inbound-mtls-e2e
Aug 20, 2026
Merged

huang195 merged 6 commits into
rossoctl:mainfrom
huang195:feat/transparent-inbound-mtls-e2e

Conversation

@huang195

@huang195 huang195 commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

What

Adds two modules to the transparent-inbound e2e suite, closing both open halves
of rossoctl/cortex#780
: test_transparent_inbound_mtls.py for inbound mTLS, and
test_transparent_inbound_ambient.py for the Istio ambient / HBONE delivery path.
Suite goes from 13 tests to 15, 0 skipped locally.

Why

#330 shipped the transparent inbound listener reusing the reverse proxy's mTLS
posture via WrapListener, and the sidecar logged mtls=true — but no TLS
client had ever been driven at :8083. The path was exercised only by its own
startup message.

The untested part is specifically the combination: SO_ORIGINAL_DST recovery
happens on the raw connection, before tlssniff peeks the first byte. Had
those two interfered, the logs would still have looked correct.

The three cases

# Case Expected What it proves
A strict + plaintext connection closed, http_code=000 tlssniff is genuinely in the transparent path — the same request is a 401 under permissive, so a closed connection can only come from the sniffer
B strict + TLS, no client cert TLS alert certificate required server-side TLS really terminates on the recovered connection (to demand a client cert it had to send its own first)
C strict + TLS, valid SVID http_code=401 the whole chain in one request: REDIRECT → SO_ORIGINAL_DST → tlssniff → tls.Server (client cert verified) → jwt-validation

C is the one that matters. It lands on 401 rather than 200 deliberately:
authentication of the transport must not be mistaken for authorization of the
request. B doubles as C's control — the same endpoint refuses a caller with
no certificate, so C cannot be explained by verification being lax.

Notes on approach

  • Borrows the agent sidecar's own SVID rather than minting a second SPIRE
    registration. Any identity in the trust domain satisfies
    RequireAndVerifyClientCert, and the assertion is that the handshake completes
    at all, not which identity completes it. Skips when SPIRE supplies no SVIDs.
  • --resolve so SNI/Host match the SVID's DNS SANs while still dialing the pod
    IP
    directly — via the Service the request would be indistinguishable from the
    Service-routed case this module is not testing.
  • conftest gains a _baseline registry. Fixtures now restore the namespace
    to what it looked like before the suite touched it, not to whatever they
    happened to observe. Without this, a second module flipping the same shared
    namespace makes restoration order-dependent.
  • Module-scoped, not session-scoped: it flips the same namespace the permissive
    fixture uses, so it must set up and tear down within its own module.

Verification

Run on kind rossoctl against operator + authbridge + proxy-init images built
from merged main (so the shipped code was under test):

13 passed in 89.56s   # 10 existing + 3 new, 0 skipped

Both namespaces confirmed restored afterwards (no inboundInterception/mtls
keys left behind, no leftover test objects).

The suite was inert in CI — root-caused and fixed

Worth stating plainly, because the green checkmark on the first two commits should
not be over-read: all 13 tests were skipping on the shared Kind e2e run,
including the 10 that merged in #2393. Signature was three 3-minute fixture stalls
(exactly READY_TIMEOUT), each followed by an instant batch of skips, because the
per-agent Keycloak client-credentials Secret was never created.

My first read of that was wrong. I called it the "intermittent Kind client
registration" that e2e-kind.yaml works around, and the earlier skip message
blamed a missing k8s.keycloak.org CRD. Neither is the cause. It is
deterministic, and the CRD is not in this code path at all — the controller uses
Keycloak's admin REST API directly.

The actual cause: 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. The fixtures' Deployment set no
serviceAccountName, so they hit this every single run. The platform's own
74-deploy-weather-agent.sh creates a dedicated SA for exactly this reason, which
is why weather-service works in CI and these agents did not.

Proven both directions on Kind: fixture shape → cannot resolve + zero Secrets +
pod Pending; add serviceAccountName → Secret appears in 20s with the exact
hash the webhook had already pre-populated
, pod Ready 10s later.

The third commit adds the SA to the manifest and rewrites the skip message and
README to point at the controller log, which prints the real reason verbatim.

This resolves the gating question — better than either option I floated
earlier. No stubbing, no waiting on a platform fix:

13 passed, 0 skipped, no TI_STUB_CREDENTIALS   # real controller-issued credentials

A latent platform inconsistency this surfaced (not a defect, not fixed here)

The AuthBridge webhook creates a per-agent ServiceAccount, sets it on the pod,
and pre-populates the annotation naming the credentials Secret — but never touches
the Deployment template the controller reads, so the webhook's fixup is
invisible to it.

That is latent rather than broken. Every path that creates a workload for real
already sets serviceAccountName — the backend's agent manifests
(agents_manifests.py:379,581,723,832), tools (tools.py:1330,1492),
simulation_manifests.py:253, agents_migration.py:487 (comment: "Ensure
serviceAccountName is set so the webhook's SPIFFE identity…"
), and the
7x-deploy-* scripts. Only a hand-written Deployment reaches the refusal, which
is why this fixture did and nothing else does. Nor is anything regressed: the
refusal has been present since the commit introducing that controller
(9637c03, 2026-03-26) and spire.enabled has defaulted true since 2025-11-06.

I initially filed this as operator#513 and generalized it to "any workload";
that was wrong and the issue is closed with a retraction.

One thing there does still seem worth fixing upstream, unrelated to the SA: those
failures surface only as logger.Info plus RequeueAfter: 30s forever — no Event,
no status condition — while the pod sits on FailedMount. That applies to every
reason client-ID resolution can fail, not just this one.

Second, minor: webhook-created SAs carry no ownerReference, so nothing
garbage-collects them. Eight had accumulated across team1/team2 during
development. Teardown now deletes ours.

The ambient / HBONE half

The suite could only ever exercise one of the two capture rules. Without a
ztunnel a pod-to-pod dial arrives as ordinary TCP and is caught in
nat PREROUTING by AB_INBOUND. Under ambient it never reaches PREROUTING:
ztunnel terminates HBONE on :15008 and re-originates a local connection, caught
instead by a mark-based DNAT at the head of AB_REDIRECT, ahead of that chain's
ztunnel-mark RETURN. Two paths, two rules, and the same 401 either way —
which is the hazard #780 names, since a PREROUTING-only implementation looks
correct while passing every mesh-delivered request through unvalidated.

So the new module asserts the delivery path as well as the status, read from
ztunnel's own access log. Without that it silently becomes a duplicate of
test_direct_pod_dial_is_validated the moment ambient stops being engaged.

That the DNAT counter previously read 0 was a config gate, not missing
infrastructure: charts/rossoctl-deps/templates/istio-operand.yaml wraps the
Istio, IstioCNI and ZTunnel operands in
{{- if and .Values.components.istio.enabled .Values.openshift }}, and
deployments/envs/dev_values*.yaml set openshift: false. Kind has no ambient
data plane by construction.

Verified

Ambient installed by hand on Kind (istiod 1.28.0 profile=ambient with
PILOT_ENABLE_AMBIENT=true, istio-cni, ztunnel), agent in team1, probe in
team2, both istio.io/dataplane-mode=ambient:

Request from team2 Result AB_INBOUND REDIRECT ambient DNAT :9091 RETURN
baseline — [2:120] [0:0] [1:60]
Service :8000 401 unchanged +1 —
direct pod dial :8000 401 unchanged +1 —
:9091/healthz 200 unchanged unchanged +1

The ambient DNAT carried every mesh-delivered request; AB_INBOUND never fired
for one. The exemption is confirmed positively — the dport-9091 rule's own
counter incremented — not by absence. The plain --mark 0x539 -j RETURN stayed
flat having taken 6 outbound HBONE packets earlier, live confirmation that
--dst-type LOCAL on the DNAT is load-bearing. Corroborated at three layers in
the same millisecond: ztunnel logged dst.hbone_addr=<podIP>:8000 with SPIFFE
identities both ends, and authbridge logged
plugin=jwt-validation status=401 reason="missing Authorization header".

Negative control, since a test that cannot fail proves nothing: deleting that
one DNAT rule from the live pod's netns makes the mesh-delivered request return
200 — the app answering unvalidated — and the module fails naming that cause,
while the health-port test keeps passing. Recreating the pod reprograms the rule
from proxy-init and both pass again.

Rule ordering and counters are not asserted in the test: not reachable from a test
pod, and unnecessary — every way the rule can regress (deleted, ordered after the
mark RETURN, matching too narrowly) ends in that same 200. The counter evidence
is recorded on #780.

One thing to flag

The ambient module is deliberately not kind_only, unlike the rest of this
suite. Ambient ships on OpenShift only, so a Kind-only ambient test could never
run where ambient is the shipped configuration; it self-gates instead on a ready
ztunnel (found by label across namespaces — the chart uses istio-ztunnel, a
community install defaults to istio-system) plus dataplane-mode=ambient on
both namespaces, naming whichever is missing.

Consequence: this becomes the first module in the suite to run on OpenShift,
so its first run there may surface pre-existing suite or platform issues rather
than ambient ones. Narrowing it to kind_only would make it skip everywhere the
feature actually ships, which is why it is not — but that is a call worth making
explicitly rather than by default.

Also worth noting the data plane used here is community Helm charts, not the
sail-operator operands the platform ships. The ztunnel namespace does not enter
the iptables tuple under test, but confirming on OpenShift is what the unmarked
test now does automatically.

Follow-up, not in this PR

The mTLS coverage lives in this repo while the code under test lives in cortex, so
a cortex regression would not fail cortex CI. The narrow gap there is a Go test
for the assembled NewInboundListener → WrapListener with mTLS on — the two
weaker cases here already duplicate existing tlssniff and origdst unit tests.

Assisted-By: Claude Code

@cwiklik cwiklik 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.

Summary

Strong extension of the transparent-inbound e2e suite covering the mTLS chain (SO_ORIGINAL_DST → tlssniff → tls.Server → jwt-validation) — the mTLS half of cortex#780. Approving; test-only, and the load-bearing assertions are precise.

Verified strict:

  • A (test_strict_rejects_plaintext) triangulates well — asserts code=200 not in, code=401 not in, and code=000 in, so a closed connection is distinguished from both a served response and a pipeline-reached 401. Proves tlssniff is genuinely in the path.
  • C (test_strict_completes_mtls_and_still_enforces) asserts exactly code=401 — the right call (transport auth ≠ request authz), not a loose "not 200".
  • No hardcoded credentials: the client SVID (cert/key/bundle) is fetched at runtime from the live sidecar and staged as a Secret. TLS verification is correctly enabled where C's claim depends on it (-k appears only in B, where skipping server-cert verification doesn't undermine what B tests). The new dedicated ServiceAccount is added to the manifest and torn down — and it actually reduces false skips by removing the default-SA refusal cause the prior suite hit.

Fast-follow (should-fix, not blocking a test-only PR):

  1. The new svid_secret fixture (conftest.py) cats /opt/svid*.pem with check=False and skips on empty output — but a kubectl-exec failure (renamed container, moved path, transient error) is indistinguishable from "SPIRE genuinely supplies no SVID." That gates test C, the one that matters, so an infra regression would silently green the security-critical case. Same skip-safety class as #2393 — please distinguish exec-failure (check the exit/stderr) from legitimate absence before skipping. A kind_only marker + the CI cluster having SPIRE is the only thing keeping C armed today; nothing in the test enforces it.

Minor:
2. Test B's assertion "certificate required" in out.lower() or "alert" in out.lower() accepts any TLS alert, which is looser than the "certificate required" behavior it claims (and than its role as C's control). Consider dropping the or "alert".
3. svid_secret writes the SVID private key to a tempfile that's never unlinked (only the in-cluster Secret is torn down). Unlink after --from-file — SVID keys are short-lived, but leaving key material on the runner is avoidable.

Author: huang195 (MEMBER — maintainer)
Areas reviewed: Python e2e tests, conftest fixtures, mTLS/SVID handling, skip-safety, secrets
CI: 22 green; Deploy & Test pending; E2E HyperShift gated on maintainer /run-e2e.

@huang195 huang195 changed the title test(e2e): cover inbound mTLS through the transparent listener test(e2e): cover inbound mTLS and the ambient/HBONE path in transparent inbound Aug 20, 2026
Closes the mTLS half of rossoctl/cortex#780. The transparent inbound listener
reuses the reverse proxy's mTLS posture via `WrapListener`, and rossoctl#330 shipped it
logging `mtls=true` — but no TLS client had ever been driven at :8083, so the
path was exercised only by its own startup message.

The untested part is specifically the combination: `SO_ORIGINAL_DST` recovery
happens on the raw connection, before `tlssniff` peeks the first byte. Had those
two interfered, the logs would still have looked correct.

Three cases, in increasing strength:

  A. strict + plaintext       -> connection closed, no HTTP at all
  B. strict + TLS, no cert    -> TLS alert demanding a client certificate
  C. strict + TLS, valid SVID -> handshake COMPLETES, then 401 from the pipeline

A is the cheap proof `tlssniff` is genuinely in the transparent path: the same
request is a 401 under permissive, so a closed connection can only come from the
sniffer. C is the one that matters — it traverses REDIRECT, destination recovery,
TLS termination, client-cert verification and jwt-validation in one request, and
lands on 401 rather than 200 because transport authentication is not request
authorization. B doubles as C's control, so C cannot be explained by lax
verification.

The probe borrows the agent sidecar's own SVID rather than minting a second SPIRE
registration: any identity in the trust domain satisfies
RequireAndVerifyClientCert, and the assertion is that the handshake completes at
all, not which identity completes it. It skips when SPIRE supplies no SVIDs.

conftest gains a `_baseline` registry so fixtures restore the namespace to what
it looked like before the suite touched it, rather than to whatever they happened
to observe. Without it, a second module flipping the same shared namespace makes
restoration order-dependent.

Verified on kind `rossoctl` against images built from merged main: 13/13 passing,
0 skipped, both namespaces restored with no leftover objects.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
…nert

The skip message and README asserted a single cause for the missing per-agent
Keycloak credentials Secret — the `k8s.keycloak.org` CRD being absent. That is
true on community-provider installs, but it is NOT what happens on the shared
Kind e2e run, so the message pointed future debuggers at the wrong thing.

The operator registers the client asynchronously, and there are two distinct
causes worth distinguishing: intermittent registration on Kind (e2e-kind.yaml
already carries a wait loop for these Secrets and marks the token-exchange suite
continue-on-error for exactly this), and the CRD being absent (in which case no
agent in the cluster ever gets a Secret). Both are now named, with the checks
that tell them apart.

Also records the consequence, which was not written down anywhere: this suite is
currently inert on the shared Kind e2e run — every test skips via the
intermittent-registration path, confirmed on the run for this PR. That has been
true since the suite merged, so a green CI is not evidence these tests ran. The
meaningful signal today is a local run with TI_STUB_CREDENTIALS=1. Making it gate
in CI means either fixing registration or setting TI_STUB_CREDENTIALS=1 in the
runner, and the latter reverses the opt-in reasoning the README already spells
out — so it is flagged as a deliberate call rather than changed here.

No behavior change: message text and docs only. Local suite still 13/13.

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]>
The README called the webhook/controller serviceAccountName split a platform
defect tracked separately. It is neither: every path that creates a workload
for real already sets serviceAccountName -- the backend's agent and tool
manifests and the 7x-deploy-* scripts -- so only a hand-written Deployment
like this fixture ever reaches the controller's refusal. Setting it here
matches those paths rather than working around a bug.

The issue this pointed at (operator#513) is closed with a retraction; the
claim generalized from a single caller.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
Review fast-follows on the inbound-mTLS suite. All three concern the same
thing: the evidence a passing run actually provides.

1. svid_secret could not tell "SPIRE supplied no SVID" from "kubectl exec
   failed" — both surfaced as empty stdout, because kubectl() drops the exit
   code and stderr. That fixture gates the completed-handshake test, the one
   security-critical case in the module, so a renamed container or a pod
   mid-restart would have silently skipped it and still reported green.
   Now: skip only on proven absence (cat's own "no such file"), raise on
   anything unexplained. Verified against real kubectl stderr — genuine
   absence skips; a renamed container and a missing binary both raise.

2. Test B accepted any TLS alert, which is looser than the missing-client-cert
   behavior it claims and than its role as C's control: a handshake_failure
   would have passed it for unrelated reasons. Narrowed to the two alerts Go
   sends when a caller presents no certificate (certificate_required on
   TLS 1.3, bad_certificate on 1.2).

3. The SVID private key went to a predictable tempfile that was never removed.
   Staged in a 0700 TemporaryDirectory instead, so it is cleaned up on the
   skip and raise paths too.

Adds kubectl_run() for the full CompletedProcess; kubectl() and kubectl_rc()
now share it rather than each calling subprocess.run.

Verified on kind-rossoctl: 13 passed, 0 skipped.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
The transparent-inbound suite could only ever exercise one of the two capture
rules. Without a ztunnel a pod-to-pod dial arrives as ordinary TCP and is caught
in `nat PREROUTING` by `AB_INBOUND`. Under ambient it never reaches PREROUTING:
ztunnel terminates HBONE on :15008 and re-originates a local connection, caught
instead by a mark-based DNAT at the head of `AB_REDIRECT`, ahead of that chain's
ztunnel-mark RETURN. Two paths, two rules, and the same 401 either way — which
is the hazard cortex#780 names, since a PREROUTING-only implementation looks
correct while passing every mesh-delivered request through unvalidated.

So the new module asserts the delivery path as well as the status, from
ztunnel's own access log. Without that it would silently become a duplicate of
test_direct_pod_dial_is_validated the moment ambient stopped being engaged.

Verified on Kind with an ambient data plane installed by hand (istiod 1.28
profile=ambient, istio-cni, ztunnel): a request from team2 to the agent in team1
arrives as terminated HBONE (dst.hbone_addr=<podIP>:8000, SPIFFE identities both
ends) and gets a 401 from jwt-validation, while the AB_INBOUND counter stays
flat and the ambient DNAT's increments. Deleting that one DNAT rule from the
live netns makes the same request return 200 — the app answering unvalidated —
and the module fails with that diagnosis; the health-port test keeps passing,
so the two assertions are independent. Counter-level evidence is on cortex#780.

Not marked kind_only, unlike the rest of the suite: the platform ships ambient
on OpenShift only (charts/rossoctl-deps/templates/istio-operand.yaml gates the
Istio/IstioCNI/ZTunnel operands on .Values.openshift), so a Kind-only ambient
test could never run where ambient is the shipped configuration. It self-gates
on a ready ztunnel found by label across namespaces plus dataplane-mode=ambient
on both namespaces, naming whichever is missing. That makes it the first module
here to run on OpenShift, so its first run there may surface pre-existing suite
or platform issues rather than ambient ones.

Suite is 15 passed / 0 skipped locally, up from 13.

Refs: rossoctl/cortex#780
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
@huang195
huang195 force-pushed the feat/transparent-inbound-mtls-e2e branch from 81eb9af to bb0739c Compare August 20, 2026 14:26
@huang195
huang195 merged commit 4c50dcd into rossoctl:main Aug 20, 2026
25 of 26 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Aug 20, 2026
@huang195
huang195 deleted the feat/transparent-inbound-mtls-e2e branch August 20, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants