generate

package
v0.4.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CA

type CA struct {
	CAConfig

	CAKeyBytes []byte

	CACerts []*x509.Certificate
	CAKey   crypto.Signer
}

CA contains the data and metadata of the certificate authority.

func NewCA

func NewCA(cfg CAConfig) (*CA, error)

NewCA creates a new root CA blueprint.

func (*CA) Generate

func (c *CA) Generate(log *slog.Logger, commonName string, validityDuration time.Duration) error

Generate the root certificate and keyfile. Populates c.CACertBytes and c.CAKeyBytes.

func (*CA) Intermediates added in v0.3.1

func (c *CA) Intermediates() []*x509.Certificate

Intermediates returns the intermediate CA certificates to be appended to the newly generated certificates.

func (*CA) IsEmpty added in v0.1.8

func (c *CA) IsEmpty() bool

IsEmpty returns true if this CA is empty.

func (*CA) Leaf added in v0.3.1

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

Leaf returns the leaf CA certificate, that is the one to be used to sign the newly generated certificates.

func (*CA) LoadFromFile

func (c *CA) LoadFromFile(caCertFile, caKeyFile string) error

LoadFromFile populates c.CACertBytes and c.CAKeyBytes by reading them from file.

func (*CA) LoadFromSecret added in v0.1.1

func (c *CA) LoadFromSecret(ctx context.Context, k8sClient *kubernetes.Clientset) error

LoadFromSecret populates c.CACertBytes and c.CAKeyBytes by reading them from a secret.

func (*CA) Reset added in v0.1.8

func (c *CA) Reset()

Reset resets ca key and ca cert values, this is useful for reload or regeneration.

func (*CA) Root added in v0.3.1

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

Root returns the certificate of the root CA.

func (*CA) StoreAsConfigMap

func (c *CA) StoreAsConfigMap(ctx context.Context, log *slog.Logger, k8sClient *kubernetes.Clientset) error

StoreAsConfigMap creates or updates the CA certificate in a K8s ConfigMap. Only the CA cert is stored in the ConfigMap, the CA key is not stored.

func (*CA) StoreAsSecret added in v0.1.1

func (c *CA) StoreAsSecret(ctx context.Context, log *slog.Logger, k8sClient *kubernetes.Clientset, force bool) error

StoreAsSecret creates or updates the CA certificate in a K8s secret.

  • If force is true, the existing secret with same name in same namespace (if available) will be overwritten.
  • If force is false and there is existing secret with same name in same namespace, just throws IsAlreadyExists error to caller.

func (*CA) ValidateExpiry added in v0.4.0

func (c *CA) ValidateExpiry(leafValidities []time.Duration) error

ValidateExpiry checks that no certificate in the CA chain has already expired, and that the CA will remain valid for the given leaf certificate validity durations.

type CAConfig added in v0.4.0

type CAConfig struct {
	SecretName      string
	SecretNamespace string

	ConfigMapName      string
	ConfigMapNamespace string
}

CAConfig contains the configuration for CA creation and storage.

type Cert

type Cert struct {
	CommonName       string
	ValidityDuration time.Duration
	Usage            []string
	Name             string
	Namespace        string
	Hosts            []string

	CA        *CA
	CertBytes []byte
	KeyBytes  []byte
}

Cert contains the data and metadata of the certificate and keyfile.

func NewCert

func NewCert(
	commonName string,
	validityDuration time.Duration,
	usage []string,
	name string,
	namespace string,
) *Cert

NewCert creates a new certificate blueprint.

func (*Cert) Generate

func (c *Cert) Generate(log *slog.Logger, ca *CA) error

Generate the certificate and keyfile and populate c.CertBytes and c.CertKey.

func (*Cert) StoreAsSecret

func (c *Cert) StoreAsSecret(ctx context.Context, log *slog.Logger, k8sClient *kubernetes.Clientset) error

StoreAsSecret creates or updates the certificate and keyfile in a K8s secret.

func (*Cert) WithHosts added in v0.1.1

func (c *Cert) WithHosts(hosts []string) *Cert

WithHosts modifies to use the given hosts instead of the default (CommonName).

Jump to

Keyboard shortcuts

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