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
|
||||
|
||||
@@ -49,4 +49,4 @@ FRESHRSS_USERNAME=ginnoir
|
||||
|
||||
# vault
|
||||
VAULT_ADDR=https://vault.ginnoir.com
|
||||
VAULT_TOKEN=hvs.QmhZvkXnFfebbRC7JVFLcNPn
|
||||
VAULT_TOKEN=hvs.CAESIMtptUgBbV_zYwyMbT8lNLW9w9CWopDb_GrsEnvYPKwNGh4KHGh2cy5NQVJrT2dEcTVDQWhCN3FyWlZ6U3Z0TVo
|
||||
@@ -0,0 +1,51 @@
|
||||
# Vault ACL policy "mcp-gateway": what the vault MCP in stacks/mcp may do.
|
||||
# Reference copy only (not mounted anywhere). Apply with a root/admin token:
|
||||
# vault policy write mcp-gateway stacks/mcp/vault-policy.hcl
|
||||
#
|
||||
# Token: orphan, periodic (720h), policies [default, mcp-gateway]. The
|
||||
# vault-token-renewer service in this stack renews it daily, so it never lapses
|
||||
# unless Vault stays sealed/unreachable for 30 days. (The default policy grants
|
||||
# renew-self / lookup-self.)
|
||||
#
|
||||
# Deliberately NOT granted: sys/* writes (mount/auth/policy/seal management),
|
||||
# auth/*, identity/*, the agent-registry mount. Mount creation and other admin
|
||||
# stays a root-token job, done by hand.
|
||||
|
||||
# list_mounts
|
||||
path "sys/mounts" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
|
||||
# KV v2 at secret/ (mount it first: vault secrets enable -path=secret kv-v2)
|
||||
path "secret/data/*" {
|
||||
capabilities = ["create", "read", "update", "delete"]
|
||||
}
|
||||
path "secret/metadata/*" {
|
||||
capabilities = ["read", "list", "delete"]
|
||||
}
|
||||
path "secret/metadata" {
|
||||
capabilities = ["list"]
|
||||
}
|
||||
path "secret/delete/*" {
|
||||
capabilities = ["update"]
|
||||
}
|
||||
path "secret/undelete/*" {
|
||||
capabilities = ["update"]
|
||||
}
|
||||
|
||||
# PKI at pki/: read config/issuers/roles and issue certs, no CA or role admin.
|
||||
path "pki/issue/*" {
|
||||
capabilities = ["create", "update"]
|
||||
}
|
||||
path "pki/roles" {
|
||||
capabilities = ["list"]
|
||||
}
|
||||
path "pki/roles/*" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
path "pki/issuers" {
|
||||
capabilities = ["list"]
|
||||
}
|
||||
path "pki/issuer/*" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
Reference in new issue
Block a user