--- # systemd's sandboxing directives (ProtectSystem, PrivateTmp, PrivateDevices and # the Protect* family) need a mount namespace, which needs CAP_SYS_ADMIN. The # test container is unprivileged on purpose, so without this drop-in the unit # fails with status 226/NAMESPACE. The drop-in resets only those directives; # the user, capabilities, environment file and ExecStart under test are the # role's own. The sandbox itself is therefore not covered by this scenario. # # User is reset too. The switch to User=traefik fails in the unprivileged container # (exit 217/USER, "Failed to keep CAP_SYS_ADMIN"), so the unit runs as root here. # The traefik user, the file ownership checks and the other unit settings are # still asserted. - name: Prepare hosts: all gather_facts: false tasks: # The image ships without apt lists, and --check does not refresh them, so the fresh-host # check finds the packages the role installs. - name: Refresh the apt cache ansible.builtin.apt: update_cache: true - name: Create the unit drop-in directory ansible.builtin.file: path: /etc/systemd/system/traefik.service.d state: directory mode: "0755" - name: Disable the namespace-based sandboxing for the unprivileged container ansible.builtin.copy: dest: /etc/systemd/system/traefik.service.d/molecule.conf mode: "0644" content: | [Service] ProtectSystem=no ProtectHome=no PrivateTmp=no PrivateDevices=no ProtectKernelModules=no ProtectKernelTunables=no ReadWritePaths= User= # traefik passes its rules through the mortis.kamino.ufw service_rules entry point, which needs ufw # installed and active. ufw_rules comes from the inventory group_vars (the SSH allow rule the # lock-out guard requires); the ufw scenario tests that role, so it runs once here, not in converge. - name: Install and enable ufw hosts: all gather_facts: false roles: - role: mortis.kamino.ufw # A stand-in release for verify's update path, behind a file:// URL: the role's download, checksum # check and swap run unchanged, without fetching another real release per host. The converge # still downloads the real role default from GitHub. - name: Prepare the stand-in release hosts: all gather_facts: false vars_files: - ../../defaults/main.yml vars: traefik_test_release: "{{ traefik_verify_other_version }}" tasks: - name: Create the stand-in release directory ansible.builtin.file: path: "/opt/molecule-download/{{ traefik_test_release }}" state: directory mode: "0755" # Answers `version` like Traefik and otherwise stays up like the service. - name: Write the stand-in binary ansible.builtin.copy: dest: "/opt/molecule-download/{{ traefik_test_release }}/traefik" mode: "0755" content: | #!/bin/sh case "$1" in version) echo "Version: {{ traefik_test_release | regex_replace('^v', '') }}" ;; *) exec sleep infinity ;; esac - name: Pack the stand-in archive ansible.builtin.command: argv: [tar, -czf, "{{ traefik_test_archive }}", -C, "/opt/molecule-download/{{ traefik_test_release }}", traefik] creates: "{{ traefik_test_archive }}" vars: traefik_test_archive: "/opt/molecule-download/{{ traefik_test_release }}/traefik_{{ traefik_test_release }}_{{ traefik_os }}_{{ traefik_arch }}.tar.gz" - name: Write the checksums file in the release format ansible.builtin.shell: cmd: sha256sum traefik_*.tar.gz > traefik_{{ traefik_test_release }}_checksums.txt chdir: "/opt/molecule-download/{{ traefik_test_release }}" creates: "traefik_{{ traefik_test_release }}_checksums.txt"