Skip to content

Commit

Permalink
Add some diagnostic logs for missing group_id (#7981)
Browse files Browse the repository at this point in the history
Could not repro this locally, so adding some diagnostic logs.

Related:
buildbuddy-io/buildbuddy-internal#4191
  • Loading branch information
bduffany authored Dec 2, 2024
1 parent 3a07358 commit 581a356
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions server/util/claims/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ go_library(
"//server/util/authutil",
"//server/util/capabilities",
"//server/util/flag",
"//server/util/log",
"//server/util/lru",
"//server/util/request_context",
"//server/util/role",
Expand Down
24 changes: 18 additions & 6 deletions server/util/claims/claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/buildbuddy-io/buildbuddy/server/util/authutil"
"github.com/buildbuddy-io/buildbuddy/server/util/capabilities"
"github.com/buildbuddy-io/buildbuddy/server/util/flag"
"github.com/buildbuddy-io/buildbuddy/server/util/log"
"github.com/buildbuddy-io/buildbuddy/server/util/lru"
"github.com/buildbuddy-io/buildbuddy/server/util/role"
"github.com/buildbuddy-io/buildbuddy/server/util/status"
Expand Down Expand Up @@ -177,11 +178,22 @@ func ClaimsFromSubID(ctx context.Context, env environment.Env, subID string) (*C
if err != nil {
return nil, err
}

requestContext := requestcontext.ProtoRequestContextFromContext(ctx)
// TODO(https://github.com/buildbuddy-io/buildbuddy-internal/issues/4191):
// return an error here once we have a better understanding of why the
// request context can be missing.
if requestContext == nil {
log.CtxInfof(ctx, "Request is missing request context")
} else if requestContext.GetGroupId() == "" {
log.CtxInfof(ctx, "Request context group ID is empty")
}

eg := ""
if c := requestcontext.ProtoRequestContextFromContext(ctx); c != nil && c.GetGroupId() != "" {
if requestContext.GetGroupId() != "" {
for _, g := range u.Groups {
if g.Group.GroupID == c.GetGroupId() {
eg = c.GetGroupId()
if g.Group.GroupID == requestContext.GetGroupId() {
eg = requestContext.GetGroupId()
}
}
}
Expand All @@ -194,13 +206,13 @@ func ClaimsFromSubID(ctx context.Context, env environment.Env, subID string) (*C
// If the user is trying to impersonate a member of another org and has Admin
// role within the configured admin group, set their authenticated user to
// *only* have access to the org being impersonated.
if c := requestcontext.ProtoRequestContextFromContext(ctx); c != nil && c.GetImpersonatingGroupId() != "" {
if requestContext.GetImpersonatingGroupId() != "" {
for _, membership := range claims.GetGroupMemberships() {
if membership.GroupID != env.GetAuthenticator().AdminGroupID() || membership.Role != role.Admin {
continue
}

ig, err := env.GetUserDB().GetGroupByID(ctx, c.GetImpersonatingGroupId())
ig, err := env.GetUserDB().GetGroupByID(ctx, requestContext.GetImpersonatingGroupId())
if err != nil {
return nil, err
}
Expand All @@ -215,7 +227,7 @@ func ClaimsFromSubID(ctx context.Context, env environment.Env, subID string) (*C
Group: *ig,
Role: uint32(role.Admin),
}}
claims, err := userClaims(u, c.GetImpersonatingGroupId())
claims, err := userClaims(u, requestContext.GetImpersonatingGroupId())
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 581a356

Please sign in to comment.