salvage 2026-11-06: uncommitted work from scratch/darkwing-proxy-precheck-1961 (disk cleanup #824)
This commit is contained in:
1 parent
c91bd3787b
commit
4b5fd01499
16 files changed
+354
-60
No files matched your search
+22
-4
@@ -14,7 +14,7 @@
|
||||
# --node is the pinned path and it and every directory above it are root's with no group or other
|
||||
# write. The script changes nothing on the host but the message F3 sends and its reply, and it never
|
||||
# opens claude-session.env. A bounded config/target query imports the copy only as the stack
|
||||
# user, with sudo and an empty environment. Root parses its two facts in bash. P10 uses the
|
||||
# user, with sudo and an empty environment. Root parses only bounded metadata in bash. P10 uses the
|
||||
# fixed system Python, also as the stack user, for a read-only SO_PEERCRED observation.
|
||||
# The config/probe supervisor is fixed root-validated system Bash plus setsid
|
||||
# and sleep, after the uid drop: query inner/outer 5/7 s, probe 2/4 s. Root
|
||||
@@ -28,6 +28,9 @@
|
||||
# One line per check, `<id> <path> <mark> <evidence>`, then `count <mark> N` for each mark and a
|
||||
# result line. F checks are `pass` or `FAIL`. P checks are `closed`, `accepted <ruling>` or
|
||||
# `unnamed`, which means no Q182, Q183 or Mos ruling names the path; each unnamed line goes to Mos.
|
||||
# The config query also carries a proxy mode fact when configured. In proxy
|
||||
# mode F8 requires the same active unit host/copy typed managed marker/usage
|
||||
# record through a second dropped-uid query; it never substitutes a legacy token file.
|
||||
#
|
||||
# Exit 0 when every F check passes, 1 when one fails, 2 on usage or a refusal (a bad args file, or
|
||||
# --root misused). A P check never changes the exit.
|
||||
@@ -321,11 +324,11 @@ legacy_run() (
|
||||
)
|
||||
# row276-legacy-end
|
||||
|
||||
TESTER_QUERY='import {readFileSync} from "node:fs";import {pathToFileURL} from "node:url";const m=await import(pathToFileURL(process.argv[1]).href);const s=m.loadSystem();console.log(JSON.stringify({dataRoot:s.dataRoot,socket:readFileSync(process.argv[2],"utf8").includes("MOSAIC_TESTER_SOCKET_V1")}));'
|
||||
TESTER_QUERY='import {readFileSync} from "node:fs";import {pathToFileURL} from "node:url";const m=await import(pathToFileURL(process.argv[1]).href);const s=m.loadSystem();console.log(JSON.stringify({dataRoot:s.dataRoot,socket:readFileSync(process.argv[2],"utf8").includes("MOSAIC_TESTER_SOCKET_V1"),...(s.proxy?{proxy:true}:{})}));'
|
||||
tester_facts() {
|
||||
local LC_ALL=C pattern='^\{"dataRoot":"([A-Za-z0-9/._@+-]+)","socket":(true|false)\}$'
|
||||
local LC_ALL=C pattern='^\{"dataRoot":"([A-Za-z0-9/._@+-]+)","socket":(true|false)(,"proxy":(true))?\}$'
|
||||
[[ "$1" =~ $pattern ]] || return 1
|
||||
TS_DATA="${BASH_REMATCH[1]}" TS_MARKED="${BASH_REMATCH[2]}"
|
||||
TS_DATA="${BASH_REMATCH[1]}" TS_MARKED="${BASH_REMATCH[2]}" TS_PROXY="${BASH_REMATCH[4]:-false}"
|
||||
}
|
||||
tester_location() {
|
||||
local LC_ALL=C data="$1" home="$2" uid="$3" prefix="$4" part at="" st
|
||||
@@ -563,8 +566,23 @@ check_f7() {
|
||||
else ffail F7 pm-live "$(clean "${out#fail }")"; fi
|
||||
}
|
||||
|
||||
PROBE_QUERY='import{pathToFileURL}from"node:url";const m=await import(pathToFileURL(process.argv[1]).href);const r=m.readAcceptanceRecord(process.argv[2],process.argv[3],process.argv[4]);console.log([r.copy,r.hostPid,r.hostStartTime,r.run,r.modelKeyId,r.inputTokens].join(" "));'
|
||||
check_f8() {
|
||||
local s
|
||||
# This is a mode fact from the existing bounded, dropped-uid config query,
|
||||
# never a readiness assertion. P2's key stays inside managed launch. The
|
||||
# second bounded dropped-uid query reads typed host-owned evidence only.
|
||||
if [ "$TS_PROXY" = true ]; then
|
||||
local out rc=0 copy host_pid host_start run key tokens
|
||||
out="$(tester_capture 5 7 4096 "$S_USER" "$S_HOME" "$(dirname "$NODE"):/usr/local/bin:/usr/bin:/bin" "$NODE" --input-type=module -e "$PROBE_QUERY" "$COPY/packages/cli/src/acceptance-record.mjs" "$DATA_ROOT" "$BUSINESS" "$COPY_ID")" || rc=$?
|
||||
if [ "$rc" = 0 ] && [[ "$out" =~ ^[a-f0-9]{40}\ [1-9][0-9]*\ [0-9]+\ r[a-f0-9]{12}\ [a-f0-9]{12}\ (0|[1-9][0-9]*)$ ]]; then
|
||||
read -r copy host_pid host_start run key tokens <<<"$out"
|
||||
if [ "$copy" = "$COPY_ID" ] && [ "$host_pid" = "$(prop "$BUS_SHOW" MainPID)" ] && [ "$tokens" -le 2000 ]; then
|
||||
fpass F8 proxy-managed-probe "same-copy host $host_pid/$host_start run $run key id $key: literal marker, $tokens input tokens and confirmed native cleanup"
|
||||
else ffail F8 proxy-managed-probe "acceptance-record-invalid: copy, active bus host or token ceiling differs"; fi
|
||||
else ffail F8 proxy-managed-probe "proxy-managed-probe-required: no trusted managed marker/token result; legacy token metadata is not proxy evidence"; fi
|
||||
return
|
||||
fi
|
||||
s="$(stat -c '%U %a %F' -- "$ROOT$CRED" 2>/dev/null)" || s="missing"
|
||||
if [ ! -L "$ROOT$CRED" ] && [ "$s" = "$S_USER 600 regular file" ]; then fpass F8 credential-file "$CRED is '$s'"
|
||||
else ffail F8 credential-file "$CRED is '$s', not '$S_USER 600 regular file'"; fi
|
||||
|
||||
+51
-11
@@ -4,7 +4,7 @@
|
||||
# nothing. It runs every check, prints one line for each, and refuses if
|
||||
# any one failed.
|
||||
#
|
||||
# case2-precheck.sh --business ID [--profile factory|library]
|
||||
# case2-precheck.sh --business ID [--profile factory|library] [--static-only]
|
||||
# case2-precheck.sh --business ID --library-status
|
||||
#
|
||||
# Checks: the config and business file validate; `sudo -n true` fails and
|
||||
@@ -18,6 +18,13 @@
|
||||
# runs claude-code; and claude-session.env sets ZAI_API_KEY, when some
|
||||
# instance's provider is zai. It prints free memory and checks that HOME is
|
||||
# <home>. It never prints a value from claude-session.env.
|
||||
# Proxy mode consumes only the running host's same-copy typed managed probe
|
||||
# record, proving literal marker, actual aggregate input<=2000 and native cleanup.
|
||||
# Missing/invalid evidence refuses proxy-managed-probe-required; it invokes no
|
||||
# direct Claude path and imports no legacy env file. A proxy business route
|
||||
# without proxy configuration refuses proxy-route-needs-config.
|
||||
# --static-only runs the pre-start checks without a provider probe. Clean
|
||||
# static checks exit 3 with PROBEPENDING, never full acceptance (exit 0).
|
||||
#
|
||||
# C2-13b adds to the library profile: the business file is <user>'s with no
|
||||
# group or other bit; businesses/.history/<id>/ is 0700 and its changes.jsonl
|
||||
@@ -40,7 +47,7 @@
|
||||
# CASE2_PROC_SYS default /proc/sys
|
||||
# CASE2_GETENT the getent command, default getent
|
||||
#
|
||||
# Exit 0 every check passed, 1 refused, 4 usage.
|
||||
# Exit 0 every check passed, 1 refused, 3 static PROBEPENDING, 4 usage.
|
||||
set -uo pipefail
|
||||
REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
UNIT_DIR="${CASE2_UNIT_DIR:-/etc/systemd/system}"
|
||||
@@ -52,18 +59,20 @@ WEBUI_UNIT="$UNIT_DIR/mosaic-webui.service"
|
||||
# Claude Code's own prompt is many times this.
|
||||
MARKER_TOKEN_CEILING=2000
|
||||
|
||||
usage() { echo 'usage: case2-precheck.sh --business ID [--profile factory|library] | --business ID --library-status' >&2; exit 4; }
|
||||
PROFILE=library PROFILE_SET=0 BUSINESS='' STATUS=0
|
||||
usage() { echo 'usage: case2-precheck.sh --business ID [--profile factory|library] [--static-only] | --business ID --library-status' >&2; exit 4; }
|
||||
PROFILE=library PROFILE_SET=0 BUSINESS='' STATUS=0 STATIC=0
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--profile) [ $# -ge 2 ] || usage; PROFILE="$2"; PROFILE_SET=1; shift 2 ;;
|
||||
--business) [ $# -ge 2 ] || usage; BUSINESS="$2"; shift 2 ;;
|
||||
--library-status) STATUS=1; shift ;;
|
||||
--static-only) [ "$STATIC" = 0 ] || usage; STATIC=1; shift ;;
|
||||
*) usage ;;
|
||||
esac
|
||||
done
|
||||
[ -n "$BUSINESS" ] || usage
|
||||
[ "$STATUS" = 0 ] || [ "$PROFILE_SET" = 0 ] || usage
|
||||
[ "$STATUS" = 0 ] || [ "$STATIC" = 0 ] || usage
|
||||
case "$PROFILE" in factory|library) ;; *) echo "case2-precheck: --profile must be factory or library: $PROFILE" >&2; exit 4 ;; esac
|
||||
[[ "$BUSINESS" =~ ^[a-z0-9][a-z0-9._-]{0,63}$ ]] || { echo "case2-precheck: --business must be a business id: $BUSINESS" >&2; exit 4; }
|
||||
|
||||
@@ -80,7 +89,7 @@ private_dir() { [ ! -L "$1" ] && [ -d "$1" ] && [ "$(stat -c '%u' -- "$1")" = "$
|
||||
if [ "$STATUS" = 1 ]; then
|
||||
status="$(cd "$REPO" && node --input-type=module -e '
|
||||
import { lstatSync } from "node:fs";
|
||||
const [repo, id] = process.argv.slice(1);
|
||||
const [repo, id, staticOnly] = process.argv.slice(1);
|
||||
const { loadSystem, rolesDir } = await import(`${repo}/packages/cli/src/config.mjs`);
|
||||
const { loadBusiness } = await import(`${repo}/packages/business/src/index.mjs`);
|
||||
const { libraryStatus, mirrorPath } = await import(`${repo}/packages/library/src/index.mjs`);
|
||||
@@ -112,7 +121,7 @@ for (const project of projects) {
|
||||
for (const p of s.problems) say("PROBLEM", p.code, quote(p.path));
|
||||
say("PROBLEMS", project, s.problems.length);
|
||||
}
|
||||
' "$REPO" "$BUSINESS" 2>&1)" || true
|
||||
' "$REPO" "$BUSINESS" "$STATIC" 2>&1)" || true
|
||||
[ -n "$status" ] || refuse "library status: the check printed nothing"
|
||||
while IFS=$'\t' read -r kind a b c; do
|
||||
case "$kind" in
|
||||
@@ -166,13 +175,21 @@ HOME_DIR="${PW_HOME:-$HOME}"
|
||||
# The helper prints tab-separated facts and never a credential.
|
||||
facts="$(cd "$REPO" && node --input-type=module -e '
|
||||
import { readFileSync } from "node:fs";
|
||||
const [repo, id] = process.argv.slice(1);
|
||||
const [repo, id, staticOnly] = process.argv.slice(1);
|
||||
const { loadSystem, rolesDir } = await import(`${repo}/packages/cli/src/config.mjs`);
|
||||
const { businessFilePath, configDir, loadBusiness, resolveInstance, systemVars } = await import(`${repo}/packages/business/src/index.mjs`);
|
||||
const say = (...f) => console.log(f.join("\t"));
|
||||
let system;
|
||||
try { system = loadSystem(); } catch (e) { say("CONFIG", "bad", e.message.split("\n")[0]); process.exit(0); }
|
||||
say("CONFIG", "ok", system.dataRoot, configDir());
|
||||
if (system.proxy) {
|
||||
say("PROXY", "on");
|
||||
if (staticOnly !== "1") try {
|
||||
const { readAcceptanceRecord, pinnedAcceptanceCopy } = await import(`${repo}/packages/cli/src/acceptance-record.mjs`);
|
||||
const r = readAcceptanceRecord(system.dataRoot, id, pinnedAcceptanceCopy(repo));
|
||||
say("PROBE", "ok", r.run, r.modelKeyId, r.inputTokens);
|
||||
} catch { say("PROBE", "missing"); }
|
||||
}
|
||||
try {
|
||||
const { readNotifyConfig } = await import(`${repo}/packages/cli/src/cli.mjs`);
|
||||
readNotifyConfig(system.dataRoot, id);
|
||||
@@ -199,7 +216,7 @@ for (const instance of Object.keys(b.roles)) {
|
||||
say("ROUTE", instance, v[h], provider);
|
||||
}
|
||||
}
|
||||
' "$REPO" "$BUSINESS" 2>&1)" || true
|
||||
' "$REPO" "$BUSINESS" "$STATIC" 2>&1)" || true
|
||||
|
||||
line() { printf '%s\n' "$facts" | awk -F'\t' -v k="$1" '$1 == k' ; }
|
||||
cfg="$(line CONFIG)"
|
||||
@@ -322,6 +339,26 @@ elif [ "$floor" -le "$port" ]; then refuse "net.ipv4.ip_unprivileged_port_start
|
||||
else ok "net.ipv4.ip_unprivileged_port_start $floor is above the Console's port $port"; fi
|
||||
|
||||
routes="$(line ROUTE)"
|
||||
# P2 releases a key only inside a managed launch in the running bus. A
|
||||
# preboot process cannot substitute a host credential or a public ready flag.
|
||||
# Only same-copy/current-host typed probe evidence can complete BOTH properties;
|
||||
# static-only remains pending regardless of an earlier record.
|
||||
DIRECT_PROBE=1
|
||||
if [ "$STATIC" = 1 ]; then
|
||||
DIRECT_PROBE=0
|
||||
elif [ "$(line PROXY)" = $'PROXY\ton' ]; then
|
||||
DIRECT_PROBE=0
|
||||
probe="$(line PROBE)"
|
||||
if [[ "$probe" =~ ^PROBE$'\t'ok$'\t'r[a-f0-9]{12}$'\t'[a-f0-9]{12}$'\t'(0|[1-9][0-9]*)$ ]]; then
|
||||
IFS=$'\t' read -r _ _ probe_run probe_key probe_tokens <<<"$probe"
|
||||
if [ "$probe_tokens" -le "$MARKER_TOKEN_CEILING" ]; then
|
||||
ok "managed proxy replaces its prompt: run $probe_run key id $probe_key, $probe_tokens input tokens; same live host/copy and native cleanup recorded"
|
||||
else refuse "proxy-managed-probe-required: recorded token ceiling failed"; fi
|
||||
else refuse "proxy-managed-probe-required: no typed same-live-host/copy marker and token-ceiling result"; fi
|
||||
elif printf '%s\n' "$routes" | awk -F'\t' '$4 == "proxy" { f = 1 } END { exit !f }'; then
|
||||
refuse "proxy-route-needs-config: a proxy route cannot use the direct host credential/probe path"
|
||||
DIRECT_PROBE=0
|
||||
fi
|
||||
SESSION_ENV="${CONFIG_DIR:-$HOME_DIR/.config/mosaic-dev}/secrets/claude-session.env"
|
||||
# The session env file, checked as the bus unit's EnvironmentFile.
|
||||
env_file_ok() {
|
||||
@@ -329,7 +366,7 @@ env_file_ok() {
|
||||
}
|
||||
|
||||
# Claude Code replaces its prompt with --system-prompt-file.
|
||||
if printf '%s\n' "$routes" | awk -F'\t' '$3 == "claude-code" { f = 1 } END { exit !f }'; then
|
||||
if [ "$DIRECT_PROBE" = 1 ] && printf '%s\n' "$routes" | awk -F'\t' '$3 == "claude-code" { f = 1 } END { exit !f }'; then
|
||||
claude="$(unit_value "$BUS_UNIT" Environment | sed -n 's/^MOSAIC_CLAUDE_BIN=//p')"
|
||||
claude="${claude:-$(command -v claude || true)}"
|
||||
if [ -z "$claude" ] || [ ! -x "$claude" ]; then refuse "an instance runs claude-code and no claude is installed"
|
||||
@@ -367,7 +404,7 @@ if printf '%s\n' "$routes" | awk -F'\t' '$3 == "claude-code" { f = 1 } END { exi
|
||||
fi
|
||||
|
||||
# ZAI_API_KEY, when some instance's provider is zai (design 10 step 2d).
|
||||
if printf '%s\n' "$routes" | awk -F'\t' '$4 == "zai" { f = 1 } END { exit !f }'; then
|
||||
if [ "$DIRECT_PROBE" = 1 ] && printf '%s\n' "$routes" | awk -F'\t' '$4 == "zai" { f = 1 } END { exit !f }'; then
|
||||
if [ -L "$SESSION_ENV" ]; then refuse "$SESSION_ENV is a symlink"
|
||||
elif [ ! -f "$SESSION_ENV" ]; then refuse "an instance's provider is zai and $SESSION_ENV is missing"
|
||||
elif ! env_file_ok; then refuse "$SESSION_ENV must be owned by $ME at 0600 (mode $(stat -c '%a' -- "$SESSION_ENV"))"
|
||||
@@ -376,6 +413,9 @@ if printf '%s\n' "$routes" | awk -F'\t' '$4 == "zai" { f = 1 } END { exit !f }';
|
||||
fi
|
||||
|
||||
echo " free memory: $(awk '$1 == "MemAvailable:" { printf "%d MiB", $2 / 1024 }' /proc/meminfo)"
|
||||
if [ "$FAILED" = 0 ]; then echo "case2-precheck: every check passed"; exit 0; fi
|
||||
if [ "$FAILED" = 0 ]; then
|
||||
if [ "$STATIC" = 1 ]; then echo "case2-precheck: PROBEPENDING (static checks passed; trusted managed probe still required)"; exit 3; fi
|
||||
echo "case2-precheck: every check passed"; exit 0
|
||||
fi
|
||||
echo "case2-precheck: refused"
|
||||
exit 1
|
||||
Reference in new issue
Block a user