fix: default to not mounting docker socket in exec #1090

Open
drewcassidy wants to merge 1 commit from drewcassidy/runner:fix-dont-mount-socket into main
Contributor

Fixes #1073

forgejo-runner exec currently defaults to mounting /var/run/docker.sock in the job container, which might not exist. This PR changes the default to not mounting anything in the job container. This mirrors the default value of the docker_host config value

If mounting a docker socket in the job container is desired, the user can use --container-daemon-socket

  • bug fixes
    • PR: fix: default to not mounting docker socket in exec
Fixes #1073 `forgejo-runner exec` currently defaults to mounting `/var/run/docker.sock` in the job container, which might not exist. This PR changes the default to not mounting anything in the job container. This mirrors the default value of the `docker_host` config value If mounting a docker socket in the job container is desired, the user can use `--container-daemon-socket` <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - bug fixes - [PR](https://code.forgejo.org/forgejo/runner/pulls/1090): <!--number 1090 --><!--line 0 --><!--description Zml4OiBkZWZhdWx0IHRvIG5vdCBtb3VudGluZyBkb2NrZXIgc29ja2V0IGluIGV4ZWM=-->fix: default to not mounting docker socket in exec<!--description--> <!--end release-notes-assistant-->
Default to not mounting docker socket in exec
Some checks failed
checks / validate pre-commit-hooks file (pull_request) Successful in 31s
checks / validate mocks (pull_request) Successful in 39s
checks / build and test (pull_request) Successful in 52s
checks / runner exec tests (pull_request) Successful in 25s
checks / runner integration tests (pull_request) Successful in 4m51s
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 13s
checks / integration tests (pull_request) Failing after 17m39s
eca5e67c0b
When running `forgejo-runner exec`, default to not mounting anything in the job container instead of mounting /var/run/docker.sock. This mirrors the behavior of the docker_host config value

If mounting a docker socket in the job container is desired, the user can use --container-daemon-socket
Author
Contributor

looks like some of the tests were written with the assumption that when ContainerDaemonSocket is set to an empty string it should mount /var/run/docker.sock. Not sure if I should update the tests or put the code I pulled from act/runner back. personally I think the default should always be not to mount anything but understand this could be a breaking change for some.

looks like some of the tests were written with the assumption that when `ContainerDaemonSocket` is set to an empty string it should mount `/var/run/docker.sock`. Not sure if I should update the tests or put the code I pulled from `act/runner` back. personally I think the default should always be not to mount anything but understand this could be a breaking change for some.
Owner

I'm not so sure of this, since it's a breaking change for users who access exec today and may have existing workflows around it. What would you think of detecting the absence of /var/run/docker.sock and proceeding with this behaviour only in that case, maybe with an info-level log message?

I'm not so sure of this, since it's a breaking change for users who access `exec` today and may have existing workflows around it. What would you think of detecting the absence of `/var/run/docker.sock` and proceeding with this behaviour only in that case, maybe with an info-level log message?
Author
Contributor

its not just about it existing, but also about it being accessible to the current user. the docker socket is only usable by users in the docker group by default. Thats what I was running into when I filed the issue (I said it didn't exist, I later realized it did exist thanks to the Podman-docker shim I installed because the docs told me to, even though I was using the podman user socket. I just didn't have write access to it)

Manually running workflows that themselves deal with docker doesnt seem like it would be a super common use case, but it is possible. maybe this could be delayed to a more major update when breaking changes are more palatable?

its not just about it existing, but also about it being accessible to the current user. the docker socket is only usable by users in the docker group by default. Thats what I was running into when I filed the issue (I said it didn't exist, I later realized it did exist thanks to the Podman-docker shim I installed because the docs told me to, even though I was using the podman user socket. I just didn't have write access to it) Manually running workflows that themselves deal with docker doesnt seem like it would be a super common use case, but it is possible. maybe this could be delayed to a more major update when breaking changes are more palatable?
Owner

Manually running workflows that themselves deal with docker doesnt seem like it would be a super common use case, but it is possible. maybe this could be delayed to a more major update when breaking changes are more palatable?

Hm, I develop almost all my workflows with forgejo-runner exec because it's a faster dev cycle, including those that build containers, but I don't do that daily. I could counter-argue that using forgejo-runner exec on a system without access to the docker socket doesn't seem like a super common use case. I think we'd both be right that neither case is common. 😉

Thinking back to making it automatic -- rather than checking if the socket exists, could we make an attempt to access the socket? I believe there's a Ping method on the docker client Go API...

> Manually running workflows that themselves deal with docker doesnt seem like it would be a super common use case, but it is possible. maybe this could be delayed to a more major update when breaking changes are more palatable? Hm, I develop almost all my workflows with `forgejo-runner exec` because it's a faster dev cycle, including those that build containers, but I don't do that daily. I could counter-argue that using `forgejo-runner exec` on a system without access to the docker socket doesn't seem like a super common use case. I think we'd both be right that neither case is common. 😉 Thinking back to making it automatic -- rather than checking if the socket exists, could we make an attempt to access the socket? I believe there's a `Ping` method on the docker client Go API...
Some checks are pending
checks / validate pre-commit-hooks file (pull_request) Successful in 31s
checks / validate mocks (pull_request) Successful in 39s
checks / build and test (pull_request) Successful in 52s
checks / runner exec tests (pull_request) Successful in 25s
Required
Details
checks / runner integration tests (pull_request) Successful in 4m51s
cascade / forgejo (pull_request_target) Has been skipped
Required
Details
cascade / debug (pull_request_target) Has been skipped
Required
Details
cascade / end-to-end (pull_request_target) Has been skipped
Required
Details
issue-labels / release-notes (pull_request_target) Successful in 13s
checks / integration tests (pull_request) Failing after 17m39s
checks / Build Forgejo Runner *
Required
checks / Run integration tests with *
Required
This pull request doesn't have enough approvals yet. 0 of 1 approvals granted.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u fix-dont-mount-socket:drewcassidy-fix-dont-mount-socket
git switch drewcassidy-fix-dont-mount-socket
Sign in to join this conversation.
No reviewers
No milestone
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
forgejo/runner!1090
No description provided.