Documentation
¶
Overview ¶
Package autocertwebhook provides a lightweight framework for building Kubernetes admission webhooks with automatic TLS certificate management.
Index ¶
- func Allowed() *admissionv1.AdmissionResponse
- func AllowedWithMessage(message string) *admissionv1.AdmissionResponse
- func Denied(message string) *admissionv1.AdmissionResponse
- func DeniedWithReason(message string, reason metav1.StatusReason, code int32) *admissionv1.AdmissionResponse
- func Errored(err error) *admissionv1.AdmissionResponse
- func ErroredWithCode(err error, code int32) *admissionv1.AdmissionResponse
- func PatchResponse(original, modified interface{}) *admissionv1.AdmissionResponse
- func PatchResponseFromPatches(patches []jsonpatch.JsonPatchOperation) *admissionv1.AdmissionResponse
- func PatchResponseFromRaw(original, modified []byte) *admissionv1.AdmissionResponse
- func Run(admission Admission) error
- func RunWithContext(ctx context.Context, admission Admission) error
- type Admission
- type AdmitFunc
- type Config
- type Hook
- type HookType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Allowed ¶
func Allowed() *admissionv1.AdmissionResponse
Allowed returns an admission response that allows the request.
func AllowedWithMessage ¶
func AllowedWithMessage(message string) *admissionv1.AdmissionResponse
AllowedWithMessage returns an admission response that allows the request with a message.
func Denied ¶
func Denied(message string) *admissionv1.AdmissionResponse
Denied returns an admission response that denies the request.
func DeniedWithReason ¶
func DeniedWithReason(message string, reason metav1.StatusReason, code int32) *admissionv1.AdmissionResponse
DeniedWithReason returns an admission response that denies the request with a specific reason.
func Errored ¶
func Errored(err error) *admissionv1.AdmissionResponse
Errored returns an admission response for an error.
func ErroredWithCode ¶
func ErroredWithCode(err error, code int32) *admissionv1.AdmissionResponse
ErroredWithCode returns an admission response for an error with a specific code.
func PatchResponse ¶
func PatchResponse(original, modified interface{}) *admissionv1.AdmissionResponse
PatchResponse creates a patch response from the original and modified objects.
func PatchResponseFromPatches ¶
func PatchResponseFromPatches(patches []jsonpatch.JsonPatchOperation) *admissionv1.AdmissionResponse
PatchResponseFromPatches creates a patch response from pre-built patches.
func PatchResponseFromRaw ¶
func PatchResponseFromRaw(original, modified []byte) *admissionv1.AdmissionResponse
PatchResponseFromRaw creates a patch response from raw JSON bytes.
Types ¶
type Admission ¶
type Admission interface {
// Configure returns the server-level configuration.
Configure() Config
// Webhooks returns all webhook definitions.
Webhooks() []Hook
}
Admission is the main interface that users need to implement.
type AdmitFunc ¶
type AdmitFunc func(ar admissionv1.AdmissionReview) *admissionv1.AdmissionResponse
AdmitFunc is the function signature for handling admission requests.
type Config ¶
type Config struct {
// Name is the webhook name, used for generating certificate resources.
// This will be used as prefix for Secret, ConfigMap, and Lease names.
// IMPORTANT: The MutatingWebhookConfiguration and ValidatingWebhookConfiguration
// must use this same name for automatic caBundle patching to work.
// Required. Env: ACW_NAME
Name string `envconfig:"NAME"`
// Namespace is the namespace where the webhook is deployed.
// If empty, auto-detected from ServiceAccount or defaults to "default".
// Env: ACW_NAMESPACE
Namespace string `envconfig:"NAMESPACE"`
// ServiceName is the name of the Kubernetes service for the webhook.
// If empty, defaults to Name.
// Env: ACW_SERVICE_NAME
ServiceName string `envconfig:"SERVICE_NAME"`
// Port is the port the webhook server listens on.
// Env: ACW_PORT
Port int `envconfig:"PORT" default:"8443"`
// MetricsEnabled enables the metrics server.
// Env: ACW_METRICS_ENABLED
MetricsEnabled *bool `envconfig:"METRICS_ENABLED" default:"true"`
// MetricsPort is the port for the metrics server.
// Env: ACW_METRICS_PORT
MetricsPort int `envconfig:"METRICS_PORT" default:"8080"`
// MetricsPath is the path for metrics endpoint.
// Env: ACW_METRICS_PATH
MetricsPath string `envconfig:"METRICS_PATH" default:"/metrics"`
// HealthzPath is the path for health check endpoint.
// Env: ACW_HEALTHZ_PATH
HealthzPath string `envconfig:"HEALTHZ_PATH" default:"/healthz"`
// ReadyzPath is the path for readiness check endpoint.
// Env: ACW_READYZ_PATH
ReadyzPath string `envconfig:"READYZ_PATH" default:"/readyz"`
// CASecretName is the name of the secret containing the CA certificate.
// If empty, defaults to "<Name>-ca".
// Env: ACW_CA_SECRET_NAME
CASecretName string `envconfig:"CA_SECRET_NAME"`
// CertSecretName is the name of the secret containing the server certificate.
// If empty, defaults to "<Name>-cert".
// Env: ACW_CERT_SECRET_NAME
CertSecretName string `envconfig:"CERT_SECRET_NAME"`
// CABundleConfigMapName is the name of the configmap containing the CA bundle.
// If empty, defaults to "<Name>-ca-bundle".
// Env: ACW_CA_BUNDLE_CONFIGMAP_NAME
CABundleConfigMapName string `envconfig:"CA_BUNDLE_CONFIGMAP_NAME"`
// CAValidity is the validity duration of the CA certificate.
// Env: ACW_CA_VALIDITY (e.g., "48h")
CAValidity time.Duration `envconfig:"CA_VALIDITY" default:"48h"`
// CARefresh is the refresh interval for the CA certificate.
// Env: ACW_CA_REFRESH (e.g., "24h")
CARefresh time.Duration `envconfig:"CA_REFRESH" default:"24h"`
// CertValidity is the validity duration of the server certificate.
// Env: ACW_CERT_VALIDITY (e.g., "24h")
CertValidity time.Duration `envconfig:"CERT_VALIDITY" default:"24h"`
// CertRefresh is the refresh interval for the server certificate.
// Env: ACW_CERT_REFRESH (e.g., "12h")
CertRefresh time.Duration `envconfig:"CERT_REFRESH" default:"12h"`
// CertSyncInterval is the interval between certificate sync checks.
// Env: ACW_CERT_SYNC_INTERVAL (e.g., "1m")
CertSyncInterval time.Duration `envconfig:"CERT_SYNC_INTERVAL" default:"1m"`
// LeaderElection enables leader election for certificate rotation.
// Env: ACW_LEADER_ELECTION
LeaderElection *bool `envconfig:"LEADER_ELECTION"`
// LeaderElectionID is the name of the lease resource for leader election.
// If empty, defaults to "<Name>-leader".
// Env: ACW_LEADER_ELECTION_ID
LeaderElectionID string `envconfig:"LEADER_ELECTION_ID"`
// LeaseDuration is the duration of the leader election lease.
// Env: ACW_LEASE_DURATION (e.g., "30s")
LeaseDuration time.Duration `envconfig:"LEASE_DURATION" default:"30s"`
// RenewDeadline is the deadline for renewing the leader election lease.
// Env: ACW_RENEW_DEADLINE (e.g., "10s")
RenewDeadline time.Duration `envconfig:"RENEW_DEADLINE" default:"10s"`
// RetryPeriod is the period between leader election retries.
// Env: ACW_RETRY_PERIOD (e.g., "5s")
RetryPeriod time.Duration `envconfig:"RETRY_PERIOD" default:"5s"`
}
Config contains all configuration for the webhook server. Configuration priority: code > environment variables > defaults. All environment variables use the "ACW_" prefix.
IMPORTANT: The framework expects the MutatingWebhookConfiguration and/or ValidatingWebhookConfiguration resources to have the same name as Config.Name. The framework will automatically patch the caBundle field of these resources.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
pod-mutating
command
Package main demonstrates a mutating admission webhook that injects labels into pods.
|
Package main demonstrates a mutating admission webhook that injects labels into pods. |
|
pod-validating
command
Package main demonstrates a validating admission webhook that enforces pod policies.
|
Package main demonstrates a validating admission webhook that enforces pod policies. |
|
internal
|
|