diff --git a/group_vars/indexers/main.yml b/group_vars/indexers/main.yml index 07c76eb..71ad192 100644 --- a/group_vars/indexers/main.yml +++ b/group_vars/indexers/main.yml @@ -34,6 +34,9 @@ common_reboot_reporting: true # yes; remove it (roles/hardening). hardening_fix_cloud_init_sshd: true +# cloud-init's apt-configure crashes on Cherry's Debian image (roles/hardening). +hardening_fix_cloud_init_apt: true + # To upgrade k3s here ahead of the fleet (a canary), set k3s_version and # k3s_upgrade_path in this file: they override group_vars/managed_boxes. # diff --git a/roles/hardening/defaults/main.yml b/roles/hardening/defaults/main.yml index 4998a2a..47060f0 100644 --- a/roles/hardening/defaults/main.yml +++ b/roles/hardening/defaults/main.yml @@ -13,6 +13,11 @@ hardening_removed_accounts: # so the IPFS boxes are left as they are; group_vars/indexers turns it on. hardening_fix_cloud_init_sshd: false +# Write a cloud-init drop-in naming the apt mirrors, so apt-configure does not +# crash, and telling it to leave the apt sources alone. Off by default; +# group_vars/indexers turns it on. +hardening_fix_cloud_init_apt: false + # Post-quantum hybrid key exchange for sshd, in order of preference, ahead of # the classical KexAlgorithms. Each is offered only where the box's OpenSSH has # it (tasks/main.yml): mlkem768x25519-sha256 needs 9.9, sntrup761x25519 8.5. diff --git a/roles/hardening/tasks/main.yml b/roles/hardening/tasks/main.yml index 317de8d..e552707 100644 --- a/roles/hardening/tasks/main.yml +++ b/roles/hardening/tasks/main.yml @@ -241,7 +241,7 @@ ansible.builtin.stat: path: /etc/cloud/cloud.cfg.d register: cloud_cfg_d - when: hardening_fix_cloud_init_sshd | bool + when: hardening_fix_cloud_init_sshd | bool or hardening_fix_cloud_init_apt | bool - name: Stop cloud-init from turning SSH password login back on ansible.builtin.copy: @@ -254,6 +254,32 @@ ssh_pwauth: false when: hardening_fix_cloud_init_sshd | bool and (cloud_cfg_d.stat.isdir | default(false)) +# On Cherry's Debian 13, cloud-init's apt-configure crashed with +# KeyError: 'security' (indexers-amst1): with no apt mirrors configured, it +# reads them from the datasource and expects both. It does that before it looks +# at generate_mirrorlists or preserve_sources_list, so naming the mirrors is what +# avoids the crash. The other two keys keep it from writing any apt sources or +# mirror lists (the image's 01_debian_cloud.cfg sets generate_mirrorlists: true), +# so the URIs go unused unless higher-priority config turns that back on. +- name: Stop cloud-init's apt-configure from crashing and keep its hands off apt sources + ansible.builtin.copy: + dest: /etc/cloud/cloud.cfg.d/99-ipni-apt.cfg + mode: "0644" + owner: root + group: root + content: | + # Managed by Ansible: leave apt sources alone (roles/hardening). + apt: + generate_mirrorlists: false + preserve_sources_list: true + primary: + - arches: [default] + uri: http://deb.debian.org/debian + security: + - arches: [default] + uri: http://deb.debian.org/debian-security + when: hardening_fix_cloud_init_apt | bool and (cloud_cfg_d.stat.isdir | default(false)) + - name: Remove cloud-init's sshd drop-in, which overrides 99-hardening.conf ansible.builtin.file: path: /etc/ssh/sshd_config.d/50-cloud-init.conf