Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions group_vars/indexers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
5 changes: 5 additions & 0 deletions roles/hardening/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 27 additions & 1 deletion roles/hardening/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
Loading