Skip to content

Conversation

@Piskoo
Copy link
Collaborator

@Piskoo Piskoo commented Dec 5, 2025

This PR adds a new organization-level setting that allows administrators to restrict contract creation to be only available for organization admins, preventing their creation by org members and project admins.

When setting is enabled and non-admin user tries to run att init without specifying contract an error is returned:

chainloop att init --project myproject --workflow newworkflow --replace
ERR failed to initialize the attestation: can't create the workflow: authorization error: only organization admins can create contracts

Signed-off-by: Sylwester Piskozub <[email protected]>
Signed-off-by: Sylwester Piskozub <[email protected]>
@Piskoo Piskoo marked this pull request as ready for review December 7, 2025 13:21
var projectID *uuid.UUID
if req.ProjectReference.IsSet() {
// Check if organization prevents project-scoped contracts
if org.PreventProjectScopedContracts {
Copy link
Member

Choose a reason for hiding this comment

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

is this the only place a contract is created? can you check during attestation init?

Copy link
Member

Choose a reason for hiding this comment

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

We need to double check that a contract can only be created on-demand from this use case. I remember it was also created during a workflow creation, or attestation init.

Would you mind posting there an evaluation of those entrypoints and how this feature will work with the other preventWorkflowCreation feature?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is what we want. What we want is to only allow administrators to create contracts if this setting is set

@migmartri
Copy link
Member

also, what's the use-case here? Can anybody create project contracts? can admins do it?

Copy link
Member

@migmartri migmartri left a comment

Choose a reason for hiding this comment

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

See my inline coments

@Piskoo Piskoo marked this pull request as draft December 12, 2025 12:02
Signed-off-by: Sylwester Piskozub <[email protected]>
@Piskoo
Copy link
Collaborator Author

Piskoo commented Dec 12, 2025

Updated with what have discussed.

is this the only place a contract is created? can you check during attestation init?

We could also restrict creation of the default contract that is created when no contract was specified in workflow creation, but is that desired behavior?

@Piskoo Piskoo marked this pull request as ready for review December 12, 2025 12:17
@migmartri
Copy link
Member

Updated with what have discussed.

is this the only place a contract is created? can you check during attestation init?

We could also restrict creation of the default contract that is created when no contract was specified in workflow creation, but is that desired behavior?

I think so yes

The idea of this feature is to prevent contract sprawl, and the main source of sprawl is the attestation process.

@Piskoo
Copy link
Collaborator Author

Piskoo commented Dec 12, 2025

Updated with what have discussed.

is this the only place a contract is created? can you check during attestation init?

We could also restrict creation of the default contract that is created when no contract was specified in workflow creation, but is that desired behavior?

I think so yes

The idea of this feature is to prevent contract sprawl, and the main source of sprawl is the attestation process.

Alright, added validation to att init as well

@migmartri
Copy link
Member

Updated with what have discussed.

is this the only place a contract is created? can you check during attestation init?

We could also restrict creation of the default contract that is created when no contract was specified in workflow creation, but is that desired behavior?

I think so yes
The idea of this feature is to prevent contract sprawl, and the main source of sprawl is the attestation process.

Alright, added validation to att init as well

Thanks

Does it work in workflow create too?

Signed-off-by: Sylwester Piskozub <[email protected]>
@Piskoo
Copy link
Collaborator Author

Piskoo commented Dec 15, 2025

Does it work in workflow create too?

Yes, there shouldn't be any other remaining cases

}

if !membership.Role.IsAdmin() {
return nil, errors.Forbidden("forbidden", "only organization admins can create contracts")
Copy link
Member

@migmartri migmartri Dec 16, 2025

Choose a reason for hiding this comment

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

can we make sure the error is cleaner and consistent with what we did in this other check? #2527

ERR creating workflows during the attestation process is disabled for this organization. Please create them in advance or contact your administrator

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated direct creation (e.g. wf contract create) to

ERR contract creation is restricted to organization administrators. Please contact your administrator

And indirect creation (e.g. att with --contract flag or wf create) to

ERR contract creation is restricted to organization administrators. Please use existing contracts or contact your administrator

Signed-off-by: Sylwester Piskozub <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants