Verifying the image
Test the image before you upload it for general use by booting a VM from it and running the verification script as root.
The script checks the following conditions: the packages are installed or available from the mirror, the OpenSSH versions meet the minimum for the release, kernel-modules-extra matches the kernel on the RHEL 10 family, no public repositories are enabled, no proxy file is in a location that bootstrap owns, python3 exists, sshd_config includes sshd_config.d, haproxy is not enabled, chrony does not use public time sources, and cloud-init finishes cleanly.
- Boot a VM from the finished image on a network with no internet access.
- Log in to the VM.
- Run the following script as root.
#!/usr/bin/env bash # verify-image.sh: check an image against the air-gapped requirements. set -u fail=0 refreshed=0 ok() { printf 'OK %s\n' "$1"; } warn() { printf 'WARN %s\n' "$1"; } bad() { printf 'FAIL %s\n' "$1"; fail=1; } . /etc/os-release major="${VERSION_ID%%.*}" case "$ID" in ubuntu) family=ubuntu ;; rhel|rocky) family=rhel ;; *) bad "unsupported distribution: $ID"; exit 1 ;; esac installed() { if [ "$family" = ubuntu ]; then dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -q 'install ok installed' else rpm -q "$1" >/dev/null 2>&1 fi } # Contact the mirror once, and only if something is missing from the image. refresh() { [ "$refreshed" = 1 ] && return refreshed=1 if [ "$family" = ubuntu ]; then apt-get update -qq || warn "package cache refresh failed" else dnf -q makecache || warn "package cache refresh failed" fi } candidate() { if [ "$family" = ubuntu ]; then apt-cache policy "$1" 2>/dev/null | awk '/Candidate:/ {print $2}' | grep -v '(none)' else dnf -q list --available "$1" >/dev/null 2>&1 && echo available fi } check_package() { if installed "$1"; then ok "$1 is installed" return fi refresh if [ -n "$(candidate "$1")" ]; then ok "$1 is available from the mirror" else bad "$1 is neither installed nor available from the mirror" fi } # Installed or mirrored OpenSSH must meet the minimum for this release. check_minimum() { pkg="$1"; min="$2" have="$(dpkg-query -W -f='${Version}' "$pkg" 2>/dev/null || true)" if [ -n "$have" ] && dpkg --compare-versions "$have" ge "$min"; then ok "$pkg $have meets minimum $min" return fi refresh cand="$(candidate "$pkg")" if [ -n "$cand" ] && dpkg --compare-versions "$cand" ge "$min"; then ok "$pkg $cand from the mirror meets minimum $min" else bad "$pkg is below minimum $min (installed: ${have:-none}, cand: ${cand:-none})" fi } if [ "$family" = ubuntu ]; then packages="apparmor apt-transport-https conntrack dbus libseccomp2 nfs-common python3-apt python3-kubernetes python3-minimal socat software-properties-common openssh-server openssh-client cloud-init haproxy chrony ca-certificates" else packages="conntrack-tools dbus libseccomp nfs-utils python3 python3-kubernetes socat openssh-server openssh-clients cloud-init haproxy chrony ca-certificates" fi for p in $packages; do check_package "$p"; done case "${VERSION_CODENAME:-}" in jammy) ssh_min='1:8.9p1-3ubuntu0.10' ;; noble) ssh_min='1:9.6p1-3ubuntu13.13' ;; *) ssh_min='' ;; esac if [ -n "$ssh_min" ]; then check_minimum openssh-server "$ssh_min" check_minimum openssh-client "$ssh_min" fi if [ "$family" = rhel ] && [ "$major" -ge 10 ]; then kme="kernel-modules-extra-$(uname -r)" if rpm -q "$kme" >/dev/null 2>&1; then ok "$kme is installed" else bad "$kme is not installed; it must match the running kernel" fi if command -v grubby >/dev/null 2>&1 && [ "$(grubby --default-kernel 2>/dev/null)" != "/boot/vmlinuz-$(uname -r)" ]; then warn "the default boot kernel is not the running kernel" fi fi # Public repositories must not be enabled. Only the host of each URL is # checked, so a mirror that keeps the upstream name in its path, such as # http://mirror.example.internal/archive.ubuntu.com/, is not reported. if [ "$family" = ubuntu ]; then public="$(grep -rhsE '^[[:space:]]*(deb|URIs:)' /etc/apt/sources.list /etc/apt/sources.list.d | sed -E 's/\[[^]]*\]//; s/^[[:space:]]*(deb-src|deb|URIs:)[[:space:]]+//' | tr ' \t' '\n\n' | sed -nE 's#^[a-z+]+://([^/@]*@)?([^/:]+).*#\2#p' | grep -E '(^|\.)(ubuntu\.com|launchpad\.net|launchpadcontent\.net)$' | sort -u || true)" else public="$(cat /etc/yum.repos.d/*.repo 2>/dev/null | awk -F= ' /^\[/ { if (on && pub) print id; id=$0; on=1; pub=0 } /^enabled *=/ { on=($2+0) } /^(baseurl|mirrorlist|metalink) *=/ { v=$0; sub(/^[^=]*= */, "", v) n=split(v, u, /[ ,]+/) for (i=1; i<=n; i++) { h=u[i]; sub(/^[a-z+]+:\/\//, "", h); sub(/\/.*$/, "", h) sub(/^.*@/, "", h); sub(/:.*$/, "", h) if (h ~ /(^|\.)(rockylinux\.org|fedoraproject\.org|redhat\.com)$/) pub=1 } } END { if (on && pub) print id }')" fi if [ -n "$public" ]; then bad "public repositories are enabled: $(echo "$public" | tr '\n' ' ')" else ok "no public repositories are enabled" fi # Bootstrap owns these proxy locations and might remove them. [ -e /etc/apt/apt.conf.d/00apt_proxy ] && warn "bootstrap manages /etc/apt/apt.conf.d/00apt_proxy; use another filename" grep -qsE '^[[:space:]]*proxy[[:space:]]*=' /etc/dnf/dnf.conf && warn "bootstrap manages proxy= in /etc/dnf/dnf.conf; set it per repository" [ -x /usr/bin/python3 ] && ok "/usr/bin/python3 exists" || bad "/usr/bin/python3 is missing" if grep -qsE '^[[:space:]]*Include[[:space:]]+/etc/ssh/sshd_config\.d/' /etc/ssh/sshd_config; then ok "sshd_config includes sshd_config.d" else bad "sshd_config does not include /etc/ssh/sshd_config.d" fi installed haproxy && [ "$(systemctl is-enabled haproxy 2>/dev/null)" = enabled ] && warn "haproxy is enabled; bootstrap enables it on the bastion only" [ "$family" = ubuntu ] && installed unattended-upgrades && warn "unattended-upgrades is installed" # Public NTP pools are unreachable; without NTP servers in the access # profile, time sync fails. ntp_public="$(grep -hsE '^[[:space:]]*(pool|server)[[:space:]]' \ /etc/chrony/chrony.conf /etc/chrony.conf /etc/chrony/sources.d/*.sources 2>/dev/null | grep -E 'ntp\.ubuntu\.com|pool\.ntp\.org' | awk '{print $2}' | sort -u | tr '\n' ' ')" [ -n "$ntp_public" ] && warn "chrony uses public time sources: $ntp_public" if command -v cloud-init >/dev/null 2>&1; then cloud-init status --wait >/dev/null 2>&1 rc=$? if [ "$rc" -eq 0 ]; then ok "cloud-init finished cleanly" else bad "cloud-init exited with $rc; run: cloud-init status --long" fi fi if [ "$fail" -eq 0 ]; then echo "RESULT: PASS"; else echo "RESULT: FAIL"; fi exit "$fail"
Exit code 0 means that the image meets the requirements. The script reports each problem as FAIL and anything worth reviewing as WARN.
