Skip to content

Conversation

migmartri
Copy link
Member

This PR continues with project-scoped API tokens #2130

  • Stores additional information in the token such as the projectID, projectName if applicable
  • Updates the new rbac primitives to take into account this data during both filtering and enforcement.
  • System-level API tokens work the same way. The new Project-level API tokens are the ones that go through the RBAC check in the service layer.

I tested it locally performing both attestations and regular operations with admin tokens or scoped tokens, for example this is what you get when you try to perform an attestation with a token from another project.

chainloop att init --name test-annotations --project project-sarah  --replace --token $CHAINLOOP_TOKEN

ERR operation not allowed: This auth token is valid only with the project "project-john"

closes #2130

migmartri added 13 commits June 26, 2025 12:10
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
@migmartri migmartri requested review from jiparis and javirln June 26, 2025 20:40
@migmartri migmartri changed the title feat(api-token): enable project-scoped RBAC feat(RBAC): enable project-scoped API tokens Jun 26, 2025
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
// If a project is provided, we store it in the token
var projectID *uuid.UUID
if options.project != nil {
projectID = ToPtr(options.project.ID)
Copy link
Member

Choose a reason for hiding this comment

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

doesn't &options.project.ID work?

Copy link
Member Author

Choose a reason for hiding this comment

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

it does, I was just using one way of doing it tbh, a little bit pointless it's true

Copy link
Member

@jiparis jiparis left a comment

Choose a reason for hiding this comment

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

Thanks, I like it. Basically "RBAC" for API tokens will be enabled only if the token has a "ProjectID" claim, right?

Name: token.Name,
CreatedAt: token.CreatedAt,
Token: token.JWT,
ProjectID: token.ProjectID,
Copy link
Member

Choose a reason for hiding this comment

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

If the token has a ProjectID, is this change checking that the ProjectID in the database is the same?

Copy link
Member Author

Choose a reason for hiding this comment

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

mm, it is not, let me add it

Copy link
Member Author

@migmartri migmartri Jun 27, 2025

Choose a reason for hiding this comment

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

Good catch, I was using the projectID from the DB when in reality we need to use the one from the token.

Now I check that both match

@migmartri
Copy link
Member Author

Thanks, I like it. Basically "RBAC" for API tokens will be enabled only if the token has a "ProjectID" claim, right?

That's correct

Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
@migmartri migmartri merged commit 67a7c03 into chainloop-dev:main Jun 27, 2025
13 checks passed
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.

Project scoped API tokens
2 participants