interplane.Get Omega
Read in your language

interplane-mv

INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority.

Brought by drakestapleton

branch main Branches Tags History

interplane-mv / adapters / aien / scripts / m5-setup-judge.sh

51 lines · 2857 bytes Raw Blame History
1#!/usr/bin/env bash
2# One-time operator setup for the VAC M5 slice: give the judge account its own P-256 signing key
3# and pin the matching public key where the operator keeps trust inputs.
4#
5# The private key is created by the judge account inside its own home (mode 700, file mode 600)
6# and never leaves it. The proposing account (RSI_USER) cannot read it. The operator account can,
7# through sudo; that is the operator's authority and is stated as a limit in every M5 receipt.
8#
9# Usage: JUDGE_BIN=<spark-rsi-judge> m5-setup-judge.sh <pinned-public-key-file>
10# An existing key is kept (never overwritten); the pin file is rewritten from it.
11set -euo pipefail
12die() { echo "M5 SETUP FAIL: $*" >&2; exit 1; }
13pin="${1:?usage: m5-setup-judge.sh <pinned-public-key-file>}"
14: "${JUDGE_BIN:?JUDGE_BIN must name the spark-rsi-judge binary}"
15judge_user="${JUDGE_USER:-aien-judge}"
16rsi_user="${RSI_USER:-aien-rsi}"
17judge_home="${JUDGE_HOME:-/var/lib/aien-judge}"
18key="$judge_home/judge.key"
19as_judge() { sudo -n -u "$judge_user" "$@"; }
20
21[ "$(as_judge stat -c %a "$judge_home")" = 700 ] || die "$judge_home must be mode 700"
22if ! as_judge test -f "$key"; then
23 as_judge sh -c 'umask 077; head -c 32 /dev/urandom | od -An -tx1 | tr -d " \n" > "$1"' _ "$key"
24fi
25[ "$(as_judge stat -c %a "$key")" = 600 ] || die "$key must be mode 600"
26# The proposer must not be able to read the key: prove the account runs at all, then require a
27# permission refusal (a missing account or sudo rule must not pass for "cannot read").
28sudo -n -u "$rsi_user" true || die "cannot run commands as $rsi_user, so the key check would prove nothing"
29if err="$(sudo -n -u "$rsi_user" cat "$key" 2>&1 >/dev/null)"; then die "$rsi_user can read $key"; fi
30case "$err" in *"Permission denied"*) ;; *) die "unexpected result reading $key as $rsi_user: $err";; esac
31bin_copy="$(as_judge mktemp "$judge_home/judge-bin.XXXXXX")"
32as_judge sh -c 'cat > "$1" && chmod 700 "$1"' _ "$bin_copy" <"$JUDGE_BIN"
33mkdir -p "$(dirname "$pin")"
34# Neither service account may replace the pinned key: not the file, its directory, or any directory
35# above it (which would let it rename the whole path), and neither may become root through sudo.
36pin_dir="$(cd "$(dirname "$pin")" && pwd -P)"
37for u in "$rsi_user" "$judge_user"; do
38 if [ -e "$pin" ] && sudo -n -u "$u" test -w "$pin"; then die "$u can write $pin"; fi
39 d="$pin_dir"
40 while :; do
41 if sudo -n -u "$u" test -w "$d"; then die "$u can write $d, above the pinned key"; fi
42 [ "$d" = / ] && break
43 d="$(dirname "$d")"
44 done
45 if sudo -n -u "$u" sudo -n true 2>/dev/null; then die "$u can use sudo"; fi
46done
47as_judge "$bin_copy" --signing-key-file "$key" --public-key >"$pin.new"
48as_judge rm -f "$bin_copy"
49grep -Eq '^04[0-9a-f]{128}$' "$pin.new" || die "unexpected public key output"
50mv "$pin.new" "$pin"
51echo "judge public key pinned at $pin"