Skip to content

fix(rbac): resolve RBAC regression for project-scoped resources in multi-namespace architecture (#25289)#26573

Open
tcfwbper wants to merge 13 commits intoargoproj:masterfrom
tcfwbper:fix/25289-rbac-logs-any-namespace
Open

fix(rbac): resolve RBAC regression for project-scoped resources in multi-namespace architecture (#25289)#26573
tcfwbper wants to merge 13 commits intoargoproj:masterfrom
tcfwbper:fix/25289-rbac-logs-any-namespace

Conversation

@tcfwbper
Copy link

Summary

This PR fixes the RBAC regression for project-scoped resources in multi-namespace architecture (#25289)

The issue was caused by inappropriate migration when we introduced "applications in any namespaces".
I have updated the following areas to restore the expected behavior:

  • Normalize policies when we load them from Configmap, AppProj, or CLI to ensure this pattern "proj/ns/app" without lossing backward compatibility.
  • Aways verify permissions using "proj/ns/app".
  • Added unit tests for policy normalization and updated current unit tests.

Checklist

Fixes #25289

@tcfwbper tcfwbper requested review from a team as code owners February 23, 2026 14:00
@bunnyshell
Copy link

bunnyshell bot commented Feb 23, 2026

🔴 Preview Environment stopped on Bunnyshell

See: Environment Details | Pipeline Logs

Available commands (reply to this comment):

  • 🔵 /bns:start to start the environment
  • 🚀 /bns:deploy to redeploy the environment
  • /bns:delete to remove the environment

@codecov
Copy link

codecov bot commented Feb 23, 2026

Codecov Report

❌ Patch coverage is 97.14286% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.21%. Comparing base (8739f91) to head (b3cbc2a).
⚠️ Report is 43 commits behind head on master.

Files with missing lines Patch % Lines
cmd/argocd/commands/admin/project.go 83.33% 1 Missing ⚠️
cmd/argocd/commands/admin/settings_rbac.go 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #26573      +/-   ##
==========================================
+ Coverage   63.00%   63.21%   +0.21%     
==========================================
  Files         414      414              
  Lines       56153    56480     +327     
==========================================
+ Hits        35378    35703     +325     
+ Misses      17410    17405       -5     
- Partials     3365     3372       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tcfwbper tcfwbper force-pushed the fix/25289-rbac-logs-any-namespace branch from d9e4ade to 8a5caa5 Compare March 2, 2026 12:27
tcfwbper added 10 commits March 12, 2026 23:14
Signed-off-by: tcfwbper <pesci861207@gmail.com>
… proj/ns/app

Signed-off-by: tcfwbper <pesci861207@gmail.com>
… project-scoped resources

Signed-off-by: tcfwbper <pesci861207@gmail.com>
Signed-off-by: tcfwbper <pesci861207@gmail.com>
Signed-off-by: tcfwbper <pesci861207@gmail.com>
Signed-off-by: tcfwbper <pesci861207@gmail.com>
Signed-off-by: tcfwbper <pesci861207@gmail.com>
Signed-off-by: tcfwbper <pesci861207@gmail.com>
Signed-off-by: tcfwbper <pesci861207@gmail.com>
Signed-off-by: tcfwbper <pesci861207@gmail.com>
@tcfwbper tcfwbper force-pushed the fix/25289-rbac-logs-any-namespace branch from 8a5caa5 to 50cc3d7 Compare March 12, 2026 15:34
…ication_SetWithNormalization.

Signed-off-by: tcfwbper <pesci861207@gmail.com>
@tcfwbper tcfwbper force-pushed the fix/25289-rbac-logs-any-namespace branch from e120870 to 3bd0def Compare March 12, 2026 15:46
@afzal442 afzal442 self-requested a review March 15, 2026 13:59
@tcfwbper
Copy link
Author

Dear reviewers, this guide might help you speed up reviewing.

The core changes of this PR are:

  1. Load Policy
    • from argocd-rbac-cm (util/rbac/rbac.go)
    • from appproj (pkg/apis/application/v1alpha1/app_project_types.go)
  2. CLI
    • argocd admin proj (cmd/argocd/commands/admin/project.go)
    • argocd admin settings (cmd/argocd/commands/admin/settings_rbac.go)
  3. API calls
    • API server: authz verification requests (server/account/account.go)
    • RBACName: generate RBAC resource name for API calls (util/security/rbac.go)
  4. Buildin policies (assets/builtin-policy.csv)
  5. e2e tests (test/e2e/accounts_test.go)

Almost other changes are corresponding adjustment for unit tests

@tcfwbper
Copy link
Author

tcfwbper commented Mar 15, 2026

FYI, I had some tests in my local environment.

Setup:

  • accounts: admin, tester (non-admin local account)
  • appproj: my-project
  • app: test-app in argocd (default ns), test-app in my-app-team (any-ns)

Experiment:
adjust policies defined in appproj
a. "my-project/*/test-app"
b. "my-project/my-app-team/test-app"
c. "my-project/argocd/test-app"
d. "my-project/test-app"
then, try to get applications/logs from UI/CLI

Results: all of the results are as expected

Screen.Recording.2026-03-15.at.11.39.38.PM.mov
Screen.Recording.2026-03-15.at.11.55.22.PM.-.Compressed.with.FlexClip.mp4

normalizedPolicy = component
} else {
normalizedPolicy = fmt.Sprintf("%s, %s", normalizedPolicy, strings.Trim(component, " "))
if _, ok := seen[normalizedPolicy]; ok {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if _, ok := seen[normalizedPolicy]; ok {
for i, role := range proj.Spec.Roles {
proj.Spec.Roles[i].Policies = normalizeUniquePolicies(role.Policies, proj.Namespace)
}

}
return false, nil
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// normalizeUniquePolicies normalizes and deduplicates a slice of policy strings.
func normalizeUniquePolicies(policies []string, namespace string) []string {
watched := make(map[string]struct{}, len(policies))
result := make([]string, 0, len(policies))
for _, policy := range policies {
normalized := rbac.NormalizePolicy(policy, namespace)
if _, ok := watched[normalized]; ok {
continue
}
watched[normalized] = struct{}{}
result = append(result, normalized)
}
return result
}

Signed-off-by: Afzal Ansari <afzal442@gmail.com>
@tcfwbper tcfwbper requested a review from afzal442 March 18, 2026 15:23
Signed-off-by: tcfwbper <pesci861207@gmail.com>
Copy link
Member

@afzal442 afzal442 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Work like a charm. 🎉 Thanks @tcfwbper

@afzal442 afzal442 requested a review from ishitasequeira March 19, 2026 00:03
@afzal442
Copy link
Member

@ishitasequeira tagged you since you reviewed the approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AppProject RBAC Policy to get logs does not work as documented for an 'Applications in any namespace' setup

2 participants