Testing a meshed .NET service — you can't audit what you never tested
The Mesh Series · Article 47 · Part I
Ambient meshPolicy as codeKubernetes operatorsCompliance evidenceAuthorizationPolicy.NET & C#SPIFFE

The pull request is one line. Somebody tidied the payments AuthorizationPolicy and, in passing, changed a namespace in a principal string. Review approves it: it is YAML, it parses, the diff is small. Argo CD syncs it. Every dashboard stays green, because nothing is failing — the policy now matches a principal that does not exist, and the rule above it happens to keep the legitimate traffic flowing. What has changed is that a service that should be refused no longer is.
Nobody finds out for seven weeks. Then someone looks.
One idea: a control you have never tried to break is a hope with a YAML file
Forty-six articles have built controls: default-deny, STRICT mTLS, JWT gates, admission policy, an access log that names the caller. Every one of them is a claim about what the platform refuses. And the awkward property of a refusal is that it is invisible when it stops working. A broken allow rule pages someone within the minute. A broken deny rule is silent until an attacker, a pentester or an auditor tries the door.
Which is why the standard three-band test pyramid — unit, integration, end-to-end — is the wrong picture for a meshed service. It tests that the things you want to happen, happen. A meshed service in a regulated estate has four bands, and the one the templates leave out is the one an auditor cares about.
Unit — no cluster. The five JWT gates (Article 12). The read-versus-write decision in the degraded identity path (Article 46). The operator's three-state verdict (Article 44). Pure logic, thousands of tests, milliseconds each. If the degraded branch has never run in a test, it has never run.
Integration on k3s, via Testcontainers. K3sBuilder starts a single-node k3s inside a container from the xUnit process: a real API server, real CRDs, a real status subresource. This is the right tool for the ComplianceProfile operator's reconcile loop. It is not a mesh. There is no ztunnel, no waypoint, no Envoy, no admission controller you did not install yourself — and pretending otherwise is how teams end up with a green suite that never exercised a single policy.
Mesh integration on kind. A throwaway cluster in CI with Istio ambient and Kyverno installed from the same GitOps manifests you ship (Article 31). Here the forbidden call meets a real data plane and gets a real RBAC: access denied. It is slow. It is the only band in which the policy is actually executed by the thing that enforces it.
The evidence contract. The apex. After the forbidden call is refused, assert that the access-log line exists and says who was refused — the SPIFFE identity of the caller, the response code, the reason. A control that refuses the call and tells no one passes every config review and vanishes in an incident.

Why it matters: "tested" is a regulatory word
DORA has a chapter on this. Articles 24 and 25 of Regulation (EU) 2022/2554 require a digital operational resilience testing programme: risk-proportionate, scheduled, covering the ICT systems that support critical functions, with findings acted upon. Articles 6, 9 and 10 assume throughout that a control is maintained and effective, not merely configured. NIS2 Article 21(2)(e) asks for security in development and maintenance — keeping a shipped control true — and 21(2)(f) for policies and procedures to assess whether your measures are effective at all. A test with a report attached is the plainest reading of that sentence.
Then the one that bites. RTS 2024/1774 Article 12 asks you to detect when logging fails. A deny that produces no log line is not a quiet success; under that article the silence is itself the defect. The evidence-contract band is the only place that defect can be caught before an incident catches it for you.
Elsewhere the wording differs and the demand does not. SAMA grades maturity — a repeatable, tested process outranks a point-in-time pass. RBI wants assurance the board can see. CERT-In's six-hour clock assumes a detection path that has been exercised, because nobody debugs a log pipeline in the first hour of an incident.
Every earlier article in this series ended with something an auditor could read. This one ends with the thing that tells you the rest are still true on Thursday.
How it comes together: which test belongs where
The honest precision first, because the phrase "Testcontainers plus kind" gets used as though they were two hats on one tool. They are different tools for different bands.
Testcontainers' Kubernetes story is the K3s module. It gives the test process a disposable API server in seconds, which is exactly what an operator test needs: create a ComplianceProfile, wait, read status, assert Satisfied, Drifting or Unproven. Nothing about that test needs a data plane.
kind is where the mesh is. One cluster per pipeline run, created once, shared by the mesh tests, destroyed at the end. Install ambient, install Kyverno, apply the same overlay you ship, enrol the namespace, add the waypoint — because the L7 policy, the bit that reads the Entra token, is enforced there and not in ztunnel. Then run the tests from inside the mesh: a probe pod with its own service account and therefore its own SPIFFE identity, because a test that calls from outside the mesh is testing the gateway, not the policy.
Three negative tests carry most of the weight. A workload with a valid identity but no allow rule is refused. A request with no token is refused at the waypoint. A pod that violates admission policy — unsigned image, missing label — is never scheduled. Each has a matching positive test, or the whole suite can be made green by denying everything.
Then the contract. Tag the forbidden request with a unique header, wait for the access-log line carrying that tag, and assert its content. Give it a timeout measured in seconds and treat a timeout as a failure of the control, not of the test.
What the suite does not do: mock the mesh. A mocked Envoy tests your belief about Envoy, and your belief is exactly what is wrong when a policy has a typo. Mock the downstream services. Never mock the control under test.
Show the config: the cluster, the refusal, the record
The cluster the mesh tests run against — built from what you ship.

The refusal, exercised by the thing that enforces it.

The record: the refusal exists in the log and names who was refused.

Security · Audit · Integration
Security: the suite tests the negative space — the refused call, the rejected token, the pod that never schedules — because the half of a policy an attacker uses is the half a happy-path test never touches.
Audit: a passing evidence-contract run is itself an artefact: dated, tied to a commit, showing that the control refused and recorded on that build — DORA Art. 24–25 testing and RTS 2024/1774 Art. 12 logging-failure detection in one result.
Integration: the kind band is the only place Entra tokens, the waypoint, SPIFFE-keyed authorisation, Kyverno admission and the access-log pipeline run together, which is why it is slow and why it finds the gaps between them.
Alternatives, and when you'd pick them
Test only in staging. Real, but shared and never resettable, so each check is a one-off performed by a person. Keep staging for soak and scale. It is a complement to a per-merge gate, not a substitute.
Mock the mesh. Fast, and a trap, for the reason above. Use mocks for downstream dependencies only.
Manual curl and a runbook. Honest for a first readiness review — it finds real misconfiguration the first time. It is not repeatable, which is a low maturity grade, but it is how you discover which tests to automate.
Full Istio inside a Testcontainers k3s fixture. One tool, in-process, attractive. Worth it only while the mesh installs in under a minute; past that it is slower and flakier than one shared kind cluster. k3s through Testcontainers for the operator; kind for the mesh.
From simple to standard, and what's next
The simple version is a unit-test project and a staging environment somebody pokes before a release. The standard version is four bands: unit tests for the gates and the degraded branch, k3s-in-a-container for the operator, a kind cluster built from shipped manifests where the forbidden call is refused by a real data plane, and an evidence contract asserting that the refusal was recorded with the caller's identity. A fail-closed branch you never exercised is a comment with ambitions. A default-deny you never tried to break is a wish. An audit log line you never asserted is a promise. CI is where all three become facts.
That closes Part I and Season 2. The platform is built, proven, operated and tested against the rulebooks of 2026. Next, Season 3 opens with Article 48: what the reference architecture didn't plan for — the 2027 wall.
You can't audit what you never tested — and you can't prove what your test never checked for.
Next in the series: Art. 48, the 2027 wall (Season 3 opener). Earlier: Art. 46 (the degraded identity branch), Art. 43/44 (the operator), Art. 31 (a merged PR is the change record), Art. 24/26 (the access log is the evidence), Art. 21 (admission policy), Art. 16 (default-deny), Art. 12 (the five JWT gates).
Key skills & topics in this article
Ambient meshPolicy as codeKubernetes operatorsCompliance evidenceAuthorizationPolicy.NET & C#SPIFFE