Documentation
¶
Overview ¶
Package cachedcert provides a Caddy tls.get_certificate module that caches certificates fetched over HTTP, so they are served from memory on subsequent TLS handshakes instead of re-fetched every time.
Index ¶
- type CachedHTTPGetter
- func (*CachedHTTPGetter) CaddyModule() caddy.ModuleInfo
- func (g *CachedHTTPGetter) GetCertificate(ctx context.Context, hello *tls.ClientHelloInfo) (*tls.Certificate, error)
- func (g *CachedHTTPGetter) Provision(ctx caddy.Context) error
- func (g *CachedHTTPGetter) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
- func (g *CachedHTTPGetter) Validate() error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CachedHTTPGetter ¶
type CachedHTTPGetter struct {
// URL is the endpoint queried on a cache miss. The certificate-providing
// server_name (and the handshake's signature_schemes / cipher_suites) are
// added as query parameters, identical to the stock http getter.
URL string `json:"url,omitempty"`
// TTL, when set, is how long a fetched certificate is cached. When zero,
// the s-maxage of the response's Cache-Control header is used, falling back
// to defaultTTL.
TTL caddy.Duration `json:"ttl,omitempty"`
// NegativeTTL is how long a 204 (no certificate) response is cached. When
// zero, defaultNegativeTTL is used.
NegativeTTL caddy.Duration `json:"negative_ttl,omitempty"`
// CacheDir, when set, persists fetched certificate bundles to disk so the
// cache survives a restart. Files are written 0600 in a 0700 directory.
// The 0700 mode is applied only when this module creates the directory; if
// you pre-create it, restrict its permissions yourself, as it holds private keys.
CacheDir string `json:"cache_dir,omitempty"`
// contains filtered or unexported fields
}
CachedHTTPGetter is a certmagic.Manager that fetches certificates from an HTTP endpoint (like Caddy's stock tls.get_certificate.http) and caches the result in memory, optionally persisting it to disk for warm restarts.
Example ¶
ExampleCachedHTTPGetter shows the configuration the module exposes. In practice it is registered as the Caddy module tls.get_certificate.cached_http and configured through the Caddyfile rather than constructed directly.
getter := &CachedHTTPGetter{
URL: "https://app.example.com/cert",
TTL: caddy.Duration(time.Hour),
NegativeTTL: caddy.Duration(time.Minute),
CacheDir: "/var/cache/caddy-certs",
}
_ = getter
func (*CachedHTTPGetter) CaddyModule ¶
func (*CachedHTTPGetter) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (*CachedHTTPGetter) GetCertificate ¶
func (g *CachedHTTPGetter) GetCertificate(ctx context.Context, hello *tls.ClientHelloInfo) (*tls.Certificate, error)
GetCertificate implements certmagic.Manager. It is called on every TLS handshake, so the hot path is a map lookup; only a miss performs HTTP.
func (*CachedHTTPGetter) Provision ¶
func (g *CachedHTTPGetter) Provision(ctx caddy.Context) error
Provision sets up the module.
func (*CachedHTTPGetter) UnmarshalCaddyfile ¶
func (g *CachedHTTPGetter) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
UnmarshalCaddyfile parses the get_certificate cached_http directive:
cached_http <url> {
ttl <duration>
negative_ttl <duration>
cache_dir <path>
}
func (*CachedHTTPGetter) Validate ¶
func (g *CachedHTTPGetter) Validate() error
Validate ensures the module is configured correctly.