Documentation
¶
Overview ¶
Package caddykms serves TLS certificates whose private keys live in a key management system, using the KMS abstraction from go.step.sm/crypto.
The private key and certificate are managed outside Caddy. Loading a certificate through this package suppresses Caddy's automatic certificate management for the names it covers, so no ACME issuance is attempted.
Index ¶
- type Entry
- type KMSOptions
- type Loader
- type Manager
- func (*Manager) CaddyModule() caddy.ModuleInfo
- func (m *Manager) Cleanup() error
- func (m *Manager) GetCertificate(_ context.Context, hello *tls.ClientHelloInfo) (*tls.Certificate, error)
- func (m *Manager) Provision(ctx caddy.Context) error
- func (m *Manager) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
- type Source
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct {
// Key is a KMS URI identifying the private key. Its scheme selects the
// backend, for example "tpmkms:name=caddy-tls" or
// "softkms:/etc/caddy/tls.key". Backend parameters carried by the URI,
// such as "device=" for the TPM, are honoured.
Key string `json:"key"`
// Certificate is the path to a PEM file holding the leaf certificate,
// optionally followed by intermediates in issuer order. When empty, the
// chain is loaded from the KMS, which only some backends support.
Certificate string `json:"certificate,omitempty"`
// KMS holds backend options that do not belong in the key URI.
KMS *KMSOptions `json:"kms,omitempty"`
// Tags are arbitrary values associated with the certificate, so that a
// connection policy can select it explicitly. Only the certificate loader
// uses them; the certificate manager ignores them.
Tags []string `json:"tags,omitempty"`
// contains filtered or unexported fields
}
Entry describes one certificate together with the KMS-resident private key that belongs to it.
type KMSOptions ¶
type KMSOptions struct {
// Pin unlocks the KMS, where the backend needs one.
Pin string `json:"pin,omitempty"`
// StorageDirectory is where the TPM KMS keeps its serialized objects. It
// must match the directory used by whichever tool created the key. When
// unset, the backend picks a default relative to the working directory,
// which is rarely what a service wants.
StorageDirectory string `json:"storage_directory,omitempty"`
}
KMSOptions holds KMS backend options that are awkward to express in a key URI. Anything the backend accepts as a URI parameter can go in the URI instead.
type Loader ¶
type Loader []Entry
Loader loads certificates whose private keys live in a KMS.
Each certificate is resolved once, when the config is loaded, and cached by Caddy as an unmanaged certificate. Caddy skips automatic certificate management for any name it already holds a certificate for, so no ACME issuance is attempted and no extra configuration is needed to prevent it. A certificate rotated outside Caddy is picked up on the next reload; use tls.get_certificate.kms instead to pick one up without reloading.
Loader must remain a slice type: the Caddyfile adapter groups certificate loaders using reflection and silently discards any loader whose kind is not a slice.
func (Loader) CaddyModule ¶
func (Loader) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (Loader) LoadCertificates ¶
func (l Loader) LoadCertificates() ([]caddytls.Certificate, error)
LoadCertificates implements caddytls.CertificateLoader.
type Manager ¶
type Manager struct {
Entry
// TTL is how long a resolved certificate is served before the KMS is read
// again. Defaults to 5m. Tags are ignored by the manager.
TTL caddy.Duration `json:"ttl,omitempty"`
// contains filtered or unexported fields
}
Manager serves a certificate whose private key lives in a KMS, re-reading it from the KMS at most once per TTL.
Use this instead of tls.certificates.load_kms when a certificate rotated outside Caddy has to be picked up without a reload. Note that certmagic consults managers only after both in-memory cache lookups miss, so a name already covered by a loaded certificate never reaches a manager: the two are alternatives for a given name rather than layers.
certmagic does not cache what a manager returns, so this is called on every handshake for the names it serves. Refreshes are collapsed so that a burst of connections causes one KMS read, and a failed refresh keeps serving the last known good certificate rather than failing handshakes.
func (*Manager) CaddyModule ¶
func (*Manager) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (*Manager) GetCertificate ¶
func (m *Manager) GetCertificate(_ context.Context, hello *tls.ClientHelloInfo) (*tls.Certificate, error)
GetCertificate implements certmagic.Manager. It returns (nil, nil) for names it has no certificate for, so that other managers and issuers still get a chance.
type Source ¶
type Source struct {
// contains filtered or unexported fields
}
Source turns one Entry into a tls.Certificate whose private key stays in the KMS. It is the only type in this package that talks to go.step.sm/crypto.
The lifecycle is newSource, Open, Resolve any number of times, Close.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
fakekms
Package fakekms provides an in-memory apiv1.KeyManager for tests, so that the rest of the module can be exercised without a TPM or any other hardware.
|
Package fakekms provides an in-memory apiv1.KeyManager for tests, so that the rest of the module can be exercised without a TPM or any other hardware. |