Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add commitstatus token scope #35383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
not7cd wants to merge 14 commits into go-gitea:main
base: main
Choose a base branch
Loading
from not7cd:not7cd/commit-status-token-scope

Conversation

Copy link

@not7cd not7cd commented Aug 29, 2025
edited
Loading

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
@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

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.

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.

lafriks reacted with thumbs up emoji

@not7cd not7cd changed the title (削除) Add commitstatus permission unit (削除ここまで) (追記) Add commitstatus token scope (追記ここまで) Aug 30, 2025
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
Reviewers

@lafriks lafriks Awaiting requested review from lafriks

Assignees
No one assigned
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
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Finer grained permission for writing commit status

AltStyle によって変換されたページ (->オリジナル) /