fix: AppProject destination restrictions allow deployment to non-allowed namespace when using negated namespaces#26772
fix: AppProject destination restrictions allow deployment to non-allowed namespace when using negated namespaces#26772aryasoni98 wants to merge 7 commits intoargoproj:masterfrom
Conversation
🔴 Preview Environment stopped on BunnyshellSee: Environment Details | Pipeline Logs Available commands (reply to this comment):
|
Signed-off-by: Kevin Joe Harris <kevinjoeharris1@gmail.com> Signed-off-by: S Kevin Joe Harris <kevinjoeharris1@gmail.com> Co-authored-by: rumstead <37445536+rumstead@users.noreply.github.com> Signed-off-by: Arya Soni <aryasoni98@gmail.com>
…amespace when using negated namespaces Signed-off-by: Arya Soni <aryasoni98@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #26772 +/- ##
==========================================
+ Coverage 62.97% 62.98% +0.01%
==========================================
Files 414 414
Lines 56154 56156 +2
==========================================
+ Hits 35362 35371 +9
+ Misses 17420 17416 -4
+ Partials 3372 3369 -3 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Thanks for the PR
I think we'll also need some doc updates
We need to call out the behavior change with something like this
Note: When combining allow rules and deny rules, deny rules can only restrict destinations already permitted by allow rules — they cannot expand the allowlist. For example, if you have allowed-ns as an allow rule and !kyverno as a deny rule, the deny entry will not grant access to namespaces other than allowed-ns. If you want to allow everything except specific namespaces, use an explicit wildcard allow rule paired with deny rules:
Ex.
destinations:
- {server: "", namespace: ""} # allow all
- {server: "*", namespace: "!kyverno"} # except kyverno
in docs/user-guide/projects.md
…wed namespace when using negated namespaces Signed-off-by: Arya Soni <aryasoni98@gmail.com>
Closes #26743
When using AppProject destination restrictions with a whitelist namespace and negated namespaces (e.g.
allowed-ns+!kyverno+!argocd), Argo CD incorrectly allowed resources to be deployed into namespaces not explicitly allowed (e.g.not-allowed-ns). Deny rules were being treated as allow rules and expanded permissions instead of restricting them.Per the documentation, a destination is valid only if: (1) an allow rule matches, and (2) no deny rule rejects it. This fix ensures deny rules can only reject destinations and never permit them.
Issue: In
isDestinationMatched, when a deny pattern like!kyvernowas checked against a non-matching namespace likenot-allowed-ns,globMatchreturnedtrue(because the destination doesn't match the denied pattern). The code incorrectly treated this as an allow match and setanyDestinationMatched = true.Fix: Only set
anyDestinationMatchedwhen the matched rule has a non-deny namespace pattern. Deny rules can now only reject, never permit.Checklist: