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
- Variables
- func DNSNames(namespace string) []string
- func IsPlaceholder(secret *corev1.Secret) bool
- type Bundle
- type CorruptSecretError
- type Manager
- func (m *Manager) AddListener(listener dynamiccertificates.Listener)
- func (m *Manager) CABundle() []byte
- func (m *Manager) CurrentCertKeyContent() ([]byte, []byte)
- func (m *Manager) Ensure(ctx context.Context) (*Bundle, error)
- func (m *Manager) Name() string
- func (m *Manager) Run(ctx context.Context, interval time.Duration)
Constants ¶
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 // ServingCertValidity is the lifetime of a serving certificate. The CA lives 10 years // (client-go certutil.NewSelfSignedCACert). ServingCertValidity = 365 * 24 * time.Hour )
const DefaultCheckInterval = 12 * time.Hour
DefaultCheckInterval is how often Run re-reads the Secret and renews the serving certificate.
Variables ¶
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 ¶
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 ¶
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 Parse ¶
Parse validates the Secret's trust material. Each failure names the field that is wrong.
func (*Bundle) NeedsRenewal ¶
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 ¶
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 ¶
CABundle returns the PEM CA that signs the served certificate, or nil before the first Ensure.
func (*Manager) CurrentCertKeyContent ¶
CurrentCertKeyContent implements dynamiccertificates.CertKeyContentProvider.
func (*Manager) Ensure ¶
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.