mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-23 19:02:17 +00:00
Merge branch 'master' into fix/xcattest-table-value-class
xCAT-test/autotest/testcase/commoncmd/vm_machine_type.sh conflicted: this branch picks q35 for an x86_64 node with firmware:efi, and master asks the vmhost libvirt for the machine type. The vmhost probe from master is kept. vm_machine_type_alias now takes the vmothersetting and returns q35 for firmware:efi, and q35 does not fall back to the libvirt default, because the x86_64 default is i440fx. xCAT-test/bats/vm_machine_type.bats conflicted where both sides added tests before assert_round_trip. Both sets are kept, with the assert_round_trip of this branch, plus one test for the q35 rule. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
@@ -100,6 +100,18 @@ fi
|
||||
if [ ! -e /usr/share/empty.sshd ]; then
|
||||
mkdir -p /usr/share/empty.sshd
|
||||
fi
|
||||
# Debian and Ubuntu build sshd with --with-privsep-path=/run/sshd, and sshd exits with
|
||||
# "Missing privilege separation directory" when it is absent. The image carries /run and not
|
||||
# /run/sshd, so Genesis on Ubuntu answered no ssh and every case that reaches a booted node
|
||||
# over xdsh failed. Created here rather than baked into the image: /run is a tmpfs on a
|
||||
# running system, and a directory under it does not survive the mount.
|
||||
# The mode is set whether or not the directory had to be created: sshd refuses a privsep
|
||||
# directory that is group or world writable, with the same message, so a wrong mode looks
|
||||
# exactly like an absent one.
|
||||
for sshd_privsep in /run/sshd /var/run/sshd; do
|
||||
mkdir -p "$sshd_privsep"
|
||||
chmod 0755 "$sshd_privsep"
|
||||
done
|
||||
echo 'Protocol 2' >> /etc/ssh/sshd_config
|
||||
/usr/sbin/sshd
|
||||
mkdir -p /etc/xcat
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# mount_snapshot.sh [<file>]
|
||||
#
|
||||
# Print the mount table without the kernel's own on-demand mounts, so the diskless cases can
|
||||
# compare a snapshot taken before genimage with one taken after it.
|
||||
#
|
||||
# genimage bind mounts /proc, /sys and /dev inside the root image. A bind it fails to remove
|
||||
# leaves the next image built on top of the host, so comparing the two snapshots is worth doing.
|
||||
#
|
||||
# What the comparison must not assert is that nothing else mounted anything meanwhile.
|
||||
# binfmt_misc is an autofs stub that becomes a real mount the first time a process reads
|
||||
# /proc/sys/fs/binfmt_misc, and tracefs appears under /sys/kernel/debug the first time anything
|
||||
# opens debugfs tracing. Both are the kernel's doing and both can happen during genimage. On one
|
||||
# openEuler 22.03 run both did, and the case failed four minutes in while the provisioning that
|
||||
# followed succeeded.
|
||||
#
|
||||
# Filtering by filesystem type would hide the leak this guards, because a leaked genimage bind IS
|
||||
# a proc or sysfs mount. The mount POINT separates them: the kernel keeps its on-demand mounts
|
||||
# inside /proc and /sys, and a leaked bind sits under the root image directory.
|
||||
#
|
||||
# With a file argument, filter that file instead of asking the kernel, so the filter is testable.
|
||||
|
||||
set -e
|
||||
|
||||
if [ $# -ge 1 ]; then
|
||||
cat -- "$1"
|
||||
else
|
||||
mount
|
||||
fi | awk '$3 !~ /^\/(proc|sys)(\/|$)/' | sort
|
||||
@@ -40,9 +40,13 @@
|
||||
XCAT_AVC_COMM='xcatd|genimage|packimage|nodeset|mknb|makedhcp|makedns|makehosts|makeknownhosts|copycds|liteimg|xdsh|xdcp|xcatprobe|xcatconfig'
|
||||
XCAT_AVC_PATH='/opt/xcat|/xcatpost|/tftpboot|/install|/var/log/xcat|/etc/xcat|/var/lib/xcat'
|
||||
|
||||
# The path must be one of those directories, or a file under one. A directory name is
|
||||
# not a string prefix: /var/lib/xcat-cluster-test holds the CI's own notification hook,
|
||||
# and matching it as /var/lib/xcat put an xcatd denial on a harness file into the count.
|
||||
# So the name starts at the quote and ends at a / or at the closing quote.
|
||||
selinux_avc_classify()
|
||||
{
|
||||
grep -E "(comm|exe)=\"[^\"]*(${XCAT_AVC_COMM})[^\"]*\"|(path|name)=\"[^\"]*(${XCAT_AVC_PATH})"
|
||||
grep -E "(comm|exe)=\"[^\"]*(${XCAT_AVC_COMM})[^\"]*\"|(path|name)=\"(${XCAT_AVC_PATH})(/|\")"
|
||||
}
|
||||
|
||||
# Report the denials ausearch answered with. An error message is not a clean window:
|
||||
|
||||
@@ -33,25 +33,94 @@ vm_machine_type_private_dir()
|
||||
fi
|
||||
}
|
||||
|
||||
# vm_machine_type_for_arch <arch> [<vmothersetting>] -- the machine type to apply.
|
||||
# An x86_64 node that asks for a UEFI firmware takes q35: every x86_64 OVMF descriptor targets
|
||||
# pc-q35-*, and libvirt refuses firmware efi on i440fx.
|
||||
vm_machine_type_for_arch()
|
||||
# alias <arch> [<vmothersetting>] -- the machine name qemu keeps pointed at the newest machine
|
||||
# of a family. An x86_64 node that asks for a UEFI firmware takes q35: every x86_64 OVMF
|
||||
# descriptor targets pc-q35-*, and libvirt refuses firmware efi on i440fx.
|
||||
vm_machine_type_alias()
|
||||
{
|
||||
case "$1" in
|
||||
ppc64*) echo 'machine:pseries-rhel7.6.0' ;;
|
||||
ppc64*) echo 'pseries' ;;
|
||||
x86_64)
|
||||
case ";$2" in
|
||||
*';firmware:efi'*) echo 'machine:q35' ;;
|
||||
*) echo 'machine:pc' ;;
|
||||
case ";${2-}" in
|
||||
*';firmware:efi'*) echo 'q35' ;;
|
||||
*) echo 'pc' ;;
|
||||
esac
|
||||
;;
|
||||
riscv64) echo 'machine:virt' ;;
|
||||
aarch64) echo 'machine:virt' ;;
|
||||
riscv64) echo 'virt' ;;
|
||||
aarch64) echo 'virt' ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# libvirt and qemu call the ppc64le guest architecture ppc64. A node on an
|
||||
# Ubuntu cell names it ppc64el.
|
||||
vm_machine_type_libvirt_arch()
|
||||
{
|
||||
case "$1" in
|
||||
ppc64*) echo 'ppc64' ;;
|
||||
x86_64) echo 'x86_64' ;;
|
||||
riscv64) echo 'riscv64' ;;
|
||||
aarch64) echo 'aarch64' ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# virsh on <host>, or here when <host> is empty. kvm.pm reaches the vmhost over
|
||||
# qemu+ssh://root@<host>/system, so root can ssh there from this node.
|
||||
vm_machine_type_virsh()
|
||||
{
|
||||
local host="$1"
|
||||
shift
|
||||
if [ -n "$host" ]; then
|
||||
ssh -o BatchMode=yes -o ConnectTimeout=10 -n "$host" virsh "$@"
|
||||
else
|
||||
virsh "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
# supported <host> <arch> <machine> -- whether libvirt on <host> accepts <machine>.
|
||||
vm_machine_type_supported()
|
||||
{
|
||||
vm_machine_type_virsh "$1" domcapabilities --arch "$2" --machine "$3" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# default <host> <arch> -- the machine type libvirt on <host> uses for <arch>.
|
||||
vm_machine_type_default()
|
||||
{
|
||||
vm_machine_type_virsh "$1" domcapabilities --arch "$2" 2>/dev/null |
|
||||
sed -n 's|.*<machine>\(.*\)</machine>.*|\1|p' | head -n 1
|
||||
}
|
||||
|
||||
# for_arch <arch> [<vmhost>] [<vmothersetting>] -- the machine type to write, as
|
||||
# "machine:<name>".
|
||||
#
|
||||
# The vmhost is what refuses the domain, so its libvirt picks the name: the plain
|
||||
# alias when that libvirt accepts it, its own default when it does not, and the
|
||||
# alias again when the vmhost cannot be asked. A versioned name does not survive
|
||||
# a host upgrade -- no qemu on AlmaLinux 10 has a pseries-rhel machine type.
|
||||
# q35 does not fall back to the default: the x86_64 default is i440fx, which UEFI cannot use.
|
||||
vm_machine_type_for_arch()
|
||||
{
|
||||
local arch="$1" vmhost="${2-}" generic libvirt_arch name
|
||||
|
||||
generic="$(vm_machine_type_alias "$arch" "${3-}")" || return 1
|
||||
libvirt_arch="$(vm_machine_type_libvirt_arch "$arch")" || return 1
|
||||
if [ "$generic" = q35 ] ||
|
||||
vm_machine_type_supported "$vmhost" "$libvirt_arch" "$generic"; then
|
||||
printf 'machine:%s\n' "$generic"
|
||||
return
|
||||
fi
|
||||
name="$(vm_machine_type_default "$vmhost" "$libvirt_arch")"
|
||||
printf 'machine:%s\n' "${name:-$generic}"
|
||||
}
|
||||
|
||||
# vmhost <node> -- the host whose libvirt runs the guest, empty when unset.
|
||||
vm_machine_type_vmhost()
|
||||
{
|
||||
lsdef "$1" -i vmhost 2>/dev/null |
|
||||
sed -n 's/^[[:space:]]*vmhost=//p' | head -n 1
|
||||
}
|
||||
|
||||
vm_machine_type_get()
|
||||
{
|
||||
local out
|
||||
@@ -117,7 +186,7 @@ vm_machine_type_apply()
|
||||
chdef "$node" "vmothersetting=$original"
|
||||
return
|
||||
fi
|
||||
if ! machine="$(vm_machine_type_for_arch "$arch" "$original")"; then
|
||||
if ! machine="$(vm_machine_type_for_arch "$arch" "$(vm_machine_type_vmhost "$node")" "$original")"; then
|
||||
echo "vm_machine_type.sh: no machine type for arch '$arch'" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -74,13 +74,13 @@ check:rc==0
|
||||
cmd:osimage="__GETNODEATTR($$SN,os)__-__GETNODEATTR($$SN,arch)__-netboot-service";otherpkglist=$(lsdef -t osimage $osimage -i otherpkglist -c|awk -F"=" '{print $2}'); cat $otherpkglist
|
||||
|
||||
cmd:if [ ! -d /tmp/mountoutput ]; then mkdir -p /tmp/mountoutput; fi
|
||||
cmd:mount |sort > /tmp/mountoutput/file.org
|
||||
cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.org
|
||||
|
||||
cmd:genimage __GETNODEATTR($$SN,os)__-__GETNODEATTR($$SN,arch)__-netboot-service
|
||||
check:rc==0
|
||||
|
||||
cmd:mount |sort > /tmp/mountoutput/file.new
|
||||
cmd:diff -y /tmp/mountoutput/file.org /tmp/mountoutput/file.new --ignore-matching-lines="fusectl"
|
||||
cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.new
|
||||
cmd:diff -y /tmp/mountoutput/file.org /tmp/mountoutput/file.new
|
||||
check:rc==0
|
||||
cmd:rm -rf /tmp/mountoutput
|
||||
|
||||
|
||||
@@ -31,16 +31,16 @@ cmd:if [[ -f /test.synclist ]] ;then mv -f /test.synclist /test.synclist.bak;fi;
|
||||
cmd:echo "/test.synclist -> /test.synclist" > /test.synclist;chdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute synclists=/test.synclist
|
||||
check:rc==0
|
||||
cmd:if [ ! -d /tmp/mountoutput ]; then mkdir -p /tmp/mountoutput; fi
|
||||
cmd:mount |sort > /tmp/mountoutput/file.org
|
||||
cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.org
|
||||
cmd:cat /tmp/mountoutput/file.org
|
||||
cmd:if [[ "__GETNODEATTR($$CN,os)__" =~ "ubuntu18.04.2" ]] && [[ "__GETNODEATTR($$CN,arch)__" =~ ppc64(el|le) ]] && [[ "__GETNODEATTR($$CN,mgt)__" =~ "kvm" ]] ; then mkdir -p /install/custom/netboot/ubuntu; sed -e 's@linux-image-generic-hwe-18.04@linux-image-generic@g' </opt/xcat/share/xcat/netboot/ubuntu/compute.ubuntu18.04.2.ppc64el.pkglist >/install/custom/netboot/ubuntu/compute.ubuntu18.04.2.ppc64el.pkglist; chdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute pkglist=/install/custom/netboot/ubuntu/compute.ubuntu18.04.2.ppc64el.pkglist; fi
|
||||
cmd:if [[ "__GETNODEATTR($$CN,os)__" =~ "ubuntu16.04.5" ]] && [[ "__GETNODEATTR($$CN,arch)__" =~ "x86" ]]; then chdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute -p pkgdir="http://archive.ubuntu.com/ubuntu xenial universe main,http://archive.ubuntu.com/ubuntu xenial-updates universe main,http://security.ubuntu.com/ubuntu xenial-security main restricted";fi
|
||||
cmd:lsdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute
|
||||
cmd:genimage __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute
|
||||
check:rc==0
|
||||
cmd:mount |sort > /tmp/mountoutput/file.new
|
||||
cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.new
|
||||
cmd:cat /tmp/mountoutput/file.new
|
||||
cmd:diff /tmp/mountoutput/file.org /tmp/mountoutput/file.new --ignore-matching-lines="fusectl"
|
||||
cmd:diff /tmp/mountoutput/file.org /tmp/mountoutput/file.new
|
||||
check:rc==0
|
||||
cmd:rm -rf /tmp/mountoutput
|
||||
cmd:packimage __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute
|
||||
@@ -148,16 +148,16 @@ cmd:if [[ -f /test.synclist ]] ;then mv -f /test.synclist /test.synclist.bak;fi;
|
||||
cmd:echo "/test.synclist -> /test.synclist" > /test.synclist;chdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute synclists=/test.synclist
|
||||
check:rc==0
|
||||
cmd:if [ ! -d /tmp/mountoutput ]; then mkdir -p /tmp/mountoutput; fi
|
||||
cmd:mount |sort > /tmp/mountoutput/file.org
|
||||
cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.org
|
||||
cmd:cat /tmp/mountoutput/file.org
|
||||
cmd:if [[ "__GETNODEATTR($$CN,os)__" =~ "ubuntu18.04.2" ]] && [[ "__GETNODEATTR($$CN,arch)__" =~ ppc64(el|le) ]] && [[ "__GETNODEATTR($$CN,mgt)__" =~ "kvm" ]] ; then mkdir -p /install/custom/netboot/ubuntu; sed -e 's@linux-image-generic-hwe-18.04@linux-image-generic@g' </opt/xcat/share/xcat/netboot/ubuntu/compute.ubuntu18.04.2.ppc64el.pkglist >/install/custom/netboot/ubuntu/compute.ubuntu18.04.2.ppc64el.pkglist; chdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute pkglist=/install/custom/netboot/ubuntu/compute.ubuntu18.04.2.ppc64el.pkglist; fi
|
||||
cmd:if [[ "__GETNODEATTR($$CN,os)__" =~ "ubuntu16.04.5" ]] && [[ "__GETNODEATTR($$CN,arch)__" =~ "x86" ]]; then chdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute -p pkgdir="http://archive.ubuntu.com/ubuntu xenial universe main,http://archive.ubuntu.com/ubuntu xenial-updates universe main,http://security.ubuntu.com/ubuntu xenial-security main restricted";fi
|
||||
cmd:lsdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute
|
||||
cmd:genimage __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute
|
||||
check:rc==0
|
||||
cmd:mount |sort > /tmp/mountoutput/file.new
|
||||
cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.new
|
||||
cmd:cat /tmp/mountoutput/file.new
|
||||
cmd:diff /tmp/mountoutput/file.org /tmp/mountoutput/file.new --ignore-matching-lines="fusectl"
|
||||
cmd:diff /tmp/mountoutput/file.org /tmp/mountoutput/file.new
|
||||
check:rc==0
|
||||
cmd:rm -rf /tmp/mountoutput
|
||||
|
||||
|
||||
+3
-3
@@ -35,15 +35,15 @@ cmd:rootimgdir=`lsdef -t osimage __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arc
|
||||
check:rc==0
|
||||
|
||||
cmd:if [ ! -d /tmp/mountoutput ]; then mkdir -p /tmp/mountoutput; fi
|
||||
cmd:mount |sort > /tmp/mountoutput/file.org
|
||||
cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.org
|
||||
cmd:cat /tmp/mountoutput/file.org
|
||||
cmd:if [[ "__GETNODEATTR($$CN,os)__" =~ "ubuntu16.04.5" ]] && [[ "__GETNODEATTR($$CN,arch)__" =~ "x86" ]]; then chdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute -p pkgdir="http://archive.ubuntu.com/ubuntu xenial universe main,http://archive.ubuntu.com/ubuntu xenial-updates universe main,http://security.ubuntu.com/ubuntu xenial-security main restricted";fi
|
||||
cmd:lsdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute
|
||||
cmd:genimage __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute
|
||||
check:rc==0
|
||||
cmd:mount |sort > /tmp/mountoutput/file.new
|
||||
cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.new
|
||||
cmd:cat /tmp/mountoutput/file.new
|
||||
cmd:diff /tmp/mountoutput/file.org /tmp/mountoutput/file.new --ignore-matching-lines="fusectl"
|
||||
cmd:diff /tmp/mountoutput/file.org /tmp/mountoutput/file.new
|
||||
check:rc==0
|
||||
cmd:rm -rf /tmp/mountoutput
|
||||
cmd:packimage __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# The privilege separation directory sshd needs, at the moment doxcat starts sshd.
|
||||
#
|
||||
# Debian and Ubuntu build sshd with --with-privsep-path=/run/sshd. The Genesis image carries
|
||||
# /run and not /run/sshd, so sshd exited with "Missing privilege separation directory" and the
|
||||
# node answered no ssh at all. Every legacy Genesis case that reaches a booted node over xdsh
|
||||
# failed on "Connection refused" while sequential discovery, which needs no ssh, passed.
|
||||
#
|
||||
# doxcat already did this for the other family -- it creates /usr/share/empty.sshd, the EL
|
||||
# privsep path -- so this is the same line for Debian. The assertions are what SSHD IMPOSES,
|
||||
# read at the moment sshd runs: the path is a directory, its owner is the user that will run
|
||||
# sshd, and it is not group or world writable. sshd refuses a loose mode with the same message
|
||||
# as an absent directory, so a wrong mode is indistinguishable from the bug.
|
||||
#
|
||||
# Read from inside the sandbox on purpose. /run there is a tmpfs, exactly as it is on a running
|
||||
# system, so a directory made before that mount -- or baked into the image -- is not there when
|
||||
# sshd starts and cannot be seen from outside afterwards.
|
||||
|
||||
load 'helpers/doxcat_sandbox'
|
||||
|
||||
PRIVSEP_PATHS='/run/sshd /var/run/sshd'
|
||||
|
||||
# Record what each privsep path looks like AT THE MOMENT sshd runs.
|
||||
#
|
||||
# doxcat runs sshd as /usr/sbin/sshd, an absolute path, so a stub on PATH is never reached and
|
||||
# the recorder is bound over that path instead. Recording from a later PATH command instead --
|
||||
# openssl is the next one -- cannot see the ORDER: moving the directories after the sshd line
|
||||
# then passes, which is the one mutation that matters most here.
|
||||
record_privsep()
|
||||
{
|
||||
local stub="${BATS_TEST_TMPDIR}/sshd-recorder"
|
||||
|
||||
cat >"$stub" <<SH
|
||||
#!/bin/sh
|
||||
for d in $PRIVSEP_PATHS; do
|
||||
if [ -d "\$d" ]; then
|
||||
# ls, not stat: the sandbox carries only the utilities the helper copies, and a
|
||||
# command missing there silently does nothing. Field 1 is the mode string, field 3
|
||||
# the owner, numeric because ls has no passwd lookup here.
|
||||
ls -ld "\$d" | awk '{ printf "%s dir %s %s\\n", "'"\$d"'", \$1, \$3 }' \\
|
||||
>>/run/fixture/sshd-privsep
|
||||
else
|
||||
printf '%s absent\n' "\$d" >>/run/fixture/sshd-privsep
|
||||
fi
|
||||
done
|
||||
exit 0
|
||||
SH
|
||||
chmod 0755 "$stub"
|
||||
sandbox+=(--ro-bind "$stub" /usr/sbin/sshd)
|
||||
}
|
||||
|
||||
seen()
|
||||
{
|
||||
local path="$1"
|
||||
awk -v p="$path" '$1 == p { print; exit }' "$fixture/sshd-privsep"
|
||||
}
|
||||
|
||||
@test "doxcat makes every privilege separation directory before it starts sshd" {
|
||||
setup_doxcat
|
||||
record_privsep
|
||||
add_doxcat_link eth0 BROADCAST,MULTICAST,UP ether 02:bb:cc:dd:ee:ff
|
||||
run_genesis 0 --setenv BOOTIF 01-02-bb-cc-dd-ee-ff
|
||||
|
||||
# The recording ran, so it happened one statement after sshd was started.
|
||||
[ -s "$fixture/sshd-privsep" ]
|
||||
|
||||
for path in $PRIVSEP_PATHS; do
|
||||
local line mode owner
|
||||
line=$(seen "$path")
|
||||
[ -n "$line" ]
|
||||
[ "$(printf '%s\n' "$line" | cut -d' ' -f2)" = dir ]
|
||||
mode=$(printf '%s\n' "$line" | cut -d' ' -f3)
|
||||
owner=$(printf '%s\n' "$line" | cut -d' ' -f4)
|
||||
# Owned by whoever runs sshd: root in Genesis, the invoking user here. ls in
|
||||
# the sandbox has no passwd lookup, so the owner comes back numeric.
|
||||
[ "$owner" = "$(id -u)" ]
|
||||
# sshd refuses a group or world writable privsep directory. Positions 6 and 9 of the
|
||||
# mode string are the group and other write bits.
|
||||
[ "$(printf '%s\n' "$mode" | cut -c6)" = - ]
|
||||
[ "$(printf '%s\n' "$mode" | cut -c9)" = - ]
|
||||
done
|
||||
}
|
||||
|
||||
@test "a privilege separation directory left group writable is corrected, not kept" {
|
||||
# The directory can already exist from an earlier boot with a mode sshd will not accept,
|
||||
# and that failure prints the same message as an absent one. So the mode is set whether or
|
||||
# not doxcat had to create the directory.
|
||||
setup_doxcat
|
||||
record_privsep
|
||||
add_doxcat_link eth0 BROADCAST,MULTICAST,UP ether 02:bb:cc:dd:ee:ff
|
||||
# /var is bound from the fixture, so this one survives into the sandbox.
|
||||
mkdir -p "$fixture/var/run/sshd"
|
||||
chmod 0777 "$fixture/var/run/sshd"
|
||||
run_genesis 0 --setenv BOOTIF 01-02-bb-cc-dd-ee-ff
|
||||
|
||||
local mode
|
||||
mode=$(printf '%s\n' "$(seen /var/run/sshd)" | cut -d' ' -f3)
|
||||
[ -n "$mode" ]
|
||||
[ "$(printf '%s\n' "$mode" | cut -c6)" = - ]
|
||||
[ "$(printf '%s\n' "$mode" | cut -c9)" = - ]
|
||||
}
|
||||
|
||||
@test "every command doxcat runs resolves inside the sandbox" {
|
||||
# The sandbox curates PATH and does NOT include /usr/bin, so a command it does not copy
|
||||
# resolves to nothing. That fails silently: doxcat's chmod did nothing under test for as
|
||||
# long as this sandbox has existed, and an assertion about a mode could never pass. The
|
||||
# mode half of the privsep fix was unmeasurable until chmod was added to the helper.
|
||||
#
|
||||
# Derived, not a list: bash calls command_not_found_handle for anything it cannot resolve,
|
||||
# so this records whatever doxcat actually invokes and goes missing. A list here would go
|
||||
# stale the next time doxcat gains a command.
|
||||
#
|
||||
# Its reach is the commands doxcat runs ON THE PATH THIS TEST DRIVES, which is not every
|
||||
# command in the script -- a branch this boot does not take is not covered. It is a floor,
|
||||
# not a completeness check on the helper's list.
|
||||
setup_doxcat
|
||||
record_privsep
|
||||
local env_file="${BATS_TEST_TMPDIR}/bash_env"
|
||||
cat >"$env_file" <<'SH'
|
||||
command_not_found_handle()
|
||||
{
|
||||
printf '%s\n' "$1" >>/run/fixture/not-found
|
||||
return 127
|
||||
}
|
||||
SH
|
||||
sandbox+=(--ro-bind "$env_file" /run/bash_env --setenv BASH_ENV /run/bash_env)
|
||||
add_doxcat_link eth0 BROADCAST,MULTICAST,UP ether 02:bb:cc:dd:ee:ff
|
||||
run_genesis 0 --setenv BOOTIF 01-02-bb-cc-dd-ee-ff
|
||||
|
||||
# The handler was installed, so an absence would have been recorded.
|
||||
[ -s "$fixture/sshd-privsep" ]
|
||||
if [ -e "$fixture/not-found" ]; then
|
||||
printf 'doxcat runs commands the sandbox does not provide:\n%s\n' \
|
||||
"$(sort -u "$fixture/not-found")" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
@@ -10,8 +10,11 @@ setup_doxcat()
|
||||
fips=$(repo_path xCAT-genesis-scripts/usr/lib/xcat/fips.sh)
|
||||
[ -r "$fips" ]
|
||||
mkdir -p "$fixture"/{etc/ssh,etc/pki/tls,real,links,addrs}
|
||||
# chmod is in this list because doxcat runs it: the sandbox has no /usr/bin on PATH, so a
|
||||
# command that is missing here is a command that silently does nothing under test. doxcat's
|
||||
# chmod of the sshd privilege separation directory was not exercised until it was added.
|
||||
for utility in bash sh cat cp awk grep sed sort tr tail rm wc cut head uname \
|
||||
timeout env ls mkdir touch readlink basename sleep; do
|
||||
timeout env ls mkdir touch readlink basename sleep chmod; do
|
||||
cp -L "$(PATH=/usr/bin:/bin type -P "$utility")" "$fixture/bin/$utility"
|
||||
done
|
||||
if [ -x /usr/bin/coreutils ]; then
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# Drive mount_snapshot.sh, which the diskless cases use to compare the mount table before and
|
||||
# after genimage. The comparison exists to catch a bind mount genimage leaves inside the root
|
||||
# image, and it must keep catching one.
|
||||
#
|
||||
# The snapshots below are real lines from an openEuler 22.03 management node. On that run
|
||||
# binfmt_misc and tracefs appeared between the two snapshots and failed the case, so the first
|
||||
# test holds down that they are ignored. The second test is the one that matters: a leaked
|
||||
# genimage bind must still be reported, which is why filtering by filesystem type is wrong.
|
||||
|
||||
load 'helpers/shell_source'
|
||||
|
||||
ROOTIMG=/install/netboot/openeuler22.03sp4/x86_64/compute/rootimg
|
||||
|
||||
setup()
|
||||
{
|
||||
SCRIPT="$(require_repo_file 'xCAT-test/autotest/testcase/commoncmd/mount_snapshot.sh')"
|
||||
BEFORE="${BATS_TEST_TMPDIR}/file.org"
|
||||
AFTER="${BATS_TEST_TMPDIR}/file.new"
|
||||
|
||||
cat >"$BEFORE" <<EOF
|
||||
/dev/vda2 on / type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
|
||||
devtmpfs on /dev type devtmpfs (rw,nosuid,size=4096k,nr_inodes=1048576,mode=755)
|
||||
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
|
||||
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
|
||||
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=34,pgrp=1,timeout=0)
|
||||
tmpfs on /run type tmpfs (rw,nosuid,nodev,size=1985536k,mode=755)
|
||||
tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime)
|
||||
EOF
|
||||
}
|
||||
|
||||
# The kernel may mount either of these at any moment. Neither is xCAT's doing.
|
||||
@test "an on-demand kernel mount appearing during genimage is ignored" {
|
||||
cp "$BEFORE" "$AFTER"
|
||||
cat >>"$AFTER" <<EOF
|
||||
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,nosuid,nodev,noexec,relatime)
|
||||
tracefs on /sys/kernel/debug/tracing type tracefs (rw,nosuid,nodev,noexec,relatime)
|
||||
EOF
|
||||
|
||||
diff <("$SCRIPT" "$BEFORE") <("$SCRIPT" "$AFTER")
|
||||
}
|
||||
|
||||
# The discriminator. A leaked bind is a proc mount, so a type filter would drop it and the
|
||||
# comparison could never fail again.
|
||||
@test "a bind mount genimage left inside the root image is still reported" {
|
||||
cp "$BEFORE" "$AFTER"
|
||||
printf 'proc on %s/proc type proc (rw,nosuid,nodev,noexec,relatime)\n' "$ROOTIMG" >>"$AFTER"
|
||||
|
||||
run diff <("$SCRIPT" "$BEFORE") <("$SCRIPT" "$AFTER")
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" == *"$ROOTIMG/proc"* ]]
|
||||
}
|
||||
|
||||
# An ordinary mount outside /proc and /sys is the other half of the same requirement.
|
||||
@test "an NFS mount left behind is still reported" {
|
||||
cp "$BEFORE" "$AFTER"
|
||||
printf '192.0.2.1:/install on /mnt/install type nfs4 (rw,relatime)\n' >>"$AFTER"
|
||||
|
||||
run diff <("$SCRIPT" "$BEFORE") <("$SCRIPT" "$AFTER")
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" == *"/mnt/install"* ]]
|
||||
}
|
||||
|
||||
@test "the snapshot keeps the real mounts and drops only the kernel's own" {
|
||||
run "$SCRIPT" "$BEFORE"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *" on / type xfs"* ]]
|
||||
[[ "$output" == *" on /run type tmpfs"* ]]
|
||||
[[ "$output" == *" on /dev type devtmpfs"* ]]
|
||||
refute_grep -q ' on /proc ' <<<"$output"
|
||||
refute_grep -q ' on /sys ' <<<"$output"
|
||||
refute_grep -q '/sys/kernel/tracing' <<<"$output"
|
||||
}
|
||||
@@ -66,6 +66,31 @@ SSH_RECORD='type=AVC msg=audit(1759000002.333:444): avc: denied { siginh } for
|
||||
[[ "$output" == *'comm="genimage"'* ]]
|
||||
}
|
||||
|
||||
# The hook cluster-test.pl registers with regnotif, executed by an xcatd worker. The
|
||||
# harness wrote this file, not xCAT, and /var/lib/xcat-cluster-test is not /var/lib/xcat.
|
||||
# Captured on build 2 of xcat-test-el10-x86_64-selinux, where it was the one denial the
|
||||
# run attributed to xCAT and selinux_cn_diskful_enforcing failed on it.
|
||||
HARNESS_RECORD='type=AVC msg=audit(1792858690.329:3003): avc: denied { execute_no_trans } for pid=51342 comm=78636174643A204442204163636573 path="/var/lib/xcat-cluster-test/event-notify.pl" dev="vda4" ino=75521321 scontext=system_u:system_r:xcat_t:s0 tcontext=unconfined_u:object_r:var_lib_t:s0 tclass=file permissive=1'
|
||||
|
||||
@test "a path that merely starts with the name of an xCAT directory is not kept" {
|
||||
run classify "$HARNESS_RECORD"
|
||||
[ -z "$output" ]
|
||||
}
|
||||
|
||||
@test "an xCAT directory is kept when the path names the directory itself" {
|
||||
local record='type=AVC msg=audit(1759000005.666:777): avc: denied { search } for pid=6789 comm="httpd" path="/install" dev="vda2" ino=56 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:default_t:s0 tclass=dir permissive=0'
|
||||
run classify "$record"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *'path="/install"'* ]]
|
||||
}
|
||||
|
||||
@test "a file under an xCAT directory is kept" {
|
||||
local record='type=AVC msg=audit(1759000006.777:888): avc: denied { read } for pid=7890 comm="httpd" path="/var/lib/xcat/cert/server-cert.pem" dev="vda2" ino=57 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:var_lib_t:s0 tclass=file permissive=0'
|
||||
run classify "$record"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *'/var/lib/xcat/cert/server-cert.pem'* ]]
|
||||
}
|
||||
|
||||
@test "a program whose name merely contains a kept word is not matched by accident" {
|
||||
local record='type=AVC msg=audit(1759000004.555:666): avc: denied { execute } for pid=5678 comm="systemd-udevd" scontext=system_u:system_r:udev_t:s0 tcontext=system_u:object_r:bin_t:s0 tclass=file permissive=0'
|
||||
run classify "$record"
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env bats
|
||||
# vm_machine_type.sh sets machine:invalid, then a valid machine type, then clears it again.
|
||||
# lsdef and chdef are shell functions that read and write vmothersetting of node cn1 in a file.
|
||||
# virsh is a shell function that answers for the vmhost, and ssh runs the command it is given
|
||||
# so that function answers it. MACHINES is what that vmhost declares.
|
||||
|
||||
load 'helpers/shell_source'
|
||||
|
||||
@@ -14,6 +16,17 @@ setup()
|
||||
LSDEF_FAIL=0
|
||||
CHDEF_FAIL=0
|
||||
CHDEF_CALLS=0
|
||||
# The vmhost of cn1, and what its libvirt declares. Every plain alias is in the set, so a
|
||||
# test that does not care which host answers gets the alias.
|
||||
VMHOST=''
|
||||
MACHINES='pseries pseries-10.2 pc pc-i440fx-rhel10.0.0 q35 virt virt-10.2'
|
||||
DEFAULT_MACHINE=''
|
||||
SSH_FAIL=0
|
||||
VIRSH_ABSENT=0
|
||||
SSH_TARGETS="${BATS_TEST_TMPDIR}/ssh-targets"
|
||||
VIRSH_ARCHS="${BATS_TEST_TMPDIR}/virsh-archs"
|
||||
: >"$SSH_TARGETS"
|
||||
: >"$VIRSH_ARCHS"
|
||||
}
|
||||
|
||||
# lsdef prints no line for an attribute without a value.
|
||||
@@ -24,9 +37,16 @@ lsdef()
|
||||
return 1
|
||||
fi
|
||||
printf 'Object name: %s\n' "$1"
|
||||
if [ -s "$VMOTHER" ]; then
|
||||
printf ' vmothersetting=%s\n' "$(cat "$VMOTHER")"
|
||||
fi
|
||||
case "$3" in
|
||||
vmhost)
|
||||
[ -z "$VMHOST" ] || printf ' vmhost=%s\n' "$VMHOST"
|
||||
;;
|
||||
*)
|
||||
if [ -s "$VMOTHER" ]; then
|
||||
printf ' vmothersetting=%s\n' "$(cat "$VMOTHER")"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
chdef()
|
||||
@@ -40,6 +60,56 @@ chdef()
|
||||
CHDEF_CALLS=$((CHDEF_CALLS + 1))
|
||||
}
|
||||
|
||||
# virsh domcapabilities, as libvirt answers it: a --machine the host does not declare is an
|
||||
# error, and the <machine> element names the default machine of the architecture.
|
||||
virsh()
|
||||
{
|
||||
local arch='' machine=''
|
||||
|
||||
if [ "$VIRSH_ABSENT" -ne 0 ]; then
|
||||
echo "bash: virsh: command not found" >&2
|
||||
return 127
|
||||
fi
|
||||
[ "$1" = domcapabilities ] || return 1
|
||||
shift
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
--arch) arch="$2"; shift 2 ;;
|
||||
--machine) machine="$2"; shift 2 ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
done
|
||||
printf '%s\n' "$arch" >>"$VIRSH_ARCHS"
|
||||
if [ -n "$machine" ] && ! printf '%s\n' $MACHINES | grep -qx -- "$machine"; then
|
||||
echo "error: invalid argument: the machine '$machine' is not supported by emulator" >&2
|
||||
return 1
|
||||
fi
|
||||
echo '<domainCapabilities>'
|
||||
[ -z "$DEFAULT_MACHINE" ] || printf ' <machine>%s</machine>\n' "$DEFAULT_MACHINE"
|
||||
echo '</domainCapabilities>'
|
||||
}
|
||||
|
||||
# ssh records the host it was asked for and runs the command, so the virsh function above
|
||||
# answers it. Real ssh joins the command words with spaces for the remote shell.
|
||||
ssh()
|
||||
{
|
||||
local target=''
|
||||
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
-o) shift 2 ;;
|
||||
-*) shift ;;
|
||||
*) target="$1"; shift; break ;;
|
||||
esac
|
||||
done
|
||||
printf '%s\n' "$target" >>"$SSH_TARGETS"
|
||||
if [ "$SSH_FAIL" -ne 0 ]; then
|
||||
echo "ssh: connect to host $target port 22: No route to host" >&2
|
||||
return 255
|
||||
fi
|
||||
"$@"
|
||||
}
|
||||
|
||||
set_vmother()
|
||||
{
|
||||
printf '%s' "$1" >"$VMOTHER"
|
||||
@@ -69,9 +139,9 @@ assert_arch()
|
||||
[ "$CHDEF_CALLS" -eq 3 ]
|
||||
}
|
||||
|
||||
@test "ppc64le: the case sets and clears pseries-rhel7.6.0" {
|
||||
assert_arch ppc64le pseries-rhel7.6.0 ''
|
||||
assert_arch ppc64le pseries-rhel7.6.0 'cpumode:host-passthrough'
|
||||
@test "ppc64le: the case sets and clears pseries" {
|
||||
assert_arch ppc64le pseries ''
|
||||
assert_arch ppc64le pseries 'cpumode:host-passthrough'
|
||||
}
|
||||
|
||||
@test "x86_64: the case sets and clears pc" {
|
||||
@@ -106,6 +176,92 @@ assert_arch()
|
||||
assert_arch aarch64 virt 'cpumode:host-passthrough'
|
||||
}
|
||||
|
||||
# The machine type comes from the vmhost, because the vmhost is what refuses the domain.
|
||||
# AlmaLinux 10 on the ppc64le vmhost declares pseries-5.0 to pseries-10.2 and no rhel machine
|
||||
# type at all, so a name from the RHEL 7.6 era is rejected at define time.
|
||||
|
||||
@test "ppc64le: the machine type is the alias the vmhost accepts" {
|
||||
MACHINES='pseries pseries-10.2 pseries-9.2'
|
||||
run vm_machine_type_for_arch ppc64le 192.0.2.10
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = 'machine:pseries' ]
|
||||
}
|
||||
|
||||
@test "ppc64le: the vmhost accepts the machine type that comes back" {
|
||||
local machine
|
||||
MACHINES='pseries pseries-10.0 pseries-10.1 pseries-10.2'
|
||||
machine="$(vm_machine_type_for_arch ppc64le 192.0.2.10)"
|
||||
[ "${machine#machine:}" != "$machine" ]
|
||||
run virsh domcapabilities --arch ppc64 --machine "${machine#machine:}"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "ppc64le: the libvirt default stands in when the vmhost refuses the alias" {
|
||||
MACHINES='pseries-10.2'
|
||||
DEFAULT_MACHINE='pseries-10.2'
|
||||
run vm_machine_type_for_arch ppc64le 192.0.2.10
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = 'machine:pseries-10.2' ]
|
||||
}
|
||||
|
||||
@test "ppc64le: the alias stands in when the vmhost cannot be reached" {
|
||||
SSH_FAIL=1
|
||||
run vm_machine_type_for_arch ppc64le 192.0.2.10
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = 'machine:pseries' ]
|
||||
}
|
||||
|
||||
@test "ppc64le: the alias stands in when the vmhost has no virsh" {
|
||||
VIRSH_ABSENT=1
|
||||
run vm_machine_type_for_arch ppc64le 192.0.2.10
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = 'machine:pseries' ]
|
||||
}
|
||||
|
||||
@test "ppc64el: the Debian architecture name gets the same machine type" {
|
||||
MACHINES='pseries pseries-10.2'
|
||||
run vm_machine_type_for_arch ppc64el 192.0.2.10
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = 'machine:pseries' ]
|
||||
}
|
||||
|
||||
@test "apply asks the vmhost of the node about architecture ppc64" {
|
||||
VMHOST=192.0.2.10
|
||||
MACHINES='pseries pseries-10.2'
|
||||
set_vmother ''
|
||||
vm_machine_type_main invalid cn1
|
||||
vm_machine_type_main apply cn1 ppc64le
|
||||
[ "$(vmother)" = 'machine:pseries' ]
|
||||
[ "$(sort -u "$SSH_TARGETS")" = '192.0.2.10' ]
|
||||
[ "$(sort -u "$VIRSH_ARCHS")" = 'ppc64' ]
|
||||
}
|
||||
|
||||
@test "apply reads the local libvirt when the node names no vmhost" {
|
||||
MACHINES='pseries pseries-10.2'
|
||||
set_vmother ''
|
||||
vm_machine_type_main invalid cn1
|
||||
vm_machine_type_main apply cn1 ppc64le
|
||||
[ "$(vmother)" = 'machine:pseries' ]
|
||||
[ ! -s "$SSH_TARGETS" ]
|
||||
[ "$(sort -u "$VIRSH_ARCHS")" = 'ppc64' ]
|
||||
}
|
||||
|
||||
@test "x86_64: the machine type stays pc, which the vmhost accepts" {
|
||||
MACHINES='pc pc-i440fx-rhel10.0.0 q35'
|
||||
DEFAULT_MACHINE='pc-i440fx-rhel10.0.0'
|
||||
run vm_machine_type_for_arch x86_64 192.0.2.10
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = 'machine:pc' ]
|
||||
}
|
||||
|
||||
@test "x86_64 with firmware:efi: q35 stays when the vmhost refuses the alias" {
|
||||
MACHINES='pc-i440fx-rhel10.0.0'
|
||||
DEFAULT_MACHINE='pc-i440fx-rhel10.0.0'
|
||||
run vm_machine_type_for_arch x86_64 192.0.2.10 'firmware:efi'
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = 'machine:q35' ]
|
||||
}
|
||||
|
||||
# assert_round_trip <arch> <original> [<machine>] -- the case ends with the exact value it
|
||||
# started with. <machine> is the machine type apply is to have written, when the caller knows it.
|
||||
assert_round_trip()
|
||||
|
||||
Reference in New Issue
Block a user