Skip to content

Commit

Permalink
Simplify authorization and cleanup unused methods (#1824)
Browse files Browse the repository at this point in the history
Use method that checks admin role, since that's the only role currently used.
  • Loading branch information
eleftherias authored Dec 5, 2023
1 parent b95e993 commit c98205d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 15 deletions.
14 changes: 0 additions & 14 deletions internal/auth/jwtauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/lestrrat-go/jwx/v2/jwt/openid"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"golang.org/x/exp/slices"

"github.com/stacklok/minder/internal/constants"
"github.com/stacklok/minder/internal/util"
Expand Down Expand Up @@ -152,19 +151,6 @@ func GetDefaultProject(ctx context.Context) (uuid.UUID, error) {
return permissions.ProjectIds[0], nil
}

// IsAuthorizedForProject returns true if the user is authorized for the given project
func IsAuthorizedForProject(ctx context.Context, projectID uuid.UUID) bool {
permissions := GetPermissionsFromContext(ctx)

return slices.Contains(permissions.ProjectIds, projectID)
}

// GetUserProjects returns all the projects where a user belongs to
func GetUserProjects(ctx context.Context) ([]uuid.UUID, error) {
permissions := GetPermissionsFromContext(ctx)
return permissions.ProjectIds, nil
}

// UserDetails is a helper struct for getting user details
type UserDetails struct {
Name string
Expand Down
2 changes: 1 addition & 1 deletion internal/controlplane/handlers_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (s *Server) ensureDefaultProjectForContext(ctx context.Context, inout *mind
// verifyValidProject verifies that the project is valid and the user is authorized to access it
// TODO: This will have to change once we have the hierarchy tree in place.
func verifyValidProject(ctx context.Context, in *engine.EntityContext) error {
if !auth.IsAuthorizedForProject(ctx, in.GetProject().GetID()) {
if err := AuthorizedOnProject(ctx, in.GetProject().GetID()); err != nil {
return status.Errorf(codes.PermissionDenied, "user is not authorized to access this resource")
}

Expand Down

0 comments on commit c98205d

Please sign in to comment.