Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
9d887cd
fix(controller): decode old object for delete requests
oliverbaehler Dec 10, 2025
221e0e8
chore: modernize golang
oliverbaehler Dec 10, 2025
052660e
chore: modernize golang
oliverbaehler Dec 10, 2025
7c418d0
chore: modernize golang
oliverbaehler Dec 10, 2025
7db5048
Merge branch 'main' of github.com:projectcapsule/capsule
oliverbaehler Dec 11, 2025
98f9add
Merge branch 'main' of github.com:projectcapsule/capsule
oliverbaehler Dec 15, 2025
f448bdf
Merge branch 'main' of github.com:projectcapsule/capsule
oliverbaehler Dec 19, 2025
033e098
Merge branch 'main' of github.com:projectcapsule/capsule
oliverbaehler Dec 19, 2025
21cd932
Merge branch 'main' of github.com:projectcapsule/capsule
oliverbaehler Dec 25, 2025
1e28f1b
Merge branch 'main' of github.com:projectcapsule/capsule
oliverbaehler Jan 5, 2026
2549518
Merge branch 'main' of github.com:projectcapsule/capsule
oliverbaehler Jan 27, 2026
ebe2b77
Merge branch 'main' of github.com:projectcapsule/capsule
oliverbaehler May 28, 2026
ea46ad4
Merge branch 'main' of github.com:projectcapsule/capsule
oliverbaehler May 28, 2026
c46f875
Merge branch 'main' of github.com:projectcapsule/capsule
oliverbaehler May 29, 2026
3f7eed0
Merge branch 'main' of github.com:projectcapsule/capsule
oliverbaehler Jun 1, 2026
45d5ed8
Merge branch 'main' of github.com:projectcapsule/capsule
oliverbaehler Jun 2, 2026
0f0d8ee
Merge branch 'main' of github.com:projectcapsule/capsule
oliverbaehler Jun 4, 2026
b1a45b6
fix: preserve ca-bundles injected from external providers
oliverbaehler Jun 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 51 additions & 4 deletions internal/controllers/admission/mutating.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,27 @@ func (r *mutatingReconciler) reconcileConfiguration(

obj.SetAnnotations(annotations)

// Preserve existing CA Information (cert-manager)
existingCABundles := mutatingWebhookCABundlesByName(obj.Webhooks)

obj.Webhooks = desiredHooks

caCert, err := tls.FetchCurrentCaBundleForAdmission(ctx, r.client, r.configuration, cfg.Client.CABundle)
if err != nil {
return err
var caCert []byte

if r.configuration.EnableTLSConfiguration() {
caCert, err = tls.FetchCurrentCaBundleForAdmission(ctx, r.client, r.configuration)
if err != nil {
return err
}
} else {
caCert = cfg.Client.CABundle
}

preserveMutatingWebhookCABundles(obj.Webhooks, caCert)
if len(caCert) > 0 {
preserveMutatingWebhookCABundles(obj.Webhooks, caCert)
} else {
restoreMutatingWebhookCABundles(obj.Webhooks, existingCABundles)
}

return err
})
Expand Down Expand Up @@ -222,10 +235,44 @@ func (r *mutatingReconciler) webhooks(
return hooks, nil
}

func mutatingWebhookCABundlesByName(
hooks []admissionv1.MutatingWebhook,
) map[string][]byte {
out := make(map[string][]byte, len(hooks))

for _, hook := range hooks {
if hook.Name == "" || len(hook.ClientConfig.CABundle) == 0 {
continue
}

out[hook.Name] = append([]byte(nil), hook.ClientConfig.CABundle...)
}

return out
}

func restoreMutatingWebhookCABundles(
hooks []admissionv1.MutatingWebhook,
existingCABundles map[string][]byte,
) {
for i := range hooks {
existingCABundle := existingCABundles[hooks[i].Name]
if len(existingCABundle) == 0 {
continue
}

hooks[i].ClientConfig.CABundle = append([]byte(nil), existingCABundle...)
}
}

func preserveMutatingWebhookCABundles(
hooks []admissionv1.MutatingWebhook,
caBundle []byte,
) {
if len(caBundle) == 0 {
return
}

for i := range hooks {
hooks[i].ClientConfig.CABundle = append([]byte(nil), caBundle...)
}
Expand Down
55 changes: 51 additions & 4 deletions internal/controllers/admission/validating.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,27 @@ func (r *validatingReconciler) reconcileValidatingConfiguration(

obj.SetAnnotations(annotations)

// Preserve existing CA Information (cert-manager)
existingCABundles := validatingWebhookCABundlesByName(obj.Webhooks)

obj.Webhooks = desiredHooks

caCert, err := tls.FetchCurrentCaBundleForAdmission(ctx, r.client, r.configuration, cfg.Client.CABundle)
if err != nil {
return err
var caCert []byte

if r.configuration.EnableTLSConfiguration() {
caCert, err = tls.FetchCurrentCaBundleForAdmission(ctx, r.client, r.configuration)
if err != nil {
return err
}
} else {
caCert = cfg.Client.CABundle
}

preserveValidatingWebhookCABundles(obj.Webhooks, caCert)
if len(caCert) > 0 {
preserveValidatingWebhookCABundles(obj.Webhooks, caCert)
} else {
restoreValidatingWebhookCABundles(obj.Webhooks, existingCABundles)
}

return err
})
Expand Down Expand Up @@ -224,10 +237,44 @@ func (r *validatingReconciler) validatingWebhooks(
return hooks, nil
}

func validatingWebhookCABundlesByName(
hooks []admissionv1.ValidatingWebhook,
) map[string][]byte {
out := make(map[string][]byte, len(hooks))

for _, hook := range hooks {
if hook.Name == "" || len(hook.ClientConfig.CABundle) == 0 {
continue
}

out[hook.Name] = append([]byte(nil), hook.ClientConfig.CABundle...)
}

return out
}

func restoreValidatingWebhookCABundles(
hooks []admissionv1.ValidatingWebhook,
existingCABundles map[string][]byte,
) {
for i := range hooks {
existingCABundle := existingCABundles[hooks[i].Name]
if len(existingCABundle) == 0 {
continue
}

hooks[i].ClientConfig.CABundle = append([]byte(nil), existingCABundle...)
}
}

func preserveValidatingWebhookCABundles(
hooks []admissionv1.ValidatingWebhook,
caBundle []byte,
) {
if len(caBundle) == 0 {
return
}

for i := range hooks {
hooks[i].ClientConfig.CABundle = append([]byte(nil), caBundle...)
}
Expand Down
9 changes: 1 addition & 8 deletions internal/controllers/tls/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,7 @@ func FetchCurrentCaBundleForAdmission(
ctx context.Context,
c client.Reader,
cfg configuration.Configuration,
configuredCABundle []byte,
) ([]byte, error) {
// Explicit configuration wins.
if len(configuredCABundle) > 0 {
return append([]byte(nil), configuredCABundle...), nil
}

// Internal Capsule TLS enabled: source of truth is the TLS Secret.
if cfg.EnableTLSConfiguration() {
secret := &corev1.Secret{}
Expand Down Expand Up @@ -175,7 +169,6 @@ func FetchCurrentCaBundleForAdmission(
return append([]byte(nil), caBundle...), nil
}

// cert-manager / external injector mode:
// return nil and preserve current webhook caBundle.
// TLS Controller not enabled
return nil, nil
}
Loading