Status: alpha / early implementation. Enclave Credential Gateway is early work toward a TEE-backed credential gateway for AI agents. The working gateway already lets clients use scoped phantom tokens (gate_...) instead of real vendor keys, and the server/CLI can be rebuilt as byte-for-byte reproducible StageX OCI artifacts. The target deployment is the Caution platform (current TEE backing: AWS Nitro Enclaves, with more planned), which provides the enclave, attestation (/attestation), and reproducible measurement verification (caution verify). Attested credential provisioning and a gate verify command are not implemented yet.
Core idea: credentials should be infrastructure, not agent state.
AI tools routinely hold real API keys in .env files, shell exports, CI secrets, and local config. That makes credentials easy to leak, hard to rotate, and difficult to audit.
Enclave Credential Gateway's target architecture is a network gateway running inside a hardware trust boundary. Agents receive revocable phantom tokens. The gateway validates the phantom, checks route scope, injects the real upstream credential server-side, and forwards the request. In the TEE-backed version, the infrastructure operator should be able to verify the binary without being able to read the real credentials.
| Capability | Local proxy | Enclave Credential Gateway target |
|---|---|---|
| Agent cannot read the real key | yes | yes |
| Central revocation and rotation | limited | yes |
| Works from other devices or CI | no | yes |
| Operator cannot read the real key | no | target: Caution enclave boundary |
| Verifiable running binary | no | target: Caution attestation + reproducible measurements |
Verification is the key idea behind the TEE path. Today caution verify --attestation-url <url> fetches the platform attestation, asserts no debug bit, reproduces the enclave from source, and confirms the measurements match the live enclave. The roadmap brings the same check into the gate CLI (gate verify). The goal is for a technical user to verify both "this server is running inside the expected enclave" and "that enclave corresponds to source I can inspect."
This repo is an early work in progress. The proxy, token registry, and CLI are usable locally and through Docker Compose:
- Gateway/proxy - Axum HTTP gateway with route matching, auth middleware, credential stripping, and upstream credential injection.
- Phantom token registry - named tokens, Blake3-hashed at rest, persisted to
tokens.json, with per-token route scope enforcement. - Admin API -
POST /admin/tokens,GET /admin/tokens,DELETE /admin/tokens/:id,POST /admin/creds,GET /admin/creds,DELETE /admin/creds/:name, protected byGATE_ADMIN_TOKEN. - CLI -
gate admin token ...for gateway administration, plusgate activateandgate git-credentialfor local tool setup. - Tool activation - generated config/env for
gh, Codex, and Claude Code. - Reproducible OCI artifacts - server and CLI images build through StageX with pinned build inputs, offline
cargo build --frozen --release, timestamp-normalized OCI exports, documented expected hashes, and verified byte-for-byte no-cache rebuilds. This is the foundation that makes the Caution EIF PCRs reproducible. See docs/BUILDING.md. - Caution-ready - the
Procfiledeploys the server image through Caution (current TEE backing: AWS Nitro Enclaves); the enclave, attestation, and measurement verification come from the platform. - Deployment scaffold - Docker Compose with Caddy TLS and optional
GATE_DOMAINfor local development.
Not implemented yet: gate verify (the gateway's own verifier, parity with caution verify), published golden PCRs, attested credential provisioning, audit log, token expiry, and additional route profiles beyond OpenAI, Anthropic, and GitHub. Attestation itself is provided by the Caution platform, not by the gateway.
See spec/roadmap.md for the implementation plan.
Prerequisites: Docker + Compose, Rust/Cargo for the CLI, gh, git, curl, and jq.
export GATE_ADMIN_TOKEN="$(openssl rand -hex 32)"
export GITHUB_TOKEN=ghp_... # real upstream token, stays server-side
export ANTHROPIC_API_KEY=sk-ant-...
export OPENAI_API_KEY=sk-...
docker compose up -d --build
curl -k https://localhost/healthGATE_ADMIN_TOKEN protects the admin API. Vendor keys are read by the gateway and injected server-side; clients receive only gate_... phantom tokens.
docker compose cp caddy:/data/caddy/pki/authorities/local/root.crt /tmp/gate-caddy-root.crtmacOS:
sudo security add-trusted-cert -d -r trustRoot \
-k /Library/Keychains/System.keychain /tmp/gate-caddy-root.crtDebian/Ubuntu:
sudo cp /tmp/gate-caddy-root.crt /usr/local/share/ca-certificates/gate-caddy-root.crt
sudo update-ca-certificatesThen verify without -k:
curl https://localhost/healthFor a real hostname, set GATE_DOMAIN=gw.example.com before docker compose up. Caddy will request a public certificate for that name.
cargo build --release -p gate-cli
export PATH="$PWD/target/release:$PATH"
mkdir -p ~/.config/gate
cat > ~/.config/gate/config.toml <<EOF
gateway_url = "https://localhost"
admin_token = "$GATE_ADMIN_TOKEN"
EOFgate admin token create --name gh-local --scope github
gate activate gh-local --tool gh
gh api user
gh repo list
gh repo clone OWNER/REPOgate admin token create talks to the gateway admin API and requires admin_token in config or GATE_ADMIN_TOKEN. gate activate is local: it reads the saved phantom token and configures the selected tool.
Activation sets GH_HOST, GH_ENTERPRISE_TOKEN, and a generated Git credential helper. Git remotes stay token-free, for example https://localhost/OWNER/REPO.git.
gate admin token create --name claude-local --scope anthropic
gate activate claude-local --tool claude-code
claudegate admin token create --name codex-local --scope openai
gate activate codex-local --tool codex
codexRegister a named upstream API key at runtime (no restart required):
gate admin creds register openai sk-... # register (or rotate) the openai cred
gate admin creds ls # list registered creds (names only, no values)
gate admin creds rm openai # remove; gateway falls back to env var
gate admin token create --name mytoken --scope openai --cred openai=openaiCredentials are RAM-only. The admin channel is encrypted end-to-end via steve when e2e = true in config (default). See docs/USING.md for admin channel config.
If someone else operates the gateway, you only need its URL and a phantom token:
# ~/.config/gate/config.toml
gateway_url = "https://gw.example.com"
[tokens.laptop]
token = "gate_..."
scope = ["github", "openai", "anthropic"]gate activate laptop --tool ghBuilt-in routes are defined in profiles/routes/ and embedded at build time. Tool adapters are defined in profiles/tools/.
| Path prefix | Scope | Upstream | Credential env |
|---|---|---|---|
/openai/... |
openai |
https://api.openai.com |
OPENAI_API_KEY |
/anthropic/... |
anthropic |
https://api.anthropic.com |
ANTHROPIC_API_KEY |
/github/... |
github |
https://api.github.com |
GITHUB_TOKEN |
/api/v3/... |
github |
https://api.github.com |
GITHUB_TOKEN (gh compatibility, strips /v3) |
/<owner>/<repo>.git/... |
github |
https://github.com |
GITHUB_TOKEN (Git smart-HTTP) |
Planned future profiles include Groq, ElevenLabs, Telegram, Together, and Ollama.
Status codes: 407 = missing/invalid token, 403 = valid token with wrong scope, 404 = unknown route, 503 = required real credential env var is not set.
client sends gate_... phantom
-> gateway validates token with a constant-time Blake3 hash comparison
-> gateway checks route scope before credential lookup
-> gateway removes the phantom credential from the request
-> gateway injects the real server-side credential
-> upstream receives only the real credential
The TEE version will keep the same request model, but move the credential boundary into a Caution enclave with platform-provided attestation. See spec/tee-security.md for the target security model.
cargo fmt --check
cargo test --workspace
./scripts/test-e2e.shtest-e2e.sh exercises the Docker flow: gateway startup, admin API, token validation, scope enforcement, revocation, and CLI activation. Live upstream checks are skipped when credentials are not set.
Build both StageX OCI artifacts — the server (Containerfile.stagex, the enclave
image) and the gate CLI (Containerfile.cli.stagex). Builds are --no-cache
and pinned to the commit timestamp, so any two builds of a commit are
byte-for-byte identical.
Certify and publish a release:
./scripts/build-stagex-oci.sh --tag v0.1.0 # build dist/ and record hashes in an annotated git tag
git push origin v0.1.0 # publish the tagBuild without tagging, or verify a tagged commit reproduces:
./scripts/build-stagex-oci.sh # build dist/ and print the hashes
./scripts/build-stagex-oci.sh --check v0.1.0 # rebuild and verify against the tag's hashes
git cat-file tag v0.1.0 # inspect the recorded hashesExpected hashes live on the annotated git tag for each certified commit, not in the repo tree. See docs/BUILDING.md for the full StageX build and reproduction steps.
- spec/vision.md - product vision and long-term direction
- spec/roadmap.md - current status and next implementation milestones
- docs/USING.md - detailed per-tool setup for Claude Code, Codex, and
gh - docs/BUILDING.md - StageX OCI image build instructions
- spec/tee-security.md - target TEE security requirements and threat model
- profiles/README.md - route and tool profile format