RemoveOrphanedConfigMaps doesn't verify object UID

Open
#2,845 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
62/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
go, kubernetes

Research direction

Start at the finalize.RemoveOrphanedConfigMaps call in internal/controller/operator/factory/vmalert/vmalert.go around line 188, then read that helper to see how owner references are compared during ConfigMap cleanup. The fix is to require the live owner's UID, not just API version/kind/name, before deleting; add or extend tests covering a same-name foreign or stale ConfigMap. Run the package's Go tests to confirm orphan cleanup still removes true orphans.

Written by the indexing model from the issue text.

Description

P2: This cleanup trusts only the owner reference's API version, kind, and name, not its UID. A stale or foreign ConfigMap with a same-name VMAlert owner reference can therefore be deleted; require the current owner's UID before enabling deletion here.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At internal/controller/operator/factory/vmalert/vmalert.go, line 188:

<comment>This cleanup trusts only the owner reference's API version, kind, and name, not its UID. A stale or foreign ConfigMap with a same-name VMAlert owner reference can therefore be deleted; require the current owner's UID before enabling deletion here.</comment>

<file context>
@@ -182,7 +182,13 @@ func CreateOrUpdate(ctx context.Context, cr *vmv1beta1.VMAlert, rclient client.C
+	if err := reconcile.Deployment(ctx, rclient, newDeploy, prevDeploy, &owner, nil); err != nil {
+		return err
+	}
+	if err := finalize.RemoveOrphanedConfigMaps(ctx, rclient, cr, sets.New(cmNames...), true); err != nil {
+		return fmt.Errorf("cannot remove rule configmaps: %w", err)
+	}
</file context>
Fix with cubic

Originally posted by @cubic-dev-ai[bot] in https://github.com/VictoriaMetrics/operator/pull/2844#discussion_r4642778933

Dominant language
Go
Stars
603
Forks
242
Avg merge
1d 14h
Merged PRs (30d)
57

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from VictoriaMetrics/operator

All issues in VictoriaMetrics/operator

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.