feat(mcp): scope the gateway's Vault token (no more root)
The vault MCP now holds an orphan periodic token (720h) with policy mcp-gateway: read sys/mounts, CRUD under secret/ (kv-v2), PKI issue/read under pki/. No sys writes, auth, policy or seal management. The policy is kept at stacks/mcp/vault-policy.hcl. A vault-token-renewer sidecar renews the token daily and notifies ntfy if a renewal fails (e.g. Vault sealed). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
977199b591
commit
d51bad2277
3 files changed
+86
-3
No files matched your search
@@ -17,8 +17,10 @@
|
||||
# env. Caddy additionally keeps it internal-only (LAN + tailnet). Not behind
|
||||
# Authentik forward_auth: agents can't do a browser login.
|
||||
#
|
||||
# The token is effectively admin over the lab (Portainer, Vault, Gitea,
|
||||
# Authentik writes). Treat it like the Portainer API key.
|
||||
# The token is effectively admin over the lab (Portainer, Gitea, Authentik
|
||||
# writes). Treat it like the Portainer API key. Vault access is scoped: the
|
||||
# gateway holds a periodic mcp-gateway-policy token, not root (vault-policy.hcl;
|
||||
# kept alive by vault-token-renewer below).
|
||||
#
|
||||
# Upstreams are the public https://*.ginnoir.com names (same as the clients
|
||||
# used before); container -> Caddy hairpin passes internal_only (172.16/12).
|
||||
@@ -52,6 +54,36 @@ services:
|
||||
retries: 3
|
||||
start_period: 60s
|
||||
|
||||
# Keeps the gateway's scoped Vault token alive. VAULT_TOKEN is an orphan
|
||||
# periodic token (720h period, policy mcp-gateway — see vault-policy.hcl), NOT
|
||||
# root. A periodic token dies if not renewed within its period, so renew it
|
||||
# daily; on failure (e.g. Vault sealed) log + ntfy the homelab topic and retry
|
||||
# hourly. Same image digest as the Vault server (portainer-compose.yml).
|
||||
vault-token-renewer:
|
||||
image: hashicorp/vault@sha256:3fd53308acccd9e4e83fde3e6c6cf5b15e0f7fac1ff7510780b8b23f5e4c3de7
|
||||
container_name: vault-token-renewer
|
||||
restart: unless-stopped
|
||||
networks: [edge]
|
||||
env_file:
|
||||
- stack.env
|
||||
labels:
|
||||
- com.centurylabs.watchtower.enable=false
|
||||
entrypoint: ["/bin/sh", "-c"]
|
||||
command:
|
||||
- |
|
||||
while :; do
|
||||
if out=$$(vault token renew -format=json 2>&1); then
|
||||
echo "$$(date -u +%FT%TZ) renewed (ttl $$(echo "$$out" | grep -o '"lease_duration": [0-9]*' | grep -o '[0-9]*')s)"
|
||||
sleep 86400
|
||||
else
|
||||
echo "$$(date -u +%FT%TZ) RENEW FAILED: $$out"
|
||||
wget -q -O- --header "Title: mcp-gateway Vault token renew failed" \
|
||||
--post-data "vault-token-renewer could not renew the gateway's Vault token (sealed?). It expires 30 days after the last good renewal. $$(echo "$$out" | tail -1)" \
|
||||
"$$NTFY_URL/$$NTFY_TOPIC" >/dev/null 2>&1 || true
|
||||
sleep 3600
|
||||
fi
|
||||
done
|
||||
|
||||
networks:
|
||||
edge:
|
||||
name: edge
|
||||
|
||||
Reference in new issue
Block a user