| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
| ), | ||
| ) | ||
| def test_docker_user_rootless_docker(info_ret, expect_root): | ||
| docker._is_rootless_docker.cache_clear() |
There was a problem hiding this comment.
🤔 maybe we should clear this before and after the test run: otherwise we risk polluting following tests with whatever value we last injected (and not the real value it reads from docker)
Sorry, something went wrong.
There was a problem hiding this comment.
usually a better approach is something like this:
@pytest.fixture(autouse=True)
def _avoid_cache():
with mock.patch.object(docker, '_is_rootless_docker', docker._is_rootless_docker.__wrapped__):
yieldthis bypasses the cache for the duration of the test
Sorry, something went wrong.
| retcode, out, _ = cmd_output_b( | ||
| 'docker', 'system', 'info', '--format', '{{ json .SecurityOptions }}', | ||
| ) | ||
| # some failures are to be expected, e.g. for 'podman' aliased as 'docker' | ||
| if retcode != 0: | ||
| return False | ||
|
|
||
| info = json.loads(out) | ||
| return any(opt == 'name=rootless' for opt in info) |
There was a problem hiding this comment.
this doesn't seem to work for podman :(
$ readlink -f $(which docker)
/usr/bin/podman
$ docker system info --format '{{ json .SecurityOptions }}'
Error: template: info:1:8: executing "info" at <.SecurityOptions>: can't evaluate field SecurityOptions in type *define.Info
Sorry, something went wrong.
There was a problem hiding this comment.
this doesn't seem to work for podman :(
$ readlink -f $(which docker) /usr/bin/podman $ docker system info --format '{{ json .SecurityOptions }}' Error: template: info:1:8: executing "info" at <.SecurityOptions>: can't evaluate field SecurityOptions in type *define.Info
It looks like the invocation we need for podman is: podman system info --format '{{ json .Host.Security.Rootless }}', I guess we could either:
Trying to find a suitable command:
Sorry, something went wrong.
There was a problem hiding this comment.
Parsing the entire info response seemed the most robust: 9bc412d
Sorry, something went wrong.
| if expect_root: | ||
| assert docker.get_docker_user() == () | ||
| else: | ||
| assert docker.get_docker_user() != () |
There was a problem hiding this comment.
don't write logic in tests -- these are two separate disparate behaviours and should be tested separately
Sorry, something went wrong.
There was a problem hiding this comment.
don't write logic in tests -- these are two separate disparate behaviours and should be tested separately
909c165 also included your cache suggestion from above
Sorry, something went wrong.
By running containers in a rootless docker context as root. This is because user and group IDs are remapped in the user namespaces uses by rootless docker, and it's unlikely that the current user ID will map to the same ID under this remap (see docs[1] for some more details). Specifically, it means ownership of mounted volumes will not be for the current user and trying to write can result in permission errors. This change borrows heavily from an existing PR[2]. The output format of `docker system info` I don't think is documented/guaranteed anywhere, but it should corresponding to the format of a `/info` API request to Docker[3] The added test _hopes_ to avoid regressions in this behaviour, but since tests aren't run in a rootless docker context on the PR checks (and I couldn't find an easy way to make it the case) there's still a risk of regressions sneaking in. Link: https://docs.docker.com/engine/security/rootless/ [1] Link: pre-commit#1484 [2] Link: https://docs.docker.com/reference/api/engine/version/v1.48/#tag/System/operation/SystemAuth [3] Co-authored-by: Kurt von Laven <Kurt-von-Laven@users.noreply.github.com> Co-authored-by: Fabrice Flore-Thébault <ffloreth@redhat.com>
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [pre-commit](https://github.com/pre-commit/pre-commit) | minor | `4.2.0` -> `4.3.0` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>pre-commit/pre-commit (pre-commit)</summary> ### [`v4.3.0`](https://github.com/pre-commit/pre-commit/blob/HEAD/CHANGELOG.md#430---2025-08-09) [Compare Source](pre-commit/pre-commit@v4.2.0...v4.3.0) \================== ##### Features - `language: docker` / `language: docker_image`: detect rootless docker. - [#​3446](pre-commit/pre-commit#3446) MR by [@​matthewhughes934](https://github.com/matthewhughes934). - [#​1243](pre-commit/pre-commit#1243) issue by [@​dkolepp](https://github.com/dkolepp). - `language: julia`: avoid `startup.jl` when executing hooks. - [#​3496](pre-commit/pre-commit#3496) MR by [@​ericphanson](https://github.com/ericphanson). - `language: dart`: support latest dart versions which require a higher sdk lower bound. - [#​3507](pre-commit/pre-commit#3507) MR by [@​bc-lee](https://github.com/bc-lee). </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS41OC4yIiwidXBkYXRlZEluVmVyIjoiNDEuNTguMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
| Back | FazBrowse Home | New Git URL |
By running containers in a rootless docker context as root. This is because user and group IDs are remapped in the user namespaces uses by rootless docker, and it's unlikely that the current user ID will map to the same ID under this remap (see docs[1] for some more details). Specifically, it means ownership of mounted volumes will not be for the current user and trying to write can result in permission errors.
This change borrows heavily from an existing PR[2].
The output format of docker system info I don't think is documented/guaranteed anywhere, but it should corresponding to the format of a /info API request to Docker[3]
The added test hopes to avoid regressions in this behaviour, but since tests aren't run in a rootless docker context on the PR checks (and I couldn't find an easy way to make it the case) there's still a risk of regressions sneaking in.
Link: https://docs.docker.com/engine/security/rootless/ [1]
Link: #1484 [2]
Link: https://docs.docker.com/reference/api/engine/version/v1.48/#tag/System/operation/SystemAuth [3]
resolves #1243