Giter VIP home page Giter VIP logo

ansible-role-docker-rootless's Introduction

Docker rootless Ansible role

An Ansible role to configure install and configure a Docker daemon running as a non-root user.

Do not use any of this without first testing in a non-operational environment.

Rootless mode allows running the Docker daemon and containers as a non-root user to mitigate potential vulnerabilities in the daemon and the container runtime. (docker)

Note There is a SLSA artifact present under the slsa action workflow for verification.

Requirements

---
roles:
  - name: konstruktoid.docker_rootless
    version: v0.52.0
    src: https://github.com/konstruktoid/ansible-role-docker-rootless.git
    scm: git

Playbook example

---
- hosts: all
  any_errors_fatal: true
  tasks:
    - name: Include the konstruktoid.docker_rootless role
      ansible.builtin.import_role:
        name: konstruktoid.docker_rootless

Role Variables with defaults

---
docker_add_alias: true
docker_allow_ping: false
docker_allow_privileged_ports: false
docker_compose: false
docker_compose_arch: x86_64
docker_compose_release: v2.29.1
docker_compose_release_shasum: 5ea89dd65d33912a83737d8a4bf070d5de534a32b8493a21fbefc924484786a9
docker_compose_url: https://github.com/docker/compose/releases/download
docker_daemon_json_template: daemon.json.j2
docker_release: 27.1.1
docker_release_rootless_shasum: 31cffd0f0c84ead9a5b28c1ad0c8e56eb9ef352036099a1f6501315574d4f63e
docker_release_shasum: 118da6b8fc8e8b6c086ab0dd5e64ee549376c3a3f963723bbc9a46db475bf21f
docker_repository_template: docker.repo.j2
docker_rootful_enabled: false
docker_rootful: false
docker_rootful_opts: false
docker_rootful_service_template: docker_rootful.service.j2
docker_rootless_script_template: docker_rootless.sh.j2
docker_rootless_service_template: docker_rootless.service.j2
docker_service_restart: true
docker_url: https://download.docker.com/linux/static/stable/x86_64
docker_user_bashrc: false
docker_user: dockeruser

Before using this role you first have to decide if you want to install Docker using the packages available to the distribution, also known as the "rootful" installation since it requires root permissions and installs the upstream Docker daemon or if you want to download the static binaries and do a manual install.

If you set docker_rootful: false you will download the static binaries and do a manual install, not requiring any root permissions.

If docker_rootful: true, then docker_rootful_enabled will decide if the daemon should be enabled as a service or not.

docker_service_restart will restart the rootless service after the Docker binaries has been extracted. This may affect any running containers.

Using docker_rootful: true and docker_rootful_enabled: true, will result in a standard Docker installation, with an additional Docker daemon, running as a non-root user.

Note that Debian 10 and earlier requires docker_rootful: false due to missing dependencies.

The docker_url, docker_release, docker_compose_url and docker_compose_release variables define where you find the relevant binaries and which version you should use when doing a manual installation.

You define the name of the Docker user that will be created with the docker_user variable. This user will download and install the binaries if docker_rootful: false or else the user will be the one running the rootless installation script and starting a isolated daemon.

Note that the sole purpose of the docker_user is to run the Docker daemon and related containers, and not for system administration or used as a regular user.

docker_release_shasum, docker_release_rootless_shasum and docker_compose_release_shasum are used to verify the files when downloaded using the get_url module. The docker_release_shasum is used for the Docker .tgz file and docker_release_rootless_shasum for the docker-ce-rootless-extras package.

docker_rootful_opts is the options to apply to the Docker daemon if running in rootful mode, if unset the settings in docker_rootful_service_template will be used.

If docker_add_alias: true, then a docker alias will be added to either .bashrc or .bash_aliases of the Ansible user. If false, a shell script named docker_rootless.sh is created in the Ansible user home directory. This works as a substitute to the docker command so that the Ansible user can execute the rootless Docker installation from the docker_user.

If docker_compose: true, then the Docker compose plugin or docker-compose will be installed. docker_compose_arch are used to define the architecture of the docker-compose binary.

If docker_user_bashrc: true, a .bashrc with completion for the docker and docker compose command will be placed inside the docker_user home.

The docker_allow_privileged_ports variable configures if exposing privileged ports (< 1024) is allowed.

The docker_allow_ping variable configures if unprivileged users can open ICMP echo sockets. On some distributions, this is not allowed, and thereby containers cannot ping to the outside.

The variables named *_template are the locations of the templates in use, this to make it easier to replace them with custom ones.

The most important template is most likely docker_daemon_json_template: daemon.json.j2, which is the location of the Docker daemon.json configuration file template.

Container management

Standalone container

Running containers is not that much different from when a rootful Docker daemon is used, but you still need to become the unprivileged user and adapt any paths to the user working directores.

If docker_add_alias: true is used, the docker command will be available as usual for the Ansible user, too. Type alias in the shell to see the keyword configuration.

- name: Register Docker user info
  become: true
  ansible.builtin.user:
    name: "{{ docker_user }}"
  check_mode: true
  register: docker_user_info

- name: Example container block
  environment:
    XDG_RUNTIME_DIR: "/run/user/{{ docker_user_info.uid }}"
    PATH: "{{ docker_user_info.home }}/bin:{{ ansible_env.PATH }}"
    DOCKER_HOST: "unix:///run/user/{{ docker_user_info.uid }}/docker.sock"
  block:
    - name: Nginx container
      become: true
      become_user: "{{ docker_user }}"
      community.docker.docker_container:
        name: nginx
        image: konstruktoid/nginx
        state: started
        cap_drop: all
        capabilities:
          - chown
          - dac_override
          - net_bind_service
          - setgid
          - setuid
        pull: true
        hostname: "{{ ansible_nodename }}"
        container_default_behavior: compatibility

Docker compose service

- name: Register Docker user info
  become: true
  ansible.builtin.user:
    name: "{{ docker_user }}"
  check_mode: true
  register: docker_user_info

- name: Example docker compose block
  become: true
  become_user: "{{ docker_user }}"
  environment:
    XDG_RUNTIME_DIR: /run/user/{{ docker_user_info.uid }}
    PATH: "{{ docker_user_info.home }}/bin:{{ ansible_env.PATH }}"
    DOCKER_HOST: "unix:///run/user/{{ docker_user_info.uid }}/docker.sock"
  block:
    - name: Install pip dependencies
      ansible.builtin.pip:
        name:
          - docker<7 # https://github.com/docker/docker-py/issues/3194
          - docker-compose

    - name: Create and start services
      community.docker.docker_compose:
        project_src: /var/tmp/
        files: "{{ docker_user }}-docker-compose.yml"
      register: compose_output

Testing with molecule

If Ansible Molecule with the vagrant plugin and related software is installed, running molecule test is supported.

tox -l will list all available tox test environments.

Contributing

Do you want to contribute? Great! Contributions are always youlcome, no matter how large or small. If you found something odd, feel free to submit a issue, improve the code by creating a pull request, or by sponsoring this project.

License

Apache License Version 2.0

Author Information

https://github.com/konstruktoid

ansible-role-docker-rootless's People

Contributors

dependabot[bot] avatar konstruktoid avatar linozen avatar msladek avatar mxmehl avatar pypb avatar renovate-bot avatar renovate[bot] avatar slhck avatar ssbarnea avatar step-security-bot avatar t2d avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ansible-role-docker-rootless's Issues

IPv6 does not work

Hi there,

we tried getting rootlesskit (with slirp4netns) by following the documentation over here: https://wiki.archlinux.org/title/docker#IPv6 to enable outgoing traffic to IPv6-only hosts and even added the corresponding flag to the rootlesskit command in the systemd unit. Is there a way to enable rootless containers to connect to IPv6 hosts? And if so, might it make sense to include its configuration here as a variable? Would love to collaborate on this but at the moment I'm out of ideas.

Many thanks for considering!

The conditional check 'not docker_user_bashrc.stat.exists' failed. The error was: error while evaluating conditional


TASK [ansible-roles/ansible-role-docker-rootless : Create Docker user .bashrc] **************************************************************************************************************************************
fatal: [65.75.210.202]: FAILED! => {"msg": "The conditional check 'not docker_user_bashrc.stat.exists' failed. The error was: error while evaluating conditional (not docker_user_bashrc.stat.exists): 'bool object' has no attribute 'stat'. 'bool object' has no attribute 'stat'\n\nThe error appears to be in '/Users/michael/Scripts/provision-server/ansible-roles/ansible-role-docker-rootless/tasks/bashrc.yml': line 8, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Create Docker user .bashrc\n  ^ here\n"}

.bash_aliases and .bashrc are created in wrong user's directory

I ran this role against a server where the docker_user differed from the ansible_user, all using default options.

The tasks included these:

image

It seems it modified the .bash_aliases of the ansible_user, and not the docker_user.

The error seems to be here:

https://github.com/konstruktoid/ansible-docker-rootless/blob/88fd38143bdc436355d914525caff1e5db95b3f4/tasks/main.yml#L49

Should this be the docker_user? (Also affects surrounding tasks.)

Dependencies on Debian 10

Thanks for this awesome role.

On Debian 10 (buster) I needed to install python3-setuptools to install docker via pip.
To run actual containers, I also needed python3-six.

I suggest to add both as dependencies and install automatically.

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (github>whitesource/merge-confidence:beta)

Unable to deploy container

Hello, thank you so much for this code. The rootless docker installs fine and docker is available to the dedicated user. I can run docker ps and see there are no containers. However, when I try to deploy the container using Ansible. I am getting the following error:

FAILED! => {"changed": false, "msg": "Failed to import the required Python library (Docker SDK for Python: docker (Python >= 2.7) or docker-py (Python 2.6)) on host machine's Python /usr/bin/python3. Please read module documentation and install in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter, for example via pip install dockerorpip install docker-py (Python 2.6). The error was: No module named 'requests'"}

I have logged into dedicated user and checked version of Python, and everything checks out. Any help would be much appreciated.

Using a private registry

Hi,
firstly thank for this good job. Do you plan to use an private registry with authentication to pull your images? Or do you see a way to do this?

thx

Cannot connect to the rootless daemon via SSH due to missing DOCKER_HOST variable

{{ tools.context.actor }}: {{ tools.context.sha }}

When I am trying to connect to a rootless daemon via e.g. the Docker SDK for Python, I'm getting an error message if the DOCKER_HOST variable is not globally available on the host where the daemon is running. A simple fix would be to set this variable globally, e.g. in /etc/environment.

Please let me know if there is a more elegant solution or if this is out of scope.

Many thanks!

Error running hello-world on Raspberry PI 4 running raspbian OS

I installed this on the raspbian OS 64 bit on my raspberry Pi 4. The installation went successful.
but when I tried to run the hello-world container. I got the following error.

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
7050e35b49f5: Pull complete
Digest: sha256:62af9efd515a25f84961b70f973a798d2eca956b1b2b026d0a4a63a3b0b6a3f2
Status: Downloaded newer image for hello-world:latest
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: unable to apply cgroup configuration: unable to start unit "docker-eaebeca8db0556fe38e61fe4b32d86e1f09f91772da385a8542dbd7933d1e559.scope" (properties [{Name:Description Value:"libcontainer container eaebeca8db0556fe38e61fe4b32d86e1f09f91772da385a8542dbd7933d1e559"} {Name:Slice Value:"user.slice"} {Name:Delegate Value:true} {Name:PIDs Value:@au [5611]} {Name:MemoryAccounting Value:true} {Name:CPUAccounting Value:true} {Name:IOAccounting Value:true} {Name:TasksAccounting Value:true} {Name:DefaultDependencies Value:false}]): Interactive authentication required.: unknown.

I had to tweak the ansible environment variables so that the aarch64 docker is installed. Here are my variables.

docker_compose: true
docker_user_bashrc: true
docker_url: "https://download.docker.com/linux/static/stable/aarch64"
docker_release_shasum: "aa2b2da571fb9160df87fd5a831f203fb97655e35fb9c4e8d46e72078ae16acf"
docker_release_rootless_shasum: "cd9256637a23164f9d86b4e6c5cd5ee4c4e7e8831ea473a855734b70612fe594"
docker_user: utkar

Can you please assist regarding this? I believe it's an issue with docker itself and not related to ansible.
Where can i find the verbose logs? How do we debug this?

Standalone ansible role

Is it planned or are you interested in to make this current example to a standalone ansible role to install rootless docker? From a first look this means removing the nginx stuff and maybe also adding support for installation of rootless docker for multiple users

Additionally you deploy a rootfull systemd service here but stop it afterwards, what's the point?

Add environment variables automatically

The role should add the environment variables to .profile automatically.

Is there any specific reason why you push a README to the remote host instead of just adding the env variables for the docker_user?

galaxy is out of date

Hi! Thanks for this awesome role. I'd like to begin consuming it, although I'm not sure that what is in galaxy is up to date with the current main branch that has more recent docker version (e.g. v0.1.0 in galaxy from 9mo ago does not contain 2ddeb3f).

What is the recommended way to consume this role? Should we be pulling directly from a git ref?

Add daemon.json config

Hi !

I have a new request ๐Ÿ™‚

Is it possible to create config file daemon.json ?
Example:

vars:
  docker_daemon_config:
    data-root: /app/docker
    dns:
      - 8.8.8.8
      - 8.8.4.4
tasks:
    - name: Create daemon.json config file
      copy:
        dest: "/home/{{ docker_user }}/.config/docker/daemon.json"
        content: "{{ docker_daemon_config | to_nice_json }}" 
      notify:
        - Restart rootless docker

Thx !

Use 'docker compose' command (without hiphen)

Hi,

Docker compose installation is not the same as Official docker compose installation.

docker compose command don't work.

docker: 'compose' is not a docker command.
See 'docker --help'

But 'docker-compose' command work well.

I add a task to create docker plugins directory and I change the destination path when downloading docker-compose:

- name: Create docker plugins directory
  file:
    path: "{{ docker_user_info.home }}/.docker/cli-plugins"
    state: directory
    owner: "{{ docker_user }}"
    group: "{{ docker_user }}"

- name: Download docker-compose
  become: true
  become_user: "{{ docker_user }}"
  ansible.builtin.get_url:
    url: "https://github.com/docker/compose/releases/download/v{{ docker_compose_release }}/docker-compose-linux-x86_64"
    dest: "{{ docker_user_info.home }}/.docker/cli-plugins/docker-compose"
    checksum: sha256:{{ docker_compose_release_shasum }}
    owner: "{{ docker_user }}"
    mode: "0755"
  when: docker_compose
  tags:
    - docker-compose

Now I can use docker compose command.

.bashrc generation tasks problem

Hello,

i'm finding a strange issue with stat tasks inside bashrc.yml

my local configuration

$ ansible --version
ansible [core 2.14.4]
  config file = None
  configured module search path = ['/Users/myuser/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/lib/python3.11/site-packages/ansible
  ansible collection location = /Users/myuser/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/homebrew/bin/ansible
  python version = 3.11.3 (main, Apr  7 2023, 21:05:46) [Clang 14.0.0 (clang-1400.0.29.202)] (/opt/homebrew/opt/[email protected]/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True
# ansible-galaxy --version
ansible-galaxy [core 2.14.4]
  config file = None
  configured module search path = ['/Users/myuser/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/lib/python3.11/site-packages/ansible
  ansible collection location = /Users/myuser/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/homebrew/bin/ansible-galaxy
  python version = 3.11.3 (main, Apr  7 2023, 21:05:46) [Clang 14.0.0 (clang-1400.0.29.202)] (/opt/homebrew/opt/[email protected]/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True
$ ansible-galaxy list | grep docker_rootless
- konstruktoid.docker_rootless, v0.15.0

The destination server configuration:

# uname -a
Linux <XXXX> 5.15.0-70-generic #77-Ubuntu SMP Tue Mar 21 14:02:37 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.2 LTS"
# python3 --version
Python 3.10.6

this is my role task content:

...
- name: Install Docker rootless
  include_role:
    name: konstruktoid.docker_rootless
  vars:
    docker_user: "{{ provisioning_username | mandatory }}"
    docker_compose: true
    docker_user_bashrc: true
...

this is the command output of

ansible-playbook -u root -i inventories/test/hosts webserver.yml -vvv --extra-vars "var_files_path=./inventories/test/host_vars/default.yml"

I'm connecting as root to the server. The {{provisioning_username}} variable is "deployer" which was created in a previous task

command output:

...
...
TASK [konstruktoid.docker_rootless : Stat Docker user .bashrc] *********************************************************************************************************************************************
task path: /Users/myuser/.ansible/roles/konstruktoid.docker_rootless/tasks/bashrc.yml:2

ok: [[email protected]] => {
    "changed": false,
    "invocation": {
        "module_args": {
            "checksum_algorithm": "sha1",
            "follow": false,
            "get_attributes": true,
            "get_checksum": true,
            "get_md5": false,
            "get_mime": true,
            "path": "/home/deployer/.bashrc"
        }
    },
    "stat": {
        "exists": false
    }
}

TASK [konstruktoid.docker_rootless : Create Docker user .bashrc] *******************************************************************************************************************************************
task path: /Users/myuser/.ansible/roles/konstruktoid.docker_rootless/tasks/bashrc.yml:8
fatal: [[email protected]]: FAILED! => {
    "msg": "The conditional check 'not docker_user_bashrc.stat.exists' failed. The error was: error while evaluating conditional (not docker_user_bashrc.stat.exists): 'bool object' has no attribute 'stat'. 'bool object' has no attribute 'stat'\n\nThe error appears to be in '/Users/myuser/.ansible/roles/konstruktoid.docker_rootless/tasks/bashrc.yml': line 8, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Create Docker user .bashrc\n  ^ here\n"
}

The previous times I used my procedure ran smoothly, in particular the docker rootless installation part, based on your awesome project.

What's wrong this time?

Thank you in advance

RootlessKit port driver

I run reverse proxies in a docker rootless setup and need source IP propagation. Thus in my employments I extended your role with the following task for changing the RootlessKit's port driver:

- name: Configure docker source IP propagation
  # https://docs.docker.com/engine/security/rootless/#docker-run--p-does-not-propagate-source-ip-addresses
  community.general.ini_file:
    path: ~/.config/systemd/user/docker.service.d/override.conf
    section: Service
    option: Environment
    values:
      - '"DOCKERD_ROOTLESS_ROOTLESSKIT_NET=slirp4netns"'
      - '"DOCKERD_ROOTLESS_ROOTLESSKIT_PORT_DRIVER=slirp4netns"'
    state: present
  become: true
  become_user: "{{ docker_user }}"
  notify: docker_service_restart

Would you be interested in a pull request extending the role with this functionality? We could introduce a var for the port driver, the default being builtin as is now but also providing slirp4netns and perhaps pasta.

If so I'd be willing to make this contribution.

docker_user = ansible_user

So I want to install rootless docker for the user I'm installing most other services for in my playbook. Apart from the alias not being created for some reason, I don't want to have to use sudo in order to connect to the daemon my user is running. As far as I can see, that's the only option in the template, but for my case, setting the DOCKER_HOST env variable would suffice.

Is this something we can implement? I think it would be straightforward and it has a very common use case in my opinion.

Docker compose is hardcoded for x86_64

Thanks for this great and convenient Ansible role!

This line hardcodes Docker-compose for x86_64 bits. I think that should be good to have an e.g. docker_arch variable so that the caller can tweak it.

I just installed on an ARM server by manually downloading and overwriting the docker-compose executable. Sorry I did not take time to do an MR (I'll let you choose this variable name to avoid bikeshedding :D ) but that would be a great addition for this role

Why not use docker_user to administer docker

Hey, thanks for the role again. I was just in the process of creating a PR which adds a .bashrc to the docker_user, when I saw the note in your README.md:

Note that the sole purpose of the docker_user is to run the Docker daemon and related containers, and not for system administration or used as a regular user.

It somehow feels strange to me to use sudo every time, I run the docker command. Because I want docker to not have admin privileges. So my idea was to just switch into the user (sudo su docker_user) and than run commands as if it was rootful.

Why are you arguing against such a use case? Would you still accept a PR with an optional .bashrc?

$ whoami
dockeruser

$ cat .bashrc 
export XDG_RUNTIME_DIR="/run/user/1002"
export DOCKER_HOST="unix:///run/user/1002/docker.sock"
export PATH="~/bin:$PATH"

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

ansible-galaxy
requirements.yml
  • ansible.posix 1.5.4
  • community.docker 3.12.0
  • community.general 9.2.0
dockerfile
action-lint/Dockerfile
github-actions
.github/workflows/dependency-review.yml
  • step-security/harden-runner v2.9.1@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
  • actions/dependency-review-action v4.3.4@5a2ce3f5b92ee19cbb1541a4984c76d921601d7c
.github/workflows/issues.yml
  • step-security/harden-runner v2.9.1@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde
  • pozil/auto-assign-issue v2.0.0@c5bca5027e680b9e8411b826d16947afd8c76b32
.github/workflows/lint.yml
  • step-security/harden-runner v2.9.1@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
  • ansible/ansible-lint-action eb92667e07cc18e1d115ff02e5f07126310cec11
.github/workflows/schedlint.yml
  • step-security/harden-runner v2.9.1@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
  • ansible/ansible-lint-action eb92667e07cc18e1d115ff02e5f07126310cec11
.github/workflows/schedmainlint.yml
  • step-security/harden-runner v2.9.1@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
.github/workflows/scorecards.yml
  • step-security/harden-runner v2.9.1@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
  • ossf/scorecard-action v2.4.0@62b2cac7ed8198b15735ed49ab1e5cf35480ba46
  • actions/upload-artifact v4.3.6@834a144ee995460fba8ed112a2fc961b36a5ec5a
  • github/codeql-action v3.26.0@eb055d739abdc2e8de2e5f4ba1a8b246daa779aa
.github/workflows/slsa.yml
  • step-security/harden-runner v2.9.1@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
  • actions/upload-artifact v4.3.6@834a144ee995460fba8ed112a2fc961b36a5ec5a
  • slsa-framework/slsa-github-generator v2.0.0
  • actions/download-artifact v4.1.8@fa0a91b85d4f404e444e00e005971372dc801d16
  • softprops/action-gh-release v2.0.8@c062e08bd532815e2082a85e87e3ef29c3e6d191

  • Check this box to trigger a request for Renovate to run again on this repository

Error accessing mounted directories using a non-root container user.

Hi @konstruktoid,

I am trying to run an instance of step-ca. As per the Dockerfile of this image the process inside the container is run as the step user which is not the root user. Since my docker imstallation is rootless, The step user inside the container doesn't have write access to the mounted volumes. This issue exists with other images as well where the process inside the container is not run as root.

I also verified that the host directory that is mounted on the container is owned by the dockeruser which is running the docker daemon as rootless.

I saw few articles online that maps the user id from host user to container user but so far I couldn't get it to work.
Could you please provide your 2 cents and assist on what I could be doing wrong?

Thanks & Regards,

Utkarsh Vishnoi

adding skip_service_restart conditional check to skip docker service restart

Hello,

Is there any way to skip handlers from running after all tasks? After some search on the web, it seems not avoidable.

Can you add a conditional check inside the Restart rootless docker to skip it?

I'll provide an example to be clear:

this is handlers/main.yml

---
- name: Restart rootless docker
  become: true
  become_user: "{{ docker_user }}"
  ansible.builtin.systemd:
    name: docker.service
    state: restarted
    scope: user
  when: not skip_service_restart

where skip_service_restart variable default is false

Alternatively, I could leverage ansible_skip_tags if you can add a tag to the task that I can use to avoid restart, something like:

---
- name: Restart rootless docker
  become: true
  become_user: "{{ docker_user }}"
  ansible.builtin.systemd:
    name: docker.service
    state: restarted
    scope: user
  tags: 
  - docker_rootless_restart_handler

Thank you in advance

Variable COMPOSE_PLUGIN_PATH not set in bash_completion.d/docker script

In the bash completion script ~/.bash_completion.d/docker a variable COMPOSE_PLUGIN_PATH is being set by running docker info, which is used to setup completion for docker compose. This command fails due to the completion scripts being sourced before the user PATH has been setup.

On Ubuntu 22.04 completion is first sourced from /etc/profile.d/bash_completion.sh before the users .bashrc, and then again from ~/.bash_completion setup by the role. Both of them is being sourced before the PATH set in the Ansible managed block.

This is visible when logging in as the docker user:

# su - docker
-bash: docker: command not found
-bash: docker: command not found
docker@myhost:~$

If I re-order the Ansible managed block in .bashrc, putting it on the top of the file, the second run (sourced from .bashrc) works:

# su - docker
-bash: docker: command not found
docker@myhost:~$

The second sourcing could be fixed by re-ordering the tasks adding to .bashrc, but I'm unsure how to best tackle the first one. Perhaps modifying the completion-script, using some other method to locate the compose plugin.

Containers are fine, however docker-compose does not work for ansible

when I su as the user, the docker-compose is installed, however when trying to deploy the compose through ansible, it fails with the following

fatal: [10.1.0.5]: FAILED! => {"changed": false, "msg": "Unable to load docker-compose. Try `pip install docker-compose`. Error: Traceback (most recent call last):\n  File \"/tmp/ansible_community.docker.docker_compose_payload_7sod8ye4/ansible_community.docker.docker_compose_payload.zip/ansible_collections/community/docker/plugins/modules/docker_compose.py\", line 526, in <module>\nModuleNotFoundError: No module named 'compose'\n"}
 - name: Create and start services
          become: true
          become_user: "{{ docker_user }}"
          community.docker.docker_compose:
            project_src: ~/project/
            build: true
          register: output

Support for exposing the Docker API via TCP

I'd like to add support for exposing the Docker API via TCP like it is documented in the docker docs.

So far I tried extending templates/docker_rootless.service.j2:

  • Add -H tcp://0.0.0.0:2376 to the ExecStart commands
  • Add Environment="DOCKERD_ROOTLESS_ROOTLESSKIT_FLAGS=-p 0.0.0.0:2376:2376/tcp"

This does not seem to work. I guess it is about the space in the env variable, but I'm unsure.

Is this something someone already has tried?

I guess we could put that behind a variable and have it configurable by the user. Happy to provide a PR, but I can't get it running.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.