-
Notifications
You must be signed in to change notification settings - Fork 11
ESO-166:Removes resources created for bitwarden server when bitwardenSecretManager is disable #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -480,6 +480,10 @@ func DeleteObject(ctx context.Context, ctrlClient operatorclient.CtrlClient, obj | |
o = DecodeSecretObjBytes(assets.MustAsset(assetName)) | ||
case *corev1.ServiceAccount: | ||
o = DecodeServiceAccountObjBytes(assets.MustAsset(assetName)) | ||
case *corev1.Service: | ||
o = DecodeServiceObjBytes(assets.MustAsset(assetName)) | ||
case *certmanagerv1.Certificate: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [claude generated] Good addition of Certificate and Service support to DeleteObject function. This properly enables cleanup of these resource types. |
||
o = DecodeCertificateObjBytes(assets.MustAsset(assetName)) | ||
default: | ||
panic(fmt.Sprintf("unsupported object type: %T", obj)) | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -21,20 +21,53 @@ var ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
func (r *Reconciler) createOrApplyCertificates(es *operatorv1alpha1.ExternalSecrets, resourceLabels map[string]string, recon bool) error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this function requires refactoring, probably new functions for handling certificate needs of webhook and bitwarden. And the comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if isCertManagerConfigEnabled(es) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err := r.createOrApplyCertificate(es, resourceLabels, webhookCertificateAssetName, recon); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Handle webhook certificate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err := r.handleWebhookCertificate(es, resourceLabels, recon); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Handle bitwarden certificate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err := r.handleBitwardenCertificate(es, resourceLabels, recon); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// handleWebhookCertificate manages the webhook certificate lifecycle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
func (r *Reconciler) handleWebhookCertificate(es *operatorv1alpha1.ExternalSecrets, resourceLabels map[string]string, recon bool) error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Only create webhook certificate if cert-manager is enabled | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if !isCertManagerConfigEnabled(es) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return r.createOrApplyCertificate(es, resourceLabels, webhookCertificateAssetName, recon) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// handleBitwardenCertificate manages the bitwarden certificate lifecycle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
func (r *Reconciler) handleBitwardenCertificate(es *operatorv1alpha1.ExternalSecrets, resourceLabels map[string]string, recon bool) error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Bitwarden certificate handling is independent of cert-manager configuration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Only handle bitwarden certificates when bitwarden is enabled | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if isBitwardenConfigEnabled(es) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bitwardenConfig := es.Spec.ExternalSecretsConfig.BitwardenSecretManagerProvider | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// If a secret reference is provided, validate it exists instead of creating a certificate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if bitwardenConfig.SecretRef.Name != "" { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return r.assertSecretRefExists(es, es.Spec.ExternalSecretsConfig.BitwardenSecretManagerProvider) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err := r.createOrApplyCertificate(es, resourceLabels, bitwardenCertificateAssetName, recon); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return r.assertSecretRefExists(es, bitwardenConfig) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Create or update bitwarden certificate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return r.createOrApplyCertificate(es, resourceLabels, bitwardenCertificateAssetName, recon) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+49
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Bitwarden certificate is created even when cert-manager is disabled (will fail). Current flow calls createOrApplyCertificate without guarding on cert-manager. With CertManagerConfig disabled/missing, updateCertificateParams errors on empty IssuerRef (or the CRD may not exist), causing reconcile failures. Guard creation behind isCertManagerConfigEnabled and no-op (or warn) when SecretRef is absent. Apply: -// handleBitwardenCertificate manages the bitwarden certificate lifecycle
+// handleBitwardenCertificate manages the Bitwarden certificate lifecycle
func (r *Reconciler) handleBitwardenCertificate(es *operatorv1alpha1.ExternalSecrets, resourceLabels map[string]string, recon bool) error {
- // Bitwarden certificate handling is independent of cert-manager configuration
- // Only handle bitwarden certificates when bitwarden is enabled
+ // Only handle Bitwarden certificates when Bitwarden is enabled
if isBitwardenConfigEnabled(es) {
bitwardenConfig := es.Spec.ExternalSecretsConfig.BitwardenSecretManagerProvider
-
- // If a secret reference is provided, validate it exists instead of creating a certificate
+
+ // If a secret reference is provided, validate it exists instead of creating a certificate
if bitwardenConfig.SecretRef.Name != "" {
return r.assertSecretRefExists(es, bitwardenConfig)
}
-
- // Create or update bitwarden certificate
- return r.createOrApplyCertificate(es, resourceLabels, bitwardenCertificateAssetName, recon)
+
+ // Create or update Bitwarden certificate only when cert-manager is enabled.
+ if !isCertManagerConfigEnabled(es) {
+ r.log.V(2).Info("Skipping Bitwarden certificate creation: cert-manager disabled and SecretRef not provided")
+ return nil
+ }
+ return r.createOrApplyCertificate(es, resourceLabels, bitwardenCertificateAssetName, recon)
}
// If bitwarden is not enabled, clean up any existing bitwarden certificate
return r.cleanupBitwardenCertificate()
} 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// If bitwarden is not enabled, clean up any existing bitwarden certificate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return r.cleanupBitwardenCertificate() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+63
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainVerify DeleteObject uses the correct namespace for deletion. We pass only assetName here; if DeleteObject decodes the asset without applying updateNamespace(es, ...), it may target the wrong namespace and fail to delete. If so, consider decoding the object, calling updateNamespace, and deleting via the client. Also applies to: 69-71 🏁 Script executed: #!/bin/bash
# Inspect DeleteObject and decode helpers for namespace handling.
rg -n 'func\s+DeleteObject\(' -n -C5 pkg/controller/common | cat
rg -n 'Decode(Service|Certificate)ObjBytes' -C3 pkg/controller/common | cat
rg -n 'updateNamespace\(' -n pkg/controller/common | cat Length of output: 2503 🏁 Script executed: #!/bin/bash
# Inspect cleanupBitwardenCertificate implementation for DeleteObject usage.
rg -n 'cleanupBitwardenCertificate' -C5 pkg/controller/external_secrets/certificate.go Length of output: 672 🏁 Script executed: #!/bin/bash
# Search for updateNamespace definition and usage across repository
rg -n 'updateNamespace' -C3 . Length of output: 6973 Ensure delete uses ExternalSecrets namespace in cleanupBitwardenCertificate 🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// cleanupBitwardenCertificate removes the bitwarden certificate when bitwarden is disabled | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
func (r *Reconciler) cleanupBitwardenCertificate() error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err := common.DeleteObject(r.ctx, r.CtrlClient, &certmanagerv1.Certificate{}, bitwardenCertificateAssetName); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return fmt.Errorf("failed to delete bitwarden certificate: %w", err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[claude generated] Excellent addition of delete permissions for certificates. This is necessary for the cleanup functionality and properly scoped to cert-manager.io resources.