interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / tools / aien-local-ci / install.sh

183 lines · 11169 bytes Raw Blame History
1#!/usr/bin/env bash
2# SPDX-License-Identifier: Apache-2.0
3# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# install.sh: idempotent host setup for the sovereign local pipeline sandbox (lane INFRA, contracts C3/C8/A2).
18# Run as drakestapleton; uses sudo -n inside. Safe to re-run: every step checks before it acts.
19#
20# What it sets up on the host:
21# * system user aien-run (home /var/lib/aien-run root:aien-run 0750 + ACL u:drakestapleton:r-x, nologin,
22# groups video+render). The home and everything a later run could read config from is root-owned, so a
23# check cannot plant ~/.cargo/config.toml, swap the registry or replace the cargo proxies (review finding 1).
24# * /var/lib/aien-run/{cargo,target,wt,mirror,rustup} with the ownership described in README.md
25# * cargo registry + git cache seeded from ~/.cargo (root-owned, read-only), toolchain copied from ~/.rustup
26# (root-owned, read-only), rustup proxies in /var/lib/aien-run/cargo/bin (no second rustup install)
27# * /usr/local/bin/crumb (root 0755), built from aien-architecture at CRUMB_COMMIT below (the trusted copy
28# on the sandbox PATH; never the operator's ~/.local/bin copy, never a copy from a tree under test)
29# * /usr/local/sbin/aien-run-exec (root 0755) and /etc/sudoers.d/aien-local-ci (validated with visudo -c)
30# * ~/.local/state/aien-local-ci/{trigger,evidence,bundles} for the trusted side
31set -euo pipefail
32here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
33RUN_USER=aien-run
34RUN_HOME=/var/lib/aien-run
35OPERATOR=${AIEN_OPERATOR:-drakestapleton}
36OP_HOME=$(getent passwd "$OPERATOR" | cut -d: -f6)
37TOOLCHAIN=${AIEN_TOOLCHAIN:-1.98.1-aarch64-unknown-linux-gnu}
38MIRI_TOOLCHAIN=${AIEN_MIRI_TOOLCHAIN:-nightly-aarch64-unknown-linux-gnu}
39STATE="$OP_HOME/.local/state/aien-local-ci"
40# crumb source: aien-architecture commit (2026-10-18, RFC-0003 amendment 1 ACCEPTED, merge of aien-architecture#271),
41# file tools/crumb/crumb.c (git blob c272f293035bb3bdac416d1cfbf1212b96d49723). Built with gcc 13.3.0 the binary's sha256 is
42# 2fb09401f1e096821e90f83d8410fc00d251cac98fed748632055ad4e3905b79 (built on the Spark 2026-10-18).
43CRUMB_COMMIT=12ad0141b41ec67ef5aa51cb4e1815894c1083bb
44CRUMB_BLOB=c272f293035bb3bdac416d1cfbf1212b96d49723
45ARCH_CLONE=${AIEN_ARCH_CLONE:-$OP_HOME/workspace/aien-architecture}
46
47say() { printf '[install] %s\n' "$*"; }
48S() { sudo -n "$@"; }
49
50[[ $(id -un) == "$OPERATOR" ]] || { echo "run as $OPERATOR" >&2; exit 1; }
51sudo -n true 2>/dev/null || { echo "passwordless sudo required" >&2; exit 1; }
52# private scratch dir (never a predictable /tmp name: the sudoers line is staged here before install)
53tmp=$(mktemp -d)
54trap 'rm -rf "$tmp"' EXIT
55
56# 1. user and groups (device groups: /dev/dri/card0 is root:video, /dev/dri/renderD128 is root:render,
57# /dev/kvm is root:kvm 0660 for the qemu profile, /dev/nvidia* are 0666 root:root so they need no group).
58# The cgroup device policy still keeps /dev/kvm closed for the host profile.
59if ! getent passwd "$RUN_USER" >/dev/null; then
60 S useradd --system --home-dir "$RUN_HOME" --create-home --shell /usr/sbin/nologin --user-group \
61 --groups video,render "$RUN_USER"
62 say "created user $RUN_USER"
63else
64 say "user $RUN_USER exists"
65fi
66for g in video render kvm; do
67 getent group "$g" >/dev/null || continue
68 id -nG "$RUN_USER" | tr ' ' '\n' | grep -qx "$g" || S usermod -aG "$g" "$RUN_USER"
69done
70# 1b. the GB10 chip lock (#627). Gate scripts and operator chip runs all flock /tmp/aien-gb10.lock, and the
71# gb10 profile shares the host /tmp. fs.protected_regular=2 refuses an O_CREAT open of another user's file in
72# sticky /tmp unless the file belongs to the directory owner, so the lock is root-owned and the operator and
73# aien-run get rw through ACL entries (effective at once, unlike a new group in running sessions).
74# chown/setfacl keep the inode, so a chip run holding the lock is not disturbed; the tmpfiles.d rule recreates
75# it the same way after /tmp is cleaned at boot.
76printf 'f /tmp/aien-gb10.lock 0664 root root -\na+ /tmp/aien-gb10.lock - - - - u:%s:rw-,u:%s:rw-\n' "$OPERATOR" "$RUN_USER" > "$tmp/aien-gb10.conf"
77S install -o root -g root -m 0644 "$tmp/aien-gb10.conf" /etc/tmpfiles.d/aien-gb10.conf
78S systemd-tmpfiles --create /etc/tmpfiles.d/aien-gb10.conf
79S chown root:root /tmp/aien-gb10.lock
80S setfacl -m "u:$OPERATOR:rw-,u:$RUN_USER:rw-" /tmp/aien-gb10.lock
81# home: root-owned, group aien-run (traverse), operator via ACL; skeleton dotfiles removed (nothing may be
82# sourced or read from an aien-run-writable file in the home).
83S chown root:"$RUN_USER" "$RUN_HOME"
84S chmod 0750 "$RUN_HOME"
85S setfacl -m "u:$OPERATOR:r-x" "$RUN_HOME"
86for f in .bashrc .profile .bash_logout .config Desktop; do
87 if S test -e "$RUN_HOME/$f"; then S rm -rf "${RUN_HOME:?}/$f"; say "removed skeleton $RUN_HOME/$f"; fi
88done
89
90# 2. directory layout (cargo/ and target/ root-owned; only target/<repo>/{pr,main} belong to aien-run)
91S install -d -o root -g root -m 0755 "$RUN_HOME/cargo" "$RUN_HOME/target" "$RUN_HOME/models"
92S chown root:root "$RUN_HOME/cargo" "$RUN_HOME/target"; S chmod 0755 "$RUN_HOME/cargo" "$RUN_HOME/target"
93for f in "$RUN_HOME"/cargo/.package-cache "$RUN_HOME"/cargo/.package-cache-mutate "$RUN_HOME"/cargo/.global-cache; do
94 if S test -e "$f"; then S chown root:root "$f"; S chmod 0644 "$f"; fi
95done
96for r in "$RUN_HOME"/target/*/; do
97 [[ -d $r ]] || continue
98 S chown root:root "$r"; S chmod 0755 "$r"
99 for c in pr main; do S install -d -o "$RUN_USER" -g "$RUN_USER" -m 0755 "$r$c"; done
100done
101S install -d -o "$OPERATOR" -g "$OPERATOR" -m 0755 "$RUN_HOME/wt" "$RUN_HOME/mirror"
102S install -d -o root -g root -m 0755 "$RUN_HOME/rustup" "$RUN_HOME/rustup/toolchains" "$RUN_HOME/rustup/update-hashes" "$RUN_HOME/rustup/downloads" "$RUN_HOME/rustup/tmp"
103install -d -m 0755 "$STATE/trigger" "$STATE/evidence" "$STATE/bundles"
104
105# 3. caches: registry + git cache copied once from the operator's ~/.cargo, then root-owned read-only.
106seed_ro() { # seed_ro SRC DST
107 local src=$1 dst=$2
108 if [[ ! -e $dst ]]; then
109 [[ -d $src ]] || { say "skip $dst (no $src)"; return; }
110 S rm -rf "$dst.tmp"
111 S cp -a "$src" "$dst.tmp"
112 S mv "$dst.tmp" "$dst"
113 say "seeded $dst from $src"
114 fi
115 S chown -R root:root "$dst"
116 S chmod -R a+rX,u-w,go-w "$dst"
117}
118seed_ro "$OP_HOME/.cargo/registry" "$RUN_HOME/cargo/registry"
119seed_ro "$OP_HOME/.cargo/git" "$RUN_HOME/cargo/git"
120seed_ro "$OP_HOME/.rustup/toolchains/$TOOLCHAIN" "$RUN_HOME/rustup/toolchains/$TOOLCHAIN"
121# SC-MIRI (#600): the operator's nightly (with the miri and rust-src components) is copied the same way, and
122# the miri sysroot is built once here, as root, into aien-run's default ~/.cache/miri. It has to be built against
123# the copied toolchain path (cargo-miri hashes the source path, so a sysroot built from ~/.rustup is rejected and
124# rebuilt, which fails on the read-only cache). The build fetches std's dependencies with a throwaway CARGO_HOME;
125# the sandbox then only reads the finished sysroot and `cargo +nightly miri setup` is a no-op.
126seed_ro "$OP_HOME/.rustup/toolchains/$MIRI_TOOLCHAIN" "$RUN_HOME/rustup/toolchains/$MIRI_TOOLCHAIN"
127if [[ -x $RUN_HOME/rustup/toolchains/$MIRI_TOOLCHAIN/bin/cargo-miri ]]; then
128 S install -d -o root -g root -m 0755 "$RUN_HOME/.cache"
129 if ! S test -d "$RUN_HOME/.cache/miri/lib"; then
130 S rm -rf "$RUN_HOME/.cache/miri" "$tmp/miri-cargo"
131 S env -i HOME=/root RUSTUP_HOME="$RUN_HOME/rustup" CARGO_HOME="$tmp/miri-cargo" \
132 MIRI_SYSROOT="$RUN_HOME/.cache/miri" PATH="$RUN_HOME/cargo/bin:/usr/bin:/bin" \
133 "$RUN_HOME/cargo/bin/cargo" "+$MIRI_TOOLCHAIN" miri setup
134 S rm -rf "$tmp/miri-cargo"
135 say "built miri sysroot $RUN_HOME/.cache/miri"
136 fi
137 S chown -R root:root "$RUN_HOME/.cache/miri"
138 S chmod -R a+rX,u-w,go-w "$RUN_HOME/.cache/miri"
139else
140 say "skip miri sysroot (no cargo-miri in $MIRI_TOOLCHAIN: rustup component add miri rust-src --toolchain nightly)"
141fi
142
143# 4. rustup: the operator's rustup binary acts as the proxy (cargo/rustc/... are symlinks to it), with
144# RUSTUP_HOME=/var/lib/aien-run/rustup holding only settings.toml + the copied toolchain. No rustup-init,
145# no downloads: rust-toolchain.toml pins resolve against the copied toolchain only.
146S install -d -o root -g root -m 0755 "$RUN_HOME/cargo/bin"
147S install -o root -g root -m 0755 "$OP_HOME/.cargo/bin/rustup" "$RUN_HOME/cargo/bin/rustup"
148for p in cargo rustc rustdoc rustfmt cargo-fmt cargo-clippy clippy-driver rust-gdb rust-lldb cargo-miri miri; do
149 S ln -sfn rustup "$RUN_HOME/cargo/bin/$p"
150done
151printf 'version = "12"\ndefault_toolchain = "%s"\nprofile = "minimal"\n\n[overrides]\n' "$TOOLCHAIN" > "$tmp/settings.toml"
152S install -o root -g root -m 0644 "$tmp/settings.toml" "$RUN_HOME/rustup/settings.toml"
153S chown root:root "$RUN_HOME/rustup"; S chmod 0755 "$RUN_HOME/rustup"
154
155# 4b. git safe.directory for aien-run: worktree roots are operator-owned (sticky), so git must be told they are safe.
156# git 2.43 has no path globs for safe.directory, so it is "*"; aien-run can only reach /var/lib/aien-run anyway.
157printf "[safe]\n\tdirectory = *\n" > "$tmp/gitconfig"
158S install -o root -g root -m 0644 "$tmp/gitconfig" "$RUN_HOME/.gitconfig"
159
160# 4c. trusted crumb on the sandbox PATH, built from the pinned aien-architecture commit (source read straight
161# from the git object store, so the clone's checked-out branch does not matter).
162git -C "$ARCH_CLONE" cat-file -e "$CRUMB_COMMIT^{commit}" 2>/dev/null \
163 || git -C "$ARCH_CLONE" fetch --quiet origin main \
164 || { echo "cannot find $CRUMB_COMMIT in $ARCH_CLONE (set AIEN_ARCH_CLONE)" >&2; exit 1; }
165blob=$(git -C "$ARCH_CLONE" rev-parse "$CRUMB_COMMIT:tools/crumb/crumb.c")
166[[ $blob == "$CRUMB_BLOB" ]] || { echo "crumb.c blob $blob != expected $CRUMB_BLOB" >&2; exit 1; }
167git -C "$ARCH_CLONE" cat-file blob "$blob" > "$tmp/crumb.c"
168cc -O2 -Wall -std=c11 -o "$tmp/crumb" "$tmp/crumb.c"
169if ! cmp -s "$tmp/crumb" /usr/local/bin/crumb 2>/dev/null; then
170 S install -o root -g root -m 0755 "$tmp/crumb" /usr/local/bin/crumb
171 say "installed /usr/local/bin/crumb from aien-architecture $CRUMB_COMMIT (sha256 $(sha256sum < "$tmp/crumb" | cut -c1-16)...)"
172else
173 say "/usr/local/bin/crumb current (aien-architecture $CRUMB_COMMIT)"
174fi
175
176# 5. exec contract + sudoers
177S install -o root -g root -m 0755 "$here/aien-run-exec" /usr/local/sbin/aien-run-exec
178printf '%s ALL=(root) NOPASSWD: /usr/local/sbin/aien-run-exec\n' "$OPERATOR" > "$tmp/sudoers"
179S visudo -cf "$tmp/sudoers" >/dev/null
180S install -o root -g root -m 0440 "$tmp/sudoers" /etc/sudoers.d/aien-local-ci
181S visudo -c >/dev/null && say "sudoers OK"
182
183say "done. verify with: $here/tests/run.sh"