vault-secrets-operator icon indicating copy to clipboard operation
vault-secrets-operator copied to clipboard

Periodically Cleanup Orphaned Shadow Secrets

Open jaireddjawed opened this issue 1 year ago • 1 comments

Description

When an HCPVaultSecretsApp is deleted, the handleDeletion() method is called to remove the app's shadow secrets from k8s. However, if handleDeletion() fails to remove the secrets for some reason, the orphaned shadow secrets remain in k8s indefinitely because we don't have a mechanism that attempts to remove these shadow secrets again later.

This PR addresses this issue by creating a goroutine that periodically checks for deleted HVS apps and removes the app's shadow secrets.

Local Testing

  • Commented the initial deletion attempt of a HCPVaultSecretsApp in Reconcile() This is to mock the scenario where the first handleDeletion() call fails (mentioned here).
Screenshot 2024-12-17 at 6 00 03 AM
  • Created an HCPVaultSecretsApp that includes a dynamic secret (yaml config below)
Screenshot 2024-12-17 at 9 41 35 AM
apiVersion: v1
data:
  clientID: redacted
  clientSecret: redacted
kind: Secret
metadata:
  name: vso-demo-sp
  namespace: default
type: Opaque

---
apiVersion: secrets.hashicorp.com/v1beta1
kind: HCPAuth
metadata:
  name: default
  namespace: vault-secrets-operator-system
spec:
  organizationID: redacted
  projectID: redacted
  servicePrincipal:
    secretRef: vso-demo-sp

---
apiVersion: secrets.hashicorp.com/v1beta1
kind: HCPVaultSecretsApp
metadata:
  name: web-application
  namespace: default
spec:
  appName: sample-app
  destination:
    create: true
    labels:
      hvs: "true"
    name: web-application
  refreshAfter: 15m
Screenshot 2024-12-17 at 6 14 27 AM
  • Confirmed that secret exists in k8s (kubectl get secrets -o yaml)
  • Deleted HCPVaultSecretsApp from k8s (kubectl delete hcpvaultsecretsapps.secrets.hashicorp.com web-application)
  • Confirmed that the secret no longer exists in k8s (kubectl get secrets -o yaml)
Screenshot 2024-12-17 at 6 15 28 AM

Jira Ticket

https://hashicorp.atlassian.net/browse/VAULT-31820

jaireddjawed avatar Dec 02 '24 10:12 jaireddjawed

@jaireddjawed let's hold off on bringing this change into the v0.10.0 release. I have moved it to the v0.10.1 milestone.

benashz avatar Feb 24 '25 19:02 benashz