Tag Retention rule with Tags: excluding ** marks genuinely tagged artifacts for deletion, in both untagged artifacts checkbox states
I set up a Tag Retention rule with Tags: excluding **, expecting it to only ever touch untagged artifacts (since ** matches literally any tag, so nothing with a real tag should get selected under excluding). Instead it's marking real, tagged artifacts for deletion.
I tried it with the untagged artifacts checkbox both checked and unchecked, thinking one of them had to be right - nope, both are broken, just in slightly different ways:
- Checkbox checked: ran a dry run on a repo with exactly 2 artifacts, both tagged, no untagged ones at all. Both got marked DEL.
- Checkbox unchecked: ran a dry run across 5 repos that only have normal tagged releases (e.g. 1.0.0 - 1.25.0). Every single artifact in every repo came back DEL - 0 retained out of the full count, every time.
So basically no matter how I set that checkbox, tagged stuff gets deleted, which seems... really not okay for a feature whose whole point is "only clean up the untagged junk."
Steps to reproduce the problem:
- Project with a few repos that only have normal tagged artifacts (no untagged ones sitting around).
- Policy - Tag Retention - Add Rule: For the repositories: matching ** By artifact count: retain the most recently pushed 0 artifacts Tags: excluding **
- Leave untagged artifacts unchecked.
- Save it, hit Dry Run.
- Open any repo's log - tagged artifacts show up as Retention: DEL.
- Flip the untagged artifacts checkbox on and dry-run again - same problem, just now on a repo that only has 2 artifacts total (both tagged), both get flagged.
Versions:
- harbor version: v2.5.4
- Running via the Helm chart on k8s, not docker-compose, so those version fields don't really apply here.
Additional context:
Went and looked at src/lib/selector/selectors/doublestar/selector.go (tagSelectExclude) to see if I was misunderstanding the checkbox, and as far as I can tell the code says a tagged artifact should only be selected if one of its tags does not match the pattern - which shouldn't ever happen with **. Checked this against both the v2.5.4 tag and current main, same code either way, so it's not like this got fixed/broken between versions. Whatever's actually happening doesn't match what that function looks like it does, so I might be missing something, but wanted to flag it either way since the practical effect (silently deleting tagged images) seems bad enough to be worth a second pair of eyes.
Possibly related: #22051 - different symptom (untagged getting protected instead of tagged getting deleted) but same selector code and same general "excluding + tagged/untagged doesn't behave right" flavor. I see comments there mentioned the untagged handling needs "finer control," which lines up with what I'm seeing.
Source: goharbor/harbor