PKI: An Internal Certificate Authority
Services inside a platform need TLS too: linkly talking to PostgreSQL, Prometheus scraping exporters, service-to-service mTLS. Public CAs won't issue certificates for postgres.linkly.internal, and a hand-made openssl CA (PKI & Certificates) turns into a folder of expired certificates and a private key on somebody's laptop. Vault's PKI engine is an API-driven CA: roles define what may be issued, certificates are short-lived, and issuing one is an authenticated, audited API call.
The usual layout: offline root, online intermediate
Linkly Root CA (pki/) ← 10 years; in production generated offline or in an HSM, used only to sign intermediates
└── Linkly Issuing CA (pki_int/) ← 1–5 years; online, issues leaf certificates
├── api.linkly.internal ← hours to days
└── postgres.linkly.internalIf the intermediate is compromised you revoke it and sign a new one; the root, and the trust every machine has in it, stays.
vault server -dev -dev-root-token-id=root -dev-listen-address=127.0.0.1:8200 > vault.log 2>&1 &
for i in $(seq 50); do vault status > /dev/null 2>&1 && break; sleep 0.2; done
export VAULT_TOKEN=root
# root CA
vault secrets enable pki > /dev/null
vault secrets tune -max-lease-ttl=87600h pki > /dev/null
vault write -field=certificate pki/root/generate/internal \
common_name="Linkly Root CA" ttl=87600h > root.crt 2> /dev/null
# intermediate: generate a CSR in pki_int, sign it with the root, import the result
vault secrets enable -path=pki_int pki > /dev/null
vault secrets tune -max-lease-ttl=43800h pki_int > /dev/null
vault write -field=csr pki_int/intermediate/generate/internal common_name="Linkly Issuing CA" > int.csr
vault write -field=certificate pki/root/sign-intermediate csr=@int.csr format=pem_bundle ttl=43800h > int.crt 2> /dev/null
vault write pki_int/intermediate/set-signed certificate=@int.crt > /dev/null 2>&1 # silences an AIA-URL warning, see below
# a role: what this CA may issue
vault write pki_int/roles/linkly-internal allowed_domains=linkly.internal allow_subdomains=true \
max_ttl=72h key_type=ec key_bits=256 > /dev/null
vault write -format=json pki_int/issue/linkly-internal common_name=api.linkly.internal \
alt_names=api-v2.linkly.internal ttl=24h > api.json
jq -r .data.certificate api.json > api.crt
jq -r '.data.ca_chain[]' api.json > chain.pem
openssl x509 -in api.crt -noout -subject -issuer -ext subjectAltName
openssl x509 -in api.crt -noout -text | grep -E 'Public Key Algorithm|ASN1 OID'
hours() { echo $(( ($(date -d "$(openssl x509 -in $1 -noout -enddate | cut -d= -f2)" +%s) - $(date -d "$(openssl x509 -in $1 -noout -startdate | cut -d= -f2)" +%s)) / 3600 )); }
echo "validity: $(hours api.crt)h (plus 30s of backdating against clock skew)"
openssl verify -CAfile root.crt -untrusted int.crt api.crt
echo "--- outside the role"
vault write pki_int/issue/linkly-internal common_name=linkly.evil.com 2>&1 | grep -E '^\*'
vault write -field=certificate pki_int/issue/linkly-internal common_name=db.linkly.internal ttl=720h > db.crt 2> /dev/null
echo "asked for 720h, got: $(hours db.crt)h"subject=CN = api.linkly.internal
issuer=CN = Linkly Issuing CA
X509v3 Subject Alternative Name:
DNS:api-v2.linkly.internal, DNS:api.linkly.internal
Public Key Algorithm: id-ecPublicKey
ASN1 OID: prime256v1
validity: 24h (plus 30s of backdating against clock skew)
api.crt: OK
--- outside the role
* common name linkly.evil.com not allowed by this role
asked for 720h, got: 72h
openssl verifybuilds the chain leaf → intermediate → root: what every client does.- The role refused a name outside
linkly.internal. Roles are the policy of a CA: allowed domains, key types, maximum lifetimes, client/server usage. - Asking for 30 days on a 72-hour role is not an error: Vault caps the TTL at
max_ttland issues it.
Revocation and short lifetimes
vault write pki_int/revoke serial_number=3a:9f:… # adds it to the CRL
vault write pki_int/tidy tidy_cert_store=true tidy_revoked_certs=true safety_buffer=72h
vault write pki_int/config/urls \
issuing_certificates="https://vault.acme.internal:8200/v1/pki_int/ca" \
crl_distribution_points="https://vault.acme.internal:8200/v1/pki_int/crl"config/urls writes the CA and CRL locations (AIA fields) into every certificate issued afterwards; Vault warns when they are missing, which is the warning the session silenced. Revocation checking is unreliable in many clients, so the robust answer is short lifetimes: a certificate that lives 24 hours needs no revocation in most incidents. That only works when renewal is automated:
- cert-manager with a
Vaultissuer requests certificates frompki_int/sign/<role>using Kubernetes auth (cert-manager); - Vault Agent templates with
pkiCertrender certificate files and renew them (Vault Agent); - Vault PKI also speaks ACME, so any ACME client (Caddy, certbot, cert-manager's ACME issuer) can use it like an internal Let's Encrypt, once ACME is enabled on the mount (
pki_int/config/acme).
Roles can set no_store=true for high-volume, short-lived certificates: Vault then doesn't keep a copy of each one, which keeps storage small (and makes revocation by serial impossible, which short lifetimes make acceptable).
Test yourself
Why issue leaf certificates from an intermediate rather than the root?
- Intermediates are faster
- The root can stay offline; a compromised intermediate can be revoked and replaced without changing trust stores
- Roots cannot sign leaves
- It is required by HTTP/2
What happens if you request a 720h certificate from a role with max_ttl=72h?
- The request fails
- Vault issues it with the TTL capped at 72h
- The role is updated
- The root CA signs it instead
Why are short certificate lifetimes often better than relying on revocation?
- They are cheaper
- Many clients don't check revocation reliably; a short-lived certificate expires before misuse matters, provided renewal is automated
- Revocation is impossible in Vault
- Short certificates are smaller