Documentation
¶
Overview ¶
Package clusterpki runs the cluster CA on top of the replicated state (ADR 0006, FA-PKI-01..04): it creates the CA at bootstrap, issues and redeems join tokens, issues and renews node certificates, keeps the revocation list at hand for TLS handshakes and manages this node's own certificate.
Index ¶
- Constants
- Variables
- type Applier
- type Authority
- func (a *Authority) Bundle(ctx context.Context) ([]*x509.Certificate, string, error)
- func (a *Authority) CreateJoinToken(ctx context.Context, role pki.Role, tenantID string, ttl time.Duration) (string, time.Time, error)
- func (a *Authority) Ensure(ctx context.Context, isLeader bool) error
- func (a *Authority) IssueSelf(ctx context.Context, nodeID string, csrDER []byte) (Issued, error)
- func (a *Authority) Redeem(ctx context.Context, token, nodeID string, csrDER []byte) (Issued, error)
- func (a *Authority) Renew(ctx context.Context, peer pki.Identity, csrDER []byte) (Issued, error)
- func (a *Authority) Revoke(ctx context.Context, cert *x509.Certificate) error
- type IssueFunc
- type Issued
- type Keyring
- type NodeCert
- func (n *NodeCert) CA() *x509.Certificate
- func (n *NodeCert) EnsureSelf(ctx context.Context, a *Authority, isLeader bool, now time.Time) error
- func (n *NodeCert) Install(key *ecdsa.PrivateKey, issued Issued) error
- func (n *NodeCert) Leaf() *x509.Certificate
- func (n *NodeCert) Load() error
- func (n *NodeCert) NeedsRenewal(now time.Time) bool
- func (n *NodeCert) NewCSR() (*ecdsa.PrivateKey, []byte, error)
- func (n *NodeCert) Renew(ctx context.Context, now time.Time, issue IssueFunc) error
- func (n *NodeCert) RunRenewal(ctx context.Context, issuer func() IssueFunc, interval time.Duration, ...)
- type Revocations
Constants ¶
const ( DefaultTokenTTL = time.Hour MaxTokenTTL = 24 * time.Hour )
Join token lifetimes (FA-PKI-02).
Variables ¶
var ErrInvalidToken = errors.New("invalid join token")
ErrInvalidToken is the only error a joining node sees for a bad token, whatever the reason (unknown, used, expired, wrong secret or CA).
var ErrNoCA = errors.New("cluster CA does not exist yet")
ErrNoCA means the cluster has no CA yet (bootstrap still running).
Functions ¶
This section is empty.
Types ¶
type Authority ¶
type Authority struct {
State store.State
Cluster Applier
Keyring Keyring
// Now is the clock; nil uses time.Now.
Now func() time.Time
}
Authority is the cluster CA. Issuing needs the CA key and therefore runs on the leader; reading the bundle works on every node.
func (*Authority) CreateJoinToken ¶
func (a *Authority) CreateJoinToken(ctx context.Context, role pki.Role, tenantID string, ttl time.Duration) (string, time.Time, error)
CreateJoinToken stores a new one-time token and returns it for the operator; the secret itself is never stored (FA-PKI-02). ttl 0 means DefaultTokenTTL.
func (*Authority) Ensure ¶
Ensure creates the cluster CA if none exists. Only the leader creates it; followers receive it through Raft. Concurrent attempts are harmless: the FSM keeps the first CA and rejects any other.
func (*Authority) IssueSelf ¶
IssueSelf issues a voter certificate for this node directly, without a token: the bootstrap node and the leader renewing its own certificate.
func (*Authority) Redeem ¶
func (a *Authority) Redeem(ctx context.Context, token, nodeID string, csrDER []byte) (Issued, error)
Redeem enrolls a node with a join token: it checks the token, uses it up through Raft and issues a certificate with the token's role and tenant. The CSR is checked before the token is used, so a broken request does not burn it. Every token problem yields ErrInvalidToken.
type IssueFunc ¶
IssueFunc obtains a certificate for a CSR: from the CA on the leader, through RenewCertificate on the leader for followers.
type Issued ¶
type Issued struct {
Identity pki.Identity
Leaf *x509.Certificate
// ChainDER is leaf then CA, as nodes present it (pki.Leaf).
ChainDER [][]byte
// BundleDER are the trusted CA certificates.
BundleDER [][]byte
}
Issued is a node certificate with the trust bundle to send to the node.
type Keyring ¶
type Keyring interface {
Encrypt(plaintext []byte, aad string) (string, error)
Decrypt(ctx context.Context, ciphertext, aad string) ([]byte, error)
}
Keyring encrypts the CA key (ADR 0011).
type NodeCert ¶
type NodeCert struct {
DataDir string
NodeID string
Holder pki.Holder
// Now is the wall clock for renewal decisions; nil uses time.Now. Tests
// set it to simulate clock skew between nodes (ADR 0020).
Now func() time.Time
// contains filtered or unexported fields
}
NodeCert manages this node's key and certificate and serves them through Holder; a renewed certificate applies from the next handshake (FA-PKI-03).
func (*NodeCert) CA ¶
func (n *NodeCert) CA() *x509.Certificate
CA returns the CA certificate the node certificate was issued by, or nil. It is the trust anchor of a joined node until the replicated state with the CA bundle has arrived.
func (*NodeCert) EnsureSelf ¶
func (n *NodeCert) EnsureSelf(ctx context.Context, a *Authority, isLeader bool, now time.Time) error
EnsureSelf gives the leader a valid certificate issued directly by the CA (bootstrap node, leader renewing its own); on followers it only loads.
func (*NodeCert) Install ¶
func (n *NodeCert) Install(key *ecdsa.PrivateKey, issued Issued) error
Install stores key and certificate (key file 0600, written atomically) and makes them the active certificate.
func (*NodeCert) Leaf ¶
func (n *NodeCert) Leaf() *x509.Certificate
Leaf returns the current certificate, or nil.
func (*NodeCert) Load ¶
Load reads the stored key and certificate, if any. A certificate whose key does not match is an error, not a reason to silently start over.
func (*NodeCert) NeedsRenewal ¶
NeedsRenewal reports whether there is no certificate or it reached its renewal time.
func (*NodeCert) NewCSR ¶
func (n *NodeCert) NewCSR() (*ecdsa.PrivateKey, []byte, error)
NewCSR creates a fresh key for the next certificate and returns its CSR; Install activates key and certificate together.
type Revocations ¶
type Revocations struct {
// contains filtered or unexported fields
}
Revocations caches the revocation list for TLS handshakes (FA-PKI-04): revoked serials and removed nodes. Both lists are small.
func (*Revocations) Revoked ¶
func (r *Revocations) Revoked(serial string) bool
Revoked reports whether a serial is revoked. Before the first load nothing is revoked.
func (*Revocations) RevokedNode ¶
func (r *Revocations) RevokedNode(nodeID string) (time.Time, bool)
RevokedNode returns when a node was revoked (pki.Verifier.RevokedNode).