Skip to content

Conversation

not7cd
Copy link

@not7cd not7cd commented Aug 29, 2025

Adds commitstatus permission unit to enable more granular permissions for applications with stricter security policies.

Resolves #32625


TODO:

  • Port Improve "generate new access token" form #33730
  • models/repo/repo_unit.go:
  • routers/api/v1/api.go:
  • routers/web/web.go:
  • routers/web/repo/repo.go:
  • routers/web/repo/setting/public_access.go:
  • services/context/context.go:
  • services/repository/repository_test.go:
  • services/repository/repository.go:
  • tests/integration/mirror_pull_test.go:

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Aug 29, 2025
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code labels Aug 29, 2025
now what?
@not7cd not7cd changed the title Add commitstatus permission unit WIP: Add commitstatus permission unit Aug 29, 2025
@not7cd not7cd changed the title WIP: Add commitstatus permission unit Add commitstatus permission unit Aug 29, 2025
Copy link
Member

@lafriks lafriks left a comment

Choose a reason for hiding this comment

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

This will be also breaking change for CI integrations especially ones automatically creating access tokens and also already created ones will be invalid

@not7cd
Copy link
Author

not7cd commented Aug 30, 2025

I'm unsure about the use of permission units. I may want to reduce scope to access tokens only. And it seems that tokenRequiresScopes is orthogonal to reqRepoWriter.

@not7cd
Copy link
Author

not7cd commented Aug 30, 2025

@lafriks, I want to implement this in a way, that write:repo should be sufficient to write to commit status. write:commitstatus should be contained within write:repo permission. This change should enable tokens with more granular scope.

@not7cd not7cd changed the title Add commitstatus permission unit Add commitstatus token scope Aug 30, 2025
@not7cd
Copy link
Author

not7cd commented Aug 30, 2025

So commitstatus is shown in the UI. I can create tokens with write:commitstatus. But I'm unable to write with only write:repo. So it is indeed breaking at this moment.

{"message":"token does not have at least one of required scope(s), required=[write:commitstatus write:repository], token scope=write:repository","url":"http://localhost:3000/api/swagger"}

@not7cd not7cd requested a review from lafriks August 30, 2025 18:03
@@ -1399,8 +1399,8 @@ func Routes() *web.Router {
}, mustAllowPulls, reqRepoReader(unit.TypeCode), context.ReferencesGitRepo())
m.Group("/statuses", func() {
m.Combo("/{sha}").Get(repo.GetCommitStatuses).
Post(reqToken(), reqRepoWriter(unit.TypeCode), bind(api.CreateStatusOption{}), repo.NewCommitStatus)
}, reqRepoReader(unit.TypeCode))
Post(reqToken(), tokenRequiresScopes(auth_model.AccessTokenScopeCategoryCommitStatus, auth_model.AccessTokenScopeCategoryRepository), bind(api.CreateStatusOption{}), repo.NewCommitStatus)
Copy link
Member

Choose a reason for hiding this comment

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

This still does not look right as Get method (Combo) should test read rights and Post - write rights

Copy link
Author

Choose a reason for hiding this comment

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

This should be fixed. I re-introduced reqRepoWriter and Reader middlewares. I'm getting an error that repository permissions are required. So there is something I don't understand in how these middlewares work.

Is there a way to write tests for routing?

Copy link
Author

Choose a reason for hiding this comment

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

Also what is the difference between unit and token permission?

@not7cd not7cd requested a review from lafriks August 31, 2025 16:47
@not7cd not7cd marked this pull request as draft September 1, 2025 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Finer grained permission for writing commit status
4 participants