localca

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 13 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 localca implements a CA whose state can be stored in a local file or Kubernetes secret.

In substrate's default setup, the CA pool state is kept in a Kubernetes secret, and administered with admin CLI commands.

If you are writing an online signing component, use a projected volume to put the secret's content into your container's filesystem, and then point a RefreshingPool at the file. Even if an administrator rotates the pool, your component will continue to work correctly with no restarts.

If you are writing an admin command, read the secret from the Kubernetes API, use Unmarshal to parse it to a Pool, manipulate the Pool, and then use Marshal to serialize the state and write it back to the secret.

For tests, generate an ephemeral ConcretePool.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(pool *ConcretePool) ([]byte, error)

Types

type CA

type CA struct {
	ID string

	// The private key to use for signing certificates.  Corresponds to
	// RootCertificate.
	SigningKey crypto.PrivateKey

	// The root certificate for this CA pool.
	RootCertificate *x509.Certificate
}

CA is a concrete certificate authority signing from a single root certificate.

In most uses, you want to use a pool of CAs, in order to seamlessly handle CA rotation.

func GenerateCA

func GenerateCA(id string, keyType KeyType, validity time.Duration) (*CA, error)

GenerateCA creates a self-signed CA with its own freshly generated key.

func (*CA) TLSCertificateChainPEM

func (ca *CA) TLSCertificateChainPEM() ([]byte, error)

TLSCertificateChainPEM returns the CA certificate in the PEM encoding used by TLS servers.

func (*CA) TLSPrivateKeyPEM

func (ca *CA) TLSPrivateKeyPEM() ([]byte, error)

TLSPrivateKeyPEM returns the CA signing key in the PKCS#8 PEM encoding used by TLS servers.

type ConcretePool

type ConcretePool struct {
	CAs []*CA

	// Which CA is active for signing operations?
	ActiveForSigning string
}

func Unmarshal

func Unmarshal(wireBytes []byte) (*ConcretePool, error)

func (*ConcretePool) CreateCertificate

func (p *ConcretePool) CreateCertificate(template *x509.Certificate, subjectPublicKey crypto.PublicKey) ([][]byte, error)

func (*ConcretePool) TrustAnchors

func (p *ConcretePool) TrustAnchors() ([]*x509.Certificate, error)

type KeyType

type KeyType int
const (
	KeyTypeED25519 KeyType = iota
	KeyTypeECDSAP256
)

type Pool

type Pool interface {
	// CreateCertificate signs the given template certificate using one of the
	// Pool's currently-active CAs.
	CreateCertificate(template *x509.Certificate, subjectPublicKey crypto.PublicKey) ([][]byte, error)

	// TrustAnchors returns the root certificates for all of the pool's CAs.
	TrustAnchors() ([]*x509.Certificate, error)
}

Pool is the interface for a CA pool.

Logically, a Pool is a collection of multiple CAs. One or more are designated as active for signing. The rest are inactive, but are still trusted for verifying certificates.

The active/inactive designation allows a Pool to be seamlessly rotated.

  1. (Steady State) The Pool has one CA, active for signing.
  2. (Publish New Root) Add a new CA, inactive.
  3. (Age In) Wait for trust in the new root to propagate throughout the system.
  4. (Switch) Switch the new CA to be active, and the old CA to be inactive.
  5. (Age Out) Wait for all certificates issued by the old CA to expire.
  6. (Cleanup) Remove the old CA from the Pool.

Normally, we let callers define their own compatibility interfaces. But in most cases you'll want to either use a RefreshingPool (for controllers and servers), or a ConcretePool (for CLIs and tests).

type RefreshingPool

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

RefreshingPool is a wrapper around Pool that periodically reloads the CA state from disk. This allows our various pieces that sign certificates (Actor identity broker, egress gateway) to properly continue signing even as an administrator rotates one of the CA pools, without requiring any components to restart.

func NewRefreshingPool

func NewRefreshingPool(stateFile string) (*RefreshingPool, error)

func (*RefreshingPool) CreateCertificate

func (p *RefreshingPool) CreateCertificate(template *x509.Certificate, subjectPublicKey crypto.PublicKey) ([][]byte, error)

func (*RefreshingPool) TrustAnchors

func (p *RefreshingPool) TrustAnchors() ([]*x509.Certificate, error)

Jump to

Keyboard shortcuts

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