Skip to main content
The PKI (Public Key Infrastructure) module provides facilities for creating and managing internal certificate authorities (CAs) within Caddy. This enables Caddy to issue certificates for internal services without relying on external CAs.

Overview

Module ID: pki The PKI app can define certificate authorities capable of signing certificates. Other modules can use these CAs for:
  • Issuing certificates for internal services
  • Establishing trust relationships
  • Local development with valid HTTPS certificates
By default, Caddy creates a “local” CA that is used for signing locally-trusted certificates. The root certificate is automatically installed in the system trust store.

Configuration

Basic Structure

Certificate Authority Configuration

CA Parameters

string
User-facing name of the certificate authority.Default: Caddy Local Authority
string
CommonName field for the root certificate.Default: {pki.ca.name} - {time.now.year} ECC RootSupports placeholders:
  • {pki.ca.name} - The CA name
  • {time.now.year} - Current year
string
CommonName field for intermediate certificates.Default: {pki.ca.name} - ECC Intermediate
duration
Lifetime for intermediate certificates.Default: 168h (7 days)Must be less than the root certificate lifetime.
boolean
Whether to install the CA’s root certificate into system trust stores, including:
  • System trust store (Windows, macOS, Linux)
  • Java trust store
  • Mozilla Firefox trust store
Default: true
object
Custom root certificate and key configuration. If omitted, Caddy generates a root certificate automatically.See KeyPair Configuration below.
object
Custom intermediate certificate and key. If omitted, Caddy generates an intermediate automatically.See KeyPair Configuration below.
duration
How often to check if certificates need renewal.Default: 10m
float
Fraction of certificate lifetime (0.0–1.0) after which renewal is attempted.For example, 0.2 means renew when 20% of the lifetime remains (~73 days for a 1-year cert).Default: 0.2
object
Custom storage module for this CA’s certificates and keys, separate from Caddy’s global storage.Useful for keeping signing keys in a different location than leaf certificates.

KeyPair Configuration

For custom root or intermediate certificates:
string
Path to the certificate file (PEM format)
string
Path to the private key file (PEM format)
string
Format of the certificate/key:
  • pem_file - PEM files on disk (default)

Multiple Certificate Authorities

You can define multiple CAs for different purposes:

Default CA

The default CA has the ID local and is provisioned automatically if the PKI app is used. It provides:
  • Automatic trust installation - Root certificate installed in system trust stores
  • Automatic renewal - Intermediate certificates renewed before expiration
  • Secure defaults - ECC (Elliptic Curve Cryptography) certificates
  • Local development - Perfect for HTTPS in development without certificate warnings

Certificate Renewal

Caddy automatically manages certificate renewal for CAs:
  1. Maintenance checks run at the interval specified by maintenance_interval (default: 10 minutes)
  2. Renewal threshold is calculated using renewal_window_ratio (default: 20% of lifetime remaining)
  3. Automatic regeneration of intermediate certificates before expiration
  4. Root certificate renewal if the root is managed by Caddy and approaching expiration
Root certificates have a default lifetime of 10 years. Intermediate certificates have a default lifetime of 7 days and renew automatically.

Storage Locations

By default, CA certificates and keys are stored at:
Where:
  • {caddy_data_dir} is typically ~/.local/share/caddy on Linux, ~/Library/Application Support/Caddy on macOS, or %AppData%/Caddy on Windows
  • {ca_id} is the CA identifier (e.g., local)

Custom Storage Backend

Use a custom storage backend for a CA:

Using Custom Root Certificates

Provide your own root certificate instead of having Caddy generate one:

Trust Store Installation

When install_trust is enabled (default), Caddy attempts to install the root certificate in:
  1. System trust store:
    • Windows: Certificate Manager
    • macOS: Keychain
    • Linux: ca-certificates (Debian/Ubuntu) or ca-trust (RHEL/Fedora)
  2. Java trust store - If Java is installed
  3. Mozilla Firefox - If Firefox is installed
You may be prompted for administrator/sudo password during trust installation.

Disable Trust Installation

To prevent automatic trust installation:

Security Considerations

  • Private keys are stored with restrictive permissions (0600)
  • Root certificates should be rotated every 10 years (or as per your policy)
  • Intermediate certificates renew automatically every 7 days by default
  • Trust installation may require administrator privileges
  • Custom storage can be used to keep signing keys separate from leaf certificates

Examples

Development Environment

Perfect for local HTTPS development:

Production Internal CA

For internal services with longer-lived intermediates: