Files
57_WolveandClaude Opus 5.5 11d219961a
build / build (push) Successful in 9m26s
patches: add v1.11.0 no-symlinks patch and its leil-rig proof
0005-posix-no-symlinks.patch makes VersityGW's posix backend resolve every
path below its root and versioning directory from a descriptor of that
directory, opened once at start: each directory on the way with openat2
and RESOLVE_NO_SYMLINKS|RESOLVE_BENEATH (one O_NOFOLLOW open per element
where openat2 is missing), the last element acted on without following
it. Upstream followed a link anywhere on a key's way, so on a host that
mounts more than one namespace a link planted in a bucket served,
overwrote and deleted another namespace's objects (Norn M5 stage 13).

A link, FIFO, socket or device is no object: at the end of a key it
reads as missing (404) and is never opened, on the way it answers as a
file there does (404, 409 ObjectParentIsFile), listings skip it and
never enter it, and PUT, copy, complete and DELETE act on the entry
itself, never on what a link points to (owner, 2026-11-27).
--bucketlinks still follows a link at the bucket level only.

Proven on leil-rig on 2026-11-27, against a stock 0001-0004 control:
- tests/no-symlinks/proof.sh, throwaway gateways on leil-test-1:
  87/87 (control 38/87).
- tests/no-symlinks/rig-replay.sh, with the build pinned on the rig's
  four instances: 75/75 twice (control 17/75).
- rig-gateway-check.sh 20/20 in both namespaces.
- go test, every package but plugins/: 35/35.
The rig was put back on 26e5a763.

docs/no-symlinks.md has the rules, the proof and what it costs: GET
+3-9%, HEAD +8-25%, listings 2x on a local disk and within noise on
LeilFS. README.md and docs/multi-version-pipeline.md name the patch and
how to check a rebase of it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 01:50:15 -06:00

175 lines
9.8 KiB
Bash

#!/bin/bash
#
# Stage 2 of the proof for patches/v1.11.0/0005-posix-no-symlinks.patch: Norn's M5 stage 13
# escape layout, replayed on leil-rig's installed gateways.
#
# sudo bash rig-replay.sh <peer IP> <test UID> <mount cache seconds> [BENCH_COUNT]
#
# Runs as root on the first gateway host (leil-mst-1), which mounts /srv/leilfs/0x0 (home
# namespace) and /srv/leilfs/0x1 (bucket namespace) and serves versitygw@0x0 and versitygw@0x1;
# <peer IP> is the other gateway host's, whose instances it reaches over the rig network. Each
# namespace's root keys are read from /etc/versitygw.d/<ns>.conf inside the admin calls and
# never printed.
#
# A throwaway account (<test UID>, leil-cluster's reserved test band) gets a home nf-home-<stamp>
# in 0x0 and a bucket nf-data-<stamp> in 0x1, each with escape/marker.txt. As root, owned by the
# UID, it plants in each a link to the other's marker (absolute, and relative ../../../<ns>/...),
# a link to the other's escape directory, a FIFO and a socket, waits out the mounts' cache, and
# drives the S3 calls at them through all four instances. Everything it made is removed at exit,
# through the mounts, with the account. BENCH_COUNT (default 0) also times that many PUT, GET,
# HEAD and DELETE calls and ten listings through the local 0x0 instance, on LeilFS.
set -uo pipefail
PEER=${1:?usage: rig-replay.sh <peer IP> <test UID> <mount cache seconds> [bench count]}
TUID=${2:?test UID}
CACHE=${3:?mount cache seconds}
BENCH=${4:-0}
HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
S3REQ=$HERE/s3req.py
[ "$(id -u)" = 0 ] || { echo "FATAL: run as root" >&2; exit 2; }
[ -f "$S3REQ" ] || { echo "FATAL: $S3REQ is missing (copy tests/owner-scope/s3req.py beside this)" >&2; exit 2; }
conf() { echo "/etc/versitygw.d/$1.conf"; }
cval() { (set -a; . "$(conf "$1")"; eval "printf '%s' \"\${$2}\""); } # cval <ns> <var>, not for secrets
declare -A S3PORT ADMPORT MNT
for ns in 0x0 0x1; do
[ -r "$(conf $ns)" ] || { echo "FATAL: no $(conf $ns)" >&2; exit 2; }
S3PORT[$ns]=$(cval $ns VGW_PORT | tr -d :) ADMPORT[$ns]=$(cval $ns VGW_ADMIN_PORT | tr -d :) MNT[$ns]=$(cval $ns VGW_BACKEND_ARG)
mountpoint -q "${MNT[$ns]}" || { echo "FATAL: ${MNT[$ns]} is not mounted" >&2; exit 2; }
done
STAMP=$(date +%s)
AK=nofollow-$STAMP
SK=$(head -c 24 /dev/urandom | base64 | tr '+/' 'AB' | tr -d '=\n')
HOMEB=nf-home-$STAMP DATAB=nf-data-$STAMP
declare -A BK=([0x0]=$HOMEB [0x1]=$DATAB)
W=$(mktemp -d /var/tmp/s3gw-nf-replay.XXXXXX)
chmod 700 "$W"
# admin <ns> <args...> -- signed with this host's root keys for <ns>, read here
admin() {
local ns=$1; shift
(set -a; . "$(conf "$ns")"; ADMIN_ACCESS_KEY_ID=$ROOT_ACCESS_KEY_ID ADMIN_SECRET_ACCESS_KEY=$ROOT_SECRET_ACCESS_KEY \
exec versitygw admin --region "$ns" --endpoint-url "http://127.0.0.1:${ADMPORT[$ns]}" "$@")
}
# req <ns> <local|peer> <s3req.py args...> -- one request as the throwaway account; prints the status
req() {
local ns=$1 where=$2 ip=127.0.0.1; shift 2
[ "$where" = peer ] && ip=$PEER
S3_ENDPOINT=http://$ip:${S3PORT[$ns]} S3_REGION=$ns S3_KEY=$AK S3_SECRET=$SK \
timeout 20 python3 -I "$S3REQ" "$@" 2>"$W/err" || [ -s "$W/err" ] || echo "no answer in 20 s" >"$W/err"
}
# mkbucket <ns> -- the account's bucket in <ns>, made as leil-cluster's leilfs-user makes one
mkbucket() {
admin "$1" create-bucket --owner "$AK" --bucket "${BK[$1]}" --object-ownership BucketOwnerPreferred \
--create-bucket-configuration "LocationConstraint=$1" &&
chown "$TUID:$TUID" "${MNT[$1]}/${BK[$1]}" && chmod 0700 "${MNT[$1]}/${BK[$1]}"
}
MADE=0
cleanup() {
if [ "$MADE" = 1 ]; then
for ns in 0x0 0x1; do
rm -rf "${MNT[$ns]}/${BK[$ns]}" "${MNT[$ns]}/.vgwlocks/$(printf %s "${BK[$ns]}" | sha256sum | cut -c1-64)"
admin "$ns" delete-user --access "$AK" >/dev/null 2>&1 || echo "WARN: could not delete $AK in $ns" >&2
done
echo "removed $AK, ${MNT[0x0]}/$HOMEB and ${MNT[0x1]}/$DATAB"
fi
rm -rf "$W"
}
trap cleanup EXIT
PASS=0 FAIL=0
ok() { PASS=$((PASS + 1)); printf 'PASS %-4s %s %s\n' "$1" "$2" "$3"; }
bad() { FAIL=$((FAIL + 1)); printf 'FAIL %-4s %s (want %s) %s [%s]\n' "$1" "${2:-none}" "$3" "$4" "$5"; }
check() { # check <id> <want> <what> <ns> <local|peer> <s3req.py args...>
local id=$1 want=$2 what=$3 got; shift 3
got=$(req "$@")
if [ "$got" = "$want" ]; then ok "$id" "$got" "$what"; else bad "$id" "$got" "$want" "$what" "$(tr '\n' ' ' <"$W/err")"; fi
}
check_cmd() { # check_cmd <id> <want: yes|no> <what> <command...>
local id=$1 want=$2 what=$3 got=yes; shift 3
"$@" >"$W/err" 2>&1 || got=no
if [ "$got" = "$want" ]; then ok "$id" "$got" "$what"; else bad "$id" "$got" "$want" "$what" "$(tr '\n' ' ' <"$W/err")"; fi
}
echo "versitygw $(sha256sum /usr/bin/versitygw | cut -c1-12) here; 0x0 S3 :${S3PORT[0x0]}, 0x1 S3 :${S3PORT[0x1]}; peer $PEER; account $AK (uid $TUID)"
echo "--- setup"
for ns in 0x0 0x1; do
check_cmd S1$ns yes "$ns create-user $AK" admin $ns create-user --access "$AK" --secret "$SK" --role user --user-id "$TUID" --group-id "$TUID"
MADE=1
check_cmd S2$ns yes "$ns create-bucket ${BK[$ns]} --owner $AK, then $TUID:$TUID 0700 as leilfs-user" mkbucket $ns
printf '%s marker' "$ns" >"$W/mark-$ns"
check S3$ns 200 "$ns PutObject ${BK[$ns]}/escape/marker.txt" $ns local PUT "/${BK[$ns]}/escape/marker.txt" --body "$W/mark-$ns"
done
H=${MNT[0x0]}/$HOMEB/escape D=${MNT[0x1]}/$DATAB/escape
plant() { # plant <dir> <other escape dir> <relative way to it>
ln -s "$2/marker.txt" "$1/link-abs" && ln -s "$3/marker.txt" "$1/link-rel" && ln -s "$2" "$1/link-dir" &&
ln -s "$2/marker.txt" "$1/link-del" && mkfifo "$1/fifo" &&
python3 -c 'import socket,sys; socket.socket(socket.AF_UNIX).bind(sys.argv[1])' "$1/sock" &&
chown -h "$TUID:$TUID" "$1"/link-* "$1/fifo" "$1/sock"
}
check_cmd S4 yes "plant in /0x0/$HOMEB/escape: links to 0x1's marker (abs, ../../../0x1/...), to its dir, FIFO, socket" \
plant "$H" "$D" "../../../0x1/$DATAB/escape"
check_cmd S5 yes "plant in /0x1/$DATAB/escape: links to 0x0's marker (abs, ../../../0x0/...), to its dir, FIFO, socket" \
plant "$D" "$H" "../../../0x0/$HOMEB/escape"
check_cmd S6 yes "the links resolve on this host" \
bash -c "[ \"\$(cat '$H/link-abs')\" = '0x1 marker' ] && [ \"\$(cat '$H/link-rel')\" = '0x1 marker' ] && [ \"\$(cat '$D/link-abs')\" = '0x0 marker' ] && [ \"\$(cat '$D/link-rel')\" = '0x0 marker' ]"
sleep $((CACHE + 1)) # the peer's mounts see the planted entries
echo "--- reads through all four instances: 404"
n=0
for ns in 0x0 0x1; do
for where in local peer; do
for key in link-abs link-rel link-dir/marker.txt fifo sock; do
n=$((n + 1)); check R$n 404 "$ns $where GetObject ${BK[$ns]}/escape/$key" $ns $where GET "/${BK[$ns]}/escape/$key" -o "$W/body"
n=$((n + 1)); check R$n 404 "$ns $where HeadObject ${BK[$ns]}/escape/$key" $ns $where HEAD "/${BK[$ns]}/escape/$key"
done
n=$((n + 1)); check R$n 404 "$ns $where CopyObject from ${BK[$ns]}/escape/link-abs" $ns $where PUT "/${BK[$ns]}/copied-$where" -H "x-amz-copy-source: /${BK[$ns]}/escape/link-abs"
done
done
echo "--- listings through all four instances: the marker alone"
n=0
for ns in 0x0 0x1; do
for where in local peer; do
for prefix in escape/ escape/link-dir/; do
req $ns $where GET "/${BK[$ns]}" "list-type=2&prefix=$prefix" -o "$W/list.xml" >/dev/null
got=$(python3 -I -c 'import re,sys; print(" ".join(re.findall(r"<Key>([^<]*)</Key>", open(sys.argv[1]).read())))' "$W/list.xml")
want=$([ "$prefix" = escape/ ] && echo escape/marker.txt)
n=$((n + 1))
if [ "$got" = "$want" ]; then ok L$n "[$got]" "$ns $where ListObjectsV2 prefix $prefix"; else bad L$n "[$got]" "[$want]" "$ns $where ListObjectsV2 prefix $prefix" "$(head -c 200 "$W/list.xml")"; fi
done
done
done
echo "--- writes and deletes act on the entry itself, never through it"
printf 'written by %s\n' "$AK" >"$W/new"
n=0
for ns in 0x0 0x1; do
for where in local peer; do
n=$((n + 1)); check W$n 409 "$ns $where PutObject ${BK[$ns]}/escape/link-dir/new-$where.txt (under the link)" $ns $where PUT "/${BK[$ns]}/escape/link-dir/new-$where.txt" --body "$W/new"
n=$((n + 1)); check W$n 204 "$ns $where DeleteObject ${BK[$ns]}/escape/link-dir/marker.txt (under the link)" $ns $where DELETE "/${BK[$ns]}/escape/link-dir/marker.txt"
done
done
check_cmd W10 yes " ...both markers are still there, nothing new beside them" \
bash -c "[ \"\$(cat '$H/marker.txt')\" = '0x0 marker' ] && [ \"\$(cat '$D/marker.txt')\" = '0x1 marker' ] && ! ls '$H' '$D' | grep -q '^new-'"
check W11 200 "0x0 peer PutObject $HOMEB/escape/link-abs (over the link)" 0x0 peer PUT "/$HOMEB/escape/link-abs" --body "$W/new"
check W12 200 "0x1 local PutObject $DATAB/escape/fifo (over the FIFO)" 0x1 local PUT "/$DATAB/escape/fifo" --body "$W/new"
check W13 204 "0x1 peer DeleteObject $DATAB/escape/link-del" 0x1 peer DELETE "/$DATAB/escape/link-del"
check W14 204 "0x0 local DeleteObject $HOMEB/escape/sock" 0x0 local DELETE "/$HOMEB/escape/sock"
sleep $((CACHE + 1))
check_cmd W15 yes " ...link-abs and fifo are now files of uid $TUID, link-del and sock are gone, both markers intact" \
bash -c "[ -f '$H/link-abs' ] && [ ! -L '$H/link-abs' ] && [ \$(stat -c %u '$H/link-abs') = $TUID ] && [ -f '$D/fifo' ] && [ ! -p '$D/fifo' ] && [ ! -L '$D/link-del' ] && [ ! -e '$H/sock' ] && [ \"\$(cat '$H/marker.txt')\" = '0x0 marker' ] && [ \"\$(cat '$D/marker.txt')\" = '0x1 marker' ]"
if [ "$BENCH" -gt 0 ]; then
echo "--- timing through the local 0x0 instance, on LeilFS ($BENCH objects)"
S3_ENDPOINT=http://127.0.0.1:${S3PORT[0x0]} S3_REGION=0x0 S3_KEY=$AK S3_SECRET=$SK S3REQ=$S3REQ \
python3 -I "$HERE/bench.py" "$HOMEB" "$BENCH" || bad B1 failed ok "bench" ""
fi
echo
echo "$PASS passed, $FAIL failed"
[ "$FAIL" = 0 ]