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

Self-hosted runner .git ownership issue after push #196

Open
jerome-benoit opened this issue Sep 18, 2023 · 4 comments
Open

Self-hosted runner .git ownership issue after push #196

jerome-benoit opened this issue Sep 18, 2023 · 4 comments

Comments

@jerome-benoit
Copy link

The ownership left in .git configuration directory after push belongs to root:

...
total 12
drwxr-xr-x. 2 root root 4096 18 sept. 16:34 .
drwxr-xr-x. 3 root root 4096 18 sept. 16:34 ..
-rw-r--r--. 1 root root   41 18 sept. 16:34 9221-53-7461

./refs/remotes:
total 12
drwxr-xr-x. 3 actions-runner actions-runner 4096 18 sept. 14:57 .
drwxr-xr-x. 4 actions-runner actions-runner 4096 18 sept. 18:31 ..
drwxr-xr-x. 3 actions-runner actions-runner 4096 18 sept. 18:31 origin

./refs/remotes/origin:
total 12
drwxr-xr-x. 3 actions-runner actions-runner 4096 18 sept. 18:31 .
drwxr-xr-x. 3 actions-runner actions-runner 4096 18 sept. 14:57 ..
drwxr-xr-x. 3 root           root           4096 18 sept. 16:34 push-action

./refs/remotes/origin/push-action:
total 12
drwxr-xr-x. 3 root           root           4096 18 sept. 16:34 .
drwxr-xr-x. 3 actions-runner actions-runner 4096 18 sept. 18:31 ..
drwxr-xr-x. 2 root           root           4096 18 sept. 16:34 6222839019

./refs/remotes/origin/push-action/6222839019:
total 12
drwxr-xr-x. 2 root root 4096 18 sept. 16:34 .
drwxr-xr-x. 3 root root 4096 18 sept. 16:34 ..

The self-hosted runner is not able to cleanup the repo checkout at next run.

Is it possible to allow to choose the uid/gid that will call git for the push?

@jerome-benoit jerome-benoit changed the title Self-hosted runner .git permission issue after push Self-hosted runner .git ownership issue after push Sep 18, 2023
@CasperWA CasperWA self-assigned this Sep 18, 2023
@CasperWA
Copy link
Owner

CasperWA commented Nov 1, 2023

I've been looking into this a bit. It seems the way to go about this (unfortunately) is that GitHub Docker Actions should indeed use root - or rather, the user is set by the host Docker runner - for self-hosted runners this should be done similarly.

Some references I could find:

If you think you have indeed setup your self-hosted runner in this manner, it would be helpful if you have some input on how you'd intend to implement the change for this action.

@CasperWA CasperWA removed their assignment Nov 1, 2023
@jerome-benoit
Copy link
Author

For now, I run a post action shell script changing the ownership to the user used to execute the runner as a custom setting. I guess GitHub runner should probably do something similar at pre or post action runner hook: cleanup the work direction or changing its ownership.

If the action is able to specify a UID/GID that will be used on the docker image to execute the action: USER <UID> in Dockerfile and UID as an ARG with a default sensible value, I think that should be enough.

I do not have enough GitHub action internal knowledge to known if it will work.

@CasperWA
Copy link
Owner

CasperWA commented Nov 2, 2023

Right - so the main issue is that setting USER in the Dockerfile might break the action (see the docs on this).

But at the same time, the excessive comments in the still open issue actions/runner#434 shows that this is a common and known issue.
From the comments here, there are multiple solutions:

  • Use the tailor-made action reset-workspace-ownership-action (I'd think this is similar to the approach you're currently taking).
  • Run the self-hosted runner as root.
  • Permanently set the user in this action's Dockerfile, risking breaking it (according to the docs).
  • Implement something similar to reset-workspace-ownership-action to either run git merge with a custom UID/GID or update the file ownership in-between merging and pushing (or at some other appropriate stage) within the action.

What do you think? You'd still prefer the custom addition of a UID/GID input to be used within the action?

@jerome-benoit
Copy link
Author

jerome-benoit commented Nov 2, 2023

Independently of the issue, running the action commands under another user than root will close a security issue.

Does running the container commands under a different UID than root (like in https://github.com/myoung34/docker-github-actions-runner/pull/223/files) will break anything?

To summarise:

  • The action should really avoid to run anything as root for security purpose
  • While fixing the previous, maybe address that issue by allowing to setup the UID

In any case, I can live with the workarounds proposed (except bullet point 2).

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

No branches or pull requests

2 participants