Skip to content

Conversation

Zettat123
Copy link
Contributor

@Zettat123 Zettat123 commented Nov 19, 2024

Resolve https://gitea.com/gitea/act_runner/issues/102

This PR allows administrators of a private repository to specify some collaborative owners. The repositories of collaborative owners will be allowed to access this repository's actions and workflows.

Settings for private repos:

image


This PR also moves "Enable Actions" setting to Actions > General page

image image

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 19, 2024
@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 Nov 19, 2024
@pull-request-size pull-request-size bot added size/L and removed size/M labels Nov 20, 2024
@Zettat123 Zettat123 marked this pull request as ready for review November 20, 2024 08:17
@Zettat123
Copy link
Contributor Author

Zettat123 commented Nov 20, 2024

To support this feature, act_runner also needs some improvements, which I am working on.

For changes in act_runner, see https://gitea.com/gitea/act/pulls/123

@Zettat123
Copy link
Contributor Author

@Zettat123 Zettat123 marked this pull request as draft November 25, 2024 02:39
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/frontend labels Nov 26, 2024
@lunny
Copy link
Member

lunny commented Dec 21, 2024

Is this related to #24635 ?

@SamuNatsu
Copy link

Any progress for it?

@IBims1ckoky
Copy link

Any progress there?

@codeguy
Copy link

codeguy commented Aug 30, 2025

Any movement here? This would really really help us in our Gitea Cloud account.

@lunny
Copy link
Member

lunny commented Aug 30, 2025

Any movement here? This would really really help us in our Gitea Cloud account.

I will take the task.

@Zettat123 Zettat123 force-pushed the private-reusable-workflow branch from 01211b3 to 82d368c Compare September 17, 2025 00:29
@Zettat123 Zettat123 force-pushed the private-reusable-workflow branch from 203ad9c to 01035bd Compare October 8, 2025 00:21
@Zettat123 Zettat123 marked this pull request as ready for review October 8, 2025 01:49
@lunny lunny added the docs-update-needed The document needs to be updated synchronously label Oct 12, 2025
@ChristopherHX ChristopherHX added the topic/gitea-actions related to the actions of Gitea label Oct 12, 2025
@github-actions github-actions bot removed the docs-update-needed The document needs to be updated synchronously label Oct 13, 2025
Co-authored-by: ChristopherHX <christopher.homberger@web.de>
Signed-off-by: Zettat123 <zettat123@gmail.com>
@Zettat123 Zettat123 added the docs-update-needed The document needs to be updated synchronously label Oct 13, 2025
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Oct 14, 2025
chhe pushed a commit to chhe/act that referenced this pull request Oct 14, 2025
Related to go-gitea/gitea#32562

Resolve https://gitea.com/gitea/act_runner/issues/102

To support using actions and workflows from private repositories, we need to enable act_runner to clone private repositories.
~~But it is not easy to know if a repository is private and whether a token is required when cloning. In this PR, I added a new option `RetryToken`. By default, token is empty. When cloning a repo returns an `authentication required` error, `act_runner` will try to clone the repo again using `RetryToken` as the token.~~

In this PR, I added a new `getGitCloneToken` function. This function returns `GITEA_TOKEN` for cloning remote actions or remote reusable workflows when the cloneURL is from the same Gitea instance that the runner is registered to. Otherwise, it returns an empty string as token for cloning public repos from other instances (such as GitHub).

Thanks @ChristopherHX for https://gitea.com/gitea/act/pulls/123#issuecomment-1046171 and https://gitea.com/gitea/act/pulls/123#issuecomment-1046285.

Reviewed-on: https://gitea.com/gitea/act/pulls/123
Reviewed-by: ChristopherHX <christopherhx@noreply.gitea.com>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Zettat123 <zettat123@gmail.com>
Co-committed-by: Zettat123 <zettat123@gmail.com>
@github-actions github-actions bot removed the docs-update-needed The document needs to be updated synchronously label Oct 16, 2025
@ChristopherHX
Copy link
Contributor

I think we should rewrite

gitea/routers/api/v1/api.go

Lines 198 to 201 in 38dd432

if task.RepoID != repo.ID {
ctx.APIErrorNotFound()
return
}
first to allow cloning public repositories, backport that then continue here.

My expectation was, I can use gitea.token to clone any public repository from my gitea instance. However I was wrong and we didn't seem to had any test on act_runner side to prevent the act change from merge.

@ChristopherHX
Copy link
Contributor

Found duplicated permission checks in

gitea/routers/api/v1/api.go

Lines 191 to 214 in ebd88af

if ctx.Doer != nil && ctx.Doer.ID == user_model.ActionsUserID {
taskID := ctx.Data["ActionsTaskID"].(int64)
task, err := actions_model.GetTaskByID(ctx, taskID)
if err != nil {
ctx.APIErrorInternal(err)
return
}
if task.RepoID != repo.ID {
ctx.APIErrorNotFound()
return
}
if task.IsForkPullRequest {
ctx.Repo.Permission.AccessMode = perm.AccessModeRead
} else {
ctx.Repo.Permission.AccessMode = perm.AccessModeWrite
}
if err := ctx.Repo.Repository.LoadUnits(ctx); err != nil {
ctx.APIErrorInternal(err)
return
}
ctx.Repo.Permission.SetUnitsWithDefaultAccessMode(ctx.Repo.Repository.Units, ctx.Repo.Permission.AccessMode)
} else {

Maybe those should use a common function, githttp access and no api access is odd.

@ChristopherHX
Copy link
Contributor

ChristopherHX commented Oct 17, 2025

Then lfs again, 3 times same code

taskID := ctx.Data["ActionsTaskID"].(int64)
task, err := actions_model.GetTaskByID(ctx, taskID)
if err != nil {
log.Error("Unable to GetTaskByID for task[%d] Error: %v", taskID, err)
return false
}
if task.RepoID != repository.ID {
return false
}
if task.IsForkPullRequest {
return accessMode <= perm_model.AccessModeRead
}
return accessMode <= perm_model.AccessModeWrite
}

See here for my proposal: #35688, then only a single method decides wether and what level you can access an repository via an actions token

@Zettat123
Copy link
Contributor Author

See here for my proposal: #35688, then only a single method decides wether and what level you can access an repository via an actions token

I convert this PR to Draft and will improve the permission check after #35688 is merged.

@Zettat123 Zettat123 marked this pull request as draft October 17, 2025 15:12
Comment on lines +269 to +282
if task.RepoID != repo.ID {
taskRepo, exist, err := db.GetByID[repo_model.Repository](ctx, task.RepoID)
if err != nil || !exist {
return perm, err
}
actionsCfg := repo.MustGetUnit(ctx, unit.TypeActions).ActionsConfig()
if !actionsCfg.IsCollaborativeOwner(taskRepo.OwnerID) || !taskRepo.IsPrivate {
// The task repo can access the current repo only if the task repo is private and
// the owner of the task repo is a collaborative owner of the current repo.
// FIXME allow public repo read access if tokenless pull is enabled
return perm, nil
}
accessMode = perm_model.AccessModeRead
} else if task.IsForkPullRequest {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please double check this change, migrated your permission check.

This feels like we need action token tests for this as well, not only api manage tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the change, I think it looks good.

I updated the test, please review:

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

Labels

lgtm/need 1 This PR needs approval from one additional maintainer to be merged. modifies/api This PR adds API routes or modifies them modifies/frontend modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files modifies/translation topic/gitea-actions related to the actions of Gitea

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants