-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Refactor Actions Token Access #35688
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
Merged
wxiaoguang
merged 24 commits into
go-gitea:main
from
ChristopherHX:refactor-action-token-permissions
Oct 22, 2025
Merged
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
20597e1
Refactor Actions Token Access
ChristopherHX 3fc4f64
block public read access
ChristopherHX c9f6e9c
Prevent create orgs
ChristopherHX 3c03b2b
fix format
ChristopherHX 2ce0dbf
fix tests
ChristopherHX 0b541ba
.
ChristopherHX ba3032b
Update models/perm/access/repo_permission.go
ChristopherHX 88caa65
fix lint
wxiaoguang 6a70c6f
Merge branch 'main' of https://github.com/go-gitea/gitea into refacto…
ChristopherHX 38fd35c
apply feedback lfs auth
ChristopherHX e1e14e7
fix lfs locks for actions user
ChristopherHX cd7c5e3
remove space
ChristopherHX 51cf3da
remove old tests
ChristopherHX 7cb4939
add access_model.ActionsTaskIDKey
ChristopherHX df0f3f3
fix name
ChristopherHX 04b2c09
fix double import
ChristopherHX 0c13471
pass taskID as parameter
ChristopherHX 5551b2f
fix comment
ChristopherHX beb0581
apply feedback
ChristopherHX 01e6831
strip duplicated auth in lfs model
ChristopherHX 236e660
remove ErrLFSUnauthorizedAction, add comment, fix test
wxiaoguang 08a0caa
fix test
wxiaoguang 2b51f0a
fix test
wxiaoguang 98ad2a2
Merge branch 'main' into refactor-action-token-permissions
wxiaoguang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| // Copyright 2025 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package integration | ||
|
|
||
| import ( | ||
| "encoding/base64" | ||
| "net/url" | ||
| "testing" | ||
|
|
||
| actions_model "code.gitea.io/gitea/models/actions" | ||
| "code.gitea.io/gitea/models/unittest" | ||
| "code.gitea.io/gitea/modules/structs" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestActionsJobTokenAccess(t *testing.T) { | ||
| onGiteaRun(t, func(t *testing.T, u *url.URL) { | ||
| t.Run("Write Access", testActionsJobTokenAccess(u, false)) | ||
| t.Run("Read Access", testActionsJobTokenAccess(u, true)) | ||
| }) | ||
| } | ||
|
|
||
| func testActionsJobTokenAccess(u *url.URL, isFork bool) func(t *testing.T) { | ||
| return func(t *testing.T) { | ||
| task := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionTask{ID: 47}) | ||
| require.NoError(t, task.GenerateToken()) | ||
| task.Status = actions_model.StatusRunning | ||
| task.IsForkPullRequest = isFork | ||
| err := actions_model.UpdateTask(t.Context(), task, "token_hash", "token_salt", "token_last_eight", "status", "is_fork_pull_request") | ||
| require.NoError(t, err) | ||
| session := emptyTestSession(t) | ||
| context := APITestContext{ | ||
| Session: session, | ||
| Token: task.Token, | ||
| Username: "user5", | ||
| Reponame: "repo4", | ||
| } | ||
| dstPath := t.TempDir() | ||
|
|
||
| u.Path = context.GitPath() | ||
| u.User = url.UserPassword("gitea-actions", task.Token) | ||
|
|
||
| t.Run("Git Clone", doGitClone(dstPath, u)) | ||
|
|
||
| t.Run("API Get Repository", doAPIGetRepository(context, func(t *testing.T, r structs.Repository) { | ||
| require.Equal(t, "repo4", r.Name) | ||
| require.Equal(t, "user5", r.Owner.UserName) | ||
| })) | ||
|
|
||
| if isFork { | ||
| context.ExpectedCode = 403 | ||
| } | ||
| t.Run("API Create File", doAPICreateFile(context, "test.txt", &structs.CreateFileOptions{ | ||
| FileOptions: structs.FileOptions{ | ||
| NewBranchName: "new-branch", | ||
| Message: "Create File", | ||
| }, | ||
| ContentBase64: base64.StdEncoding.EncodeToString([]byte(`This is a test file created using job token.`)), | ||
| })) | ||
|
|
||
| context.ExpectedCode = 500 | ||
| t.Run("Fail to Create Repository", doAPICreateRepository(context, true)) | ||
|
|
||
| context.ExpectedCode = 403 | ||
| t.Run("Fail to Delete Repository", doAPIDeleteRepository(context)) | ||
|
|
||
| t.Run("Fail to Create Organization", doAPICreateOrganization(context, &structs.CreateOrgOption{ | ||
| UserName: "actions", | ||
| FullName: "Gitea Actions", | ||
| })) | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.