ca

package
v0.1.0-alpha.8 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package ca implements the embedded cluster certificate authority. A single ECDSA P-256 root, persisted under <data-dir>/ca/, signs the TLS certificates for the API/registry listeners and the per-node client+server certs that carry each node's identity in a URI SAN (zattera://node/<nodeID>). The API's auth layer reads that URI SAN to establish node identity from mTLS.

The root key is never regenerated: if it exists but fails to parse we fail loudly rather than mint a new CA, because a fresh CA silently invalidates every node's trust and every issued cert.

Index

Constants

View Source
const (

	// NodeCertTTL is the default validity of a node identity cert (1 year).
	NodeCertTTL = 365 * 24 * time.Hour
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CA

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

CA is the cluster certificate authority: an ECDSA P-256 root that issues leaf certs. It is safe for concurrent use (its fields are read-only after construction).

func LoadOrCreate

func LoadOrCreate(dir string) (*CA, error)

LoadOrCreate loads the root CA from <dir>/ca.crt + ca.key, creating a fresh root (and persisting it 0600) if none exists. A present-but-unparseable key is a hard error — never silently regenerate.

func (*CA) CABundlePEM

func (c *CA) CABundlePEM() []byte

CABundlePEM returns the root certificate in PEM (the trust bundle handed to joining nodes and CLI clients).

func (*CA) Certificate

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

Certificate returns the parsed root certificate (used for the CA-pin hash in join tokens, T-12).

func (*CA) ClientTLSConfig

func (c *CA) ClientTLSConfig(nodeCert tls.Certificate) *tls.Config

ClientTLSConfig returns a *tls.Config presenting nodeCert (a node identity leaf) and trusting the cluster root — for node→control mTLS dials.

func (*CA) IssueNode

func (c *CA) IssueNode(nodeID string, meshIP net.IP, ttl time.Duration) (*Leaf, error)

IssueNode mints a node identity cert used both as a client and a server cert (nodes speak mTLS both ways). Its identity is carried in a URI SAN zattera://node/<nodeID> plus DNS SAN node-<nodeID>.

func (*CA) IssueServer

func (c *CA) IssueServer(dnsNames []string, ips []net.IP, ttl time.Duration) (*Leaf, error)

IssueServer mints a server cert for the API/registry listeners. Callers should include 127.0.0.1, the node's mesh IP, the cluster domain and localhost among dnsNames/ips.

func (*CA) Pool

func (c *CA) Pool() *x509.CertPool

Pool returns a cert pool trusting the root.

func (*CA) PrivateKeyPEM

func (c *CA) PrivateKeyPEM() ([]byte, error)

PrivateKeyPEM returns the root CA private key in PEM (EC PRIVATE KEY). It is handed to a joining control node over the mTLS join hop (T-55) so every control node can independently sign node certs, serve its API cert, and run ACME. Guard it like any cluster secret — a leak is a full trust compromise.

func (*CA) ServerTLSConfig

func (c *CA) ServerTLSConfig(dnsNames []string, ips []net.IP) (*tls.Config, error)

ServerTLSConfig returns a *tls.Config presenting a freshly issued server cert for the given SANs, requesting (not requiring) client certs so both token-bearing CLIs and mTLS nodes can share the listener.

func (*CA) SignCSR

func (c *CA) SignCSR(csrPEM []byte, nodeID string, meshIP net.IP, ttl time.Duration) ([]byte, error)

SignCSR verifies a CSR's self-signature, ignores any SANs it requested, and issues a node identity cert with SANs we impose (the join flow, T-17).

type Leaf

type Leaf struct {
	CertPEM []byte
	KeyPEM  []byte
	// contains filtered or unexported fields
}

Leaf is one issued certificate + its private key, in PEM.

func (*Leaf) TLSCertificate

func (l *Leaf) TLSCertificate(caPEM []byte) (tls.Certificate, error)

TLSCertificate builds a tls.Certificate from an issued leaf, with the CA appended so peers can build the chain.

Jump to

Keyboard shortcuts

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