Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .agents/skills/axis-e2e/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
name: axis-e2e
description: Run AXIS on a real Linux host to verify a change end to end - gated real-runtime tests, MXC and native launches, an agent or TUI inside the sandbox, or main against a pull request in the same harness - and report the result. Use when a change touches launch, seccomp, Landlock, MXC, the proxy or policy translation and unit tests are not enough, or when reproducing a runtime issue. Not for the local checks in DEVELOPMENT.md, or for benchmark numbers (docs/runtime-performance-benchmarks.md).
---

# AXIS end to end on a real host

Read these first; they are the source of truth and this skill does not repeat them:

- [docs/security-test-tiers.md](../../../docs/security-test-tiers.md): gated tests, their environment variables, skip rules.
- [docs/linux-setup.md](../../../docs/linux-setup.md): what each backend and network mode needs from the host, and how `auto` picks a backend.
- [docs/runtime-performance-benchmarks.md](../../../docs/runtime-performance-benchmarks.md): numbers for launch-path and proxy changes.

## Scripts

`scripts/` has helpers for the steps below; each prints its usage with `-h`. Run them from an AXIS checkout and keep their output for the report.

- `preflight.sh --require mxc,strace,tty --out host.txt`: records the host and fails when a requirement is missing.
- `build.sh WORK base=origin/main pr=pr-123@origin/main`: builds each revision in its own worktree and target directory, with the `lxc-exec` its `ci.yml` pins, into `WORK/bin/NAME`. It checks the paths AXIS will accept and refuses identical binaries from different commits. `build.sh --clean WORK` removes everything it created.
- `run-tui.sh --axis WORK/bin/pr/axis --policy p.yaml --out runs/pr-1 --expect TEXT -- PROGRAM`: runs a terminal program in a PTY with a fresh home, types Ctrl-C, and writes `result.txt` (came up, exited, leftovers). A leftover is a process that names the run directory or PROGRAM and did not exist before the run; the script lists and stops it, and leaves your other processes alone. `--axis none` runs it without AXIS, which is how to pick `--expect`. `--strace` adds `denied.txt`.

Alternate the builds over several runs, for example `for i in 1 2 3; do for b in base pr; do run-tui.sh --axis WORK/bin/$b/axis --out runs/$b-$i ...; done; done`.

## Build what you test

- Build the helpers too: `cargo build --release --locked -p axis-cli -p axis-sandbox --bins`. Without `-p axis-sandbox --bins` there is no `axis-seccomp-launcher`, and MXC refuses to start.
- MXC needs `lxc-exec` built at the `MXC_REF` pinned in `.github/workflows/ci.yml`. Another revision fails with "Config schema version ... is newer than supported".
- When you compare builds (main against a pull request, or variants), give each source tree its own `CARGO_TARGET_DIR` and check that the binaries differ (`md5sum */axis`). Trees unpacked with `git archive` carry commit-time mtimes, so a shared target directory silently reuses the first build.

## Where the binaries live

AXIS looks for `axis-seccomp-launcher` and `lxc-exec` beside `axis`, then in its install directories, then in absolute `PATH` entries. It skips a candidate unless every path component is owned by root or the effective user, is not a symlink, and is not group- or world-writable. The error only says "no safe ... found", so check the components first (`namei -l`):

- Not under `/tmp`, and not in a directory created under `umask 002`: `chmod -R go-w` the bin directory.
- A root caller needs root-owned directories, for example a new directory under `/opt`, not a user's home.

## Choose the backend and network mode on purpose

- The bundled agent policies use `network.mode: proxy`, and `auto` runs strict proxy on the native backend. To test MXC, copy the policy and set `runtime.provider: mxc`; confirm the backend in the log or the process tree (`lxc-exec`, `bwrap`).
- MXC proxy needs unprivileged user and network namespaces; native proxy needs `CAP_NET_ADMIN` or the netns helper.
- MXC `block` mode denies every socket domain except `AF_UNIX`, so a program that serves on TCP loopback (agent TUIs often start a local server) fails there for that reason alone. Use `allow` for those and say which mode you tested.

## Running

- Give each run its own fake `HOME` and a short workspace path. Never point a test at a real `~/.config`, `~/.ssh` or agent state. The PTY bridge socket lives under the workspace and its path must stay under 108 bytes.
- Run with a clean environment (`env -i PATH=/usr/bin:/bin HOME=...`), as CI does. Extra tools on `PATH`, such as another `python3`, change results.
- `axis run` first tries axisd at `$XDG_RUNTIME_DIR/axis/axisd.sock` or `/tmp/axis-axisd.sock`, which on a shared host can be someone else's. Pass `--socket` with a path that does not exist to keep the run standalone.
- Interactive programs need a terminal: `script -qfec "<cmd>" /dev/null`, or tmux. Ctrl-C reaches the program only as the byte `0x03` through the PTY bridge, so type it (`printf '\003'` into the script's stdin, or `tmux send-keys C-c`); a signal sent to `script` is not what a user does. To stop a stuck run, send SIGTERM to `axis`, which tears the sandbox down.
- Do not wrap the command inside the sandbox with `timeout`: seccomp denies `timer_create`. Put `timeout` outside `axis run`.
- To see what seccomp denies: `strace -f -qq --status=failed -o trace.log axis run ...` and count `= -1 EPERM` by syscall. `prctl(PR_CAPBSET_DROP)` and `setsockopt(SO_*BUFFORCE)` failures come from Bubblewrap and MXC setup, not from the payload. Judge behavior only from runs without strace.
- To find which allowed syscall matters, add it to `process.blocked_syscalls` in a copy of the policy and rerun; no rebuild needed. A name AXIS does not know fails the launch.
- Run MXC as a non-root user. As root, Bubblewrap failed to set up its uid map on a host where the same non-root user could run it.

## Shared hosts

Work in a private directory (`chmod 700`), do not use sudo unless the person you work for agreed, do not touch other users' processes or sockets, and remove what you created, including stray clones and network namespaces.

## Report

| Item | Detail |
|---|---|
| Commits | Head SHA, the `main` it was tested on, and any local merge or patch |
| Host | Distribution, kernel, caller (root or not), backend, network mode |
| Commands | The exact commands, or the script that ran them |
| Results | Pass, fail and ignored counts; for a launch, what the program showed, over several alternating runs |
| Comparison | The same harness on `main`, when the claim is "fixed" or "no change" |
| Not run | Each skipped case and why. A skip is not a pass. |
139 changes: 139 additions & 0 deletions .agents/skills/axis-e2e/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/usr/bin/env bash
# Copyright 2026 Advanced Micro Devices, Inc.
# SPDX-License-Identifier: Apache-2.0

# Build AXIS revisions side by side for end-to-end runs, each with the
# lxc-exec its ci.yml pins, into bin directories AXIS accepts.
#
# build.sh WORK NAME=REF[@BASE] [NAME=REF[@BASE] ...]
# build.sh --clean WORK
#
# Run it inside an AXIS checkout. REF is anything `git rev-parse` accepts;
# fetch a pull request first (git fetch origin pull/N/head:pr-N).
# NAME=REF@BASE builds REF merged onto BASE, for testing a PR on current main.
# Binaries land in WORK/bin/NAME with a BUILD_INFO file.
# MXC_SRC=<clone of microsoft/mxc> avoids a fresh clone; NO_MXC=1 skips lxc-exec.

set -euo pipefail

die() { echo "build: $*" >&2; exit 1; }
repo=$(git rev-parse --show-toplevel 2>/dev/null) || die "run inside an AXIS git checkout"

if [ "${1:-}" = "--clean" ]; then
work=${2:?usage: build.sh --clean WORK}
for src in "$work"/src/*/; do
[ -d "$src" ] && git -C "$repo" worktree remove --force "$src" 2>/dev/null || true
done
git -C "$repo" worktree prune
rm -rf "$work"
echo "removed $work"
exit 0
fi

[ $# -ge 2 ] || { sed -n '5,16p' "$0" >&2; exit 2; }
work=$(realpath -m "$1"); shift
for spec in "$@"; do
case "$spec" in ?*=?*) ;; *) die "expected NAME=REF[@BASE], got '$spec'" ;; esac
done
umask 022
mkdir -p "$work"/{src,target,bin,mxc}
chmod 700 "$work"

ci_value() { sed -n "s/^ $1: \(.*\)\$/\1/p" "$2/.github/workflows/ci.yml" | head -1; }

build_lxc_exec() { # MXC_REF MXC_REPOSITORY -> path
local ref=$1 url=$2 dir=$work/mxc/$1
if [ ! -x "$dir/lxc-exec" ]; then
local src=$dir/src
if [ -n "${MXC_SRC:-}" ]; then
git -C "$MXC_SRC" worktree add --detach "$src" "$ref" >&2
else
git clone -q --filter=blob:none "$url" "$src" >&2
git -C "$src" checkout -q "$ref"
fi
cargo build --release --locked --manifest-path "$src/src/Cargo.toml" -p lxc --no-default-features >&2
install -m 755 "$src/src/target/release/lxc-exec" "$dir/lxc-exec"
fi
echo "$dir/lxc-exec"
}

# Mirrors validate_safe_executable_path in crates/axis-sandbox/src/linux/mxc.rs;
# keep the two in step.
check_safe_path() { # path: every component owned by root or us, no symlink, not group/world-writable
local path=$1 current="" part
IFS=/ read -ra parts <<< "${path#/}"
for part in "${parts[@]}"; do
current="$current/$part"
[ -L "$current" ] && die "$current is a symlink; AXIS will not use helpers under it"
read -r uid mode <<< "$(stat -c '%u %a' "$current")"
if [ "$uid" != 0 ] && [ "$uid" != "$(id -u)" ]; then
die "$current is owned by uid $uid; AXIS needs root or the effective user"
fi
if (( 8#$mode & 8#022 )); then
die "$current is group- or world-writable (mode $mode); AXIS will not use helpers under it"
fi
done
}

declare -a names=()
for spec in "$@"; do
name=${spec%%=*}; refs=${spec#*=}
[ "$name" != "$spec" ] && [ -n "$name" ] || die "expected NAME=REF[@BASE], got '$spec'"
ref=${refs%%@*}; base=""; [ "$refs" != "$ref" ] && base=${refs#*@}
src=$work/src/$name; bin=$work/bin/$name
[ -e "$src" ] && die "$src exists; use another NAME or build.sh --clean"

head=$(git -C "$repo" rev-parse --verify "$ref^{commit}") || die "unknown ref '$ref'"
if [ -n "$base" ]; then
basec=$(git -C "$repo" rev-parse --verify "$base^{commit}") || die "unknown ref '$base'"
git -C "$repo" worktree add -q --detach "$src" "$basec"
git -C "$src" -c user.name=axis-e2e -c user.email=axis-e2e@invalid merge -q --no-edit --no-ff "$head" \
|| { git -C "$src" merge --abort; die "$ref does not merge cleanly onto $base"; }
else
git -C "$repo" worktree add -q --detach "$src" "$head"
fi
commit=$(git -C "$src" rev-parse HEAD)

echo "== $name: building $commit" >&2
(cd "$src" && CARGO_TARGET_DIR=$work/target/$name cargo build --release --locked -p axis-cli -p axis-sandbox --bins >&2)

install -d -m 755 "$bin"
for f in axis axis-seccomp-launcher axis-netns-helper; do
if [ -x "$work/target/$name/release/$f" ]; then
install -m 755 "$work/target/$name/release/$f" "$bin/$f"
fi
done
[ -x "$bin/axis-seccomp-launcher" ] || die "$name: axis-seccomp-launcher was not built"

mxc_ref=$(ci_value MXC_REF "$src")
if [ -z "${NO_MXC:-}" ]; then
[ -n "$mxc_ref" ] || die "$name: no MXC_REF in .github/workflows/ci.yml"
install -m 755 "$(build_lxc_exec "$mxc_ref" "$(ci_value MXC_REPOSITORY "$src")")" "$bin/lxc-exec"
fi

{
echo "name=$name"
echo "ref=$ref"
echo "base=${base:-none}"
echo "head_commit=$head"
echo "built_commit=$commit"
echo "mxc_ref=${mxc_ref:-none}"
echo "rustc=$(cd "$src" && rustc --version)"
(cd "$bin" && sha256sum ./*)
} > "$bin/BUILD_INFO"
names+=("$name")
done

check_safe_path "$work/bin"
for name in "${names[@]}"; do check_safe_path "$work/bin/$name"; done

declare -A by_hash=()
for name in "${names[@]}"; do
commit=$(sed -n 's/^built_commit=//p' "$work/bin/$name/BUILD_INFO")
hash=$(sha256sum "$work/bin/$name/axis" | cut -d' ' -f1)
if [ -n "${by_hash[$hash]:-}" ] && [ "${by_hash[$hash]%%:*}" != "$commit" ]; then
die "$name and ${by_hash[$hash]#*:} have the same axis binary from different commits; a build was reused"
fi
by_hash[$hash]="$commit:$name"
printf '%-16s %s axis %s\n' "$name" "${commit:0:12}" "${hash:0:12}"
done
75 changes: 75 additions & 0 deletions .agents/skills/axis-e2e/scripts/preflight.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env bash
# Copyright 2026 Advanced Micro Devices, Inc.
# SPDX-License-Identifier: Apache-2.0

# Record what this host offers AXIS end-to-end runs, and fail when a
# requirement given with --require is missing.
#
# preflight.sh [--require mxc,strace,tty] [--out FILE]

set -uo pipefail

require=""
out=""
while [ $# -gt 0 ]; do
case "$1" in
--require) require="$2"; shift 2 ;;
--out) out="$2"; shift 2 ;;
-h|--help) sed -n '5,9p' "$0"; exit 0 ;;
*) echo "preflight: unknown argument: $1" >&2; exit 2 ;;
esac
done

report=""
missing=()
record() { report+="$1=$2"$'\n'; }
need() { case ",$require," in *",$1,"*) missing+=("$1: $2") ;; esac; }
tool() { PATH="$PATH:/usr/sbin:/usr/bin:/sbin:/bin" command -v "$1" 2>/dev/null || true; }

record date "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
record kernel "$(uname -r)"
record distro "$(sed -n 's/^PRETTY_NAME="\{0,1\}\([^"]*\)"\{0,1\}$/\1/p' /etc/os-release 2>/dev/null)"
record arch "$(uname -m)"
record uid "$(id -u)"
record lsm "$(cat /sys/kernel/security/lsm 2>/dev/null || echo unreadable)"
record apparmor_restrict_unprivileged_userns "$(cat /proc/sys/kernel/apparmor_restrict_unprivileged_userns 2>/dev/null || echo absent)"
record ptrace_scope "$(cat /proc/sys/kernel/yama/ptrace_scope 2>/dev/null || echo absent)"
record rustc "$(rustc --version 2>/dev/null || echo missing)"

for t in git cargo bwrap slirp4netns unshare nsenter iptables ip6tables iptables-restore ip6tables-restore script strace; do
record "tool_$t" "$(tool "$t")"
done

if [ -n "$(tool bwrap)" ] && bwrap --unshare-user --uid 0 --gid 0 --ro-bind / / -- true 2>/dev/null; then
record bwrap_userns ok
else
record bwrap_userns failed
need mxc "bwrap cannot create a user namespace (see apparmor_restrict_unprivileged_userns)"
fi
for t in bwrap slirp4netns unshare nsenter iptables ip6tables iptables-restore ip6tables-restore; do
[ -n "$(tool "$t")" ] || need mxc "$t is not installed"
done
[ -c /dev/net/tun ] || need mxc "/dev/net/tun is missing"

if [ -n "$(tool strace)" ]; then
if strace --status=failed -qq -o /dev/null true 2>/dev/null; then record strace_status_filter ok; else record strace_status_filter unsupported; fi
case "$(cat /proc/sys/kernel/yama/ptrace_scope 2>/dev/null || echo 0)" in
0|1) ;;
*) need strace "kernel.yama.ptrace_scope does not allow tracing" ;;
esac
else
need strace "strace is not installed"
fi
[ -n "$(tool script)" ] || need tty "script (util-linux) is not installed"

if [ "$(id -u)" = 0 ]; then
record note "running as root; MXC runs should use a non-root user"
fi

printf '%s' "$report"
[ -n "$out" ] && printf '%s' "$report" > "$out"

if [ ${#missing[@]} -gt 0 ]; then
printf 'preflight: missing %s\n' "${missing[@]}" >&2
exit 1
fi
Loading
Loading