Files
ilkerandClaude Opus 5 0ea8bdc759 hpcod: the portal's own checks were testing the Apache they replaced
Two tasks in the ondemand role could not pass, and c002 is where it
showed: the play aborted on "Confirm the portal refuses a caller with
no certificate" against a portal that was configured correctly.

Handlers run at the end of a play, which is after these checks. The
configuration had been rewritten on disk and Apache was still serving
the old one - "Start the portal" uses state: started, which does
nothing to a process already running. So the check tested the Apache
that was being replaced, failed, aborted the play, and the restart
never happened at all; the next run found the same state. Handlers
are now flushed before anything reads the result back.

The trusted-caller probe insisted on 401 while its own status_code
excluded it, so it could never pass either. It is skipped without a
client key, which is why nothing noticed.

And the pinned certificate is now read back as a certificate. A value
that arrives truncated still writes a file, Apache still starts, and
the failure surfaces much later as a handshake refused for no stated
reason. Passing the PEM through a command line did exactly that here:
ten bytes on disk, and every check downstream was happy.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 00:21:49 +02:00

454 lines
18 KiB
YAML

---
# Open OnDemand: the layer a tenant's users actually touch.
#
# Until now a provisioned tenant arrived with Slurm, MUNGE, OpenHPC, NFS /home
# and sshd - everything a scheduler needs and nothing a user sees (§21.1). OOD
# puts a web interface in front of the scheduler this cluster already runs: job
# submission, a file browser over the NFS home, and a shell. It is free, it is
# Slurm-native, and it wants exactly the machine we already have, because the
# head node is both the Slurm controller and the /home server.
#
# Reachability is deliberately not solved here. The portal listens on the
# management address only: not on the tenant fabric, where compute nodes have
# no business reaching it, and not on the internet. Publishing a tenant portal
# needs a reverse proxy in the control plane or a per-tenant DNS and
# certificate scheme, and that is a decision about attack surface rather than
# a missing line of configuration (§21.4).
# Software goes in the template, configuration comes at tenant time. Anything
# tagged install runs once, when the golden image is built, and is skipped on
# the clone (see roles/selfconfig).
- name: Enable the Ruby and Node streams OnDemand needs
ansible.builtin.command:
cmd: dnf module enable -y ruby:3.3 nodejs:22
register: ondemand_modules
changed_when: "'Nothing to do' not in ondemand_modules.stdout"
tags: [install]
- name: Trust the OnDemand signing key
ansible.builtin.rpm_key:
key: https://yum.osc.edu/ondemand/RPM-GPG-KEY-ondemand-SHA512
state: present
tags: [install]
# Two transactions, not one. The release RPM is what defines the repository
# that carries the portal, and dnf resolves the whole transaction against the
# repositories it knew about when it started - so asking for both at once
# fails with "No package ondemand available", which reads like the package
# does not exist rather than like an ordering mistake.
- name: Install the OnDemand repository definition
ansible.builtin.dnf:
name: "https://yum.osc.edu/ondemand/{{ ondemand_version }}/ondemand-release-web-{{ ondemand_version }}-1.el9.noarch.rpm"
state: present
disable_gpg_check: false
tags: [install]
- name: Confirm the repository is there before asking it for anything
ansible.builtin.stat:
path: /etc/yum.repos.d/ondemand-web.repo
register: ondemand_repo
failed_when: not ondemand_repo.stat.exists
tags: [install]
- name: Install the portal
ansible.builtin.dnf:
name:
- ondemand
state: present
tags: [install]
# ---------------------------------------------------------------------------
# From here on: per-tenant configuration, which runs on every clone.
# ---------------------------------------------------------------------------
# OpenHPC installs Slurm under a versioned prefix, so the path is discovered
# rather than written down: a hardcoded one would survive exactly until the
# next OpenHPC release and then fail as "cluster not configured", which says
# nothing about the cause.
- name: Find the Slurm binaries
ansible.builtin.shell:
cmd: set -o pipefail; dirname "$(command -v sbatch)"
executable: /bin/bash
register: ondemand_slurm_bin
changed_when: false
# The package ships /etc/ood/config with its own example portal config and an
# ondemand.d/, but not clusters.d - that one is the administrator's to create,
# and its absence surfaces as "Destination directory does not exist" rather
# than as anything about clusters.
- name: Make room for the cluster definition
ansible.builtin.file:
path: /etc/ood/config/clusters.d
state: directory
owner: root
group: root
mode: "0755"
- name: Describe this tenant's cluster to OnDemand
ansible.builtin.copy:
dest: /etc/ood/config/clusters.d/{{ ondemand_cluster_id }}.yml
owner: root
group: root
mode: "0644"
content: |
---
# Written by Ansible. One cluster: the tenant this head node serves.
v2:
metadata:
title: "{{ ondemand_cluster_id }}"
login:
host: "{{ head_cluster_ip }}"
job:
adapter: "slurm"
# No "cluster:" key. It makes every sbatch pass --cluster, which
# Slurm can only resolve through slurmdbd - and there is no
# accounting database here, so submission fails with "'c001'
# can't be reached now, or it is an invalid entry". The key is
# for federated Slurm; this head talks to its own controller.
bin: "{{ ondemand_slurm_bin.stdout }}"
# Without this the portal can list jobs and nothing else: every
# interactive app needs somewhere to run, and batch_connect is
# where OnDemand is told there is such a thing here.
#
# The two wrappers are written out rather than shared with a YAML
# anchor - the anchor parsed fine and the dashboard then refused
# to start at all.
batch_connect:
basic:
# The whole job runs inside the desktop container, not just
# the session script: the VNC server starts from before.sh,
# which the job sources first, so wrapping only the inner
# script left vncserver looking for TurboVNC on the node.
#
# /opt/apps is bound, not /opt - binding the host's /opt
# mounts it over the container's own and hides
# /opt/TurboVNC, and vncserver is then "command not found"
# from inside an image that demonstrably contains it.
#
# PATH is stated because --cleanenv drops the image's own.
script_wrapper: |
set -e
cat > "${PWD}/hpcod-job.sh" <<'HPCOD_JOB'
%s
HPCOD_JOB
exec apptainer exec --cleanenv --writable-tmpfs \
--env PATH=/opt/TurboVNC/bin:/usr/local/bin:/usr/bin:/bin \
--bind "${PWD}" --bind /home --bind {{ ondemand_apps_dir }} \
{{ ondemand_slurm_binds }} \
{{ ondemand_desktop_sif }} bash "${PWD}/hpcod-job.sh"
set_host: "host=$(hostname -s)"
vnc:
# The template's default is /opt/websockify/run, which does
# not exist here. Without this the session came all the way
# up - Xvnc running, XFCE started - and died on
# "[websockify]: failed to launch!".
websockify_cmd: "/usr/bin/websockify"
script_wrapper: |
set -e
cat > "${PWD}/hpcod-job.sh" <<'HPCOD_JOB'
%s
HPCOD_JOB
exec apptainer exec --cleanenv --writable-tmpfs \
--env PATH=/opt/TurboVNC/bin:/usr/local/bin:/usr/bin:/bin \
--bind "${PWD}" --bind /home --bind {{ ondemand_apps_dir }} \
{{ ondemand_slurm_binds }} \
{{ ondemand_desktop_sif }} bash "${PWD}/hpcod-job.sh"
set_host: "host=$(hostname -s)"
notify: restart httpd
# The portal password and its htpasswd file are gone. They were how the
# cluster authenticated people before the control plane did it, and
# keeping them would leave a second way in that nobody maintains.
- name: Generate the portal certificate
ansible.builtin.command:
cmd: >-
openssl req -x509 -newkey rsa:2048 -nodes -days 3650
-subj "/CN={{ ondemand_servername }}"
-addext "subjectAltName=DNS:{{ ondemand_servername }},IP:{{ ondemand_listen_addr }}"
-keyout /etc/pki/tls/private/ood-portal.key
-out /etc/pki/tls/certs/ood-portal.crt
creates: /etc/pki/tls/certs/ood-portal.crt
- name: Protect the portal key
ansible.builtin.file:
path: /etc/pki/tls/private/ood-portal.key
owner: root
group: root
mode: "0600"
- name: Configure the portal
ansible.builtin.copy:
dest: /etc/ood/config/ood_portal.yml
owner: root
group: root
mode: "0644"
content: |
---
# Written by Ansible. Bound to the management address on purpose: the
# tenant fabric is for provisioning and MPI, and compute nodes have no
# reason to reach the portal.
servername: {{ ondemand_servername }}
listen_addr_port:
- "{{ ondemand_listen_addr }}:443"
# Without these Apache never creates the proxy locations, and an
# interactive session comes all the way up - VNC running, desktop
# started, connection details written - and then the browser gets
# 404 on the websocket. The session looks fine from every side
# except the only one that matters.
node_uri: "/node"
rnode_uri: "/rnode"
ssl:
- 'SSLCertificateFile "/etc/pki/tls/certs/ood-portal.crt"'
- 'SSLCertificateKeyFile "/etc/pki/tls/private/ood-portal.key"'
# Authentication happens once, at the control plane, and the
# cluster trusts it because of this: the only client whose
# certificate verifies against the pinned file below is the
# control plane's proxy. Nothing else on the management network
# can complete the handshake, let alone reach a login prompt.
- 'SSLCACertificateFile "{{ ondemand_client_ca }}"'
- 'SSLVerifyClient require'
- 'SSLVerifyDepth 1'
auth:
# REMOTE_USER comes from the verified certificate, not from a
# header. A header would have to be trusted, and anything trusted
# can be forged the day the trust assumption stops holding; a
# subject name from a verified certificate cannot be.
- 'SSLUserName SSL_CLIENT_S_DN_CN'
- 'Require ssl-verify-client'
# The control plane authenticates people; this cluster has one
# account. The mapping is explicit rather than implied by naming the
# certificate after the account, so the certificate can go on saying
# what it actually is.
user_map_cmd: '/opt/ood/map-user'
notify: restart httpd
- name: Install the control plane's certificate
ansible.builtin.copy:
dest: "{{ ondemand_client_ca }}"
owner: root
group: root
mode: "0644"
content: "{{ control_plane_cert }}"
when: control_plane_cert | default('') | length > 0
notify: restart httpd
# Read the file back as a certificate, because everything downstream
# assumes it is one and nothing else would say otherwise. A value that
# arrived truncated - passed through a shell, a command line or a
# template - still writes a file, Apache still starts, and the failure
# surfaces as a handshake refused for no stated reason. This once wrote
# ten bytes and looked exactly like success.
- name: Confirm the pinned certificate is a certificate
ansible.builtin.command:
cmd: "openssl x509 -noout -subject -in {{ ondemand_client_ca }}"
register: ondemand_ca_check
changed_when: false
when: control_plane_cert | default('') | length > 0
- name: Map the control plane's identity to the cluster account
ansible.builtin.copy:
dest: /opt/ood/map-user
owner: root
group: root
mode: "0755"
content: |
#!/bin/sh
# Written by Ansible. Whoever the control plane vouches for acts as
# the cluster's one account; it has already decided they may.
echo {{ hpc_user }}
notify: restart httpd
# The desktop is not a tenant's application - nobody asks for it and
# everybody gets it - so the portal fetches it rather than the catalogue.
# Onto the shared /opt, where the compute nodes see it without carrying it
# in the image they hold in RAM.
- name: Fetch the desktop image
ansible.builtin.command:
cmd: >-
apptainer pull --allow-unsigned
{{ ondemand_desktop_sif }} {{ ondemand_desktop_image }}
creates: "{{ ondemand_desktop_sif }}"
environment:
APPTAINER_CACHEDIR: /var/cache/apptainer
register: ondemand_desktop_pull
failed_when: false
# A missing desktop is not a reason to leave the portal unbuilt, but it is
# a reason to say so: the app will be offered and every session will fail
# at the point where it tries to start one.
- name: Report a desktop that could not be fetched
ansible.builtin.debug:
msg: >-
The desktop image could not be fetched ({{ ondemand_desktop_image }}).
The portal works; Desktop sessions will not.
when: ondemand_desktop_pull.rc | default(0) != 0
- name: Make the desktop readable from the compute nodes
ansible.builtin.file:
path: "{{ ondemand_desktop_sif }}"
mode: "0644"
when: ondemand_desktop_pull.rc | default(1) == 0
- name: Offer the interactive desktop on this cluster
ansible.builtin.file:
path: /etc/ood/config/apps/bc_desktop
state: directory
owner: root
group: root
mode: "0755"
# The Desktop app is installed by the ondemand package but offers nothing
# until a cluster is named here. An empty bc_desktop directory is why the
# app appears in the menu and then has no form to fill in.
- name: Name this cluster in the Desktop app
ansible.builtin.copy:
dest: /etc/ood/config/apps/bc_desktop/{{ ondemand_cluster_id }}.yml
owner: root
group: root
mode: "0644"
content: |
---
# Written by Ansible.
title: "Desktop"
cluster: "{{ ondemand_cluster_id }}"
attributes:
desktop:
label: "Desktop environment"
widget: select
value: "xfce"
options:
- ["XFCE", "xfce"]
bc_vnc_idle: 0
bc_vnc_resolution:
required: true
value: "1280x800"
# Bounded on purpose. An interactive session nobody closes holds
# a compute node until the cluster's lease ends.
bc_num_hours:
value: 2
max: {{ ondemand_desktop_max_hours }}
form:
- desktop
- bc_vnc_resolution
- bc_num_hours
notify: restart httpd
# The generator turns the YAML above into the Apache configuration Apache
# actually reads. Editing ood_portal.yml without running it changes nothing,
# which is the failure mode this system has hit repeatedly in other tools.
- name: Regenerate the Apache configuration
ansible.builtin.command:
cmd: /opt/ood/ood-portal-generator/sbin/update_ood_portal
register: ondemand_generated
changed_when: "'Generating' in ondemand_generated.stdout or ondemand_generated.rc == 0"
notify: restart httpd
- name: Let the portal reach the scheduler and the home directories
ansible.posix.seboolean:
name: "{{ item }}"
state: true
persistent: true
loop:
- httpd_can_network_connect
- httpd_use_nfs
failed_when: false
- name: Open the portal port on the management zone
ansible.posix.firewalld:
port: 443/tcp
zone: public
permanent: true
immediate: true
state: enabled
# mod_ssl ships /etc/httpd/conf.d/ssl.conf with "Listen 443 https" and a
# default vhost of its own. OnDemand's generated config listens on the
# management address and port 443 too, so Apache binds the wildcard first and
# then refuses the specific one: "Address already in use ... no listening
# sockets available". Renaming is enough - Apache reads only *.conf - and the
# module itself loads from conf.modules.d/00-ssl.conf, which is untouched, so
# TLS still works. OnDemand owns the TLS vhost here.
- name: Stand down the stock SSL vhost that would claim port 443
ansible.builtin.command:
cmd: mv /etc/httpd/conf.d/ssl.conf /etc/httpd/conf.d/ssl.conf.disabled
removes: /etc/httpd/conf.d/ssl.conf
creates: /etc/httpd/conf.d/ssl.conf.disabled
notify: restart httpd
- name: Confirm Apache accepts the configuration before starting it
ansible.builtin.command:
cmd: httpd -t
register: ondemand_httpd_t
changed_when: false
failed_when: "'Syntax OK' not in ondemand_httpd_t.stderr + ondemand_httpd_t.stdout"
- name: Start the portal
ansible.builtin.systemd_service:
name: httpd
enabled: true
state: started
# Handlers run at the end of the play, which is after the checks below.
# Without this they tested the Apache that was already running: the
# configuration had changed on disk, the process had not reloaded it, and
# the refusal check failed against a portal that was correctly configured
# and simply not restarted yet. A failing task then aborts the play, so
# the restart never happened at all and the next run saw the same thing.
- name: Load the configuration that was just written
ansible.builtin.meta: flush_handlers
# Read the result back rather than trusting the exit codes above: a portal
# that answers is the only evidence that the generator, the certificate, the
# auth file and the cluster definition all landed together.
# Asks the dashboard directly, with the public Host and without following
# redirects, and insists on a 401.
#
# Each of those three is load-bearing. The dashboard, because that is where
# auth is enforced - the root only redirects to it, and accepting a redirect
# would pass against a portal that serves its dashboard to anyone. The Host
# header, because Apache answers 301 to anything addressed to the IP,
# canonicalising to the servername. And no redirect following, because with
# it the check leaves the machine: it chases the public name out through
# DNS, Caddy and the control plane, and then reports on whether the tenant
# happens to be published rather than on whether the portal works. That is
# how this check first failed - with a 200 from the control plane's login
# page.
# The portal used to answer 401 and this asked for one. It no longer
# authenticates people itself: a caller with no client certificate is
# turned away during the handshake, so there is no status code to check
# and the old probe failed against a portal that was working correctly.
#
# What is worth confirming is exactly that - the refusal - because it is
# the thing standing between the management network and the cluster.
- name: Confirm the portal refuses a caller with no certificate
ansible.builtin.command:
cmd: >-
openssl s_client -connect {{ ondemand_listen_addr }}:443
-servername {{ ondemand_servername }} -verify_quiet -brief
register: ondemand_probe
changed_when: false
failed_when: >-
'certificate required' not in (ondemand_probe.stderr | default(''))
and 'alert' not in (ondemand_probe.stderr | default(''))
and ondemand_probe.rc == 0
- name: Confirm the portal answers a caller it trusts
ansible.builtin.uri:
url: "https://{{ ondemand_listen_addr }}/pun/sys/dashboard"
headers:
Host: "{{ ondemand_servername }}"
validate_certs: false
client_cert: "{{ ondemand_client_ca }}"
client_key: "{{ ondemand_probe_key | default(omit) }}"
follow_redirects: none
status_code: [200, 302, 303]
when: ondemand_probe_key is defined
register: ondemand_probe
retries: 6
delay: 5
# It used to insist on 401, which status_code above already rejects, so
# the task could not pass. It is skipped without a key, which is why
# nothing noticed.
until: ondemand_probe.status in [200, 302, 303]