Skip to content

feat(rbac): allow creating orgs to tokens with proper permissions#2703

Merged
jiparis merged 6 commits intochainloop-dev:mainfrom
jiparis:PFM-4137
Feb 5, 2026
Merged

feat(rbac): allow creating orgs to tokens with proper permissions#2703
jiparis merged 6 commits intochainloop-dev:mainfrom
jiparis:PFM-4137

Conversation

@jiparis
Copy link
Member

@jiparis jiparis commented Feb 4, 2026

This PR adds the ability for tokens to create organizations, if they have the "organization:create" policy associated.

I've removed the ad hoc permissions check that this endpoint used to have, and replaced with policy checks, both for users and API tokens.

See some execution logs:

With restrict_org_creation: false:

regular user (Instance Admin): allowed 🟢

✗ cldev org create --name org16
DBG using config file path="/Users/jiparis/Library/Application Support/chainloop/config.devel.toml"
WRN API contacted in insecure mode
INF Organization "org16" created!

regular user (Org Viewer in another org): allowed 🟢

cldev org create --name org17
DBG using config file path="/Users/jiparis/Library/Application Support/chainloop/config.devel.toml"
WRN API contacted in insecure mode
INF Organization "org17" created!

regular API token in a different org: not allowed 🔴

cldev org create --name org18
DBG using config file path="/Users/jiparis/Library/Application Support/chainloop/config.devel.toml"
WRN API contacted in insecure mode
ERR not allowed
exit status 1

Instance Admin API token: allowed 🟢

 cldev org create --name org19
DBG using config file path="/Users/jiparis/Library/Application Support/chainloop/config.devel.toml"
WRN API contacted in insecure mode
INF Organization "org19" created!

With restrict_org_creation: true:

regular user (Instance admin): allowed 🟢

cldev org create --name org22
DBG using config file path="/Users/jiparis/Library/Application Support/chainloop/config.devel.toml"
WRN API contacted in insecure mode
INF Organization "org22" created!

regular user (Org viewer in different org): not allowed 🔴

cldev org create --name org23
DBG using config file path="/Users/jiparis/Library/Application Support/chainloop/config.devel.toml"
WRN API contacted in insecure mode
ERR not allowed

regular API token from existing org: not allowed 🔴

cldev org create --name org21
DBG using config file path="/Users/jiparis/Library/Application Support/chainloop/config.devel.toml"
WRN API contacted in insecure mode
ERR not allowed
exit status 1

Instance admin API token: allowed 🟢

cldev org create --name org20
DBG using config file path="/Users/jiparis/Library/Application Support/chainloop/config.devel.toml"
WRN API contacted in insecure mode
INF Organization "org20" created!

Closes #2704

Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
@jiparis jiparis requested review from javirln and migmartri February 4, 2026 10:03
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
@jiparis jiparis requested a review from Piskoo February 4, 2026 10:12
javirln
javirln previously approved these changes Feb 4, 2026
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.

Added some comments, I'd like to get some understanding on what's the expected behavior of the org create with both token/users and restrictedCreation/non-restricted

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.

Please double check my comments

Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
@jiparis
Copy link
Member Author

jiparis commented Feb 4, 2026

Added some comments, I'd like to get some understanding on what's the expected behavior of the org create with both token/users and restrictedCreation/non-restricted

I've updated the description with some tests with and without restrict_org_description setting

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.

thanks

// Restricted org creation is disabled, allow creation
if !s.authz.RestrictOrgCreation {
// if org creation restriction is disabled, allow creation to all users
if !s.authz.RestrictOrgCreation && entities.CurrentUser(ctx) != nil {
Copy link
Member

Choose a reason for hiding this comment

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

yeah, more clear now, thanks

Copy link
Collaborator

@Piskoo Piskoo left a comment

Choose a reason for hiding this comment

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

looks good, thanks @jiparis !

@jiparis jiparis merged commit bd14af8 into chainloop-dev:main Feb 5, 2026
13 checks passed
@jiparis jiparis deleted the PFM-4137 branch February 5, 2026 09:54
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.

feat: allow API tokens to create organizations

4 participants