Files
alzeo/engine-secrets.sh
T
Hasan BasbunarandClaude Opus 5.5 780b9bd166 engines: the key comes through a config file SGLang merges in memory, on no command line
--api-key "$(cat .../api-key)" put the key in the argv of the docker client and of the
server, readable by any local user in /proc. The units, the flash launcher and run.sh pass
--config /out/engine-secrets.yaml instead (the parse checked in both serving images),
written from the api-key file by engine-secrets.sh before every start (ExecStartPre, the
launcher, run.sh) and only when its content changes, so a hand-changed key still reaches
the next start and an unchanged one restarts nothing. install.sh installs the helper at
step 6; the CI flash gate, SECURITY.md and the uninstall listing follow. Also: a test's
fake subprocess.run leaked into every later test of the process; it is put back.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 23:42:45 +02:00

28 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# The engine's key, where SGLang reads it without a command line. This writes
# engine-secrets.yaml next to the api-key file, and the units, the flash launcher and
# run.sh hand it to the server as `--config /out/engine-secrets.yaml`: SGLang merges
# that file into its arguments in memory, so the key is in no process's argv. As
# --api-key "$(cat ...)" it was in the docker client's and in the server's, which any
# local user reads in /proc (found in review, 2026-09-24). It runs before every start,
# so a key changed by hand still reaches the engine at its next start, as it did.
# Usage: engine-secrets.sh [config dir] (default: the folder this script sits in)
set -euo pipefail
d="${1:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}"
key="$(cat "$d/api-key")"
case "$key" in
"" | *[\"\\]* | *[[:cntrl:]]*)
echo "engine-secrets.sh: $d/api-key is empty, or holds a quote, a backslash or a control character" >&2
exit 1 ;;
esac
want="api-key: \"$key\""
# Written only when it changes: install.sh keeps an engine whose inputs are older than its
# start, and a rewrite of the same bytes would make it restart the engine at every run.
if [ -f "$d/engine-secrets.yaml" ] && [ "$(cat "$d/engine-secrets.yaml")" = "$want" ]; then
chmod 600 "$d/engine-secrets.yaml"
exit 0
fi
umask 077
printf '%s\n' "$want" > "$d/.engine-secrets.yaml.tmp"
mv -f "$d/.engine-secrets.yaml.tmp" "$d/engine-secrets.yaml"