Skip to content

Commit

Permalink
refactor claims to use const and dockerfile proper version
Browse files Browse the repository at this point in the history
Signed-off-by: Atif Ali <atali@redhat.com>
  • Loading branch information
aali309 committed Nov 25, 2024
1 parent 415ebbb commit 57ce118
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions cmd/argocd/commands/utils/claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ import (
"github.com/golang-jwt/jwt/v4"
)

const (
federatedClaimsKey = "federated_claims"
userIDKey = "user_id"
subKey = "sub"
)

// GetUserIdentifier returns a consistent user identifier, checking federated_claims.user_id when Dex is in use
func GetUserIdentifier(claims jwt.MapClaims) string {
if federatedClaims, ok := claims["federated_claims"].(map[string]interface{}); ok {
if userID, exists := federatedClaims["user_id"].(string); exists && userID != "" {
if federatedClaims, ok := claims[federatedClaimsKey].(map[string]interface{}); ok {
if userID, exists := federatedClaims[userIDKey].(string); exists && userID != "" {
return userID
}
}
// Fallback to sub
if sub, ok := claims["sub"].(string); ok && sub != "" {
if sub, ok := claims[subKey].(string); ok && sub != "" {
return sub
}
return ""
Expand Down
2 changes: 1 addition & 1 deletion test/container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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.1@sha256:4f063a24d429510e512cc730c3330292ff49f3ade3ae79bda8f84a24fa25ecb0 as golang
FROM docker.io/library/golang:1.23.3@sha256:d56c3e08fe5b27729ee3834854ae8f7015af48fd651cd25d1e3bcf3c19830174 as golang

FROM docker.io/library/registry:2.8@sha256:ac0192b549007e22998eb74e8d8488dcfe70f1489520c3b144a6047ac5efbe90 as registry

Expand Down

0 comments on commit 57ce118

Please sign in to comment.