Skip to content
Merged
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
155 changes: 86 additions & 69 deletions app/controlplane/api/controlplane/v1/organization.pb.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions app/controlplane/api/controlplane/v1/organization.proto
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ message OrganizationServiceUpdateRequest {

// prevent workflows and projects from being created implicitly during attestation init
optional bool prevent_implicit_workflow_creation = 5;

// restrict_contract_creation_to_org_admins restricts contract creation (org-level and project-level) to only organization admins (owner/admin roles)
optional bool restrict_contract_creation_to_org_admins = 6;
}

message OrganizationServiceUpdateResponse {
Expand Down
330 changes: 172 additions & 158 deletions app/controlplane/api/controlplane/v1/response_messages.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions app/controlplane/api/controlplane/v1/response_messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ message OrgItem {
repeated string policy_allowed_hostnames = 5;
// prevent workflows and projects from being created implicitly during attestation init
bool prevent_implicit_workflow_creation = 7;
// restrict_contract_creation_to_org_admins restricts contract creation (org-level and project-level) to only organization admins (owner/admin roles)
bool restrict_contract_creation_to_org_admins = 8;

enum PolicyViolationBlockingStrategy {
POLICY_VIOLATION_BLOCKING_STRATEGY_UNSPECIFIED = 0;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions app/controlplane/cmd/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 19 additions & 6 deletions app/controlplane/internal/service/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type AttestationService struct {
projectVersionUseCase *biz.ProjectVersionUseCase
projectUseCase *biz.ProjectUseCase
signingUseCase *biz.SigningUseCase
userUseCase *biz.UserUseCase
}

type NewAttestationServiceOpts struct {
Expand All @@ -78,6 +79,7 @@ type NewAttestationServiceOpts struct {
ProjectUC *biz.ProjectUseCase
ProjectVersionUC *biz.ProjectVersionUseCase
SigningUseCase *biz.SigningUseCase
UserUC *biz.UserUseCase
Opts []NewOpt
}

Expand All @@ -100,6 +102,7 @@ func NewAttestationService(opts *NewAttestationServiceOpts) *AttestationService
projectUseCase: opts.ProjectUC,
projectVersionUseCase: opts.ProjectVersionUC,
signingUseCase: opts.SigningUseCase,
userUseCase: opts.UserUC,
}
}

Expand Down Expand Up @@ -748,14 +751,21 @@ func (s *AttestationService) FindOrCreateWorkflow(ctx context.Context, req *cpAP
return &cpAPI.FindOrCreateWorkflowResponse{Result: bizWorkflowToPb(wf)}, nil
}

// Get organization
org, err := s.orgUseCase.FindByID(ctx, apiToken.OrgID)
if err != nil {
return nil, handleUseCaseErr(err, s.log)
}

// the workflow does not exist, let's create it alongside its project and contract
createOpts := &biz.WorkflowCreateOpts{
OrgID: apiToken.OrgID,
Name: req.GetWorkflowName(),
Project: req.GetProjectName(),
ContractName: req.GetContractName(),
ContractBytes: req.GetContractBytes(),
ImplicitCreation: true, // Mark as implicit creation from attestation init
OrgID: apiToken.OrgID,
Name: req.GetWorkflowName(),
Project: req.GetProjectName(),
ContractName: req.GetContractName(),
ContractBytes: req.GetContractBytes(),
ImplicitCreation: true, // Mark as implicit creation from attestation init
OrgRestrictContractCreationToAdmins: org.RestrictContractCreationToOrgAdmins,
}

// set project owner if RBAC is enabled
Expand All @@ -766,6 +776,9 @@ func (s *AttestationService) FindOrCreateWorkflow(ctx context.Context, req *cpAP
return nil, handleUseCaseErr(err, s.log)
}
createOpts.Owner = &userID

// Check if user is an org admin
createOpts.UserIsOrgAdmin = isUserOrgAdmin(ctx)
}

wf, err := s.workflowUseCase.Create(ctx, createOpts)
Expand Down
9 changes: 5 additions & 4 deletions app/controlplane/internal/service/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ func (s *ContextService) Current(ctx context.Context, _ *pb.ContextServiceCurren

func bizOrgToPb(m *biz.Organization) *pb.OrgItem {
return &pb.OrgItem{Id: m.ID, Name: m.Name, CreatedAt: timestamppb.New(*m.CreatedAt),
UpdatedAt: timestamppb.New(*m.UpdatedAt),
DefaultPolicyViolationStrategy: bizPolicyViolationBlockingStrategyToPb(m.BlockOnPolicyViolation),
PolicyAllowedHostnames: m.PoliciesAllowedHostnames,
PreventImplicitWorkflowCreation: m.PreventImplicitWorkflowCreation,
UpdatedAt: timestamppb.New(*m.UpdatedAt),
DefaultPolicyViolationStrategy: bizPolicyViolationBlockingStrategyToPb(m.BlockOnPolicyViolation),
PolicyAllowedHostnames: m.PoliciesAllowedHostnames,
PreventImplicitWorkflowCreation: m.PreventImplicitWorkflowCreation,
RestrictContractCreationToOrgAdmins: m.RestrictContractCreationToOrgAdmins,
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/controlplane/internal/service/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *OrganizationService) Update(ctx context.Context, req *pb.OrganizationSe
}
}

org, err := s.orgUC.Update(ctx, currentUser.ID, req.Name, req.BlockOnPolicyViolation, policiesAllowedHostnames, req.PreventImplicitWorkflowCreation)
org, err := s.orgUC.Update(ctx, currentUser.ID, req.Name, req.BlockOnPolicyViolation, policiesAllowedHostnames, req.PreventImplicitWorkflowCreation, req.RestrictContractCreationToOrgAdmins)
if err != nil {
return nil, handleUseCaseErr(err, s.log)
}
Expand Down
6 changes: 6 additions & 0 deletions app/controlplane/internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ func (s *service) visibleProjects(ctx context.Context) []uuid.UUID {
return projects
}

// isUserOrgAdmin checks if the current user is an org admin or owner
func isUserOrgAdmin(ctx context.Context) bool {
userRole := usercontext.CurrentAuthzSubject(ctx)
return authz.Role(userRole).IsAdmin()
}

// initializePaginationOpts initializes the pagination options with the provided request pagination options.
func initializePaginationOpts(reqPagination *pb.OffsetPaginationRequest) (*pagination.OffsetPaginationOpts, error) {
// Initialize the pagination options, with default values
Expand Down
Loading
Loading