Files
werewulf/hpcod/ansible/golden.yml
T
ilker 683a4ff6ac hpcod: Apptainer instead of SingularityCE, and a working application catalogue
The catalogue could read but not fetch. It resolved a name to an image and
derived the hardware that image needs, and then nothing pulled anything -
which made it a schema, not a system. This closes that, and changes the
container runtime while it is open.

Apptainer, not SingularityCE, and without the suid package. They are the
same project either side of a 2021 split, both read SIF, and apptainer also
provides the `singularity` command, so nothing a user wrote stops working.
The reason is the setuid binary: SingularityCE installs starter-suid
unconditionally, and it was on every compute node. Apptainer splits it out,
so not installing apptainer-suid leaves no setuid-root binary on a machine
running other people's jobs, and user namespaces do the work instead
(measured on a node: max_user_namespaces is 23437, and a container runs).
Governance and 36 MB against 55 MB are the secondary arguments; the image
went 950 MB to 889 MB, and in a tmpfs root every megabyte is paid twice.

singularity-ce was never asked for. It arrived as a weak dependency of
ohpc-base-compute, on the one dnf line in the image build that had no
install_weak_deps=False. A setuid-root binary reached every node because a
flag was missing from one line.

The fetch half: the control plane resolves names against its catalogue and
Terraform carries the resolved image references - names and URIs, nothing
else - through cloud-init to the head, which pulls them into /opt/apps.
/opt is already exported read-only to the nodes, so one pull makes an image
visible everywhere without a second distribution path, and the head needs
no catalogue, no credentials for one, and no opinion about what an
application is. The head gets apptainer too, since it is the machine with
the network and the writable /opt; the role refuses to run if
apptainer-suid is present there either.

A failed pull fails the provision. A cluster that comes up without the
software it was asked for looks healthy and is useless.

Three bugs, all mine, all in the checks rather than the system. The
read-back used `apptainer inspect --type container`, and this version has
no --type, so a valid image failed verification - the check reporting its
own bug as the system's. Bare inspect was then measured to discriminate:
exit 0 on a real SIF, 255 on a file. The suite grepped inspect's output for
the image name, which is build metadata and does not contain it. And its
wait condition was `sinfo | grep -q idle`, which passes when any node is
idle rather than all of them, so a two-node check ran against one node that
had registered and one that had not. That last one was in three scripts,
which means some of today's passes were luck.

Verified from empty, 8 of 8, 145s: busybox.sif pulled into /opt/apps, a
valid container, no setuid binary and no apptainer-suid on the nodes, and
BusyBox v1.38.0 running under hpcuser on both of them.
2026-09-20 22:32:32 +02:00

145 lines
5.5 KiB
YAML

---
# Build the golden head node: everything a tenant head node needs installed,
# and nothing that identifies a tenant.
#
# The split matters. Anything installed here is paid for once, at build time.
# Anything left to site.yml is paid for by every tenant, while a user waits.
#
# ansible-playbook -i inventory/golden.yml golden.yml
- name: Install the head node software stack
hosts: golden
become: true
gather_facts: true
# compute_nodes is required by site.yml but meaningless for a template, so
# the install-tagged tasks are run without it.
vars:
compute_nodes: []
tasks:
# Included without "apply", deliberately. "apply: tags: [install]" adds the
# tag to every task in the role instead of selecting the tagged ones, so
# the whole role runs - including tenant configuration that has no meaning
# on a template. The selection is made by --tags install on the command
# line, which the build script passes.
- name: Base system
ansible.builtin.include_role:
name: common
tags: [install]
- name: Warewulf
ansible.builtin.include_role:
name: warewulf
tags: [install]
- name: OpenHPC, Slurm and MUNGE
ansible.builtin.include_role:
name: slurm
tags: [install]
# Import the node image here too. It is the same ~1 GB whichever host
# fetches it, so fetching it once at build time removes it from every
# tenant's critical path. The tenant's node_image role then finds it
# already present and does nothing.
- name: Node image
ansible.builtin.include_role:
name: node_image
tags: [install]
# The portal's own software: Apache, Ruby, Node and OnDemand itself. A
# large install, and precisely the kind that belongs in a template rather
# than on every tenant's critical path.
# Only its install half runs here: apptainer into the template, no
# images - those are per cluster and the template has no list.
- name: Application runtime
ansible.builtin.include_role:
name: apps
tags: [install]
- name: User-facing portal
ansible.builtin.include_role:
name: ondemand
tags: [install]
# Last, because it copies the playbook directory into the template: run it
# after the roles above so the copy is of the tree that just built this.
- name: Self-configuration runtime
ansible.builtin.include_role:
name: selfconfig
tags: [install]
- name: Strip every trace of this build from the image
hosts: golden
become: true
gather_facts: false
tags: [always]
tasks:
# A MUNGE key baked into the template would be shared by every tenant
# cloned from it, which means any tenant could authenticate to any other
# tenant's Slurm. It is regenerated per tenant by the slurm role.
- name: Remove the MUNGE key
ansible.builtin.file:
path: /etc/munge/munge.key
state: absent
# nodes.conf is deliberately NOT removed. Its contents are tenant-specific,
# but the file itself must exist: without it "wwctl configure --all" cannot
# build the host overlay and dhcpd refuses to start. The golden run never
# adds a node, so what the template carries is the package default.
- name: Remove host identity and per-tenant secrets
ansible.builtin.file:
path: "{{ item }}"
state: absent
loop:
- /root/.ssh/cluster
- /root/.ssh/cluster.pub
# The registry pull credential. A tenant has no use for it - the image
# it would fetch is already in this template - and leaving it here
# ships a credential, however narrow, to every tenant that is ever
# cloned from this. A control-plane run that genuinely needs to pull
# writes it again from the environment.
- /root/.docker/config.json
- /var/lib/warewulf/overlays/hpc
# Only the overlays, not all of provision/. That directory holds two
# unlike things: provision/overlays/<node>/ carries this tenant's MUNGE
# key and SSH keys and must not survive into a template, while
# provision/images/ is the compiled node image - 1.2 GB that is byte
# for byte the same for every tenant and holds no secret. Deleting both
# made each tenant spend ~28s recompressing an image it could have
# inherited; it was the single slowest task in the whole provision.
- /var/lib/warewulf/provision/overlays
- name: Remove SSH host keys so each clone generates its own
ansible.builtin.shell: rm -f /etc/ssh/ssh_host_*
changed_when: true
# An identical machine-id across clones breaks anything keyed on it, and
# systemd will regenerate it on first boot when the file is empty.
- name: Blank the machine id
ansible.builtin.copy:
content: ""
dest: /etc/machine-id
mode: "0444"
- name: Make cloud-init run again on the clone
ansible.builtin.command: cloud-init clean --logs --seed
changed_when: true
- name: Clear caches, logs and history
ansible.builtin.shell: |
dnf clean all
rm -rf /var/log/journal/* /var/log/dnf* /var/log/hawkey*
rm -f /root/.bash_history /home/*/.bash_history
truncate -s0 /var/log/wtmp /var/log/lastlog 2>/dev/null || true
changed_when: true
- name: Report
ansible.builtin.debug:
msg: >-
Golden image ready. Shut down and convert to a Proxmox template;
the tenant playbook will regenerate the MUNGE key, SSH host keys
and machine id on first boot.