tlsleaf

package
v0.0.0-...-230ac96 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 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 tlsleaf provides a lazily-generated self-signed CA and per-hostname leaf issuer for the AgentMon DB proxy's TLS termination path. The CA is persisted under a caller-provided StateDir; leaves are issued on demand and cached in-process. Operators copy the CA cert into client trust stores (sslrootcert) so downstream PostgreSQL clients accept proxied connections.

The package is platform-agnostic; tests run on every supported OS.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CA

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

CA is the AgentMon-DB self-signed certificate authority. Construct via LoadOrCreate. Methods are safe for concurrent use.

func LoadOrCreate

func LoadOrCreate(stateDir string, clock func() time.Time) (*CA, error)

LoadOrCreate loads the CA from stateDir if both files are present, or generates a fresh CA on first call and persists it (key 0600, cert 0644). stateDir must already exist; the parent of any sub-path is not created.

Manual recovery: if a crash leaves the StateDir with only one of the two files (key without cert, or vice versa), LoadOrCreate refuses to regenerate. Remove the orphaned file by hand and call LoadOrCreate again.

func (*CA) Cert

func (c *CA) Cert() *x509.Certificate

Cert returns the CA certificate. Safe for concurrent use; callers must not mutate the returned value.

func (*CA) IssueLeaf

func (c *CA) IssueLeaf(hostname string) (*tls.Certificate, error)

IssueLeaf returns a tls.Certificate whose leaf is signed by the CA and whose only SAN is hostname. Cached in-process under hostname; cache size is bounded at 256 entries (LRU). Repeated calls for the same hostname return the cached certificate (no re-issuance).

func (*CA) Now

func (c *CA) Now() time.Time

Now returns the configured clock's notion of "now", or time.Now if no clock was injected. Useful when external callers want to align timestamps with the same clock the CA was constructed with; internal callers in leaf.go read c.clk directly under the existing lock.

Jump to

Keyboard shortcuts

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