Skip to content
Open
Show file tree
Hide file tree
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
21 changes: 12 additions & 9 deletions app/controlplane/internal/service/cascredential.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,23 @@ func (s *CASCredentialsService) Get(ctx context.Context, req *pb.CASCredentialsS
projectIDs[orgID] = []uuid.UUID{*currentAPIToken.ProjectID}
}
mapping, err = s.casMappingUC.FindCASMappingForDownloadByOrg(ctx, req.Digest, []uuid.UUID{orgID}, projectIDs)
}

if err != nil && !biz.IsNotFound(err) {
if biz.IsErrValidation(err) {
return nil, errors.BadRequest("invalid", err.Error())
if err != nil && !biz.IsNotFound(err) {
if biz.IsErrValidation(err) {
return nil, errors.BadRequest("invalid", err.Error())
}
return nil, handleUseCaseErr(err, s.log)
}
return nil, handleUseCaseErr(err, s.log)
}

if mapping != nil {
backend = mapping.CASBackend
} else if authz.Role(currentAuthzSubject).IsAdmin() {
// fallback to default mapping for admins
backend = defaultBackend
} else {
// fallback to default backend if the user or the token is allowed to
if ok, err := s.authzUC.Enforce(ctx, currentAuthzSubject, authz.PolicyDefaultBackendArtifactRead); err != nil {
Copy link
Member Author

Choose a reason for hiding this comment

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

this will allow us to customize API tokens with PolicyDefaultBackendArtifactRead

return nil, handleUseCaseErr(err, s.log)
} else if ok {
backend = defaultBackend
}
}
case casJWT.Uploader:
backend = defaultBackend
Expand Down
5 changes: 5 additions & 0 deletions app/controlplane/pkg/authz/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const (
ResourceAPIToken = "api_token"
ResourceProjectMembership = "project_membership"
ResourceOrganizationInvitations = "organization_invitations"
ResourceDefaultBackend = "default_backend"

// Top level instance admin role
// this is used to know if an user is a super admin of the chainloop instance
Expand Down Expand Up @@ -107,6 +108,8 @@ var (
// Artifact
PolicyArtifactDownload = &Policy{ResourceCASArtifact, ActionRead}
PolicyArtifactUpload = &Policy{ResourceCASArtifact, ActionCreate}
// Being able to read from the default backend
PolicyDefaultBackendArtifactRead = &Policy{ResourceDefaultBackend, ActionRead}
// CAS backend
PolicyCASBackendList = &Policy{ResourceCASBackend, ActionList}
PolicyCASBackendUpdate = &Policy{ResourceCASBackend, ActionUpdate}
Expand Down Expand Up @@ -198,6 +201,8 @@ var RolesMap = map[Role][]*Policy{
PolicyArtifactUpload,
// We manually check this policy to be able to know if the user can invite users to the system
PolicyOrganizationInvitationsCreate,
// Being able to read from the default backend
PolicyDefaultBackendArtifactRead,
// + all the policies from the viewer role inherited automatically
},
// RoleViewer is an org-scoped role that provides read-only access to all resources
Expand Down
Loading