91 lines
3.2 KiB
Bash
91 lines
3.2 KiB
Bash
set -euo pipefail
|
|
umask 077
|
|
test "$(hostname -s | tr A-Z a-z)" = absdev-ci
|
|
stage=$(mktemp -d /var/tmp/absdev-op-provision.XXXXXX)
|
|
suffix=$(tr '[:upper:]' '[:lower:]' <<< "${stage##*.}")
|
|
op="abop$suffix"
|
|
other="abno$suffix"
|
|
created_op=0
|
|
created_other=0
|
|
cleanup() {
|
|
rc=$?
|
|
if ((created_other)); then userdel "$other" || rc=1; fi
|
|
if ((created_op)); then userdel "$op" || rc=1; fi
|
|
rm -rf -- "$stage" || rc=1
|
|
exit "$rc"
|
|
}
|
|
trap cleanup EXIT
|
|
mkdir "$stage/source" "$stage/evidence"
|
|
tar -xf - -C "$stage/source"
|
|
chmod 0755 "$stage"
|
|
chmod -R a+rX "$stage/source"
|
|
useradd -U -M -d /nonexistent -s /usr/sbin/nologin "$op"
|
|
created_op=1
|
|
useradd -U -M -d /nonexistent -s /usr/sbin/nologin "$other"
|
|
created_other=1
|
|
lab="$stage/lab"
|
|
install -d -m 0755 "$lab"
|
|
install -d -m 0700 -o "$op" -g "$op" "$lab/state"
|
|
policy() {
|
|
printf '{"uid":%s,"operations":%s}\n' "$(id -u "$op")" "$1" > "$lab/policy.json"
|
|
chmod 0644 "$lab/policy.json"
|
|
}
|
|
rotate() {
|
|
python3 -c 'import secrets,sys; sys.stdout.buffer.write(secrets.token_bytes(32))' > "$lab/key.new"
|
|
chgrp "$op" "$lab/key.new"
|
|
chmod 0640 "$lab/key.new"
|
|
mv -f "$lab/key.new" "$lab/operator.key"
|
|
}
|
|
cd "$stage/source"
|
|
out="$stage/evidence"
|
|
python3 -B bin/absdev-deploy capabilities > "$out/capabilities-before.json"
|
|
python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); f=[v for k,v in d.items() if k.endswith("_enabled") or k=="production_ready"]; assert len(f)==6 and all(v is False for v in f)' "$out/capabilities-before.json"
|
|
policy '["issue","execute"]'
|
|
rotate
|
|
deny() { if "$@"; then echo "Unexpected access: $*" >&2; exit 1; fi; }
|
|
probe() { runuser -u "$op" -- python3 -B probe.py "$lab" "$1"; }
|
|
{
|
|
printf 'host=%s\nrevision=b0dda75809a7efa2dd8ae3dc910dab23db9cfb61\n' "$(hostname -s)"
|
|
id "$op"
|
|
id "$other"
|
|
test "$(getent passwd "$op" | cut -d: -f7)" = /usr/sbin/nologin
|
|
test "$(getent passwd "$other" | cut -d: -f7)" = /usr/sbin/nologin
|
|
test "$(passwd -S "$op" | awk '{print $2}')" = L
|
|
test "$(passwd -S "$other" | awk '{print $2}')" = L
|
|
echo 'PASS: both accounts have locked passwords and no login shell'
|
|
stat -c '%a %U %G %n' "$lab/operator.key" "$lab/policy.json" "$lab/state"
|
|
runuser -u "$op" -- test -r "$lab/operator.key"
|
|
deny runuser -u "$op" -- test -w "$lab/operator.key"
|
|
deny runuser -u "$op" -- test -w "$lab/policy.json"
|
|
deny runuser -u "$other" -- test -r "$lab/operator.key"
|
|
deny runuser -u "$other" -- test -x "$lab/state"
|
|
echo 'PASS: operator can read the key; neither operator account can modify key or policy; ungranted account cannot read key or enter state'
|
|
probe wrong-principal
|
|
probe issue
|
|
probe consume
|
|
probe replay
|
|
probe issue
|
|
policy '[]'
|
|
probe grant-revoked
|
|
policy '["issue","execute"]'
|
|
rotate
|
|
probe key-revoked
|
|
probe issue
|
|
probe consume
|
|
probe replay
|
|
userdel "$other"
|
|
created_other=0
|
|
userdel "$op"
|
|
created_op=0
|
|
deny getent passwd "$op"
|
|
deny getent passwd "$other"
|
|
rm -rf -- "$lab"
|
|
test ! -e "$lab"
|
|
echo 'PASS: temporary accounts and key/state removed'
|
|
} > "$out/qualification.log"
|
|
python3 -B bin/absdev-deploy capabilities > "$out/capabilities-after.json"
|
|
cmp "$out/capabilities-before.json" "$out/capabilities-after.json"
|
|
cp probe.py "$out/"
|
|
(cd "$out" && sha256sum ./* > SHA256SUMS)
|
|
tar -czf - -C "$out" .
|