mirror of
https://github.com/argoproj/argo-cd
synced 2026-04-21 17:07:16 +00:00
Expand RBAC role to be able to create application events. Fix username claims extraction. (#479)
This commit is contained in:
parent
9f5a718323
commit
00299707e5
6 changed files with 46 additions and 20 deletions
2
VERSION
2
VERSION
|
|
@ -1 +1 @@
|
|||
0.7.0
|
||||
0.7.1
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ func NewApplicationController(
|
|||
statusRefreshTimeout: appResyncPeriod,
|
||||
forceRefreshApps: make(map[string]bool),
|
||||
forceRefreshAppsMutex: &sync.Mutex{},
|
||||
auditLogger: argo.NewAuditLogger(namespace, kubeClientset, "appcontroller"),
|
||||
auditLogger: argo.NewAuditLogger(namespace, kubeClientset, "application-controller"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,3 +27,11 @@ rules:
|
|||
- update
|
||||
- patch
|
||||
- delete
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
- events
|
||||
verbs:
|
||||
- create
|
||||
- list
|
||||
|
||||
|
|
|
|||
|
|
@ -30,3 +30,10 @@ rules:
|
|||
- update
|
||||
- delete
|
||||
- patch
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
- events
|
||||
verbs:
|
||||
- create
|
||||
- list
|
||||
|
|
|
|||
|
|
@ -126,6 +126,14 @@ rules:
|
|||
- update
|
||||
- patch
|
||||
- delete
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
- events
|
||||
verbs:
|
||||
- create
|
||||
- list
|
||||
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: RoleBinding
|
||||
|
|
@ -194,6 +202,13 @@ rules:
|
|||
- update
|
||||
- delete
|
||||
- patch
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
- events
|
||||
verbs:
|
||||
- create
|
||||
- list
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: RoleBinding
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import (
|
|||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/argoproj/argo-cd/common"
|
||||
jwtutil "github.com/argoproj/argo-cd/util/jwt"
|
||||
passwordutil "github.com/argoproj/argo-cd/util/password"
|
||||
"github.com/argoproj/argo-cd/util/settings"
|
||||
)
|
||||
|
|
@ -166,26 +167,21 @@ func (mgr *SessionManager) VerifyToken(tokenString string) (jwt.Claims, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func stringFromMap(input map[string]interface{}, key string) string {
|
||||
if val, ok := input[key]; ok {
|
||||
if res, ok := val.(string); ok {
|
||||
return res
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func Username(ctx context.Context) string {
|
||||
if claims, ok := ctx.Value("claims").(*jwt.MapClaims); ok {
|
||||
mapClaims := *claims
|
||||
switch stringFromMap(mapClaims, "iss") {
|
||||
case SessionManagerClaimsIssuer:
|
||||
return stringFromMap(mapClaims, "sub")
|
||||
default:
|
||||
return stringFromMap(mapClaims, "email")
|
||||
}
|
||||
claims, ok := ctx.Value("claims").(jwt.Claims)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
mapClaims, err := jwtutil.MapClaims(claims)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
switch jwtutil.GetField(mapClaims, "iss") {
|
||||
case SessionManagerClaimsIssuer:
|
||||
return jwtutil.GetField(mapClaims, "sub")
|
||||
default:
|
||||
return jwtutil.GetField(mapClaims, "email")
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// MakeCookieMetadata generates a string representing a Web cookie. Yum!
|
||||
|
|
|
|||
Loading…
Reference in a new issue