Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions vault/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ func AuthChecker() gin.HandlerFunc {
return
}
setAuthContext(c, token, claims)
if !RequestTokenHasAudience(c, config.SentinelClientID) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Accept Vault in any audience position

When Sentinel returns a valid multi-valued aud claim such as ["another-service", config.SentinelClientID], this rejects the token because setAuthContext stores only audiences[0] and RequestTokenHasAudience compares only that value. JWT audience arrays are unordered sets of intended recipients, so the middleware should test every value returned by claimStringSlice rather than requiring Vault to be first.

Useful? React with 👍 / 👎.

c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "token is not intended for Vault"})
return
}
logger.SugarLogger.Infof("Decoded token: entity=%s audience=%s scope=%s", GetRequestTokenEntityID(c), GetRequestTokenAudience(c), GetRequestTokenScopes(c))
}
c.Next()
Expand Down Expand Up @@ -176,15 +180,6 @@ func RequestTokenExists(c *gin.Context) bool {
return exists
}

func RequestTokenHasScope(c *gin.Context, scope string) bool {
for _, tokenScope := range strings.Fields(GetRequestTokenScopes(c)) {
if tokenScope == scope {
return true
}
}
return false
}

func RequestTokenHasAudience(c *gin.Context, audience string) bool {
return GetRequestTokenAudience(c) == audience
}
Expand Down Expand Up @@ -215,9 +210,6 @@ func RequestTokenCanAccessAccount(c *gin.Context, account model.Account) bool {
if !RequestTokenExists(c) {
return false
}
if RequestTokenHasScope(c, "sentinel:all") {
return true
}
if RequestTokenHasGroupName(c, "Admins") {
return true
}
Expand All @@ -231,9 +223,6 @@ func RequestTokenCanAccessApplication(c *gin.Context, application model.Applicat
if !RequestTokenExists(c) {
return false
}
if RequestTokenHasScope(c, "sentinel:all") {
return true
}
if RequestTokenHasGroupName(c, "Admins") {
return true
}
Expand All @@ -244,11 +233,11 @@ func RequestTokenCanAccessApplication(c *gin.Context, application model.Applicat
}

func RequestTokenCanViewAuditLogs(c *gin.Context) bool {
return RequestTokenHasScope(c, "sentinel:all") || RequestTokenHasGroupName(c, "Admins")
return RequestTokenHasGroupName(c, "Admins")
}

func RequestTokenCanManageSettings(c *gin.Context) bool {
return RequestTokenHasScope(c, "sentinel:all") || RequestTokenHasGroupName(c, "Admins")
return RequestTokenHasGroupName(c, "Admins")
}

func RequestTokenCanManageGitHubActionsRules(c *gin.Context) bool {
Expand Down
Loading