fix(mars): rotated keys reach every Hermes profile's .env
Named profiles keep their own .env, so coder kept the old OpenCode key and librarian, with no OPENCODE line at all, was left on an exhausted pool entry. The OpenCode key now goes to every profile; other keys only to profiles that already carry them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011XkDJkdDzneVVdnkZfrvTY
This commit is contained in:
@@ -280,23 +280,37 @@ in
|
||||
# DID pass through) but answered every bearer token with
|
||||
# "Invalid gateway API key" — the passthrough list carries the plain
|
||||
# API_SERVER_* vars and drops the secret one.
|
||||
#
|
||||
# Each named profile has its own .env, cloned from the root one at
|
||||
# creation, so a rotation must reach those too (coder and librarian kept
|
||||
# the old OpenCode key). Profiles only get keys they already carry, unless
|
||||
# the second argument is "all": librarian had no OPENCODE line and was
|
||||
# left on an exhausted pool entry for the lapsed key.
|
||||
write_env_key() {
|
||||
setpriv --reuid=${hermesUid} --regid=${hermesGid} --clear-groups \
|
||||
${pkgs.runtimeShell} -c '
|
||||
set -eu
|
||||
envf=$1
|
||||
home=$1
|
||||
name=$2
|
||||
scope=$3
|
||||
umask 077
|
||||
key=$(cat)
|
||||
[ -e "$envf" ] || : > "$envf"
|
||||
[ -e "$home/.env" ] || : > "$home/.env"
|
||||
for envf in "$home/.env" "$home"/profiles/*/.env; do
|
||||
[ -f "$envf" ] || continue
|
||||
if [ "$envf" != "$home/.env" ] && [ "$scope" != all ] \
|
||||
&& ! grep -q "^$name=" "$envf"; then
|
||||
continue
|
||||
fi
|
||||
{ grep -v "^$name=" "$envf" || true
|
||||
printf "%s=%s\n" "$name" "$key"; } > "$envf.new"
|
||||
mv -f "$envf.new" "$envf"
|
||||
' _ ${hermesHome}/.env "$1"
|
||||
done
|
||||
' _ ${hermesHome} "$1" "''${2:-}"
|
||||
}
|
||||
# OPENCODE_GO_API_KEY does pass through, but a stale .env line from
|
||||
# `hermes setup` overrides it — that is how a rotated key kept 401ing.
|
||||
write_env_key OPENCODE_GO_API_KEY < ${config.sops.secrets.opencode_go_api_key.path}
|
||||
write_env_key OPENCODE_GO_API_KEY all < ${config.sops.secrets.opencode_go_api_key.path}
|
||||
write_env_key ELEVENLABS_API_KEY < ${config.sops.secrets.elevenlabs_api_key.path}
|
||||
|
||||
# Only these keys are asserted; anything Hermes adds to honcho.json stays.
|
||||
|
||||
Reference in New Issue
Block a user