certloader

package
v1.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package certloader builds a reloadable crypto/tls.Config backed by files on disk, so cert rotation does not require a server restart. The package is transport-agnostic — the produced crypto/tls.Config is consumed by the Tetragon gRPC server.

The design — directory-watched material, atomic snapshot swapped on reload, crypto/tls.Config.GetConfigForClient pinning a snapshot for the duration of each handshake — is adapted from cilium/cilium/pkg/crypto/certloader (Apache-2.0).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Watch

func Watch(ctx context.Context, r *Reloader)

Watch starts a background watcher that reloads r whenever any of its TLS files change on disk. Runs until ctx is canceled; failures are logged.

Types

type Config

type Config struct {
	// CertFile is a PEM-encoded server cert (leaf + optional intermediates).
	CertFile string
	// KeyFile is the PEM-encoded private key for CertFile.
	KeyFile string
	// ClientCAFiles is a list of PEM CA bundles used to verify client
	// certs. Required when RequireClientCert is true.
	ClientCAFiles []string
	// RequireClientCert toggles mTLS (RequireAndVerifyClientCert).
	RequireClientCert bool
}

Config drives a server-side TLS configuration. Zero values disable TLS.

func (Config) Enabled

func (c Config) Enabled() bool

Enabled reports whether a server cert is configured.

func (Config) Validate

func (c Config) Validate() error

Validate enforces flag-layer invariants so callers can construct a Reloader without going through viper.

type Reloader

type Reloader struct {
	// contains filtered or unexported fields
}

Reloader holds TLS material and atomically swaps it on Reload, so a rotation does not interrupt in-flight handshakes. Safe for concurrent use.

func NewReloaderLazy

func NewReloaderLazy(cfg Config) (*Reloader, error)

NewReloaderLazy constructs a Reloader without requiring the TLS material to exist on disk. Handshakes performed before the first successful Reload fail with "certloader: no certificate loaded"; pair with Watch so the first reload happens automatically once the files appear.

Use this when the agent may start before its provisioner (cert-manager, cilium-certgen Job) has written the Secret.

func (*Reloader) Ready

func (r *Reloader) Ready() bool

Ready reports whether a Reload has succeeded at least once. A Reloader returned by [NewReloader] is always Ready; one returned by NewReloaderLazy becomes Ready after Watch observes the TLS files on disk.

func (*Reloader) Reload

func (r *Reloader) Reload() error

Reload re-reads the cert/key and CA bundles from disk and atomically replaces the active snapshot when they changed. Concurrent calls are serialized by reloadMu.

func (*Reloader) ServerConfig

func (r *Reloader) ServerConfig() *tls.Config

ServerConfig returns a tls.Config suitable for [credentials.NewTLS]. The returned value is stable across reloads.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL