Running your own PKI and mTLS in practice: certificates, trust, and rotation
Getting a TLS certificate for a public website is relatively straightforward. A certificate authority issues it, browsers already trust that authority, and the website can establish a secure connection. Much of the work
Getting a TLS certificate for a public website is relatively straightforward. A certificate authority issues it, browsers already trust that authority, and the website can establish a secure connection. Much of the work involved in establishing trust has been done for you.
That changes when you start authenticating services within your own infrastructure. You are responsible for deciding who may issue certificates, which identities they represent and how that trust is maintained over time.
This article looks at internal public key infrastructure (PKI) and mutual TLS (mTLS) from that perspective. It assumes familiarity with TLS, certificates and asymmetric cryptography. Rather than walking through a particular product or implementation, it concentrates on the architectural and operational decisions involved in running a PKI, whether you build one yourself or obtain it from a vendor.
1. The problem: public CAs and bearer secrets
A public certificate authority (CA) makes sense for a public endpoint. Its principal advantage is that clients already trust it. For a name such as payments.internal, however, a public CA cannot issue a publicly trusted certificate. Using publicly registrable names for internal services can also expose those names through public Certificate Transparency logs and makes internal trust dependent on an external organisation. There is a good reason to keep control of that trust within your own infrastructure.
Authentication introduces a separate problem. Consider an API key passed in an HTTP header. The receiving service has no way to distinguish the legitimate holder of that key from someone who copied it out of a proxy log or a configuration file. Both present the same credential.
With mTLS, the caller must demonstrate possession of the private key associated with its certificate. The certificate itself can be public, and the private key need not be exportable from the system on which it was generated.
Three questions are worth asking when designing the system:
- Who may issue credentials? Public trust encompasses hundreds of organisations. Within your infrastructure, you can restrict issuance to your own authority.
- What establishes the caller's identity? A bearer token relies on possession of a string, whereas certificate authentication relies on possession of a private key.
- How much damage can a compromised credential cause? A stolen bearer credential remains usable while valid unless it is revoked or otherwise invalidated. A certificate can be limited to a particular service and given a short lifetime.
An internal PKI gives you control over issuance. Mutual TLS provides the mechanism for authenticating the parties using the resulting certificates.
2. The model: a CA hierarchy
Start with the trust anchor. In a conventional internal PKI, this is a self-signed root CA certificate. A service certificate is trusted when its chain of signatures can be validated back to that root, subject to the relevant validation rules.
| Term | Name | Role |
|---|---|---|
| Root CA | Root certificate authority | Self-signed trust anchor. Signs issuing CAs and is kept offline. |
| Issuing CA | Intermediate certificate authority | Signed by the root; handles routine certificate issuance. |
| Leaf | End-entity certificate | Short-lived certificate issued to an individual server or client service. |
| CSR | Certificate signing request | Contains a public key and requested attributes, signed using the requester's private key. |
| SAN | Subject alternative name | Contains the names, IP addresses or other identifiers associated with the certificate. |
The root should sign a small number of issuing CAs. Those CAs do the routine work of issuing leaf certificates. Only the public root certificate needs to be distributed as a trust anchor; its private key is brought into use infrequently, principally when an issuing CA is created or rotated. At other times it should be kept offline.
There is an important operational reason for separating the two levels. Once the root certificate is installed across your infrastructure, replacing it means updating every relevant trust store. If a single CA serves as both root and day-to-day issuer, compromise of that CA leaves you with precisely this problem.
A separate issuing CA can instead be revoked and replaced under the existing root, provided the relying parties enforce its revocation. The trust anchor does not have to change.
3. Identity lives in the SAN, not the CN
Suppose a client connects to api.internal and receives a certificate with api.internal in its Common Name (CN), but with no corresponding Subject Alternative Name (SAN). The certificate may look entirely reasonable when inspected by an administrator. Modern TLS clients performing SAN-based hostname validation will nevertheless reject it.
The SAN extension is where the names used for validation belong. Include every name through which the service is legitimately accessed, including its primary name. If you populate the CN, treat it as a label rather than the sole source of identity.
The rest of the certificate profile deserves similar attention:
- Use the
serverAuthextended key usage (EKU) for server authentication andclientAuthfor client authentication. Both roles are involved in mTLS. Leaf certificates must not be authorised to act as CAs (CA: FALSE). - Set the key usage according to the certificate's role.
digitalSignatureis appropriate for leaf certificates used for signing during authentication;keyEnciphermentis needed for RSA key exchange. CA certificates usekeyCertSignandcRLSignin the hierarchy described here. - If you need to pin a peer, consider pinning a hash of its Subject Public Key Info (SPKI) rather than the entire certificate. A renewal using the same key then preserves the pin. A change of key still requires a corresponding pin update.
It is tempting to issue a wildcard certificate for *.internal and use it across a number of services. From an accountability and compromise-containment perspective, that is a poor trade-off. A single exposed private key can represent every service sharing the certificate. Individual leaf certificates avoid that coupling.
4. mTLS: binding a caller to a key
In a conventional TLS connection, the server authenticates itself to the client. Client authentication normally takes place later, at the application layer, using a password, token or some other credential.
Mutual TLS brings client authentication into the TLS handshake. The client presents its certificate and demonstrates possession of the corresponding private key. The server validates the certificate before accepting ordinary authenticated application traffic.
The useful distinction here is that copying a certificate does not enable someone to authenticate with it. They also need access to the private key. Generating that key on the service's host and making it non-exportable provides an additional degree of protection.
There are two approaches to deciding which clients a server should accept. For a large or changing population of services, trust the appropriate issuing CA, validate the certificate and use the client's identity (for example, its SAN) in application authorisation decisions. Alternatively, for a small and relatively stable set of callers, maintain an explicit allowlist of their SPKI hashes.
A TPM or another suitable secure element can protect the private key against extraction, even if the process using it is compromised. It does not necessarily prevent a compromised process from using the key while it has access to it. Where hardware protection is unavailable, an on-disk private key needs the same treatment as any high-value secret: restrictive permissions and no copies in source repositories or logs.
None of this means that every endpoint should require a client certificate. For a conventional browser-facing public website, a public TLS certificate and application-level user authentication remain the natural choice. Service-to-service communication within infrastructure you control is where mTLS is particularly useful.
5. Short-lived certificates and rotation
Certificate lifetime is partly an operational decision. Public certificates are subject to externally defined validity limits, which have been moving towards shorter lifetimes. With an internal PKI, you determine the lifetime appropriate to your services.
Issuing certificates for a year or longer may appear to reduce maintenance work. It also extends the period during which a compromised credential can be used. A certificate that lasts a few days or weeks, and is renewed automatically, places a much smaller upper bound on that exposure. It reduces dependence on certificate revocation as well.
For this to work reliably, renewal must take place while the existing certificate is still valid. Plan for overlap rather than a simultaneous change throughout the infrastructure:
- Issue the replacement certificate sufficiently far in advance of expiry.
- Allow servers to start presenting their replacement certificates while clients continue to trust the applicable issuers. Clients can renew independently.
- When changing issuing CAs, ensure the new chain is accepted before deploying its leaf certificates. Retain acceptance of the old, uncompromised chain until its remaining leaves expire, then retire it. Where issuer-specific trust configuration is used, both issuers need to be accepted during the transition.
Consider a certificate expiring at 02:00 with no replacement available. From that moment, correctly configured peers begin rejecting connections. The underlying services may be perfectly healthy, yet unable to communicate. Monitoring renewal and planning overlap are therefore part of service availability, not just certificate administration.
6. Revocation is weak; prefer expiry
What happens if a private key is compromised halfway through the certificate's lifetime? In principle, revocation lets you invalidate the certificate immediately. In practice, the effectiveness of that decision depends on every system that accepts the certificate.
A certificate revocation list (CRL) is a signed list of revoked serial numbers. Clients need to obtain a sufficiently current copy. OCSP, the Online Certificate Status Protocol, lets a relying party request certificate status, but introduces another network dependency and can disclose information about the certificates being checked.
Both mechanisms are subject to a difficult operational choice. If revocation information cannot be obtained and a client fails open, a revoked certificate may still be accepted. If it fails closed, a problem with the revocation service can prevent otherwise legitimate connections.
Short certificate lifetimes make that trade-off less troublesome. With automatic renewal and validity measured in days, the exposure from a compromised leaf certificate is bounded more tightly even when revocation checking is unreliable.
Keep a working revocation mechanism for urgent cases, especially the compromise of a longer-lived issuing CA. Check that the necessary endpoints are reachable from the networks in which clients actually run. Their behaviour when those endpoints are unavailable should be an explicit, tested policy.
7. Distributing trust is where it actually breaks
Creating a root certificate is a relatively small part of deploying an internal PKI. Getting every relevant client to trust it is a much larger undertaking. Installing the root on the host operating system is not sufficient in all environments.
| Environment | What needs attention |
|---|---|
| Operating systems | Linux system CA bundles, commonly managed with tools such as update-ca-certificates, and Windows certificate stores cover many applications. |
| Containers | Images may carry their own CA bundle. Include the root during the build or mount and refresh it when the container starts. |
| Language runtimes | Some runtimes ship a separate bundle or require configuration directing them to the internal CA. |
| Browsers | Chromium-family browsers often integrate with system trust. Firefox can use a separate NSS certificate database; check the platform and configuration. |
The material distributed to these systems is the public root certificate, never the CA's private key.
Account for each relevant trust store in your provisioning process and automate installation. An openssl verify check against the intended root is useful, but so is a real connection made by the application with certificate verification enabled. The latter can uncover differences between the trust configuration of the host and that of the application itself.
A missing trust store is an obvious place to look when an internal TLS connection succeeds on one machine but fails on another.
8. Protecting the CA private key
Of all the private keys in the infrastructure, the root CA's key deserves the most protection. A party that acquires it can issue certificates representing services throughout the trust domain. The consequences are not confined to the system from which the key was stolen.
The root key should remain offline except for the limited operations that require it, such as creating a replacement issuing CA. Keeping it off reachable systems reduces the opportunity for compromise.
Access to the root key should not depend on a single administrator. A threshold scheme can split the material needed to reconstruct the key among several holders, with shares stored separately on offline media. This follows the same principle as protecting a key store with a split master key: neither one person nor one stolen device should be sufficient to recover the secret.
The issuing CA has different operational requirements. It must be available for routine certificate issuance, but that does not justify unrestricted access. Run it in an isolated environment, audit issuance and ensure that it can be replaced.
Prepare for both types of compromise. For an issuing CA, revoke it, establish a replacement under the uncompromised root and replace affected leaves. Effective revocation enforcement is essential to this recovery. Compromise of the root itself requires a new trust anchor and redistribution to all relevant trust stores. The architecture should make that second scenario exceptionally difficult to bring about.
9. Failure modes and operational practice
When investigating PKI problems, the cryptographic algorithms are seldom the first place to look. Several more ordinary failures deserve attention:
- Expiry: Monitor leaf and issuing CA validity dates. Renewal of an issuing CA should be a planned and rehearsed operation, with alerts well before expiry.
-
Clock skew: A host with an incorrect clock may reject a certificate whose
notBeforeornotAftervalues would otherwise be acceptable. Reliable time synchronisation matters. - Incomplete certificate chains: A server that presents its leaf without the necessary intermediate certificates may work for clients that already have those intermediates cached. Other clients fail to build the chain to the root.
- Missing SAN: Trust in the issuer can be perfectly correct while hostname validation still fails because the requested name is missing from the SAN.
- Trust store drift: Newly provisioned machines, container images and runtimes may lack the internal root. Incorporate trust configuration into provisioning.
- Unavailable revocation endpoints: Fail-closed clients may lose connectivity when CRL or OCSP services become unreachable. Fail-open clients may accept revoked certificates. Test the chosen behaviour rather than assuming it.
10. Common mistakes
The following are worth checking during a design or deployment review:
- Relying on the CN for hostname validation without populating the SAN.
- Reusing one wildcard certificate and private key across multiple services.
- Giving leaf certificates long lifetimes simply to avoid automating renewal.
- Distributing a CA private key to hosts that need only its public trust anchor.
- Using the same CA as both trust anchor and routine issuer.
- Omitting necessary intermediates from the certificate chain presented by a server.
- Assuming that installing the root on a host covers its containers, browsers and every application runtime.
- Depending on revocation checks that are disabled or silently fail open.
11. Checklist for your own PKI or a vendor assessment
- [ ] Is the root CA offline and used only to sign issuing CAs, with routine leaf issuance delegated to an online CA?
- [ ] Is the root private key protected by a threshold scheme requiring several holders to cooperate?
- [ ] Do leaf certificates have appropriate SAN and EKU values (
serverAuth/clientAuth) andCA: FALSE? - [ ] Are certificates short-lived, with automated renewal and sufficient overlap to avoid downtime?
- [ ] Are mTLS private keys generated on their respective hosts and kept non-exportable, preferably using hardware protection?
- [ ] Is only the public root distributed as a trust anchor, with installation automated and verified across operating systems, containers, runtimes and browsers?
- [ ] Has the procedure for revoking and replacing an issuing CA under the existing root been tested?
- [ ] Are expiry dates monitored, clocks synchronised and complete intermediate chains presented?
- [ ] Is client behaviour defined when revocation information cannot be obtained?
Conclusion
An internal PKI is a long-term operational responsibility. A well-protected root, replaceable issuing CAs, correctly profiled certificates and automated renewal all contribute to keeping that responsibility manageable. Trust distribution and key protection need as much attention as the initial certificate issuance.
For service authentication, mTLS offers an advantage that bearer credentials cannot provide on their own: the caller must demonstrate possession of the private key associated with its identity, rather than simply present a string.
There is also a broader architectural consideration. Running your own PKI means retaining control over who establishes trust within your infrastructure, instead of delegating that authority to an outside organisation. It is the same sovereignty-first principle that applies when deciding where your keys and data should reside.
Sources
- RFC 5280 β Internet X.509 Public Key Infrastructure Certificate and CRL Profile.
- RFC 8446 β The Transport Layer Security (TLS) Protocol Version 1.3.
- RFC 6960 β X.509 Internet Public Key Infrastructure Online Certificate Status Protocol (OCSP).
- NIST SP 800-57 β Recommendation for Key Management.
- CA/Browser Forum β Baseline Requirements (reference for public-certificate validity and certificate profiles).
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.