Skip to content
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

fix: Override sub with federated_claims.user_id when dex is used #20683

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

aali309
Copy link
Contributor

@aali309 aali309 commented Nov 6, 2024

Fixes: #17908

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • The title of the PR conforms to the Toolchain Guide
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).
  • My new feature complies with the feature status guidelines.
  • I have added a brief description of why this PR is necessary and/or what this PR solves.
  • Optional. My organization is added to USERS.md.
  • Optional. For bug fixes, I've indicated what older releases this fix should be cherry-picked into (this may or may not happen depending on risk/complexity).

Copy link

bunnyshell bot commented Nov 6, 2024

🔴 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

@aali309 aali309 force-pushed the ldap-rbac branch 9 times, most recently from 3f5b5c7 to dee232e Compare November 12, 2024 20:57
@aali309 aali309 force-pushed the ldap-rbac branch 2 times, most recently from eb08b64 to e374df5 Compare November 14, 2024 17:12
Copy link

codecov bot commented Nov 17, 2024

Codecov Report

Attention: Patch coverage is 74.13793% with 45 lines in your changes missing coverage. Please review.

Project coverage is 55.24%. Comparing base (8126508) to head (96efc42).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
cmd/argocd/commands/project_role.go 0.00% 15 Missing ⚠️
util/session/sessionmanager.go 80.00% 11 Missing and 3 partials ⚠️
cmd/argocd/commands/utils/claims.go 52.94% 8 Missing ⚠️
server/server.go 50.00% 7 Missing ⚠️
util/oidc/oidc.go 96.77% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #20683      +/-   ##
==========================================
+ Coverage   55.19%   55.24%   +0.04%     
==========================================
  Files         337      338       +1     
  Lines       57058    57192     +134     
==========================================
+ Hits        31496    31594      +98     
- Misses      22863    22903      +40     
+ Partials     2699     2695       -4     

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

Comment on lines 9 to 10
if federatedClaims, ok := claims["federated_claims"].(map[string]interface{}); ok {
if userID, exists := federatedClaims["user_id"].(string); exists && userID != "" {
Copy link
Member

Choose a reason for hiding this comment

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

nit: move the values "federated_claims", "user_id", "sub" to constants.

@@ -8,7 +8,7 @@ RUN ln -s /usr/lib/$(uname -m)-linux-gnu /usr/lib/linux-gnu
# Please make sure to also check the contained yarn version and update the references below when upgrading this image's version
FROM docker.io/library/node:22.9.0@sha256:69e667a79aa41ec0db50bc452a60e705ca16f35285eaf037ebe627a65a5cdf52 as node

FROM docker.io/library/golang:1.23.3@sha256:d56c3e08fe5b27729ee3834854ae8f7015af48fd651cd25d1e3bcf3c19830174 as golang
FROM docker.io/library/golang:1.23.1@sha256:4f063a24d429510e512cc730c3330292ff49f3ade3ae79bda8f84a24fa25ecb0 as golang
Copy link
Member

Choose a reason for hiding this comment

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

Is this downgrade on purpose or the PR just needs a rebase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes did it on purpose when testing virtually, I forgot to revert.

@aali309 aali309 marked this pull request as ready for review November 18, 2024 15:25
@aali309 aali309 requested a review from a team as a code owner November 18, 2024 15:25
@aali309 aali309 force-pushed the ldap-rbac branch 4 times, most recently from 4cf2359 to d131b41 Compare November 21, 2024 19:44
Copy link
Member

@ishitasequeira ishitasequeira left a comment

Choose a reason for hiding this comment

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

Overall code change looks good!!

@jannfis @pasha-codefresh do you see any concerns with the change?

@aali309 aali309 force-pushed the ldap-rbac branch 2 times, most recently from 4e8b021 to 1393382 Compare December 3, 2024 21:06
@agaudreault agaudreault self-requested a review December 4, 2024 05:17
Copy link
Member

@agaudreault agaudreault left a comment

Choose a reason for hiding this comment

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

The change from RegisterClaims to MapClaims makes this PR a lot more impactful and the blast radius is hard to grasp, especially that not the same claims seems to be added in the context object.

Comment on lines 510 to 527
// Assert that claims is of type jwt.MapClaims
mapClaims, ok := claims.(jwt.MapClaims)
if !ok {
http.Error(w, "Invalid claims type", http.StatusUnauthorized)
return
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should use MapClaims. See the comment on the RegisterClaims object

// RegisteredClaims are a structured version of the JWT Claims Set,
// restricted to Registered Claim Names, as referenced at
// https://datatracker.ietf.org/doc/html/rfc7519#section-4.1
//
// This type can be used on its own, but then additional private and
// public claims embedded in the JWT will not be parsed. The typical usecase
// therefore is to embedded this in a user-defined claim type.

basically, define a new struct

type ArgoClaims struct {
	RegisteredClaims
	OtherClaim string `json:"othet,omitempty"`
	...

@aali309 aali309 force-pushed the ldap-rbac branch 3 times, most recently from 68b2da0 to df53a24 Compare December 12, 2024 04:09
@aali309 aali309 requested a review from agaudreault December 12, 2024 04:12
@aali309 aali309 force-pushed the ldap-rbac branch 2 times, most recently from 16f3368 to 4a7e597 Compare December 19, 2024 17:51
@aali309 aali309 force-pushed the ldap-rbac branch 5 times, most recently from c6f8115 to eff4007 Compare January 6, 2025 17:09
aali309 added 17 commits January 7, 2025 08:47
Signed-off-by: Atif Ali <[email protected]>
Signed-off-by: Atif Ali <[email protected]>
Signed-off-by: Atif Ali <[email protected]>
Signed-off-by: Atif Ali <[email protected]>
Signed-off-by: Atif Ali <[email protected]>
Signed-off-by: Atif Ali <[email protected]>
Signed-off-by: Atif Ali <[email protected]>
Signed-off-by: Atif Ali <[email protected]>
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.

RBAC using LDAP is not working (Not assigning the policies)
3 participants