PKI for FortiGate, Part 2: Designing the Hierarchy and Protecting the Keys
Part 1 covered the model. This post turns it into the design I run in the lab: how many CAs, how long everything lasts, and where each private key lives. The design is small, but it has the same shape as a large one, and the reasoning is what carries over.
If you want the argument for a dedicated CA over FortiManager acting as the CA, that is in Beyond PSK, Part 1. Here I take that decision as made.
The hierarchy
Three tiers of certificate, all EC P-256:
| Tier | Name in the lab | Lifetime | Where the private key lives |
|---|---|---|---|
| Root CA | Fortinet HomeLab Root CA | 10 years, 2026-10-25 to 2036-10-22 | Encrypted file on my admin workstation, not on any server |
| Intermediate CA | Fortinet HomeLab Intermediate CA | 5 years, to 2031-10-24 | On the CA server, themis |
| Leaf (device) | hub1.lab, spoke1.lab, and so on | 1 year at most | Generated on each FortiGate, never exported |
I used one curve family for everything. The IKE proposal in this lab uses Diffie-Hellman group 19, which is the P-256 curve. The certificate key type and the DH group are separate choices, but using one curve keeps the lab simple, and EC keys are small and fast on a virtual FortiGate.
The intermediate does the daily work. It signs every device certificate and it publishes the revocation list for them. The root signs exactly two kinds of thing: the intermediate, once every five years, and a revocation list for the intermediate, which Part 5 builds and tests.
Why two tiers and not one
With one CA, the key that anchors all trust is also the key that is online and signing every day. It has to be reachable, so it is exposed. If it leaks, there is nothing above it to revoke it from, and the only recovery is replacing the trust anchor on every device.
With two tiers, the online key is the intermediate. If it leaks, the root can revoke it, you stand up a new intermediate, and you re-issue the leaves. Devices keep the same root. You have lost a few days, not the whole trust model.
The root key therefore has one job: be there for the rare event. That is why the design puts it away from the network.
What “offline” means here
I want to be accurate about this, because “offline root” can sound grander than it is.
My root key is a passphrase-encrypted file on an administration workstation. It is not on the CA server, not on any server, and not reachable from the lab network. Every time I use it, openssl prompts for the passphrase:
Using configuration from openssl.cnf
Enter pass phrase for ../root_ca.key:
That is a reasonable arrangement for a lab. It is not an air-gapped machine or a hardware security module. In a production environment I would want the root key generated on an HSM or a dedicated offline machine, with a written key ceremony, and more than one protected copy. The lab shows the shape of the arrangement. It does not give the same protection.
What each key costs you if it goes
This is the table I use to decide how much care each key deserves:
| Key | If it leaks | Recovery |
|---|---|---|
| Root | Anyone can issue certificates that every device trusts | Replace the root on every device and re-issue everything. This is the expensive one |
| Intermediate | Anyone can issue certificates under the intermediate | Revoke the intermediate from the root, issue a new one, re-issue the leaves. Devices keep the root |
| Leaf (one device) | One device’s identity can be impersonated | Revoke that serial. Other devices are unaffected |
| Provisioner key | Whoever holds it can request certificates for names the CA allows | Rotate the provisioner. Revoke anything issued that you did not intend |
The provisioner row is easy to forget. In step-ca, the provisioner is the credential that authorises issuance and revocation. It is not a CA key, but it is the practical gate on who can obtain a certificate, so it deserves the same care as the intermediate.
The leaf row is the reason to do this at all. With a pre-shared key, losing one device means changing a secret on every device that shares it. With a certificate, you revoke one serial and the rest of the estate does not notice.
Where the keys sit in the lab
- Root key: on the workstation, encrypted, used only when I sign something.
- Intermediate key: on
themis, readable only by the unprivilegedstepuser that runs the CA, with its password in a file on the same machine so the service can start unattended. That is a convenience trade, and it is the first thing I would change in production, with the key moved into an HSM or a managed key service. - Leaf keys: each FortiGate generates its own with
execute vpn certificate local generate, and only the CSR leaves the device. - Trust anchors on the devices: the root and the intermediate are both imported as CA certificates on each FortiGate. FortiOS names them as it imports them, so in the debug output later they appear as
CA_Cert_1(the root) andCA_Cert_2(the intermediate).
The step-ca post has the full build, including the systemd unit and the firewall rules around themis, so I am not repeating them.
The decisions that are hard to change later
A few choices are cheap now and expensive once certificates are in the field:
- Subject naming. The FortiGate in this lab accepts a peer by checking the issuer and the common name. If your names are inconsistent, you cannot write a clean rule. Pick one scheme, such as
<host>.lab, before the first certificate is issued. - Lifetimes. A leaf lifetime of one year means one renewal per device per year. Shorter lifetimes limit exposure but need renewal automation, which I have not built in this lab. Part 7 covers renewals as a manual process and says so.
- Where the revocation list lives. The CRL URL is baked into the FortiGate configuration. Moving it means touching every device.
- Key type. Changing from EC to RSA later means a new chain.
Part 3 uses this design to issue and renew a certificate on a FortiGate.