Skip to content
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

Vault-agent configmap created by mutating webhook is not deleted when pod is finished #1663

Open
dhpizza opened this issue Aug 1, 2022 · 5 comments
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@dhpizza
Copy link

dhpizza commented Aug 1, 2022

Describe the issue

vault-agent configmap is not deleted when pod is gone. This becomes an issue when having hundreds of thousands of these orphaned resources in the cluster which can happen quite easily.

Expected behaviour

Configmap to be deleted when corresponding pod is deleted

Steps to reproduce

Minimal pod template with annotations to trigger the mutating webhook to create containers consul-template and vault-agent in as init containers.

after startup of mya-pod, you see a configmap created my-pod-vault-agent-config.
Now delete the pod, you see that the configmap stays deployed as an orphaned resource.

Suggestion for a fix

adding pod id as ownerReference in the configmap

like this

metadata:
   ownerReferences:
     - apiVersion: v1
        blockOwnerDeletion: true
        controller: true
       kind: Pod
       name: <pod-name>
       uid: <pod-uid>

so that the configmap is deleted when the pod is deleted.

Environment details:

Kubernetes version (e.g. v1.10.2): v1.21.11"
Cloud-provider/provisioner (e.g. AKS, GKE, EKS, PKE etc): -
bank-vaults version (e.g. 0.4.17): (webhook chart version): 1.15.11

  • ghcr.io/banzaicloud/vault-secrets-webhook:1.15.3
  • hashicorp/consul-template:0.27.2
  • vault:1.6.2

Install method (e.g. helm or static manifests): helm chart
Logs from the misbehaving component (and any other relevant logs): see above
Resource definition (possibly in YAML format) that caused the issue, without sensitive data:

  • pod.yaml:
apiVersion: v1
kind: Pod
metadata:
  annotations:
    vault.security.banzaicloud.io/run-as-non-root: "false"
    vault.security.banzaicloud.io/vault-client-timeout: 120s
    vault.security.banzaicloud.io/vault-ct-configmap: my-configmap
    vault.security.banzaicloud.io/vault-ct-once: "true"
    vault.security.banzaicloud.io/vault-path: k8scl-k8slab
    vault.security.banzaicloud.io/vault-role: reference-apps
  labels:
    run: my-pod
  name: my-pod
spec:
  containers:
  - image: busybox
    imagePullPolicy: IfNotPresent
    name: my-pod
  • ct-configmap.yaml
apiVersion: v1
data:
  config.hcl: |
    vault {
      vault_agent_token_file = "/vault/.vault-token"
      renew_token = true
    }
    template {
      contents = <<EOH
    {{- with secret "secret/" -}}
    {{ index .Data "blabla.keytab" | base64Decode }}
    {{- end -}}
    EOH
      destination = "/vault/secrets/blabla.keytab"
    }
kind: ConfigMap
@dhpizza
Copy link
Author

dhpizza commented Oct 4, 2022

/kind bug

Copy link

Thank you for your contribution! This issue has been automatically marked as stale because it has no recent activity in the last 60 days. It will be closed in 20 days, if no further activity occurs. If this issue is still relevant, please leave a comment to let us know, and the stale label will be automatically removed.

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR that has become stale and will be auto-closed. label Jan 28, 2024
@ramizpolic
Copy link
Member

Hi @dhpizza, could you verify if this is still relevant?

@github-actions github-actions bot removed the lifecycle/stale Denotes an issue or PR that has become stale and will be auto-closed. label Feb 4, 2024
Copy link

github-actions bot commented Apr 7, 2024

Thank you for your contribution! This issue has been automatically marked as stale because it has no recent activity in the last 60 days. It will be closed in 20 days, if no further activity occurs. If this issue is still relevant, please leave a comment to let us know, and the stale label will be automatically removed.

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR that has become stale and will be auto-closed. label Apr 7, 2024
@ramizpolic ramizpolic removed the lifecycle/stale Denotes an issue or PR that has become stale and will be auto-closed. label Apr 7, 2024
@dhpizza
Copy link
Author

dhpizza commented Apr 7, 2024

Hi @dhpizza, could you verify if this is still relevant?

Hi @ramizpolic
yes still relevant, thanks

@ramizpolic ramizpolic added the kind/bug Categorizes issue or PR as related to a bug. label Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
Status: 🆕 New
Development

No branches or pull requests

2 participants