Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Internal mTLS CA

Purpose

Fleet mTLS Root CA is the trust anchor for private machine-to-machine TLS inside the fleet. It is not a public CA, or a replacement for ACME certificates, or a general purpose CA and must not be added to the operating system trust store.

The root signs one intermediate per service. Each service intermediate signs only that service’s leaf certificates. This keeps a compromised intermediate from minting certificates for another service.

Trust hierarchy

Fleet mTLS Root CA (offline, pathlen 1, 10 years)
├── SeaweedFS Intermediate CA (offline, pathlen 0, 5 years)
│   └── master, volume, filer, admin, client, worker leaves (2 years)
├── Alloy Dynamic Capture Intermediate CA (offline, pathlen 0, 5 years)
│   ├── per-host capture API server leaves (2 years)
│   └── alloy-capture-relay client leaf (2 years)
└── DB Guardian Intermediate CA (offline, pathlen 0, 5 years)
    ├── per-host guardian server leaves (2 years)
    └── db-guardian-coordinator client leaf (2 years)

The root and intermediates are CAs. Leaf certificates are never CAs.

Consumers

Keep the used domain aligned with data.site.domain.

ConsumerIntermediateLeaf profileTrust store file
SeaweedFS gRPC and Caddy proxySeaweedFS Intermediate CAserverAuth + clientAuth, SANs for seaweedfs.${data.site.domain} and <service>.seaweedfs.${data.site.domain}hosts/server/nixio/seaweedfs-tls/CA
Alloy dynamic capture APIAlloy Dynamic Capture Intermediate CAserverAuth, SANs for <host>, <host>.localdomain, <host>.${data.site.domain}, 127.0.0.1hosts/server/<host>/alloy/CA_CERT
Alloy capture relay clientAlloy Dynamic Capture Intermediate CAclientAuth, CN alloy-capture-relayhosts/server/nixmon/alloy/CA_CERT
DB Guardian serverDB Guardian Intermediate CAserverAuth, SANs for <host> and <host>.localdomainhosts/server/<host>/db-guardian-tls/CA_CERT
DB Guardian coordinator clientDB Guardian Intermediate CAclientAuth, CN db-guardian-coordinatorhosts/server/<database primary>/db-guardian-tls/CA_CERT

Service-specific leaf details live in:

Key custody

  • Root private key: offline only, used only to sign or rotate service intermediates.
  • Intermediate private keys: offline only, used only to sign that service’s leaves.
  • Leaf private keys: stored in SOPS for the consuming service.
  • Root and intermediate certificates are public and may be distributed.

The provisioning helpers stream CA private keys read from the vault into memory and pass them to OpenSSL on standard input; they never write those keys to the work directory.

If an intermediate key is compromised, rotate that intermediate and reissue its leaves. The other service and the root remain unaffected.

Secret layout

TLS material is stored as binary SOPS files, not inline YAML values. sops.secrets declarations point at these files with format = "binary".

PurposePath
SeaweedFS trust bundlehosts/server/nixio/seaweedfs-tls/CA
SeaweedFS leaf chainhosts/server/nixio/seaweedfs-tls/<SERVICE>_CRT
SeaweedFS leaf keyhosts/server/nixio/seaweedfs-tls/<SERVICE>_KEY
Alloy trust roothosts/server/<host>/alloy/CA_CERT
Alloy server chainhosts/server/<host>/alloy/SERVER_CERT
Alloy server keyhosts/server/<host>/alloy/SERVER_KEY
Alloy client chainhosts/server/nixmon/alloy/CLIENT_CERT
Alloy client keyhosts/server/nixmon/alloy/CLIENT_KEY
DB Guardian trust filehosts/server/<host>/db-guardian-tls/CA_CERT
DB Guardian server chainhosts/server/<host>/db-guardian-tls/SERVER_CERT
DB Guardian server keyhosts/server/<host>/db-guardian-tls/SERVER_KEY
DB Guardian client chainhosts/server/<database primary>/db-guardian-tls/CLIENT_CERT
DB Guardian client keyhosts/server/<database primary>/db-guardian-tls/CLIENT_KEY

The service intermediate is not a trust anchor, and relying parties receive the intermediate from the peer’s certificate chain. The DB Guardian is the exception: its CA_CERT holds the intermediate certificate rather than the root. Trusting the root there would accept a leaf minted by any other service intermediate, and the guardian authorises by client common name, so an Alloy intermediate key could then mint CN=db-guardian-coordinator and drive every guardian. Pinning the intermediate is what makes the separate CA meaningful; the peer’s chain terminates at it with VERIFY_X509_PARTIAL_CHAIN, which ssl.create_default_context enables and the guardian’s own context sets explicitly.

Issuing certificates

DB Guardian leaves are issued by provision-db-guardian-certs, which reads the DB Guardian intermediate from a KeePassXC vault. See DB Guardian for the helper and the following procedure for the certificate profiles it implements.

SeaweedFS leaves are issued by provision-seaweedfs-certs, which reads the SeaweedFS intermediate from the vault. See SeaweedFS for the profiles it implements, including the master hostname alias.

Create the root once:

openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:4096 -out root.key
openssl req -x509 -new -key root.key -sha256 -days 3650 \
  -subj "/CN=Fleet mTLS Root CA" \
  -addext "basicConstraints=critical,CA:TRUE,pathlen:1" \
  -addext "keyUsage=critical,keyCertSign,cRLSign" \
  -out root.crt

Create a service intermediate with the provisioning helper:

provision-intermediate-ca --vault pki.kdbx --vault-password-file vault-pass \
  --prefix "<service>"

The helper appends Intermediate CA to the prefix. It reads the root certificate and key from root/Fleet mTLS Root CA, issues a five-year intermediate with pathlen:0 and keyCertSign,cRLSign, verifies it against the root, and merges it into the vault under intermediate/<slug>/<common name> with cert.pem and key.pem attachments. The root private key is streamed into memory for signing and is not written to the work directory. Use --vault-group for an explicit destination group, and --days, --path-length, or --key-bits to change the profile.

Create a service intermediate manually with the equivalent steps:

openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:4096 -out <service>-intermediate.key
openssl req -new -key <service>-intermediate.key \
  -subj "/CN=<service> Intermediate CA" -out <service>-intermediate.csr
openssl x509 -req -in <service>-intermediate.csr \
  -CA root.crt -CAkey root.key -CAcreateserial \
  -days 1825 -sha256 -out <service>-intermediate.crt -extensions v3 \
  -extfile <(printf '[v3]\nbasicConstraints=critical,CA:TRUE,pathlen:0\nkeyUsage=critical,keyCertSign,cRLSign\nsubjectKeyIdentifier=hash\nauthorityKeyIdentifier=keyid,issuer\n')

Create a leaf with the service intermediate, then build the chain:

openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:4096 -out <leaf>.key
openssl req -new -key <leaf>.key -subj "/CN=<common-name>" -out <leaf>.csr
openssl x509 -req -in <leaf>.csr \
  -CA <service>-intermediate.crt -CAkey <service>-intermediate.key -CAcreateserial \
  -days 730 -sha256 -out <leaf>.crt -extensions v3 \
  -extfile <(printf '[v3]\nbasicConstraints=critical,CA:FALSE\nkeyUsage=critical,digitalSignature,keyEncipherment\nextendedKeyUsage=<eku>\nsubjectKeyIdentifier=hash\nauthorityKeyIdentifier=keyid,issuer\nsubjectAltName=<sans>\n')

cat <leaf>.crt <service>-intermediate.crt > <leaf>-chain.crt

Write a chain or trust bundle to its target file, then encrypt it in place:

mkdir -p hosts/server/<host>/alloy
cp <leaf>-chain.crt hosts/server/<host>/alloy/SERVER_CERT
sops encrypt --input-type binary --in-place hosts/server/<host>/alloy/SERVER_CERT

sops uses the target path to select the .sops.yaml recipients. The encrypted file is a SOPS JSON envelope; format = "binary" makes sops-nix decrypt it back to the original PEM.

Rotation

  • Leaf renewal: sign with the current service intermediate. No trust-store change is needed.
  • Intermediate rotation: sign a new intermediate with the root, reissue that service’s leaves, and deploy the new chains. The trust store stays on the root, except for DB Guardian, whose trust file is the intermediate itself and must be replaced at the same time. The three service intermediates are SeaweedFS, Alloy Dynamic Capture and DB Guardian; rotating one never requires touching the others.
  • Root rotation: add the new root to the trust bundle, reissue all intermediates and leaves, deploy them, then remove the old root.
  • Revocation: neither the Alloy API, the SeaweedFS/Caddy path nor the DB Guardian checks CRLs or OCSP. A leaked leaf certificate stays usable until it expires, or until its issuing intermediate is rotated and the service leaves are reissued. Per-leaf revocation would require adding CRL/OCSP support or using short-lived leaves.

Verification

Verify a leaf against the root and intermediate:

openssl verify -CAfile root.crt -untrusted <service>-intermediate.crt <leaf>.crt

Verify a live mTLS peer:

openssl s_client -connect <host>:<port> \
  -CAfile root.crt -cert <client-chain>.crt -key <client>.key \
  -verify_hostname <host>

Verify a live guardian, whose trust file is the intermediate rather than the root:

openssl s_client -connect <host>:9876 \
  -CAfile guardian-intermediate.crt -cert CLIENT_CERT -key CLIENT_KEY \
  -verify_hostname <host> -partial_chain -verify_return_error

-partial_chain is required here: without it a healthy guardian reports Verify return code: 2 (unable to get issuer certificate), because the trust file is an intermediate and the check insists on reaching a self-signed root. -verify_return_error turns a failed verification into a failed check instead of a warning followed by a successful handshake.

Trust store policy

Do not install this CA with security.pki or any other OS-wide trust store. Adding the CA to the OS trust store would let any process trust certificates signed by this CA for any hostname, which is broader than these services need.