servingcert

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 22 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 servingcert manages the aggregated API server's serving certificate.

The server keeps a private CA and a CA-signed serving certificate in one Secret in its own namespace. The serving certificate is served through a dynamiccertificates.CertKeyContentProvider, so the generic API server's DynamicServingCertificateController picks up renewals without a restart. The CA is what the APIService caBundle will trust (#137).

Index

Constants

View Source
const (
	// ServiceName is the Service that fronts the aggregated API server (deploy/apiserver-service.yaml).
	ServiceName = "coder-k8s-apiserver"
	// SecretName is the Secret that holds the CA and the serving certificate.
	SecretName = "coder-k8s-apiserver-tls" //nolint:gosec // G101: a resource name, not a credential.
	// SecretType marks the Secret as coder-k8s's aggregated API server CA. It is deliberately not
	// kubernetes.io/tls: the Secret also holds the CA private key.
	SecretType corev1.SecretType = "coder.com/aggregated-apiserver-serving-ca" //nolint:gosec // G101: a type name, not a credential.

	// CACertKey is the Secret data key for the PEM CA certificate.
	CACertKey = "ca.crt"
	// CAKeyKey is the Secret data key for the PEM CA private key.
	CAKeyKey = "ca.key"
	// CertKey is the Secret data key for the PEM serving certificate.
	CertKey = corev1.TLSCertKey
	// KeyKey is the Secret data key for the PEM serving private key.
	KeyKey = corev1.TLSPrivateKeyKey

	// CAValidity is the lifetime of the CA, counted from the issuing clock (the same 10 years as
	// client-go certutil.NewSelfSignedCACert).
	CAValidity = 10 * 365 * 24 * time.Hour
	// ServingCertValidity is the lifetime of a serving certificate.
	ServingCertValidity = 365 * 24 * time.Hour
)
View Source
const DefaultCheckInterval = 12 * time.Hour

DefaultCheckInterval is how often Run re-reads the Secret and renews the serving certificate.

Variables

View Source
var SecretLabels = map[string]string{
	"app.kubernetes.io/name":       "coder-k8s",
	"app.kubernetes.io/component":  "aggregated-apiserver-serving-ca",
	"app.kubernetes.io/managed-by": "coder-k8s",
}

SecretLabels mark the Secret as managed by coder-k8s.

Functions

func DNSNames

func DNSNames(namespace string) []string

DNSNames returns the serving certificate's subject alternative names for the Service in namespace. kube-apiserver verifies the aggregated server with ServerName "<service>.<namespace>.svc".

func IsPlaceholder

func IsPlaceholder(secret *corev1.Secret) bool

IsPlaceholder reports whether secret is an empty placeholder the server may fill: exactly the managed type and zero data keys. Anything else is parsed, and invalid material stays corrupt.

Types

type Bundle

type Bundle struct {
	CACertPEM []byte
	CAKeyPEM  []byte
	CertPEM   []byte
	KeyPEM    []byte

	CACert *x509.Certificate
	Cert   *x509.Certificate
	// contains filtered or unexported fields
}

Bundle is parsed, validated trust material from the Secret.

func Generate

func Generate(namespace string, now time.Time) (*Bundle, error)

Generate creates a new CA and a serving certificate for namespace.

func Parse

func Parse(secret *corev1.Secret, namespace string, now time.Time) (*Bundle, error)

Parse validates the Secret's trust material. Each failure names the field that is wrong.

func (*Bundle) Data

func (b *Bundle) Data() map[string][]byte

Data returns the Secret data for the bundle.

func (*Bundle) NeedsRenewal

func (b *Bundle) NeedsRenewal(namespace string, now time.Time) bool

NeedsRenewal reports whether the serving certificate must be re-issued: less than a third of its lifetime is left, it is not yet valid or expired, or it does not cover the Service names of namespace (for example after the Secret was copied from another namespace).

type CorruptSecretError

type CorruptSecretError struct {
	Namespace string
	Problem   string
}

CorruptSecretError reports trust material that cannot be used. The server never replaces such a Secret on its own, because clients may already trust its CA.

func (*CorruptSecretError) Error

func (e *CorruptSecretError) Error() string

type Manager

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

Manager keeps the serving certificate in sync with the Secret.

Ensure is the adopt path: any valid Secret is used as is (so a later "bring your own Secret" mode only has to skip generation and renewal). Listeners registered through CertKeyContentProvider().AddListener are notified whenever the served certificate or the CA changes, so an APIService caBundle controller can react without polling.

func NewManager

func NewManager(client kubernetes.Interface, namespace string) (*Manager, error)

NewManager returns a Manager for the Secret in namespace.

func (*Manager) AddListener

func (m *Manager) AddListener(listener dynamiccertificates.Listener)

AddListener implements dynamiccertificates.Notifier.

func (*Manager) CABundle

func (m *Manager) CABundle() []byte

CABundle returns the PEM CA that signs the served certificate, or nil before the first Ensure.

func (*Manager) CurrentCertKeyContent

func (m *Manager) CurrentCertKeyContent() ([]byte, []byte)

CurrentCertKeyContent implements dynamiccertificates.CertKeyContentProvider.

func (*Manager) Ensure

func (m *Manager) Ensure(ctx context.Context) (*Bundle, error)

Ensure loads, creates, or renews the Secret and makes it the served certificate. Invalid trust material returns a *CorruptSecretError and is never overwritten.

An existing placeholder (see IsPlaceholder) is filled with a new CA instead of being created, so an identity that may only get and update this one Secret can still bootstrap it.

func (*Manager) Name

func (m *Manager) Name() string

Name implements dynamiccertificates.CertKeyContentProvider.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context, interval time.Duration)

Run calls Ensure every interval until ctx is done. Failures are logged and the current certificate keeps being served.

Jump to

Keyboard shortcuts

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