Skip to content
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

Checkout breaks symlinked gitconfig on self-hosted runner #650

Open
msdrigg opened this issue Dec 8, 2021 · 10 comments · May be fixed by #651
Open

Checkout breaks symlinked gitconfig on self-hosted runner #650

msdrigg opened this issue Dec 8, 2021 · 10 comments · May be fixed by #651

Comments

@msdrigg
Copy link

msdrigg commented Dec 8, 2021

I am running actions on a self-hosted runner and my $HOME/.gitconfig is symlinked somewhere else (thanks to https://github.com/anishathalye/dotbot). When I run github actions, I see that the following lines have been added to my gitconfig.

[http "https://github.com/"]
    extraheader = AUTHORIZATION: basic *** [it was a token]
[url "https://github.com/"]
    insteadOf = git@github.com:
    insteadOf = org-45189381@github.com:

I tracked this down to several lines in the self-hosted runner logs:

2021-12-04T01:29:22.8379527Z Switched to a new branch 'main'
2021-12-04T01:29:22.8380661Z Branch 'main' set up to track remote branch 'main' from 'origin'.
2021-12-04T01:29:22.8382186Z ##[endgroup]
2021-12-04T01:29:22.8383552Z ##[group]Setting up auth for fetching submodules
2021-12-04T01:29:22.8385435Z Copying '/home/user/.gitconfig' to '/home/user/.local/share/actions-runner/_work/_temp/1ccda36a-b42c-42b0-9664-29b4f1e31ba3/.gitconfig'
2021-12-04T01:29:22.8396391Z Temporarily overriding HOME='/home/user/.local/share/actions-runner/_work/_temp/1ccda36a-b42c-42b0-9664-29b4f1e31ba3' before making global git config changes
2021-12-04T01:29:22.8398638Z [command]/usr/bin/git config --global http.https://github.com/.extraheader AUTHORIZATION: basic ***
2021-12-04T01:29:22.8427546Z [command]/usr/bin/git config --global --unset-all url.https://github.com/.insteadOf
2021-12-04T01:29:22.8451850Z [command]/usr/bin/git config --global --add url.https://github.com/.insteadOf git@github.com:
2021-12-04T01:29:22.8473658Z [command]/usr/bin/git config --global --add url.https://github.com/.insteadOf org-45189381@github.com:
2021-12-04T01:29:22.8494913Z ##[endgroup]
2021-12-04T01:29:22.8496341Z ##[group]Fetching submodules
2021-12-04T01:29:22.8497466Z [command]/usr/bin/git submodule sync --recursive

It seems that when the checkout action copies $HOME/.gitconfig to temporarily modify it, it copies the symlink and so the changes propagate to the main file as well.

This is a big issue because the updated .gitconfig cannot push or pull any of my repos. So I have to constantly go back and edit the ~/.gitconfig to fix this problem.

@msdrigg
Copy link
Author

msdrigg commented Dec 8, 2021

Note the line in question is here

await io.cp(gitConfigPath, newGitConfigPath)

I am not familiar enough with github actions io to fix, but there needs to be some check if the file is a symlink and then copy the actual contents of the file rather than the symlink itself.

@msdrigg
Copy link
Author

msdrigg commented Dec 8, 2021

Looking at the source for @actions/io, it seems like there needs to be some check like this:

for lines here:

if (configExists) {
core.info(`Copying '${gitConfigPath}' to '${newGitConfigPath}'`)
await io.cp(gitConfigPath, newGitConfigPath)
} else {
await fs.promises.writeFile(newGitConfigPath, '')
}

if (configExists) {
  core.info(`Copying '${gitConfigPath}' to '${newGitConfigPath}'`)
  if ((await ioUtil.lstat(gitConfigPath)).isSymbolicLink()) {
    // get true link
    const symlinkFull: string = await ioUtil.readlink(srcFile)
    await io.cp(symlinkFull, newGitConfigPath)
  } else {
    await io.cp(gitConfigPath, newGitConfigPath)
  }
} else {
  await fs.promises.writeFile(newGitConfigPath, '')
}

@msdrigg msdrigg linked a pull request Dec 8, 2021 that will close this issue
@sdiebolt
Copy link

sdiebolt commented Apr 1, 2022

Thanks for pointing this out, I've been struggling for some time trying to understand why none of my repos were accessibe anymore: this was caused by the GitHub Actions runner modifying my symlinked .gitconfig file!

@msdrigg
Copy link
Author

msdrigg commented Apr 2, 2022

I made a pr but they dont seem too interested

@beingminimal
Copy link

This Issue is open since last 7 months and @msdrigg has already submitted PR for the same and awaiting for review and merge.
It's an humble request to look into this issue and merge the changes. @thboop @TingluoHuang
Due to this issue, we are not able to setup Github Self hosted runner in our local environment. So for us it is blocker.

@archon810
Copy link

Does v4 solve this?

@msdrigg
Copy link
Author

msdrigg commented Mar 27, 2024

I am not self-hosting runners any more, but it doesn't look like it

await io.cp(gitConfigPath, newGitConfigPath)

(Same line as above that uses io.cp)

@danielfrg
Copy link

I can confirm v4 doesnt solve the issue.

@wespiard
Copy link

This is still causing problems for me, too.

@williamsentl
Copy link

williamsentl commented Feb 8, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants