Technical Insight How-to Guide

Mutual TLS in Kubernetes Without a Service Mesh

A production-focused guide to securing Kubernetes service-to-service traffic with mutual TLS, cert-manager, SPIFFE/SPIRE, and workload identity—without deploying a service mesh.

Mutual TLS authentication between Kubernetes services
On this page

Kubernetes gives workloads service discovery and network connectivity, but it does not automatically authenticate every service-to-service connection. A NetworkPolicy can restrict which pods communicate; it cannot prove the identity of the application on the other end of a connection.

Mutual TLS (mTLS) closes that gap. Both peers present certificates, validate a trusted issuer, and establish an encrypted channel. A service mesh can manage much of this lifecycle, but it is not the only option. For teams with a limited number of services, existing PKI infrastructure, or a preference for application-level security, mTLS without a mesh can be a practical architecture.

The difficult part is not turning on TLS. It is issuing identities, distributing trust, rotating credentials, authorizing callers, and proving that plaintext cannot bypass the protected endpoint.

What mTLS guarantees and what it does not

In ordinary HTTPS, the client authenticates the server. With mTLS, the server also authenticates the client using a certificate. A successful handshake provides encrypted transport and cryptographic authentication of both peers.

Diagram source
sequenceDiagram
    participant A as Service A (client)
    participant B as Service B (server)
    A->>B: TLS ClientHello
    B-->>A: Server certificate
    A->>A: Validate CA and server identity
    A->>B: Client certificate
    B->>B: Validate CA and client identity
    A->>B: Encrypted application request
    B-->>A: Encrypted response

A valid certificate alone does not mean a client is authorized to invoke every API. The server must also apply an authorization policy to the authenticated identity, such as an allowed DNS SAN, URI SAN, or SPIFFE ID. Similarly, mTLS does not replace NetworkPolicies, application authorization, or protection of private keys.

Choose the right operating model

ApproachCertificate lifecycleWorkload identityBest fit
cert-manager and an internal CACertificate renewal and Kubernetes Secret updatesCertificate SANs, with authorization implemented by the applicationA small to medium service estate with established PKI practices
SPIFFE/SPIREShort-lived SVID issuance and rotation through the Workload APIAttested SPIFFE IDsLarger or more dynamic environments needing consistent workload identity
Manually managed certificatesEntirely operator-ownedWhatever identity convention the operator definesLabs, migration bridges, and exceptional integrations

Recommendation: For a handful of applications that already support client certificates, start with cert-manager and explicit peer authorization. Consider SPIRE when workload identity, federation, or certificate lifecycle management becomes a platform capability rather than an application-specific task.

Option 1: cert-manager with an internal CA

cert-manager manages Kubernetes Certificate resources and stores issued key pairs in Secrets. It does not automatically configure applications to use certificates or reload them after renewal.

Establish the CA and issuer

For a self-contained demonstration, create a CA certificate in the same namespace as the issuer. The example deliberately uses a namespaced Issuer, because a ClusterIssuer using the CA issuer type expects its signing Secret in the cert-manager cluster resource namespace, not an arbitrary application namespace.

apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
  name: bootstrap-selfsigned
  namespace: production
spec:
  selfSigned: {}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: workload-ca
  namespace: production
spec:
  isCA: true
  commonName: workload-ca
  secretName: workload-ca-keypair
  duration: 8760h
  privateKey:
    algorithm: ECDSA
    size: 256
  issuerRef:
    name: bootstrap-selfsigned
    kind: Issuer
---
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
  name: workload-ca-issuer
  namespace: production
spec:
  ca:
    secretName: workload-ca-keypair

This is a demonstration CA, not an ideal production root of trust. In production, use an enterprise PKI, a controlled intermediate CA, or an approved external issuer. Keep CA private keys outside ordinary application namespaces where possible; constrain access to signing material and plan CA rollover before issuing certificates.

Issue distinct certificates for server and client

Separate certificates make the intended roles explicit and reduce unnecessary credential reuse. Here service-b accepts HTTPS connections and service-a calls it.

apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: service-b-server
  namespace: production
spec:
  secretName: service-b-server-tls
  duration: 720h
  renewBefore: 168h
  privateKey:
    algorithm: ECDSA
    size: 256
    rotationPolicy: Always
  usages:
    - digital signature
    - server auth
  dnsNames:
    - service-b.production.svc
    - service-b.production.svc.cluster.local
  issuerRef:
    name: workload-ca-issuer
    kind: Issuer
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: service-a-client
  namespace: production
spec:
  secretName: service-a-client-tls
  duration: 720h
  renewBefore: 168h
  privateKey:
    algorithm: ECDSA
    size: 256
    rotationPolicy: Always
  usages:
    - digital signature
    - client auth
  # A URI SAN can be used as a client identity when applications enforce it.
  uris:
    - spiffe://example.internal/ns/production/sa/service-a
  issuerRef:
    name: workload-ca-issuer
    kind: Issuer

The URI above is only an identity string embedded in a certificate; cert-manager does not attest that the requesting pod actually has that Kubernetes service account. Do not treat a self-declared URI SAN as equivalent to a SPIRE-issued, attested SPIFFE identity. Restrict who can create Certificate resources and who can read or modify the resulting Secrets.

Inspect issuance:

kubectl get certificates,certificaterequests -n production
kubectl describe certificate service-b-server -n production
kubectl get secret service-b-server-tls -n production

Distribute certificates and trust safely

Mount the server certificate and key from its Secret, and mount the trusted CA bundle separately. The client needs its own certificate and key, plus the CA certificate used to validate service-b.

# Relevant part of the service-b Pod specification
spec:
  containers:
    - name: service-b
      image: registry.example.internal/service-b:1.0.0
      ports:
        - containerPort: 8443
      volumeMounts:
        - name: server-tls
          mountPath: /etc/tls/server
          readOnly: true
        - name: trust-bundle
          mountPath: /etc/tls/trust
          readOnly: true
  volumes:
    - name: server-tls
      secret:
        secretName: service-b-server-tls
    - name: trust-bundle
      configMap:
        name: workload-ca-bundle

The workload-ca-bundle ConfigMap must be provisioned with the CA certificate as ca.crt; it is not created by the snippet above. Prefer a managed trust-distribution mechanism, such as trust-manager, when several namespaces or applications consume the same CA. Never assume every issued Secret will contain a usable ca.crt, particularly when the issuer is external or the trust chain changes.

Mounted Secret files are updated eventually by Kubernetes, but the application must reload certificates and trust bundles. Many TLS servers load key material only at startup. Use a tested reload mechanism or a controlled rollout on renewal.

Implementing mTLS in Go

Go’s standard library supports mTLS without an additional proxy. The server must verify client certificates and authorize their identities.

package main

import (
    "crypto/tls"
    "crypto/x509"
    "log"
    "net/http"
    "os"
)

func main() {
    pair, err := tls.LoadX509KeyPair(
        "/etc/tls/server/tls.crt",
        "/etc/tls/server/tls.key",
    )
    if err != nil { log.Fatal(err) }

    pem, err := os.ReadFile("/etc/tls/trust/ca.crt")
    if err != nil { log.Fatal(err) }
    roots := x509.NewCertPool()
    if !roots.AppendCertsFromPEM(pem) { log.Fatal("invalid CA bundle") }

    tlsConfig := &tls.Config{
        MinVersion:   tls.VersionTLS12,
        Certificates: []tls.Certificate{pair},
        ClientCAs:    roots,
        ClientAuth:   tls.RequireAndVerifyClientCert,
    }

    handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        if r.TLS == nil || len(r.TLS.PeerCertificates) == 0 {
            http.Error(w, "client certificate required", http.StatusUnauthorized)
            return
        }
        // Explicit application authorization; adapt this to your identity model.
        const allowed = "spiffe://example.internal/ns/production/sa/service-a"
        authorized := false
        for _, uri := range r.TLS.PeerCertificates[0].URIs {
            if uri.String() == allowed { authorized = true; break }
        }
        if !authorized {
            http.Error(w, "client not authorized", http.StatusForbidden)
            return
        }
        _, _ = w.Write([]byte("mTLS connection accepted\n"))
    })

    server := &http.Server{
        Addr:      ":8443",
        Handler:   handler,
        TLSConfig: tlsConfig,
    }
    log.Fatal(server.ListenAndServeTLS("", ""))
}

For production, make the allowed identities configuration-driven, handle certificate rotation without an unsafe gap, and validate the authorization logic with negative tests. The example uses an exact URI comparison for clarity, not a full policy engine.

A Go client can present its certificate while validating the server’s DNS name:

pair, err := tls.LoadX509KeyPair("/etc/tls/client/tls.crt", "/etc/tls/client/tls.key")
if err != nil { log.Fatal(err) }
caPEM, err := os.ReadFile("/etc/tls/trust/ca.crt")
if err != nil { log.Fatal(err) }
roots := x509.NewCertPool()
if !roots.AppendCertsFromPEM(caPEM) { log.Fatal("invalid CA") }

client := &http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{
    MinVersion:   tls.VersionTLS12,
    Certificates: []tls.Certificate{pair},
    RootCAs:      roots,
}}}
resp, err := client.Get("https://service-b.production.svc:8443/")

The imports and surrounding function are omitted from this client fragment. Do not set InsecureSkipVerify: true to work around certificate-name or trust-chain problems.

Option 2: SPIFFE/SPIRE for attested workload identity

SPIFFE standardizes workload identities, while SPIRE can attest Kubernetes workloads and issue short-lived X.509 SVIDs. Rather than giving every application a long-lived Kubernetes Secret, an application or compatible proxy retrieves credentials through the SPIFFE Workload API.

Diagram source
flowchart LR
    K[Kubernetes workload metadata] --> A[SPIRE Agent]
    S[SPIRE Server] -->|Identity policy and signed SVIDs| A
    A -->|Workload API| W[Service A]
    A -->|Workload API| X[Service B]
    W <-->|mTLS with SPIFFE ID authorization| X

A production SPIRE deployment requires more than a Server StatefulSet and Agent DaemonSet. Plan for:

  • A protected trust domain and signing-key lifecycle.
  • Kubernetes node attestation and workload attestation, with correct RBAC and service-account token audiences.
  • Highly available SPIRE servers and durable datastore configuration.
  • Secure Workload API socket access and isolation between workloads.
  • Explicit registration policy, identity naming, and trust-domain federation where required.
  • Integration with the application using a SPIFFE-aware library or a proxy that validates peer IDs.

For Go applications, the go-spiffe library provides a workload API source and mTLS helpers. The following is a conceptual client configuration; the Workload API socket and SPIRE registration must already be working:

source, err := workloadapi.NewX509Source(ctx)
if err != nil { return err }
defer source.Close()

expected := spiffeid.RequireFromString("spiffe://example.internal/ns/production/sa/service-b")
tlsConfig := tlsconfig.MTLSClientConfig(
    source,
    source,
    tlsconfig.AuthorizeID(expected),
)
client := &http.Client{Transport: &http.Transport{TLSClientConfig: tlsConfig}}

Key difference: a properly configured SPIRE deployment binds identity issuance to attestation evidence. A manually assigned SPIFFE-shaped URI in a cert-manager certificate does not offer the same guarantee.

Option 3: Manual PKI for constrained cases

OpenSSL-generated certificates are useful for interoperability tests or short-lived migrations. They are a poor default for production because the platform team must manage signing keys, certificate expiry, distribution, revocation, and rotation independently.

If manual issuance is unavoidable, require unique private keys per workload, SAN-based identity validation, short certificate lifetimes, encrypted key storage, and an auditable renewal procedure. Never commit private keys or unencrypted CA signing keys to Git. Treat generated Kubernetes Secrets as sensitive, even when their manifests are base64-encoded.

NetworkPolicy is complementary—not an mTLS switch

A NetworkPolicy can allow traffic only from selected pods to a TLS listener. It cannot inspect the TLS handshake or enforce client-certificate verification. That remains the application’s or proxy’s responsibility.

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: service-b-ingress
  namespace: production
spec:
  podSelector:
    matchLabels:
      app: service-b
  policyTypes:
    - Ingress
  ingress:
    - from:
        - podSelector:
            matchLabels:
              app: service-a
      ports:
        - protocol: TCP
          port: 8443

This policy only restricts ingress to pods labeled app: service-b; it does not prove that the source is the intended application. Protect label mutation and workload creation with RBAC and admission policies, and ensure there is no alternate plaintext port or bypass path.

Certificate rotation and trust rollover

Certificate automation is not complete until renewal works without downtime. Test the entire lifecycle:

  1. Issue a certificate with the correct SANs and extended key usage.
  2. Verify the server rejects clients without trusted certificates.
  3. Verify an authenticated but unauthorized client is rejected.
  4. Renew the certificate and confirm the running process begins using it.
  5. Introduce a new CA, distribute an overlapping trust bundle, reissue leaf certificates, then retire the old CA.
  6. Verify expired, revoked where supported, or otherwise untrusted credentials cannot connect.

For a CA change, distributing the new trust anchor before switching leaf certificates avoids breaking clients. Revocation support varies by TLS stack; short-lived credentials and fast trust removal are often operationally more reliable than assuming CRL or OCSP checks are enabled everywhere.

Useful checks:

kubectl get certificate -n production
kubectl describe certificate service-b-server -n production

# Test the endpoint using a client certificate and explicit CA trust.
curl --fail --show-error \
  --cacert ca.crt \
  --cert service-a.crt \
  --key service-a.key \
  https://service-b.production.svc:8443/

# A connection without a client certificate should fail at TLS authentication.
curl --cacert ca.crt https://service-b.production.svc:8443/

Run these commands from an environment with appropriate network reachability and authorized access to the test credentials.

Observability and operational controls

A production mTLS rollout should expose both security and reliability signals. Monitor certificate expiry and renewal errors, TLS handshake failures, peer-authorization denials, and application request latency. Alert on impending expiry before the renewal window closes, not only after connections fail.

Keep audit events useful without logging private keys, entire certificates, or sensitive payloads. Track which identity was authenticated, which authorization decision was made, and which service was called. Correlate these events with cert-manager controller health or SPIRE issuance failures.

For OpenShift, use the supported cert-manager operator and cluster security controls appropriate to the installed version. Avoid assuming an upstream SPIRE DaemonSet requiring host-level access will run unchanged under default Security Context Constraints (SCCs). Any elevated privileges or host mounts need an explicit platform security review.

Production readiness checklist

[ ] Identity: Every workload has a distinct identity, and servers authorize specific peers.
[ ] Trust: Trust anchors have documented ownership, distribution, and rollover procedures.
[ ] Secrets: Signing keys and workload private keys are access-controlled and never committed to source control.
[ ] Rotation: Certificate renewal and application reload are tested under load.
[ ] Transport: There is no alternate plaintext listener or bypass route.
[ ] Segmentation: NetworkPolicies reduce unnecessary connectivity.
[ ] Observability: Expiry, issuance failures, and authentication errors are monitored.
[ ] Recovery: The team can recover from CA compromise, expired certificates, and an unavailable identity service.

Conclusion

You do not need a service mesh to implement robust mutual TLS in Kubernetes. You do need a deliberate identity and certificate lifecycle architecture.

For a small set of services, cert-manager combined with application-level TLS and explicit authorization is often sufficient. For platform-wide workload identity, SPIFFE/SPIRE provides stronger attestation and a standardized delivery mechanism. In both cases, success depends less on the initial YAML than on safe rotation, reliable trust distribution, and operational visibility.

At ape factory, we treat service-to-service security as a platform engineering concern: identity, network segmentation, deployment automation, and day-two operations must work together for security controls to remain effective in production.

Related Articles

Stay ahead

Get the latest insights.

Insights on cloud, AI and open source — delivered to your inbox.

Email subscriptions are coming soon.