Internal mTLS Between Services With a Private CA (step-ca)

Two services talking over plain HTTP on your internal network trust anything that can reach the port. That is not a network boundary; it is an open door with a hostname on it.

Flat internal networks age badly. The moment an attacker lands on one host — a poisoned dependency, a leaked credential, a misconfigured egress rule — every service reachable from that host is fair game, because none of them can tell a legitimate caller from a hostile one. Mutual TLS fixes this by making each service prove who it is with a certificate, and refuse anyone who cannot. You do not need a service mesh to get there. You need a small private certificate authority, short-lived certificates, and about an afternoon. This is how to build it with Smallstep’s step-ca.

Identity, not network position

The point of mTLS is to move the trust decision away from “which subnet did this packet come from” and onto “which certificate did the caller present”. A service that requires a client certificate signed by your private root will reject a curl from a compromised host, an unregistered container, or anything else that cannot produce a valid leaf. That is identity-based access without an identity provider in the request path.

Free · 4 minutes

Would you survive contact with a determined attacker — or an auditor?

Fourteen questions on access, patching, detection, and recovery — the basics that prevent most real incidents, and the ones most often assumed rather than verified. Banded finding on screen, full sheet by email.

The design decision that matters most is certificate lifetime. The instinct is to issue long-lived certificates and maintain a revocation list for when one leaks. In practice, revocation is where PKI goes to die: CRLs go stale, OCSP responders become a dependency you forgot to make highly available, and clients quietly fail open when the check times out. Short-lived certificates sidestep the whole problem. If a leaf lives for twenty-four hours and renews itself automatically, a leaked key is worthless by tomorrow and you never operate a revocation list at all. Expiry is your revocation mechanism. This is the same reasoning that underpins running mutual TLS between internal APIs without a service mesh — the mesh automates the certificate lifecycle for you, and here you are doing that part yourself, deliberately and visibly.

Stand up the CA

Install the tooling from Smallstep’s package repository. You need two things: step-ca, the CA server, and step, the CLI that talks to it and manages certificates on each host.

# Debian/Ubuntu: add the Smallstep repository and install both packages
apt-get update && apt-get install -y --no-install-recommends curl gpg ca-certificates
curl -fsSL https://packages.smallstep.com/keys/apt/repo-signing-key.gpg -o /etc/apt/keyrings/smallstep.asc
cat << 'EOF' > /etc/apt/sources.list.d/smallstep.sources
Types: deb
URIs: https://packages.smallstep.com/stable/debian
Suites: debs
Components: main
Signed-By: /etc/apt/keyrings/smallstep.asc
EOF
apt-get update && apt-get -y install step-cli step-ca

Initialise the PKI. This generates a root CA, an intermediate that actually signs leaves, and a default provisioner — the authority that decides who is allowed to request certificates. Keep the root offline in anger; here it lives on the CA host for simplicity.

# Create the certificate authority
step ca init \
  --name "Sixteen Pillars Internal CA" \
  --dns ca.internal \
  --address :9000 \
  --provisioner ops@internal

# Run the CA (it will prompt for the provisioner password)
step-ca $(step path)/config/ca.json

# Print the root fingerprint — services need this to bootstrap trust
step certificate fingerprint $(step path)/certs/root_ca.crt

Run step-ca under systemd on a dedicated, tightly-firewalled host — port 9000 open only to the hosts that will request certificates, nothing else. The fingerprint you printed is the anchor of the whole system: it is how every service confirms it is talking to your CA and not an impostor.

Issue a short-lived leaf to each service

On each service host, bootstrap trust once using the CA URL and root fingerprint. That installs the root certificate locally so the host can both verify the CA and verify peers. Then request a leaf certificate for the service, capped to a short lifetime.

# One-off: pin trust to the CA by URL and fingerprint
step ca bootstrap \
  --ca-url https://ca.internal:9000 \
  --fingerprint 6c7e3...paste-your-root-fingerprint

# Issue a 24-hour leaf certificate for this service
mkdir -p /etc/step/certs
step ca certificate payments.internal \
  /etc/step/certs/payments.crt \
  /etc/step/certs/payments.key \
  --provisioner ops@internal \
  --not-after 24h

# Copy the root into place so peers can be verified
step ca root /etc/step/certs/root_ca.crt

The --not-after 24h flag is the crux: this certificate is dead in a day. The common name and SANs (here payments.internal) become the service’s verifiable identity. Every service gets its own leaf; nothing shares a key.

Make both ends verify each other

Now wire the certificates into the transport. On the server side, present the leaf and demand a client certificate signed by your root. Most internal services sit behind a reverse proxy, so terminate mTLS there. The example is nginx; if you prefer terminating internal TLS somewhere with less ceremony, the same shape applies to Caddy for internal services.

server {
    listen 8443 ssl;
    server_name payments.internal;

    ssl_certificate     /etc/step/certs/payments.crt;
    ssl_certificate_key /etc/step/certs/payments.key;

    # Require a client cert signed by our private root, and reject anything else
    ssl_client_certificate /etc/step/certs/root_ca.crt;
    ssl_verify_client on;
    ssl_verify_depth  1;

    location / {
        # Hand the verified caller identity to the app
        proxy_set_header X-Client-DN $ssl_client_s_dn;
        proxy_pass http://127.0.0.1:8080;
    }
}

With ssl_verify_client on, nginx returns a TLS handshake failure to any caller that does not present a valid leaf. The calling service, in turn, presents its own certificate and verifies the server against the same root:

# The 'ledger' service calling 'payments' over mutual TLS
curl --cacert /etc/step/certs/root_ca.crt \
     --cert   /etc/step/certs/ledger.crt \
     --key    /etc/step/certs/ledger.key \
     https://payments.internal:8443/health

Drop any one of those three flags and the call fails. That is the whole security property, made concrete: no valid client certificate, no connection.

Renew before expiry, automatically

Short lifetimes are only workable if renewal is invisible. A day-long certificate that a human has to reissue is an outage waiting for a weekend. Smallstep ships a systemd template for exactly this: a timer that fires every fifteen minutes, checks whether the certificate is near expiry, renews it if so, and reloads the dependent service.

# /etc/systemd/system/cert-renewer@.service
[Unit]
Description=Certificate renewer for %I
After=network-online.target
StartLimitIntervalSec=0

[Service]
Type=oneshot
User=root
Environment=CERT_LOCATION=/etc/step/certs/%i.crt \
            KEY_LOCATION=/etc/step/certs/%i.key

# Renew only when the cert is genuinely close to expiry
ExecCondition=/usr/bin/step certificate needs-renewal ${CERT_LOCATION}
ExecStart=/usr/bin/step ca renew --force ${CERT_LOCATION} ${KEY_LOCATION}

# Reload the service that uses the cert, if it is running
ExecStartPost=/usr/bin/env sh -c "! systemctl --quiet is-active %i.service || systemctl try-reload-or-restart %i"
# /etc/systemd/system/cert-renewer@.timer
[Unit]
Description=Timer for certificate renewal of %I

[Timer]
Persistent=true
OnCalendar=*:1/15
# Spread renewals so hosts do not all hit the CA at once
RandomizedDelaySec=5m
Unit=cert-renewer@%i.service

[Install]
WantedBy=timers.target

Enable it per service and the certificate lifecycle runs itself:

systemctl daemon-reload
systemctl enable --now cert-renewer@payments.timer

The needs-renewal guard means the renewer does nothing until roughly two-thirds of the certificate’s life has elapsed, so a twenty-four-hour leaf renews well before it lapses without hammering the CA. If the CA is briefly unreachable, the timer simply tries again fifteen minutes later; nothing breaks until the leaf actually expires, which gives you hours of slack.

What you have, and what to watch

You now have service-to-service calls where each end proves its identity cryptographically, certificates that expire faster than a leaked key is useful, and renewal that no one has to think about. No revocation infrastructure, no mesh, no sidecars. The one thing that will bite you if you ignore it is the CA host itself: it is now load-bearing. If step-ca is down when a certificate expires, that service goes dark. Run it with the same seriousness you would give a database — monitored, backed up, and reachable — and protect the root key above everything else. A private CA does not remove trust from your network; it concentrates it into one certificate. Guard that certificate accordingly.

Free interactive tool

Website compliance checklist

What your site has to do, based on what it actually does

Answer as much or as little as you like — the list builds as you go. Nothing is stored against your name and no email is required.

Most technology problems are not technology problems. They are control problems.

The systems exist. The investment has been made. The question is whether leadership can understand, direct, evidence, and sustain what those systems produce. Find out where control exists — and where it only appears to.