Files
ilker fd4fef4e36 hpcod: move the node image to a platform namespace, and drop the pull token
The image every tenant boots lived under a personal account,
gitea.mynodes.xyz/ilker/hpc-node. It is now hpcod/node-image, with a
second organisation, hpcapps, for the application images a tenant can
request. Both are public, because this registry exists to distribute
code and images and is meant to be readable.

That last sentence is a correction. This change was started on the
strength of a measurement I read as an exposure: an unrelated Gitea
account could fetch the node image manifest. It is not an exposure, it is
the intended posture - and the measurement was wrong in the other
direction too. Testing a container registry with plain curl gets a 401
because the client is expected to fetch a bearer token first; doing the
token exchange shows the image is anonymously pullable, more open than I
had reported. The namespace move is still worth having, but for the
ordinary reason: platform infrastructure should not sit under one
person's username, and applications should have a namespace of their own.

The useful consequence is that the registry credential can go. If the
image pulls anonymously, nothing in the provisioning path needs a token:
registry_pull_user is empty, the credential tasks skip, and a template
builds and imports the image with no secret involved - verified, the run
skipped three tasks and still pulled. The mechanism stays for a site
whose registry is private. The best-handled secret is the one that is not
in the path.

Also verified on the way: a tenant provisions from the new location, the
import taking 27s, with no other change.
2026-09-20 19:45:04 +02:00

70 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
# Build the compute node image and publish it.
#
# Run on the control plane host. The tag is the cache key a tenant request
# resolves to, so bump it whenever the stack changes.
#
# Rootless podman as a service account needs two things that a normal login
# gets for free, and fails differently for each:
#
# /etc/subuid, /etc/subgid a range for the account, or unpacking a layer
# dies on "lchown: invalid argument" - the build
# cannot map uid 0 inside the namespace.
# loginctl enable-linger a persistent user session, or runc cannot create
# the build container for want of a delegated
# cgroup.
#
# Neither can be set with usermod while a service is running as the account,
# so /etc/subuid and /etc/subgid are edited directly. See PREFLIGHT below.
set -euo pipefail
REGISTRY=${REGISTRY:-gitea.mynodes.xyz}
# The platform organisation rather than a personal account. Organisational,
# not a security boundary - this registry is public on purpose.
OWNER=${OWNER:-hpcod}
NAME=${NAME:-node-image}
TAG=${TAG:-rocky9-ohpc3}
IMAGE="${REGISTRY}/${OWNER}/${NAME}:${TAG}"
# Keep the registry credential somewhere stable. Podman defaults to
# $XDG_RUNTIME_DIR/containers/auth.json, so a login performed under one runtime
# directory is invisible to a build run under another - which shows up as
# "unauthorized" on push, long after a successful login.
export REGISTRY_AUTH_FILE="${REGISTRY_AUTH_FILE:-$HOME/.config/containers/auth.json}"
cd "$(dirname "$0")"
: "${XDG_RUNTIME_DIR:?set XDG_RUNTIME_DIR=/run/user/\$(id -u) - rootless podman needs it}"
# PREFLIGHT: fail with the actual cause rather than a layer-unpacking error.
if ! grep -q "^$(id -un):" /etc/subuid 2>/dev/null; then
echo "no subuid range for $(id -un). As root:" >&2
echo " echo '$(id -un):400000:65536' >> /etc/subuid" >&2
echo " echo '$(id -un):400000:65536' >> /etc/subgid" >&2
echo " loginctl enable-linger $(id -u)" >&2
exit 1
fi
if [ ! -d "/run/user/$(id -u)" ]; then
echo "no user runtime dir. As root: loginctl enable-linger $(id -u)" >&2
exit 1
fi
echo "==> building ${IMAGE}"
# --squash-all, not --squash: --squash keeps the base image layers, so files
# deleted in our layers still ship in the layers underneath. Only squashing
# everything into a single layer actually shrinks what gets pulled.
podman build --squash-all -t "${IMAGE}" .
echo "==> pushing"
if ! podman push "${IMAGE}"; then
echo "push failed. If this says unauthorized, log in with the same" >&2
echo "REGISTRY_AUTH_FILE this script uses:" >&2
echo " REGISTRY_AUTH_FILE=${REGISTRY_AUTH_FILE} podman login ${REGISTRY} -u <user>" >&2
exit 1
fi
echo
echo "IMAGE PUBLISHED: ${IMAGE}"
echo "Tenants import it with:"
echo " wwctl image import docker://${IMAGE} <name>"