-
Notifications
You must be signed in to change notification settings - Fork 7.3k
feat: disambiguate local users from SSO users in RBAC with strict mode #28233
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
Open
christianh814
wants to merge
5
commits into
argoproj:master
Choose a base branch
from
christianh814:feat/unambiguate-local-users
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a00bcd8
Added the ability to disambiguate local users to that RBAC can differ…
christianh814 51c4f00
Merge branch 'master' into feat/unambiguate-local-users
christianh814 7e0ff0d
Merge branch 'master' into feat/unambiguate-local-users
christianh814 9c9fd04
Merge branch 'master' into feat/unambiguate-local-users
christianh814 2d1f7f4
Merge branch 'master' into feat/unambiguate-local-users
christianh814 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package session | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/golang-jwt/jwt/v5" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/client-go/kubernetes/fake" | ||
|
|
||
| "github.com/argoproj/argo-cd/v3/common" | ||
| "github.com/argoproj/argo-cd/v3/server/rbacpolicy" | ||
| "github.com/argoproj/argo-cd/v3/util/rbac" | ||
| sessionmgr "github.com/argoproj/argo-cd/v3/util/session" | ||
| "github.com/argoproj/argo-cd/v3/util/settings" | ||
| ) | ||
|
|
||
| func newTestSessionServer(t *testing.T, cmData map[string]string) *Server { | ||
| t.Helper() | ||
| const ns = "default" | ||
| kubeClient := fake.NewClientset( | ||
| &corev1.ConfigMap{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: common.ArgoCDConfigMapName, | ||
| Namespace: ns, | ||
| Labels: map[string]string{"app.kubernetes.io/part-of": "argocd"}, | ||
| }, | ||
| Data: cmData, | ||
| }, | ||
| &corev1.Secret{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: common.ArgoCDSecretName, | ||
| Namespace: ns, | ||
| }, | ||
| Data: map[string][]byte{"server.secretkey": []byte("test")}, | ||
| }, | ||
| ) | ||
| settingsMgr := settings.NewSettingsManager(t.Context(), kubeClient, ns) | ||
| enf := rbac.NewEnforcer(kubeClient, ns, common.ArgoCDConfigMapName, nil) | ||
| policyEnf := rbacpolicy.NewRBACPolicyEnforcer(enf, nil) | ||
| return NewServer(nil, settingsMgr, nil, policyEnf, nil) | ||
| } | ||
|
|
||
| func ctxWithClaims(claims jwt.MapClaims) context.Context { | ||
| //nolint:staticcheck // the production code reads the "claims" string key from context | ||
| return context.WithValue(context.Background(), "claims", claims) | ||
| } | ||
|
|
||
| func TestGetUserInfo_LocalUserStrictMode(t *testing.T) { | ||
| localClaims := jwt.MapClaims{"sub": "sally", "iss": sessionmgr.SessionManagerClaimsIssuer} | ||
| ssoClaims := jwt.MapClaims{"sub": "sally", "iss": "https://accounts.google.com", "email": "sally@example.com"} | ||
|
|
||
| t.Run("strict mode appends @local for local accounts", func(t *testing.T) { | ||
| s := newTestSessionServer(t, map[string]string{"rbac.local.user.strictmode": "true"}) | ||
| resp, err := s.GetUserInfo(ctxWithClaims(localClaims), nil) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, "sally@local", resp.Username) | ||
| assert.Equal(t, sessionmgr.SessionManagerClaimsIssuer, resp.Iss) | ||
| }) | ||
|
|
||
| t.Run("strict mode does not affect SSO users", func(t *testing.T) { | ||
| s := newTestSessionServer(t, map[string]string{"rbac.local.user.strictmode": "true"}) | ||
| resp, err := s.GetUserInfo(ctxWithClaims(ssoClaims), nil) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, "sally@example.com", resp.Username) | ||
| }) | ||
|
|
||
| t.Run("strict mode disabled leaves local username unchanged", func(t *testing.T) { | ||
| s := newTestSessionServer(t, map[string]string{}) | ||
| resp, err := s.GetUserInfo(ctxWithClaims(localClaims), nil) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, "sally", resp.Username) | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a UI expert but is this change correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The panel only renders for the logged-in local user (
iss === 'argocd'), so this is always a self-service password change.Passing an empty name tells the backend's
UpdatePasswordto resolve the account from the authenticated token instead of a client-supplied name. This is needed because the new strict mode now displaysuserInfo.usernameassally@local(for example), which would no longer match the real account name (e.g.sally) and would break the update.Empty name is correct in both strict and non-strict modes.