Zero Labs
Industry News / AI

Building a Zero Trust Security Architecture (Part 5)

Source · Towards AI By TheProdSDE

From the publisher’s feed, collected in the ZeroLabs newsroom.

Identity, OPA, Vault, mTLS, encryption, and audit logging — combined into one reference design for production systems.Series: Part 1 · Part 2 · Part 3 · Part 4 · Part 5 — you are hereTL;DR — what this part actually deliversWhy authentication, authorization, secret management, encryption, audit, and network control are six different jobs — and why collapsing them into one system is the #1 architecture mistake.A full reference architecture (with diagrams) connecting an IdP, OPA, a service mesh, Vault/cloud secret managers, and a SIEM.A corrected, OPA-1.0-compatible Rego policy example.A current Istio mTLS + AuthorizationPolicy configuration.A maturity model and decision matrix so you know what to build next, not everything at once.A real incident-response runbook for a compromised service.Image created by GeminiIn Part 1, the focus was why secrets become a security problem. Part 2 explored Vault and dynamic credentials. Part 3 covered Azure Key Vault, AWS Secrets Manager, managed identities, and IAM roles. Part 4 explained why Kubernetes Secrets are not a full secret management platform.Now everything comes together.The goal isn’t to build the most complex system possible — most breaches don’t happen because a team was missing some exotic tool. They happen because basic separation of concerns broke down somewhere. The goal is a system where:Identity is verified.Authorization is enforced.Secrets are protected.Data is encrypted.Access is auditable.Compromise has a limited blast radius.The Layers Teams ConfuseA common mistake is treating security components as interchangeable. They are not.Each layer solves a different problem. Good architecture is largely the discipline of not collapsing these concerns into one overloaded system — the JWT that tries to carry every permission, the database password that doubles as every service’s identity, the “temporary” admin token nobody ever revoked.The Complete Reference ArchitectureImage: Reference architecture for modern applicationsEvery component has a specific responsibility. That separation is what makes the system understandable, auditable, and recoverable during an incident.A precision note on the Vault → Kafka edge: unlike databases, Kafka doesn’t have a first-party, built-in Vault dynamic-secrets engine in the same way Postgres or MySQL do. In production, that edge usually means one of: Vault PKI issuing short-lived mTLS certificates for Kafka’s TLS listeners, Vault generating short-lived SASL credentials through a custom or community secrets plugin, or a mesh handling the mTLS layer instead of Vault directly. Worth knowing before you draw this on a whiteboard and someone asks “wait, which Vault engine does that?”Step 1 — User AuthenticationUsers authenticate through an identity provider such as Keycloak, Okta, Auth0, or Microsoft Entra ID.Image: User Authentication Flow Source: Created by authorAt this point, identity is established. Nothing more.JWT validation is not authorizationA valid JWT proves who the user is. It does not prove what the user is allowed to do. That’s where policy evaluation enters the design.Step 2 — Authorization Through OPAOPA becomes the centralized authorization engine. Applications ask for decisions instead of hardcoding complex rules in scattered services.ArchitectureImage: Created by authorRequest flowImage: Request Flow Created by authorA realistic policy exampleA production policy should use more than a flat role string. It should consider action, resource, ownership, and environment.package authzimport rego.v1default allow := falseallow if { input.user.role == "analyst" input.action == "read" input.resource.owner_team == input.user.team input.resource.environment != "production"}Why import rego.v1 and if matter: OPA 1.0 (the default for every current OPA release) requires the ifkeyword in rule bodies and treats rego.v1 semantics as standard. Code written in the older style — bare allow { ... } blocks with no if — will fail opa check on a modern OPA install. If you're copy-pasting Rego from older blog posts or Stack Overflow answers, run opa fmt --rego-v1 on it before trusting it in CI.That’s more realistic than embedding all permissions directly into JWTs.Anti-pattern: JWT contains all permissionsPutting every permission in the token creates staleness and revocation problems — you can’t “un-issue” a JWT that’s already in someone’s hands. Prefer tokens for identity claims and OPA (or a comparable policy engine) for dynamic authorization decisions.Step 3 — Service AuthenticationUser authentication is not enough. Microservices also need strong identity.A common anti-pattern looks like this:Shared API keysShared service passwordsLong-lived tokens copied across servicesPrefer this model instead:Image: Created by authorService identity becomes the authentication mechanism.Kubernetes workload identity patternImage: Identity Flow Created by authorNo stored credentials required — but it’s worth being precise about which mechanism is doing the work, since “OIDC provider” gets used loosely:Vault’s Kubernetes auth method validates the pod’s projected service-account token directly against the cluster’s API/JWKS endpoint. No external OIDC provider is required for this path.Cloud-native federation (AWS IRSA, GCP Workload Identity Federation, Azure AD Workload Identity) is the path where the cluster’s OIDC issuer actually federates with a cloud IAM provider, letting a pod assume a cloud role without any static keys.Both achieve the same outcome — no long-lived secrets sitting in a pod — through different plumbing. Know which one you’re actually running.Step 4 — Secret Retrieval and Dynamic CredentialsAfter authentication, services retrieve secrets or dynamic credentials on demand.Image: Secret retrival Flow Created by authorNotice what’s missing: hardcoded passwords.Traditional vs. modern modelImage: Traditional Flow Created by authorImage: Modern Flow Created by authorEach application receives:Unique credentialsUnique identityShort lifetimeStep 5 — mTLS and Service MeshService-to-service authentication usually becomes operationally manageable through a service mesh. Mentioning “mTLS” as a concept isn’t enough; teams need an implementation path.A common production pattern uses Istio or Linkerd for mesh identity and transport security.Mesh architectureImage: Mesh Architecture Created by authorEach service proves identity cryptographically. The mesh automates certificate presentation, rotation, and peer verification.Istio exampleapiVersion: security.istio.io/v1kind: PeerAuthenticationmetadata: name: default namespace: prodspec: mtls: mode: STRICTapiVersion: security.istio.io/v1kind: AuthorizationPolicymetadata: name: service-b-allow-service-a namespace: prodspec: selector: matchLabels: app: service-b action: ALLOW rules: - from: - source: principals: ["cluster.local/ns/prod/sa/service-a"]Two small but real corrections here: security.istio.io/v1 is the current stable API group (v1beta1 is the older, legacy version still floating around in a lot of tutorials), and action: ALLOW is written explicitly. Istio defaults to ALLOW when the field is omitted, but spelling it out makes the policy's intent obvious in a code review six months from now — and obvious during an incident, when someone is reading this YAML at 2 a.m. trying to figure out what's allowed to talk to what.That’s how architecture becomes enforceable rather than aspirational.Vault PKI with cert-managerWhere mesh-native issuance isn’t enough, or a separate PKI is required, Vault PKI can integrate with cert-manager to issue internal certificates automatically.Step 6 — Encryption ArchitectureAnother common mistake is letting applications own long-lived encryption keys. That creates key sprawl and inconsistent key handling.Prefer a central cryptographic service.Image: central cryptographic service Flow Created by authorTransit flowImage: Transit Flow Created by authorDecryption:Image: Decryption Flow Created by authorKeys remain protected because they don’t live inside the application process as ordinary static assets.Step 7 — Network PoliciesZero Trust is incomplete if every pod can talk to every other pod by default. NetworkPolicy complements identity and secret management by reducing reachable paths.apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata: name: allow-service-a-to-db namespace: prodspec: podSelector: matchLabels: app: database policyTypes: - Ingress ingress: - from: - podSelector: matchLabels: app: service-a ports: - protocol: TCP port: 5432This doesn’t replace authorization, but it materially reduces lateral movement options.Step 8 — Audit ArchitectureSecurity without auditing is incomplete. Every meaningful decision should be traceable.Image: Audit Flow Created by authorQuestions the platform should answer quickly:Who accessed data?When?Which policy allowed it?Which secret or lease was used?Which workload identity made the call?SIEM integration goalsA mature design usually includes:Central log aggregationStructured event schemasRetention policiesAlerting on unusual secret accessCorrelation across API, Vault, and identity eventsExamples of useful detections:A sudden spike in secret readsAccess to secrets outside normal namespace or service patternsLease revocation followed by repeated failed usageCross-region secret access anomaliesIncident Response Runbook ExampleSuppose Service A is compromised.Traditional architecture often means:Shared credentialsPermanent accessWeak attributionModern architecture should support a runbook like this:Identify the workload identity, token accessor, or Vault lease tied to Service A.Revoke the affected Vault token or leases.Trigger dynamic credential rotation where needed.Query audit logs for every action performed by that identity.Tighten policy or disable the role.Redeploy the workload with corrected configuration.Review whether network policy and mesh policy limited the blast radius.This is where short-lived credentials and strong audit trails become operational advantages, not just design principles you put on a slide.Compliance MappingMany frameworks map naturally onto the controls discussed in this series.Relevant frameworks often include:SOC 2ISO 27001PCI DSSHIPAANIST Cybersecurity FrameworkCompliance doesn’t create security by itself, but a strong architecture usually makes compliance work easier — auditors like systems that can already answer “who accessed what, and why.”Security Maturity ModelMost organizations move through stages.Level 0Passwords in source code.Level 1Environment variables and manually managed credentials.Level 2Kubernetes Secrets and basic secret segregation.Level 3Secret manager plus scheduled rotation.Level 4Identity-based access, dynamic credentials, workload identity.Level 5Zero Trust, policy as code, continuous verification, strong audit analytics, mesh identity, and reduced lateral movement.This model helps teams choose the next practical step instead of trying to jump directly to the end state — which, in practice, mostly just produces a half-finished Vault deployment and a very tired platform team.Decision MatrixSmall startupGrowing SaaS platformRecommended pattern:OIDCOPACloud secret managerNamespace-scoped RBACNetwork policiesBenefits:Centralized authorizationBetter governanceBetter traceabilityLarge enterpriseRecommended pattern:OIDCOPAVault or an equivalent advanced secret platformPKImTLSDynamic credentialsSIEM integrationFormal runbooks and access review processesBenefits:Fine-grained authorizationStronger incident containmentBetter compliance postureBetter separation of dutiesCommon Anti-PatternsAnti-pattern 1JWT contains every permission.Problem: permissions become stale and hard to revoke.Anti-pattern 2Database password shared across services.Problem: no accountability and a large blast radius.Anti-pattern 3Secrets stored in Git.Problem: permanent exposure risk, even after deletion — history doesn’t forget, and neither do forks.Anti-pattern 4Long-lived cloud access keys.Problem: credential theft risk.Prefer:Managed IdentityIAM rolesWorkload identityAnti-pattern 5A single shared admin Vault token for multiple teams.Problem: broken accountability and dangerous privilege concentration.Frequently Asked QuestionsIs OPA the same thing as Kubernetes RBAC?No. Kubernetes RBAC controls access to the Kubernetes API itself (who can create a Deployment, read a Secret, etc.). OPA is a general-purpose policy engine that your applications call to make their own authorization decisions — it can evaluate Kubernetes admission requests too (via Gatekeeper), but its scope goes well beyond the cluster API.Does a service mesh replace a secret manager like Vault?No, they solve different problems. A mesh (Istio, Linkerd) handles service-to-service transport security and identity via mTLS. A secret manager (Vault, AWS Secrets Manager, Azure Key Vault) handles credential issuance, rotation, and storage for things like database passwords and API keys. Most mature architectures run both.Do I need Vault if I’m a small team?Usually not on day one. A cloud-native secret manager paired with an OIDC provider covers most early-stage needs with far less operational overhead. Vault tends to earn its complexity once you have multiple teams, multiple clouds, or compliance requirements that demand fine-grained, auditable access.Can a Kubernetes NetworkPolicy replace a service mesh?No. NetworkPolicy controls reachability at the IP/port level — which pods can even open a connection to which other pods. It doesn't provide encryption, cryptographic identity, or application-layer authorization. Use both: NetworkPolicy to shrink the attack surface, mTLS/mesh to verify identity on the connections that are allowed.What’s the single highest-leverage change a team stuck at Level 1 or 2 can make?Move from static, shared credentials to short-lived, identity-bound ones — even before introducing OPA or a mesh. Almost every other improvement in this series compounds on top of that one change.Final ThoughtsModern security architecture is no longer about protecting a single perimeter. It’s about continuously verifying identity, minimizing trust, and shrinking blast radius.The most important conceptual split is this:Authentication proves identity.Authorization determines permissions.Secret management protects machine identities.Encryption protects data.Auditing proves what happened.Network controls limit reachability.Organizations with the strongest security postures aren’t the ones with the most tools. They’re the ones with the clearest separation of responsibilities between identity, authorization, secrets, encryption, network boundaries, and observability.If you’ve followed this series from Part 1 to here, you now have a working mental model that most teams only build after a painful incident forces them to. If something in here matches — or doesn’t match — what you’re running in production, I’d genuinely like to hear about it in the comments. What level is your stack actually at?If this helped you think more clearly about secrets management, the best thing you can do is share it with someone building on the same problems.Follow TheProdSDE for more content on platform engineering, cloud architecture, and production systems:🔗 LinkedIn: linkedin.com/in/TheProdSDE🐦 X (Twitter): x.com/TheProdSDE▶️ YouTube: youtube.com/@TheProdSDE✍️ Medium: medium.com/@TheProdSDEEvery article, video, and thread in this space is aimed at one thing: helping engineers build production systems that don’t break quietly.If this series helped your team, share it with the engineers who still think base64 is encryption.@theProdSDEBuilding a Zero Trust Security Architecture (Part 5) was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.