fix: private repository cloning with authentication token #1268
No reviewers
Labels
No labels
FreeBSD
Kind/Breaking
Kind/Bug
Kind/Chore
Kind/DependencyUpdate
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
Windows
linux-powerpc64le
linux-riscv64
linux-s390x
run-end-to-end-tests
run-forgejo-tests
No milestone
No project
No assignees
5 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
forgejo/runner!1268
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "syncstack/runner:fix/git-credential-store-url-format"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
After patch that replaced go-git with shell git commands, the runner fails to clone private repositories with error:
Root cause:
The credential-store helper expects credentials in URL format (
https://user:token@host/path), but the current implementation writes only the raw token to the file, causing git to prompt for username interactively.Solution:
https://x-access-token:TOKEN@host/pathcredential.useHttpPath=trueto respect repository paths in credential matching@syncstack Thanks a lot for reporting, fixing, and testing the problem. Looks great. Could you provide your reproduction steps? I'd like to check whether they match up with mine.
@mfenniak We seem to need more and better tests, ideally some with a running Forgejo instance. Does that a better fit for https://code.forgejo.org/forgejo/end-to-end/ or should we introduce such tests here, but this time in a separate directory so that we can separate them from the rest of the test suite? We already have two such tests here (
internal/app/cmd/create-runner-file_test.go).@aahlenst
We run a modified runner that enables cloning of private actions (described in this issue). Because of our modifications, we encountered this bug much earlier than typical deployments would.
I think it can be reproduced with the following scenario (though I haven't tested it personally on vanilla):
Even if the bug is rare in current vanilla deployments, it will inevitably be encountered as users adopt more complex workflow patterns.
@aahlenst I created a pull request to show how to set a context where a private repository is used for checkout. Variations can be added to verify a scenario such as the one this pull request is expected to fix.
forgejo/end-to-end@!1409 (commit
b9e49cdb77)@aahlenst wrote in #1268 (comment):
I think this seems like a better fit for the end-to-end test repo, where we have infrastructure set up to test all the supported Forgejo versions (or selectively exclude tests)... currently the CI here only uses the last Forgejo LTS and so we couldn't do the private access test without a different Forgejo. The downside is that the end-to-end repo is difficult to work in, in my opinion... opinionated about where tools are expected, documentation is limited, and entirely bash scripting. But I think it's conceptually ideal for integration testing these systems, and just needs technical improvements over time. 🙂
cascading-pr updated at actions/setup-forgejo#814
The change here seems to make sense, but it's failing for me in manual testing.
Minus the customization that @syncstack mentions, the only in-tree support for cloning a private repository is when using #1249's capability to use a private action... and when I attempt to do that, either with a bare action (eg.
uses: mfenniak/checkout@main) or with a fully qualified address (uses: https://.../mfenniak/basic-checkout@main), it works correctly onmain. (mfenniak/basic-checkout is a private repository in the same org as the running workflow).On the other hand, when I'm running this modification, I'm getting this error from a clone w/
uses: https://.../mfenniak/basic-checkout@mainI've added some diagnostic output for the contents written to the credential file, and the git CLI, and they seem to be as-expected from the patch:
(Note: I've removed
~/.cache/actbetween manual testing steps to ensure a clone is required)manual testing failures
I’ll bring up a test environment with a vanilla Forgejo setup and investigate this.
I’d appreciate it if @mfenniak could share the exact workflow file they’re using, and clarify whether the relevant repositories/actions are private or public (and in which org/owner), so I can reproduce the issue accurately.
fix: private repository cloning with authentication tokento WIP: fix: private repository cloning with authentication tokenAbsolutely. I have a repo
mfenniak/testwhich is a private repo, and has this workflow in.forgejo/workflows/main.yml:Forgejo is current dev branch (d9de2833), and has DEFAULT_ACTIONS_URL configured:
basic-checkout is a repo with the attached content, which is a private repository at
mfenniak/basic-checkout. Local git CLI isgit version 2.51.2.@mfenniak Thanks for the detailed reproduction steps.
Wait a minute — you mentioned that both
mfenniak/testandmfenniak/basic-checkoutare private repositories.As far as I know, this scenario (calling a private action/workflow from a different private repository) cannot work at all in vanilla Forgejo v13.0.4 + forgejo-runner v12.5.0.
The maximum that currently works in vanilla is a composite workflow within the same private repository calling itself.
So the described use case doesn't work for me as-is in vanilla builds.
Ah! Great insight. I've added some debugging code into my Forgejo instance to figure out why this is being permitted, and it appears Forgejo is receiving basic auth with my user's username & password. My guess is that running
gitsubprocesses, and running the runner as my development user, it's accessing my session's credential store to login. I think thatcredential.useHttpPathinterrupts that because whatever creds I have stored for a different repo aren't accessible for the different target action repo.I'll run this through another set of manual tests on an environment where these factors won't have any influence, tomorrow, and verify that those guesses.
There's probably nothing wrong in this patch, but it would be nice if we could isolate the git commands from the development session. (and also, I noted, in some cases when the cred store fails it's accessing the runner's stdin to prompt). Unrelated to this work, though.
WIP: fix: private repository cloning with authentication tokento fix: private repository cloning with authentication tokenBy the way, you're right - if you run the runner on a machine where there are already some git credentials stored, the behavior can indeed be unpredictable.
Although, on the other hand, this is exactly what we were missing at the beginning of our experience with Forgejo, so it's not a bug but a feature ))