DEV Community

Florient DOGBE
Florient DOGBE

Posted on

mTLS Without a Service Mesh: Encrypting Internal Traffic with cert-manager and SPIFFE

Istio, Linkerd and Cilium's mesh mode all solve mutual TLS, and they solve a lot of other things too: L7 routing, retries, circuit breaking, distributed tracing, authorization policies. If what you actually need is "service A must prove it is service A, and the bytes on the wire must be encrypted", a mesh is a large amount of control plane, sidecar (or eBPF) machinery, and upgrade risk for a small requirement.

There is a middle road that most teams overlook: issue a short-lived X.509 SVID to every workload, mount it into the pod, rotate it automatically, and let the application (or a thin TLS terminator you already run) do mutual TLS. No sidecar, no iptables redirection, no mesh upgrades. The building blocks are cert-manager, csi-driver-spiffe, trust-manager, and approver-policy.

This article walks through a production-shaped setup on OpenShift/Kubernetes, including the OpenShift-specific traps.

The problem: mutual authentication without a mesh tax

Internal service-to-service traffic in a cluster is frequently plaintext HTTP. The usual mitigations are weak:

  • Network policies give you reachability control, not identity. A compromised pod that is allowed to reach payments-api is indistinguishable from the legitimate caller.
  • Shared static certificates stored in a Secret are copied into etcd, mounted in many pods, live for a year, and are effectively impossible to revoke.
  • Bearer tokens require a token issuer, token validation logic, and leak on replay if TLS is absent.

What you want is a cryptographic, per-workload identity with a lifetime measured in hours, where the private key never leaves the node it was generated on, and where both sides of a connection authenticate each other.

SPIFFE formalizes that identity as a URI SAN:

spiffe://cluster.example.com/ns/payments/sa/payments-api
Enter fullscreen mode Exit fullscreen mode

The trust domain (cluster.example.com) is yours, the path encodes namespace and ServiceAccount. Authorization becomes a string comparison on a verified certificate field.

What you give up compared to a mesh

Be honest about the trade-off before you commit:

  • The application must speak TLS itself (or you front it with Envoy/NGINX/HAProxy that you already operate).
  • No transparent interception: legacy binaries that only speak plaintext stay plaintext.
  • No L7 telemetry, no retries/outlier detection, no request-level authorization policy.

What you get: no sidecars, no control plane in the data path, ~3 lightweight controllers, and certificates that are standard X.509 — usable from Go, Java, NGINX, Postgres, Kafka, anything.

Architecture in one paragraph

cert-manager runs a CA ClusterIssuer (backed by a private key in a Secret, or better, by Vault/AWS Private CA). csi-driver-spiffe runs as a DaemonSet and registers an ephemeral CSI driver. When a pod declares a csi volume with driver spiffe.csi.cert-manager.io, the node plugin generates a keypair inside the pod's tmpfs, derives the SPIFFE ID from the pod's ServiceAccount (validated via a TokenRequest), creates a CertificateRequest, and writes tls.crt, tls.key and ca.crt into the volume. approver-policy decides whether that request is allowed. trust-manager distributes the root CA bundle to every namespace as a ConfigMap, so clients can validate peers even if they do not mount an SVID.

Building the trust domain

cert-manager and the CA ClusterIssuer

Install cert-manager with the built-in approver disabled — approver-policy will take over.

helm repo add jetstack https://charts.jetstack.io
helm repo update

helm upgrade --install cert-manager jetstack/cert-manager \
  --namespace cert-manager --create-namespace \
  --version v1.16.2 \
  --set crds.enabled=true \
  --set "extraArgs={--controllers=*\,-certificaterequests-approver}"

helm upgrade --install cert-manager-approver-policy jetstack/cert-manager-approver-policy \
  --namespace cert-manager \
  --version v0.19.0 \
  --set app.approveSignerNames="{clusterissuers.cert-manager.io/*}"
Enter fullscreen mode Exit fullscreen mode

On OpenShift you can also install cert-manager through the Red Hat operator; in that case set the controller args in the CertManager CR instead.

Now the CA. For a lab, bootstrap a self-signed root. For production, keep the root offline and issue an intermediate per cluster — or point the ClusterIssuer at Vault's PKI engine so the private key never lands in etcd.

apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: selfsigned-bootstrap
spec:
  selfSigned: {}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: spiffe-root-ca
  namespace: cert-manager
spec:
  isCA: true
  commonName: spiffe-root-ca
  secretName: spiffe-root-ca
  duration: 43800h   # 5 years
  renewBefore: 8760h # 1 year
  privateKey:
    algorithm: ECDSA
    size: 256
    rotationPolicy: Always
  issuerRef:
    name: selfsigned-bootstrap
    kind: ClusterIssuer
    group: cert-manager.io
---
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: spiffe-ca
spec:
  ca:
    secretName: spiffe-root-ca
Enter fullscreen mode Exit fullscreen mode

A ClusterIssuer of kind ca reads its Secret from the cluster resource namespace (cert-manager by default). Nothing else in the cluster needs read access to that Secret.

Distributing the trust bundle with trust-manager

Clients need the root CA to validate servers. Copying a Secret into 40 namespaces by hand is how trust rotation fails. trust-manager does it declaratively.

helm upgrade --install trust-manager jetstack/trust-manager \
  --namespace cert-manager \
  --version v0.13.0 \
  --set app.trust.namespace=cert-manager
Enter fullscreen mode Exit fullscreen mode
apiVersion: trust.cert-manager.io/v1alpha1
kind: Bundle
metadata:
  name: spiffe-trust-bundle
spec:
  sources:
    - secret:
        name: spiffe-root-ca
        key: tls.crt
  target:
    configMap:
      key: root-certs.pem
    namespaceSelector:
      matchLabels:
        spiffe.io/trust-bundle: "true"
Enter fullscreen mode Exit fullscreen mode
oc label namespace payments orders spiffe.io/trust-bundle=true
oc get configmap spiffe-trust-bundle -n orders -o jsonpath='{.data.root-certs\.pem}' | head -2
Enter fullscreen mode Exit fullscreen mode

During a root rotation you temporarily list two sources in the same Bundle; every consumer trusts old and new simultaneously, and you remove the old one once all leaves are reissued.

Issuing per-workload SVIDs with csi-driver-spiffe

Install the driver

helm upgrade --install cert-manager-csi-driver-spiffe jetstack/cert-manager-csi-driver-spiffe \
  --namespace cert-manager \
  --version v0.8.2 \
  --set "app.logLevel=1" \
  --set "app.trustDomain=cluster.example.com" \
  --set "app.issuer.name=spiffe-ca" \
  --set "app.issuer.kind=ClusterIssuer" \
  --set "app.issuer.group=cert-manager.io" \
  --set "app.certificateRequestDuration=1h" \
  --set "app.driver.volumes[0].name=root-cas" \
  --set "app.driver.volumes[0].secret.secretName=spiffe-root-ca" \
  --set "app.driver.volumeMounts[0].name=root-cas" \
  --set "app.driver.volumeMounts[0].mountPath=/var/run/secrets/cert-manager-csi-driver-spiffe" \
  --set "app.driver.sourceCABundle=/var/run/secrets/cert-manager-csi-driver-spiffe/tls.crt"
Enter fullscreen mode Exit fullscreen mode

sourceCABundle is what makes the driver write ca.crt next to the leaf. The node plugin mounts the kubelet pods directory, so on OpenShift it needs the privileged SCC:

oc adm policy add-scc-to-user privileged \
  -z cert-manager-csi-driver-spiffe -n cert-manager
oc rollout status ds/cert-manager-csi-driver-spiffe -n cert-manager
Enter fullscreen mode Exit fullscreen mode

Gate issuance with approver-policy

The driver derives the SPIFFE ID from the pod's ServiceAccount, so a workload cannot ask for someone else's identity. approver-policy is defence in depth and the place where you enforce lifetime and key constraints.

apiVersion: policy.cert-manager.io/v1alpha1
kind: CertificateRequestPolicy
metadata:
  name: spiffe-workloads
spec:
  allowed:
    dnsNames: {}
    ipAddresses: {}
    emailAddresses: {}
    commonName: {}
    uris:
      values: ["spiffe://cluster.example.com/ns/{{ .Namespace }}/sa/*"]
  constraints:
    maxDuration: 1h
    privateKey:
      algorithm: ECDSA
      minSize: 256
      maxSize: 521
  selector:
    issuerRef:
      name: spiffe-ca
      kind: ClusterIssuer
      group: cert-manager.io
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: spiffe-workloads-policy-user
rules:
  - apiGroups: ["policy.cert-manager.io"]
    resources: ["certificaterequestpolicies"]
    verbs: ["use"]
    resourceNames: ["spiffe-workloads"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: spiffe-workloads-policy-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: spiffe-workloads-policy-user
subjects:
  - kind: ServiceAccount
    name: cert-manager-csi-driver-spiffe
    namespace: cert-manager
Enter fullscreen mode Exit fullscreen mode

Anything not matched by a policy the requester is allowed to use is denied, and the denial is visible on the CertificateRequest status — make sure you alert on it.

OpenShift: allow inline CSI volumes

restricted-v2 does not list csi in its allowed volume types, so an inline CSI ephemeral volume is rejected by the SCC admission plugin. Create a minimal derivative instead of granting privileged to application workloads:

apiVersion: security.openshift.io/v1
kind: SecurityContextConstraints
metadata:
  name: restricted-v2-csi
allowHostDirVolumePlugin: false
allowHostIPC: false
allowHostNetwork: false
allowHostPID: false
allowHostPorts: false
allowPrivilegeEscalation: false
allowPrivilegedContainer: false
defaultAddCapabilities: null
fsGroup:
  type: MustRunAs
readOnlyRootFilesystem: false
requiredDropCapabilities:
  - ALL
runAsUser:
  type: MustRunAsRange
seLinuxContext:
  type: MustRunAs
seccompProfiles:
  - runtime/default
supplementalGroups:
  type: RunAsAny
volumes:
  - configMap
  - csi
  - downwardAPI
  - emptyDir
  - ephemeral
  - persistentVolumeClaim
  - projected
  - secret
Enter fullscreen mode Exit fullscreen mode
oc apply -f scc-restricted-v2-csi.yaml
oc adm policy add-scc-to-user restricted-v2-csi -z payments-api -n payments
Enter fullscreen mode Exit fullscreen mode

Consuming the SVID

apiVersion: apps/v1
kind: Deployment
metadata:
  name: payments-api
  namespace: payments
spec:
  replicas: 2
  selector:
    matchLabels:
      app: payments-api
  template:
    metadata:
      labels:
        app: payments-api
    spec:
      serviceAccountName: payments-api
      containers:
        - name: api
          image: registry.example.com/payments/api:1.8.3
          ports:
            - containerPort: 8443
          env:
            - name: TLS_CERT_FILE
              value: /var/run/secrets/spiffe.io/tls.crt
            - name: TLS_KEY_FILE
              value: /var/run/secrets/spiffe.io/tls.key
            - name: TLS_CA_FILE
              value: /var/run/secrets/spiffe.io/ca.crt
          volumeMounts:
            - name: spiffe
              mountPath: /var/run/secrets/spiffe.io
              readOnly: true
          securityContext:
            allowPrivilegeEscalation: false
            runAsNonRoot: true
            capabilities:
              drop: ["ALL"]
      volumes:
        - name: spiffe
          csi:
            driver: spiffe.csi.cert-manager.io
            readOnly: true
Enter fullscreen mode Exit fullscreen mode

No Secret object is created. The private key is generated in the pod's tmpfs, never written to etcd, and dies with the pod.

Verifying identity and rotation

oc exec -n payments deploy/payments-api -- \
  openssl x509 -in /var/run/secrets/spiffe.io/tls.crt -noout -text \
  | grep -A1 'Subject Alternative Name'
# URI:spiffe://cluster.example.com/ns/payments/sa/payments-api

oc get certificaterequests -n payments \
  -o custom-columns=NAME:.metadata.name,APPROVED:.status.conditions[?\(@.type==\"Approved\"\)].status,READY:.status.conditions[?\(@.type==\"Ready\"\)].status
Enter fullscreen mode Exit fullscreen mode

With a one-hour duration the driver re-issues roughly two thirds of the way through the lifetime and rewrites the files in place. The pod is not restarted, so your application must reload the keypair. In Go, watch the directory with fsnotify and keep an atomic pointer behind tls.Config.GetCertificate; with NGINX, a periodic nginx -s reload or a reloader sidecar works. Validate this explicitly in a soak test — a silent failure to reload surfaces 40 minutes later as handshake errors in production.

Enforcing identity in the application

Verification is two steps: standard chain validation against ca.crt, then an authorization check on the peer's URI SAN. DNS-based hostname verification is meaningless here; the leaf has no DNS SAN.

peerAllowed := map[string]bool{
    "spiffe://cluster.example.com/ns/orders/sa/orders-api": true,
}

tlsCfg := &tls.Config{
    MinVersion:            tls.VersionTLS13,
    ClientAuth:            tls.RequireAndVerifyClientCert,
    ClientCAs:             caPool,
    GetCertificate:        certStore.Current, // reloaded on fsnotify event
    VerifyPeerCertificate: func(_ [][]byte, chains [][]*x509.Certificate) error {
        for _, u := range chains[0][0].URIs {
            if peerAllowed[u.String()] {
                return nil
            }
        }
        return errors.New("peer SPIFFE ID not authorized")
    },
}
Enter fullscreen mode Exit fullscreen mode

If you prefer not to touch application code, run a per-pod Envoy or an ingress-less NGINX in front of it with ssl_verify_client on; and ssl_client_certificate /var/run/secrets/spiffe.io/ca.crt; — but note that matching on the URI SAN in NGINX requires njs or a $ssl_client_escaped_cert parse, so app-level checks are usually cleaner.

Security best practices

  • Keep leaf lifetimes short (1h or less). X.509 revocation does not work at this scale; expiry is your revocation mechanism. A stolen key is useless within the hour.
  • Never store workload keys in Secrets. The CSI approach keeps keys in tmpfs, node-local, out of etcd and out of etcd backups.
  • Use an intermediate per cluster, signed by an offline or HSM-backed root. Compromise of one cluster's issuer should not forge identities in another. Give each cluster its own trust domain (prod-eu1.example.com) so SPIFFE IDs are globally unambiguous.
  • Lock down approver-policy. One policy per class of workload, maxDuration enforced, dnsNames/ipAddresses empty, and RBAC use granted only to the driver's ServiceAccount. Alert on Denied conditions on CertificateRequest — they usually mean either a misconfiguration or someone probing the CA.
  • Restrict who can create Certificate/CertificateRequest objects against the SPIFFE issuer. A developer with create certificaterequests in a namespace plus a permissive policy can mint an identity.
  • Distribute trust with trust-manager, never by copy-paste. Dual-source bundles during rotation make CA rollover a non-event.
  • Authorize on SPIFFE ID, not on IP or DNS. Keep the allowlist in config, version it, and fail closed.
  • Keep NetworkPolicies. mTLS proves who is calling; network policy limits who can even attempt a handshake, and protects non-mTLS ports (metrics, debug endpoints).
  • Monitor cert-manager metrics: certmanager_certificate_expiration_timestamp_seconds, controller sync errors, and driver pod restarts. A wedged DaemonSet on one node means new pods on that node start without certificates.
  • Pin the SCC. Grant restricted-v2-csi only to ServiceAccounts that actually need an SVID; privileged stays on the driver's ServiceAccount alone.
  • Test expiry behaviour in CI: run a workload with a 10-minute certificate for an hour and assert zero handshake failures.

Conclusion

You do not need a service mesh to get mutual TLS with strong workload identity. Four controllers — cert-manager, approver-policy, trust-manager and csi-driver-spiffe — give you SPIFFE-shaped, hourly-rotated certificates with node-local private keys, no sidecars, and no data-path component to upgrade.

Key takeaways:

  • Identity comes from the ServiceAccount, enforced by the driver via TokenRequest and double-checked by approver-policy.
  • Keys never reach etcd: the CSI ephemeral volume generates them in the pod's tmpfs.
  • Short lifetimes replace revocation, which makes automatic reload in the application a hard requirement, not an optimization.
  • trust-manager owns trust distribution, making CA rotation a two-source Bundle edit instead of a cluster-wide incident.
  • OpenShift needs two explicit grants: privileged for the driver DaemonSet, and an SCC allowing the csi volume type for the workloads.

If you later adopt Istio, none of this is wasted: cert-manager-istio-csr plugs the same CA and policies into the mesh's certificate flow. Start with the smallest thing that gives you cryptographic identity, and add the mesh only when you need what a mesh actually provides.

Top comments (1)

Collapse
 
nigel_douglas_edera profile image
Nigel Douglas •

I've always wondered why more organisations don't simply run Envoy as a daemonset. Drop the sidecars entirely. You could still achieve mTLS without it necessarily being a service mesh, and therefore without all the associated bloat of sidecars. But maybe I don't know enough about service meshes. I really appreciate your sharing this.