[GH-ISSUE #451] Should not inherit container PATH from host PATH #316

Closed
opened 2026-03-01 21:42:19 +03:00 by kerem · 8 comments
Owner

Originally created by @andersk on GitHub (Dec 17, 2020).
Original GitHub issue: https://github.com/nektos/act/issues/451

On NixOS, running act, say in the act repository itself, eventually gives this error:

[push/Test                                                                 ] ⭐  Run go test -cover ./...
| OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: \"bash\": executable file not found in $PATH": unknown
[push/Test                                                                 ]   ❌  Failure - go test -cover ./...
Error: exit with `FAILURE`: 126

This is because PATH on NixOS does not have the usual /bin and /usr/bin directories. Running env PATH=/bin:/usr/bin act succeeds, at least for this step. Adding a run: printenv step confirms that anything I put in the host PATH is inherited in the container PATH.

CI tests are supposed to be entirely self-contained, so they should not inherit any environment variables from the host, including PATH.

Originally created by @andersk on GitHub (Dec 17, 2020). Original GitHub issue: https://github.com/nektos/act/issues/451 On NixOS, running `act`, say in the `act` repository itself, eventually gives this error: ``` [push/Test ] ⭐ Run go test -cover ./... | OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: \"bash\": executable file not found in $PATH": unknown [push/Test ] ❌ Failure - go test -cover ./... Error: exit with `FAILURE`: 126 ``` This is because `PATH` on NixOS does not have the usual `/bin` and `/usr/bin` directories. Running `env PATH=/bin:/usr/bin act` succeeds, at least for this step. Adding a `run: printenv` step confirms that anything I put in the host `PATH` is inherited in the container `PATH`. CI tests are supposed to be entirely self-contained, so they should not inherit any environment variables from the host, including `PATH`.
kerem closed this issue 2026-03-01 21:42:20 +03:00
Author
Owner

@andersk commented on GitHub (Dec 17, 2020):

Looks like this happens here:

github.com/nektos/act@e47a2395a5/pkg/runner/step_context.go (L96)

<!-- gh-comment-id:747163150 --> @andersk commented on GitHub (Dec 17, 2020): Looks like this happens here: https://github.com/nektos/act/blob/e47a2395a5260aca1cec1506f0243e919ed4e70c/pkg/runner/step_context.go#L96
Author
Owner

@msxdan commented on GitHub (Dec 27, 2020):

image

....
←[34m|←[0m dotnet-install: Installation finished successfully.
←[34m[Bit CI/Build on Windows] ←[0m ⚙ ::add-path:: /github/home/.dotnet
←[34m[Bit CI/Build on Windows] ←[0m ⚙ ::set-env:: DOTNET_ROOT=/github/home/.dotnet
←[34m|←[0m /github/home/.dotnet:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
←[34m[Bit CI/Build on Windows] ←[0m ❓ ##[add-matcher]/actions/actions-setup-dotnet@v1/.github/csc.json
←[34m[Bit CI/Build on Windows] ←[0m ✅ Success - Install .NET Core
←[34m[Bit CI/Build on Windows] ←[0m⭐ Run Install Dependencies
←[34m|←[0m OCI runtime exec failed: exec failed: container_linux.go:370: starting container process caused: exec: "bash": executable file not found in $PATH: unknown
←[34m[Bit CI/Build on Windows] ←[0m ❌ Failure - Install Dependencies
Error: exit with FAILURE: 126

Kinda anoying on Windows, is there any fix?

<!-- gh-comment-id:751468587 --> @msxdan commented on GitHub (Dec 27, 2020): ![image](https://user-images.githubusercontent.com/32611659/103171974-5c6a8380-4850-11eb-8a3d-64e8e48dcef1.png) `....` `←[34m|←[0m dotnet-install: Installation finished successfully.` `←[34m[Bit CI/Build on Windows] ←[0m ⚙ ::add-path:: /github/home/.dotnet` `←[34m[Bit CI/Build on Windows] ←[0m ⚙ ::set-env:: DOTNET_ROOT=/github/home/.dotnet` `←[34m|←[0m /github/home/.dotnet:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin` `←[34m[Bit CI/Build on Windows] ←[0m ❓ ##[add-matcher]/actions/actions-setup-dotnet@v1/.github/csc.json` `←[34m[Bit CI/Build on Windows] ←[0m ✅ Success - Install .NET Core` `←[34m[Bit CI/Build on Windows] ←[0m⭐ Run Install Dependencies` `←[34m|←[0m OCI runtime exec failed: exec failed: container_linux.go:370: starting container process caused: exec: "bash": executable file not found in $PATH: unknown` `←[34m[Bit CI/Build on Windows] ←[0m ❌ Failure - Install Dependencies` `Error: exit with `FAILURE`: 126` Kinda anoying on Windows, is there any fix?
Author
Owner

@catthehacker commented on GitHub (Dec 31, 2020):

Currently the only workaround I can think of for that is to use hardcoded default $PATH (which is applied here: https://github.com/CatTheHacker/act/tree/env-path-fix) in act or define $PATH yourself in your workflow.
Permanent fix would have to attach to destination container, extract the $PATH under user scope that will run the command and apply it for next command run.
os.PathListSeparator also should not be used, since it if used on Windows running Linux container, $PATH will be separated with ; instead of : and vice versa.
github.com/nektos/act@3f3de6e0b1/pkg/runner/step_context.go (L95-L98)

<!-- gh-comment-id:752817839 --> @catthehacker commented on GitHub (Dec 31, 2020): Currently the only workaround I can think of for that is to use hardcoded default `$PATH` (which is applied here: https://github.com/CatTheHacker/act/tree/env-path-fix) in `act` or define `$PATH` yourself in your workflow. Permanent fix would have to attach to destination container, extract the `$PATH` under user scope that will run the command and apply it for next command run. `os.PathListSeparator` also should not be used, since it if used on Windows running Linux container, `$PATH` will be separated with `;` instead of `:` and vice versa. https://github.com/nektos/act/blob/3f3de6e0b1cd8b3a38e2df386078445392ab3fe1/pkg/runner/step_context.go#L95-L98
Author
Owner

@nickray commented on GitHub (Jan 5, 2021):

This surprising error occurs also on Arch Linux (and the same hack env PATH=/bin:/usr/bin act fixes, but why should host PATH have anything to do with the container?)

<!-- gh-comment-id:754307431 --> @nickray commented on GitHub (Jan 5, 2021): This surprising error occurs also on Arch Linux (and the same hack `env PATH=/bin:/usr/bin act` fixes, but why should host PATH have anything to do with the container?)
Author
Owner

@catthehacker commented on GitHub (Jan 5, 2021):

why should host PATH have anything to do with the container?

Because it's a bit tricky to obtain PATH from container/image. Much easier (and breaking) solution was to copy PATH from host.

<!-- gh-comment-id:754536803 --> @catthehacker commented on GitHub (Jan 5, 2021): > why should host PATH have anything to do with the container? Because it's a bit tricky to obtain `PATH` from container/image. Much easier (and breaking) solution was to copy `PATH` from host.
Author
Owner

@andersk commented on GitHub (Jan 5, 2021):

It can be found in docker image inspect. (I assume there’s some equivalent in the Go API.)

[
    {
        …
        "Config": {
            …
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            …
        },
        …
    }
]
<!-- gh-comment-id:754544555 --> @andersk commented on GitHub (Jan 5, 2021): It can be found in `docker image inspect`. (I assume there’s some equivalent in the Go API.) ``` [ { … "Config": { … "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], … }, … } ] ```
Author
Owner

@catthehacker commented on GitHub (Jan 5, 2021):

@andersk It's a start, but it should not rely on PATH in image manifest. The correct way to obtain PATH is to execute login shell as a user that will run command and grab PATH from env.
I have yet to find a nice clean way to do that in act.

<!-- gh-comment-id:754554085 --> @catthehacker commented on GitHub (Jan 5, 2021): @andersk It's a start, but it should not rely on `PATH` in image manifest. The correct way to obtain `PATH` is to execute login shell as a user that will run command and grab `PATH` from `env`. I have yet to find a nice clean way to do that in `act`.
Author
Owner

@hellt commented on GitHub (Jan 6, 2021):

happened to me on Centos linux as well
the workaround worked

PATH=/bin:/usr/bin /usr/local/bin/act  ...
<!-- gh-comment-id:755214077 --> @hellt commented on GitHub (Jan 6, 2021): happened to me on Centos linux as well the workaround worked ``` PATH=/bin:/usr/bin /usr/local/bin/act ... ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
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
starred/act#316
No description provided.