Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a185a301db | ||
|
|
c7c38c6bc0 |
No files matched your search
@@ -0,0 +1,6 @@
|
||||
---
|
||||
minor_changes:
|
||||
- >-
|
||||
docker - New input ``docker_keyring_checksum``: the Docker APT key is verified against a pinned
|
||||
sha256, and a changed key fails the install until a person has checked it and updated the hash.
|
||||
Set ``docker_keyring_checksum`` too when ``docker_gpg_url`` is overridden.
|
||||
@@ -27,6 +27,7 @@ The role targets Ubuntu hosts only: it installs from Docker's Ubuntu repository,
|
||||
| `docker_keyring_path` | `/etc/apt/keyrings/docker.asc` | no | Repository key location. |
|
||||
| `docker_apt_list_path` | `/etc/apt/sources.list.d/docker.list` | no | APT source file. |
|
||||
| `docker_gpg_url` | `https://download.docker.com/linux/ubuntu/gpg` | no | Key URL. |
|
||||
| `docker_keyring_checksum` | sha256 of the current Docker key | no | Expected sha256 (hex, no `sha256:` prefix) of the key at `docker_gpg_url`; set it too when `docker_gpg_url` is overridden; a mismatch fails the download, so a changed key stops the install until this is updated. |
|
||||
| `docker_repo_base_url` | `https://download.docker.com/linux/ubuntu` | no | Repository base URL. |
|
||||
| `docker_apt_arch` | derived from the host | no | Architecture in the APT source. Empty derives it (`x86_64` gives `amd64`, `aarch64` gives `arm64`); another architecture fails until this is set. A value set here is always used; lowercase letters and digits only. |
|
||||
| `docker_start_missed` | `false` | no | Install a boot unit that starts the containers Docker skipped after a reboot (see [Boot and shutdown units](#boot-and-shutdown-units)). |
|
||||
@@ -86,17 +87,18 @@ With any of `docker_daemon_options`, `docker_live_restore`, `docker_log_driver`,
|
||||
|
||||
## Tests
|
||||
|
||||
`molecule/default` runs in CI only (`.gitea/workflows/molecule.yml`, no local runner), on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). A real Docker Engine cannot run there: `dockerd` needs the bridge, iptables rules and a delegated cgroup, and the container has no privileged mode. So the scenario builds a local APT repository, signs it with a throwaway key, and points the role at it with `docker_gpg_url` and `docker_repo_base_url`. The repository holds empty stand-ins for `docker-ce`, `docker-ce-cli` and `containerd.io`. The stand-in `docker-ce` ships a stub `docker.service` (`sleep infinity`) and creates the `docker` group, as the real package does. It runs `check` before the converge (on a fresh host) and after it (on the configured host).
|
||||
`molecule/default` runs in CI only (`.gitea/workflows/molecule.yml`, no local runner), on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). A real Docker Engine cannot run there: `dockerd` needs the bridge, iptables rules and a delegated cgroup, and the container has no privileged mode. So the scenario builds a local APT repository, signs it with a throwaway key, and points the role at it with `docker_gpg_url`, `docker_keyring_checksum` (the throwaway key's hash) and `docker_repo_base_url`. The repository holds empty stand-ins for `docker-ce`, `docker-ce-cli` and `containerd.io`. The stand-in `docker-ce` ships a stub `docker.service` (`sleep infinity`) and creates the `docker` group, as the real package does. It runs `check` before the converge (on a fresh host) and after it (on the configured host).
|
||||
|
||||
What it shows, with the role's tasks running unchanged:
|
||||
|
||||
- The key is fetched, stored at `docker_keyring_path` with mode `0644`, and apt really verifies the repository against it (an unsigned or wrongly signed repository would leave no install candidate).
|
||||
- The key is fetched, checked against `docker_keyring_checksum`, stored at `docker_keyring_path` with mode `0644`, and apt really verifies the repository against it (an unsigned or wrongly signed repository would leave no install candidate).
|
||||
- The source line has the architecture, the `signed-by` keyring and `ansible_facts['distribution_release']`.
|
||||
- The packages are installed from that repository, the unit is enabled and active, and `docker_users` join `docker_group`.
|
||||
- `docker_remove` with `docker_remove_data` removes the source line, the keyring, the packages, the unit and `/var/lib/docker`.
|
||||
- Both units are installed, enabled, ordered against `docker.service` as stated, the shutdown unit is active, a unit is removed when its input is `false`, and `docker_remove` removes both.
|
||||
- With the daemon inputs set, `/etc/docker/daemon.json` is valid JSON with exactly the expected keys, mode `0644` and root-owned. A change with `docker_daemon_restart: false` leaves dockerd running (its start time is unchanged); with `true` it restarts it. A key set both in `docker_daemon_options` and by a dedicated input, and a bad log size, driver or file count, are refused before any change.
|
||||
- The argument check refuses a mapping for `docker_users`, a non-boolean `docker_remove` and a `docker_stop_at_shutdown_timeout` of 0.
|
||||
- A key whose hash does not match `docker_keyring_checksum` fails the key download.
|
||||
- A second run changes nothing (molecule's idempotence check).
|
||||
|
||||
What it does not show: what the units do at a real boot or shutdown (the container has no dockerd, no NFS shares and no reboot; the selection logic of `docker-start-missed` is unit-tested in `tests/scripts/test_docker_files.py`), that the upstream repository and key at `download.docker.com` are reachable and valid, that the real packages install, that `dockerd` starts, anything about container networking or iptables, the `docker_update` path (`tasks/update.yml`), and removal without `docker_remove_data` (the removal stops the unit first, so it can run only once per install). It needs the Ubuntu mirrors, for the `curl` the role installs. These gaps are a known residual risk of the role.
|
||||
|
||||
@@ -11,6 +11,10 @@ docker_packages:
|
||||
docker_keyring_path: /etc/apt/keyrings/docker.asc
|
||||
docker_apt_list_path: /etc/apt/sources.list.d/docker.list
|
||||
docker_gpg_url: https://download.docker.com/linux/ubuntu/gpg
|
||||
# sha256 of Docker's package signing key (9DC858229FC7DD38854AE2D88D81803C0EBFCD88), as the ASCII-armored file
|
||||
# docker_gpg_url serves. Static on purpose: a rotated or re-armored key fails the install until a person has checked the
|
||||
# new one and updated this hash.
|
||||
docker_keyring_checksum: "1500c1f56fa9e26b9b8f42452a553675796ade0807cdce11975eb98170b3a570"
|
||||
docker_repo_base_url: https://download.docker.com/linux/ubuntu
|
||||
|
||||
# Architecture written into the APT source. Empty (the default) derives it from the host: x86_64 gives amd64, aarch64 gives arm64, any
|
||||
|
||||
@@ -49,6 +49,14 @@ argument_specs:
|
||||
default: https://download.docker.com/linux/ubuntu/gpg
|
||||
description:
|
||||
- URL of the repository signing key.
|
||||
docker_keyring_checksum:
|
||||
type: str
|
||||
default: 1500c1f56fa9e26b9b8f42452a553675796ade0807cdce11975eb98170b3a570
|
||||
description:
|
||||
- >-
|
||||
sha256 of the key at C(docker_gpg_url), as the hex digest without the C(sha256:) prefix. The download fails
|
||||
on a mismatch, so a rotated or re-armored upstream key stops the install until the new key is checked and
|
||||
the hash updated. Set C(docker_keyring_checksum) too when C(docker_gpg_url) is overridden.
|
||||
docker_repo_base_url:
|
||||
type: str
|
||||
default: https://download.docker.com/linux/ubuntu
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
hosts: all
|
||||
vars:
|
||||
docker_gpg_url: file:///srv/docker-stub-repo/docker.asc
|
||||
# The stand-in key is generated per run, so its hash is read here rather than pinned.
|
||||
docker_keyring_checksum: "{{ docker_stub_key.stat.checksum }}"
|
||||
docker_repo_base_url: file:///srv/docker-stub-repo
|
||||
docker_users: [moleculeuser]
|
||||
docker_start_missed: true
|
||||
@@ -18,5 +20,11 @@
|
||||
docker_log_max_file: "3"
|
||||
docker_daemon_options:
|
||||
max-concurrent-downloads: 3
|
||||
pre_tasks:
|
||||
- name: Stat the stand-in repository key
|
||||
ansible.builtin.stat:
|
||||
path: /srv/docker-stub-repo/docker.asc
|
||||
checksum_algorithm: sha256
|
||||
register: docker_stub_key
|
||||
roles:
|
||||
- role: mortis.kamino.docker
|
||||
@@ -0,0 +1,27 @@
|
||||
---
|
||||
# The zeroed hash matches no file, so the key task must be the one that fails.
|
||||
- name: Run the role with a checksum the stand-in key does not have
|
||||
block:
|
||||
- name: Include the role
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.docker
|
||||
vars:
|
||||
docker_gpg_url: file:///srv/docker-stub-repo/docker.asc
|
||||
docker_repo_base_url: file:///srv/docker-stub-repo
|
||||
docker_keyring_path: /tmp/docker-refused-key.asc
|
||||
docker_keyring_checksum: "{{ '0' * 64 }}"
|
||||
- name: Fail when the wrong key was accepted
|
||||
ansible.builtin.fail:
|
||||
msg: MOLECULE-ACCEPTED
|
||||
rescue:
|
||||
- name: The key download stopped the play
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- ansible_failed_task.name == 'Install Docker APT GPG key'
|
||||
- "'did not match' in ansible_failed_result.msg | default('')"
|
||||
quiet: true
|
||||
always:
|
||||
- name: Remove the refused key path
|
||||
ansible.builtin.file:
|
||||
path: /tmp/docker-refused-key.asc
|
||||
state: absent
|
||||
@@ -302,12 +302,19 @@
|
||||
hosts: all
|
||||
vars:
|
||||
docker_gpg_url: file:///srv/docker-stub-repo/docker.asc
|
||||
docker_keyring_checksum: "{{ docker_stub_key.stat.checksum }}"
|
||||
docker_repo_base_url: file:///srv/docker-stub-repo
|
||||
docker_users: [moleculeuser]
|
||||
docker_start_missed: false
|
||||
docker_stop_at_shutdown: true
|
||||
docker_stop_at_shutdown_timeout: 20
|
||||
tasks:
|
||||
- name: Stat the stand-in repository key
|
||||
ansible.builtin.stat:
|
||||
path: /srv/docker-stub-repo/docker.asc
|
||||
checksum_algorithm: sha256
|
||||
register: docker_stub_key
|
||||
|
||||
- name: Apply the role with the boot unit off
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.docker
|
||||
@@ -368,6 +375,7 @@
|
||||
hosts: all
|
||||
vars:
|
||||
docker_gpg_url: file:///srv/docker-stub-repo/docker.asc
|
||||
docker_keyring_checksum: "{{ docker_stub_key.stat.checksum }}"
|
||||
docker_repo_base_url: file:///srv/docker-stub-repo
|
||||
docker_users: [moleculeuser]
|
||||
docker_start_missed: true
|
||||
@@ -378,6 +386,12 @@
|
||||
docker_log_max_file: "3"
|
||||
docker_live_restore: true
|
||||
tasks:
|
||||
- name: Stat the stand-in repository key
|
||||
ansible.builtin.stat:
|
||||
path: /srv/docker-stub-repo/docker.asc
|
||||
checksum_algorithm: sha256
|
||||
register: docker_stub_key
|
||||
|
||||
- name: Read the start time of the service
|
||||
ansible.builtin.command: systemctl show -p ActiveEnterTimestampMonotonic docker.service # noqa: command-instead-of-module
|
||||
register: docker_verify_before
|
||||
@@ -420,6 +434,14 @@
|
||||
- (docker_verify_daemon_after.content | b64decode | from_json)['max-concurrent-downloads'] == 6
|
||||
quiet: true
|
||||
|
||||
# A key that does not match docker_keyring_checksum fails at the key download, so the source line and packages are untouched. It goes to a separate path, so
|
||||
# the installed key stays for the removal below.
|
||||
- name: A key that does not match the pinned checksum is refused
|
||||
hosts: all
|
||||
tasks:
|
||||
- name: Apply the role with a wrong checksum
|
||||
ansible.builtin.include_tasks: tasks/refuse_checksum.yml
|
||||
|
||||
# docker_remove_data is set, so this also covers the destructive path: the packages are
|
||||
# purged and /var/lib/docker, seeded in prepare.yml, is deleted. The removal stops the unit
|
||||
# before the package takes it away, so it can only run once; a second run would fail on the
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
ansible.builtin.get_url:
|
||||
url: "{{ docker_gpg_url }}"
|
||||
dest: "{{ docker_keyring_path }}"
|
||||
checksum: "sha256:{{ docker_keyring_checksum }}"
|
||||
mode: "0644"
|
||||
tags: [docker, install]
|
||||
|
||||
|
||||
Reference in new issue
Block a user