feat(mars): expose luna over the OpenAI-compatible API server
API_SERVER_ENABLED/HOST/PORT in the env template, bound 0.0.0.0 for the
same reason the dashboard is: the container is --network=host and nothing
opens 8642 in the firewall, so it is reachable over tailscale0 only.
API_SERVER_KEY has to go through .env like the ElevenLabs key did
(461d6cc). Confirmed the same way: with the key set only in the container
env the server came up — so API_SERVER_ENABLED/HOST *did* pass through —
but answered every bearer token with "Invalid gateway API key". The s6
passthrough list carries the plain API_SERVER_* vars and drops the secret
one. The .env write is now a write_env_key helper so both keys share it.
restartUnits gains prepare-dirs, which is what writes the .env line; the
container then has to come back up to read it.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+22
-11
@@ -272,17 +272,28 @@ in
|
|||||||
# setpriv because root must not write into hermesHome — luna could plant a
|
# setpriv because root must not write into hermesHome — luna could plant a
|
||||||
# symlink there. The key arrives on an fd opened while still root, so it
|
# symlink there. The key arrives on an fd opened while still root, so it
|
||||||
# never lands in argv or the journal and her uid needs no /run/secrets access.
|
# never lands in argv or the journal and her uid needs no /run/secrets access.
|
||||||
setpriv --reuid=${hermesUid} --regid=${hermesGid} --clear-groups \
|
#
|
||||||
${pkgs.runtimeShell} -c '
|
# API_SERVER_KEY is in the same boat, confirmed the same way: with it set
|
||||||
set -eu
|
# only in the container env the server came up (so API_SERVER_ENABLED/HOST
|
||||||
envf=$1
|
# DID pass through) but answered every bearer token with
|
||||||
umask 077
|
# "Invalid gateway API key" — the passthrough list carries the plain
|
||||||
key=$(cat)
|
# API_SERVER_* vars and drops the secret one.
|
||||||
[ -e "$envf" ] || : > "$envf"
|
write_env_key() {
|
||||||
{ grep -v "^ELEVENLABS_API_KEY=" "$envf" || true
|
setpriv --reuid=${hermesUid} --regid=${hermesGid} --clear-groups \
|
||||||
printf "ELEVENLABS_API_KEY=%s\n" "$key"; } > "$envf.new"
|
${pkgs.runtimeShell} -c '
|
||||||
mv -f "$envf.new" "$envf"
|
set -eu
|
||||||
' _ ${hermesHome}/.env < ${config.sops.secrets.elevenlabs_api_key.path}
|
envf=$1
|
||||||
|
name=$2
|
||||||
|
umask 077
|
||||||
|
key=$(cat)
|
||||||
|
[ -e "$envf" ] || : > "$envf"
|
||||||
|
{ grep -v "^$name=" "$envf" || true
|
||||||
|
printf "%s=%s\n" "$name" "$key"; } > "$envf.new"
|
||||||
|
mv -f "$envf.new" "$envf"
|
||||||
|
' _ ${hermesHome}/.env "$1"
|
||||||
|
}
|
||||||
|
write_env_key ELEVENLABS_API_KEY < ${config.sops.secrets.elevenlabs_api_key.path}
|
||||||
|
write_env_key API_SERVER_KEY < ${config.sops.secrets.hermes_api_server_key.path}
|
||||||
|
|
||||||
if [ -d ${hermesHome}/.config ]; then
|
if [ -d ${hermesHome}/.config ]; then
|
||||||
chown ${hermesUid}:${hermesGid} ${hermesHome}/.config
|
chown ${hermesUid}:${hermesGid} ${hermesHome}/.config
|
||||||
|
|||||||
@@ -40,6 +40,18 @@
|
|||||||
sops.secrets.gitea_hermes_webhook_secret = {
|
sops.secrets.gitea_hermes_webhook_secret = {
|
||||||
restartUnits = [ "hermes-agent-webhook-routes.service" ];
|
restartUnits = [ "hermes-agent-webhook-routes.service" ];
|
||||||
};
|
};
|
||||||
|
# Bearer token for the OpenAI-compatible API server (see the env template
|
||||||
|
# below). Same value in secrets/terra.yaml, where luna-voiced reads it.
|
||||||
|
# API_SERVER_HOST=0.0.0.0 for the same reason the dashboard binds it (see
|
||||||
|
# hermes-agent.nix): the container is --network=host and nothing opens 8642
|
||||||
|
# in the firewall, so it is reachable over tailscale0 only — LAN-closed.
|
||||||
|
# prepare-dirs writes it into luna's .env (the container env alone does not
|
||||||
|
# reach the gateway — see hermes-agent.nix); the container then has to come
|
||||||
|
# back up to read it.
|
||||||
|
sops.secrets.hermes_api_server_key.restartUnits = [
|
||||||
|
"hermes-agent-prepare-dirs.service"
|
||||||
|
"podman-hermes-agent.service"
|
||||||
|
];
|
||||||
sops.templates."hermes-agent.env".content = ''
|
sops.templates."hermes-agent.env".content = ''
|
||||||
OPENCODE_GO_API_KEY=${config.sops.placeholder.opencode_go_api_key}
|
OPENCODE_GO_API_KEY=${config.sops.placeholder.opencode_go_api_key}
|
||||||
TELEGRAM_BOT_TOKEN=${config.sops.placeholder.telegram_bot_token}
|
TELEGRAM_BOT_TOKEN=${config.sops.placeholder.telegram_bot_token}
|
||||||
@@ -49,6 +61,10 @@
|
|||||||
WEBHOOK_PORT=8644
|
WEBHOOK_PORT=8644
|
||||||
HERMES_DASHBOARD_OIDC_CLIENT_SECRET=${config.sops.placeholder.hermes_dashboard_oidc_client_secret}
|
HERMES_DASHBOARD_OIDC_CLIENT_SECRET=${config.sops.placeholder.hermes_dashboard_oidc_client_secret}
|
||||||
ELEVENLABS_API_KEY=${config.sops.placeholder.elevenlabs_api_key}
|
ELEVENLABS_API_KEY=${config.sops.placeholder.elevenlabs_api_key}
|
||||||
|
API_SERVER_ENABLED=true
|
||||||
|
API_SERVER_HOST=0.0.0.0
|
||||||
|
API_SERVER_PORT=8642
|
||||||
|
API_SERVER_KEY=${config.sops.placeholder.hermes_api_server_key}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# luna's gitea push token (services/dev/gitea.nix provisions the account +
|
# luna's gitea push token (services/dev/gitea.nix provisions the account +
|
||||||
|
|||||||
Reference in New Issue
Block a user