Skip to content

Commit

Permalink
Output user-friendly error messages if default project cannot be dete…
Browse files Browse the repository at this point in the history
…rmined.
  • Loading branch information
JAORMX committed Feb 2, 2024
1 parent ae93ea4 commit b86eba5
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions internal/controlplane/handlers_authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,24 @@ func getProjectFromRequestOrDefault(

userInfo, err := store.GetUserBySubject(ctx, subject)
if err != nil {
return uuid.UUID{}, status.Errorf(codes.NotFound, "user not found")
// Note that we're revealing that the user is not registered in minder
// since the caller has a valid token (this is checked in earlier middleware).
// Therefore, we assume it's safe output that the user is not found.
return uuid.UUID{}, util.UserVisibleError(codes.NotFound, "user not found")
}
projects, err := authzClient.ProjectsForUser(ctx, userInfo.IdentitySubject)
if err != nil {
return uuid.UUID{}, status.Errorf(codes.NotFound, "cannot find projects for user")
return uuid.UUID{}, status.Errorf(codes.Internal, "cannot find projects for user")
}

if len(projects) == 0 {
return uuid.UUID{}, util.UserVisibleError(codes.PermissionDenied, "User has no role grants in projects")
}

if len(projects) != 1 {
return uuid.UUID{}, status.Errorf(codes.InvalidArgument, "cannot get default project")
return uuid.UUID{}, util.UserVisibleError(codes.PermissionDenied, "Cannot determine default project. Please specify one.")
}

return projects[0], nil
}

Expand Down

0 comments on commit b86eba5

Please sign in to comment.