Skip to content

About

Early alpha -- TEE-hardened universal API credential proxy for AI agents, with semantic policy enforcement

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Enclave Credential Gateway

Reproducible build

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.


Vision

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."


Working Today

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 by GATE_ADMIN_TOKEN.
  • CLI - gate admin token ... for gateway administration, plus gate activate and gate git-credential for 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 Procfile deploys 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_DOMAIN for 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.


Quick Start

Prerequisites: Docker + Compose, Rust/Cargo for the CLI, gh, git, curl, and jq.

1. Start the Gateway

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/health

GATE_ADMIN_TOKEN protects the admin API. Vendor keys are read by the gateway and injected server-side; clients receive only gate_... phantom tokens.

2. Trust Caddy's Local Certificate

docker compose cp caddy:/data/caddy/pki/authorities/local/root.crt /tmp/gate-caddy-root.crt

macOS:

sudo security add-trusted-cert -d -r trustRoot \
  -k /Library/Keychains/System.keychain /tmp/gate-caddy-root.crt

Debian/Ubuntu:

sudo cp /tmp/gate-caddy-root.crt /usr/local/share/ca-certificates/gate-caddy-root.crt
sudo update-ca-certificates

Then verify without -k:

curl https://localhost/health

For a real hostname, set GATE_DOMAIN=gw.example.com before docker compose up. Caddy will request a public certificate for that name.

3. Install the CLI

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"
EOF

Usage Examples

GitHub CLI and Git

gate admin token create --name gh-local --scope github
gate activate gh-local --tool gh

gh api user
gh repo list
gh repo clone OWNER/REPO

gate 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.

Claude Code

gate admin token create --name claude-local --scope anthropic
gate activate claude-local --tool claude-code
claude

Codex

gate admin token create --name codex-local --scope openai
gate activate codex-local --tool codex
codex

Runtime Service Tokens

Register 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=openai

Credentials 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.

Existing Gateway

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 gh

Routes

Built-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.


How It Works Today

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.


Testing

cargo fmt --check
cargo test --workspace
./scripts/test-e2e.sh

test-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.

Reproducible OCI Builds

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 tag

Build 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 hashes

Expected 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.


Docs

About

Early alpha -- TEE-hardened universal API credential proxy for AI agents, with semantic policy enforcement

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages