Skip to content

Conversation

@Excellencedev
Copy link

Summary

Implements Issue #24635 - Support configuring permissions of automatic tokens for Actions jobs.

This PR adds the ability to configure the default permissions granted to the GITHUB_TOKEN when running workflow jobs in a repository. Users can now choose between:

  • Permissive mode (default): Workflows have read and write permissions for all scopes (backwards compatible with existing behavior)
  • Restricted mode: Workflows have read-only permissions by default

Changes

Backend

  • Extended ActionsConfig struct in models/repo/repo_unit.go with:

    • ActionsTokenPermissionMode type (permissive/restricted)
    • ActionsTokenPermissions struct for per-unit permissions (Contents, Issues, PullRequests, Packages, Actions, Wiki)
    • Helper methods for getting effective permissions and clamping
  • Modified GetActionsUserRepoPermission in models/perm/access/repo_permission.go to use configurable per-unit permissions instead of hardcoded access modes

  • Added UpdateTokenPermissions handler in routers/web/repo/setting/actions.go

Frontend

  • Added Token Permissions UI section in repository Settings → Actions → General
  • Added locale strings in options/locale/locale_en-US.ini

Tests

  • Added unit tests in models/repo/repo_unit_test.go for token permission methods
  • Added integration test TestActionsTokenPermissionsModes in tests/integration/actions_job_token_test.go

Screenshots

The new Token Permissions section appears in Settings → Actions → General:

  • Radio buttons for Permissive/Restricted mode
  • Warning note about fork PRs always being read-only
Screenshot 2025-12-17 071658

Notes

  • Fork pull requests always receive read-only access regardless of settings (security feature)
  • Default behavior is "permissive" for backwards compatibility
  • No database migration required - settings stored as JSON in existing repo_unit config

Related Issues

Closes #24635
/claim #24635

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 17, 2025
@github-actions github-actions bot added modifies/translation modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files labels Dec 17, 2025
@Excellencedev
Copy link
Author

@lunny @wxiaoguang Please review this

@wxiaoguang
Copy link
Contributor

Thank you for asking me to review, but I don't use Actions. You can invite the maintainers from the original issue to review.

@Excellencedev
Copy link
Author

Thank you for asking me to review, but I don't use Actions. You can invite the maintainers from the original issue to review.

@silverwind Please review

@lunny lunny requested a review from Zettat123 December 17, 2025 16:53
@silverwind
Copy link
Member

I review mostly frontend stuff and am not much of an actions user myself, so please be patient until someone finds time to review it properly.

@Excellencedev
Copy link
Author

I review mostly frontend stuff and am not much of an actions user myself, so please be patient until someone finds time to review it properly.

No problem

@wxiaoguang
Copy link
Contributor

By the way, I see another (older) PR: Feat/actions token permissions #36113 , it added more than 2000 lines of code.

What are the differences? Which PR would win ....... @Zettat123

@Zettat123
Copy link
Contributor

By the way, I see another (older) PR: Feat/actions token permissions #36113 , it added more than 2000 lines of code.

What are the differences? Which PR would win ....... @Zettat123

This PR doesn't fully implement the proposal in #24635. (For example, it doesn't support configuring actions access between repositories in the same organization)

It seems that #36113 implemented these features, but I think its code needs improvement.

@silverwind
Copy link
Member

silverwind commented Dec 18, 2025

Issues I see on this screenshot:

image
  • Header text is black on dark theme
  • Contrast on light text is too low

I can probably help fix those, the first one may be a missing override of the fomantic CSS.

@Excellencedev
Copy link
Author

@Zettat123 @silverwind Pls give me a few hours(15-20 hours) and this PR will be ready to go
I will make sure to address all your comments and make sure I do everything from the issue
Drafting until then
When it is done, I will undraft it and notify you

@Excellencedev Excellencedev marked this pull request as draft December 18, 2025 01:53
@wxiaoguang
Copy link
Contributor

By the way, I see another (older) PR: Feat/actions token permissions #36113 , it added more than 2000 lines of code.
What are the differences? Which PR would win ....... @Zettat123

This PR doesn't fully implement the proposal in #24635. (For example, it doesn't support configuring actions access between repositories in the same organization)

It seems that #36113 implemented these features, but I think its code needs improvement.

But "PR: Feat/actions token permissions #36113" came first, and it is more complete, why not respect the first author, but only review this second one?

@Excellencedev
Copy link
Author

By the way, I see another (older) PR: Feat/actions token permissions #36113 , it added more than 2000 lines of code.
What are the differences? Which PR would win ....... @Zettat123

This PR doesn't fully implement the proposal in #24635. (For example, it doesn't support configuring actions access between repositories in the same organization)
It seems that #36113 implemented these features, but I think its code needs improvement.

But "PR: Feat/actions token permissions #36113" came first, and it is more complete, why not respect the first author, but only review this second one?

@wxiaoguang should i close my pr ?

@wxiaoguang
Copy link
Contributor

By the way, I see another (older) PR: Feat/actions token permissions #36113 , it added more than 2000 lines of code.
What are the differences? Which PR would win ....... @Zettat123

This PR doesn't fully implement the proposal in #24635. (For example, it doesn't support configuring actions access between repositories in the same organization)
It seems that #36113 implemented these features, but I think its code needs improvement.

But "PR: Feat/actions token permissions #36113" came first, and it is more complete, why not respect the first author, but only review this second one?

@wxiaoguang should i close my pr ?

I don't know. Reviewers decide.

@Zettat123
Copy link
Contributor

By the way, I see another (older) PR: Feat/actions token permissions #36113 , it added more than 2000 lines of code.
What are the differences? Which PR would win ....... @Zettat123

This PR doesn't fully implement the proposal in #24635. (For example, it doesn't support configuring actions access between repositories in the same organization)
It seems that #36113 implemented these features, but I think its code needs improvement.

But "PR: Feat/actions token permissions #36113" came first, and it is more complete, why not respect the first author, but only review this second one?

I reviewed both PRs, but did not receive responses to my comments in #36113. If @Excellencedev will address the review comments, I think we should keep this PR.

@silverwind
Copy link
Member

silverwind commented Dec 18, 2025

Imho, the only sensible thing we can do is race these 2 PRs.

@Excellencedev
Copy link
Author

Excellencedev commented Dec 18, 2025

Adressed most your comments in my latest commit, now i just need to make sure i fully implement the proposal in #24635

@Zettat123
Copy link
Contributor

According to the solution in #24635, I think this PR does not implement:

  • Support configuring the permissions
  • Support configuring access between repositories
  • Private packages can be accessed by Actions only when they have been linked to repositories

@Excellencedev
Copy link
Author

According to the solution in #24635, I think this PR does not implement:

  • Support configuring the permissions
  • Support configuring access between repositories
  • Private packages can be accessed by Actions only when they have been linked to repositories

Ok no problem. I'm working on it

@github-actions github-actions bot added the modifies/api This PR adds API routes or modifies them label Dec 18, 2025
@Excellencedev Excellencedev marked this pull request as ready for review December 18, 2025 15:32
@Excellencedev
Copy link
Author

@Zettat123 My PR is now ready for review !
It implements ALL the features in the issue description
Just need t make sure tests pass though

}

// HasRead checks if the permission has read access for the given scope
func (p ActionsTokenPermissions) HasRead(scope string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

HasRead and HasWrite can be combined into a single function like

func (p ActionsTokenPermissions) HasAccess(scope string, required perm.AccessMode) bool {
	var mode perm.AccessMode
	switch scope {
	case "actions":
		mode = p.Actions
	case "contents":
		mode = p.Contents
	case "issues":
		mode = p.Issues
	case "packages":
		mode = p.Packages
	case "pull_requests":
		mode = p.PullRequests
	case "wiki":
		mode = p.Wiki
	}
	return mode >= required
}

@@ -0,0 +1,43 @@
// Copyright 2024 The Gitea Authors. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be 2025. Please also check other files.

}
}

// 3. Fallthrough to GetActionsUserRepoPermission
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a TODO? Should we check the permission from GetActionsUserRepoPermission?

@Zettat123
Copy link
Contributor

I got a 500 Error on repo/settings/actions

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🙋 Bounty claim 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 modifies/templates This PR modifies the template files modifies/translation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Proposal] Support configuring permissions of automatic tokens of Actions jobs

5 participants