@@ -20,7 +20,13 @@ GATEWAY="${AGENT_GATEWAY_DEMO_GATEWAY:-127.0.0.1:8443}"
2020GATEWAY_CA=" ${AGENT_GATEWAY_DEMO_GATEWAY_CA:- $REPO_ROOT / certs/ server-ca.pem} "
2121MOCK_CA=" ${AGENT_GATEWAY_DEMO_MOCK_CA:- $REPO_ROOT / certs/ mock-ca.pem} "
2222SIDECAR_BIN=" $REPO_ROOT /target/debug/agent_gateway_sidecar"
23- VERIFY_TIMEOUT_SECONDS=" ${AGENT_GATEWAY_DEMO_VERIFY_TIMEOUT_SECONDS:- 120} "
23+ RESET_SERVER_PORT=" ${AGENT_GATEWAY_DEMO_RESET_SERVER_PORT:- 8765} "
24+ PIDS_DIR=" $REPO_ROOT /.run"
25+
26+ RESET_MODE=false
27+ if [[ " ${1:- } " == " --reset" ]]; then
28+ RESET_MODE=true
29+ fi
2430
2531export COMPOSE_PROJECT_NAME
2632
@@ -95,51 +101,117 @@ state_dir() {
95101 printf ' %s/%s\n' " $STATE_ROOT " " $HANDLE "
96102}
97103
98- print_verification_diagnostics () {
99- local sidecar_log
100- sidecar_log=" $( state_dir) /sidecar.log"
104+ clear_enrollment () {
105+ echo " ==> Stopping sidecar"
106+ local sidecar_pid_file
107+ sidecar_pid_file=" $( state_dir) /sidecar_pid"
108+ if [[ -f " $sidecar_pid_file " ]]; then
109+ local pid
110+ pid=" $( < " $sidecar_pid_file " ) "
111+ kill " $pid " 2> /dev/null || true
112+ fi
113+
114+ echo " ==> Clearing agent state and TPM store"
115+ rm -rf " $STATE_ROOT " " $TPM2_PKCS11_STORE "
116+
117+ echo " ==> Clearing enrollment records from database"
118+ psql " $DATABASE_URL " -v ON_ERROR_STOP=1 << 'SQL '
119+ DELETE FROM permission_registry;
120+ DELETE FROM principal_key_permissions;
121+ DELETE FROM principal_signing_keys;
122+ SQL
123+ }
124+
125+ enroll () {
126+ demo_env=(
127+ " AGENT_GATEWAY_DATABASE_URL=$DATABASE_URL "
128+ " AGENT_GATEWAY_DEMO_GATEWAY=$GATEWAY "
129+ " AGENT_GATEWAY_DEMO_GATEWAY_CA=$GATEWAY_CA "
130+ " AGENT_GATEWAY_DEMO_MOCK_CA=$MOCK_CA "
131+ " AGENT_GATEWAY_DEMO_SIDECAR_BIN=$SIDECAR_BIN "
132+ " AGENT_GATEWAY_DEMO_STATE_DIR=$STATE_ROOT "
133+ " AGENT_GATEWAY_TPM_USER_PIN=$USER_PIN "
134+ " AGENT_GATEWAY_TPM_SO_PIN=$SO_PIN "
135+ " AGENT_GATEWAY_RESET_TPM_STORE=false"
136+ " CLAUDE_CODE_PROXY_RESOLVES_HOSTS=1"
137+ " CURL_CA_BUNDLE=$MOCK_CA "
138+ " NODE_EXTRA_CA_CERTS=$MOCK_CA "
139+ " SSL_CERT_FILE=$MOCK_CA "
140+ " TPM2_PKCS11_STORE=$TPM2_PKCS11_STORE "
141+ " AGENT_GATEWAY_DEMO_DASHBOARD_URL=http://localhost:3000"
142+ )
143+
144+ echo " ==> Registering demo principal $PRINCIPAL "
145+ env " ${demo_env[@]} " " $REPO_ROOT /registry-cli/register-principal-key.sh" " $PRINCIPAL "
146+
147+ echo " ==> Granting demo scopes"
148+ env " ${demo_env[@]} " " $REPO_ROOT /registry-cli/grant-principal-scope.sh" " $PRINCIPAL " docstore messaging api.anthropic.com
149+
150+ echo " ==> Creating demo agent $HANDLE "
151+ env " ${demo_env[@]} " " $SCRIPT_DIR /demo-agent.sh" create \
152+ --identity " $IDENTITY " \
153+ --handle " $HANDLE " \
154+ --grant docstore \
155+ --grant api.anthropic.com > /dev/null
156+ }
157+
158+ start_reset_server () {
159+ mkdir -p " $PIDS_DIR "
101160
102- echo " Check the gateway, sidecar, and mock service logs before retrying." >&2
103- echo " Sidecar log: $sidecar_log " >&2
104- if [[ -f " $sidecar_log " ]]; then
105- echo >&2
106- echo " Recent sidecar log lines:" >&2
107- tail -n 80 " $sidecar_log " >&2 || true
161+ # Kill any existing reset server
162+ if [[ -f " $PIDS_DIR /reset-server.pid" ]]; then
163+ kill " $( < " $PIDS_DIR /reset-server.pid" ) " 2> /dev/null || true
164+ rm -f " $PIDS_DIR /reset-server.pid"
108165 fi
166+
167+ local setup_script=" $SCRIPT_DIR /setup.sh"
168+ nohup node -e "
169+ const http = require('http');
170+ const { spawn } = require('child_process');
171+ http.createServer((req, res) => {
172+ if (req.method !== 'POST' || new URL(req.url, 'http://x').pathname !== '/reset') {
173+ res.writeHead(404); res.end(); return;
174+ }
175+ const proc = spawn('bash', ['$setup_script ', '--reset'], { stdio: 'inherit' });
176+ proc.on('exit', code => {
177+ res.writeHead(code === 0 ? 200 : 500, {'Content-Type': 'application/json'});
178+ res.end(JSON.stringify({ ok: code === 0 }));
179+ });
180+ }).listen($RESET_SERVER_PORT , '0.0.0.0', () => {
181+ process.stdout.write('Reset server listening on $RESET_SERVER_PORT \n');
182+ });
183+ " > " $PIDS_DIR /reset-server.log" 2>&1 &
184+ echo $! > " $PIDS_DIR /reset-server.pid"
185+ echo " ==> Reset server started on port $RESET_SERVER_PORT "
109186}
110187
111- demo_env=(
112- " AGENT_GATEWAY_DATABASE_URL=$DATABASE_URL "
113- " AGENT_GATEWAY_DEMO_GATEWAY=$GATEWAY "
114- " AGENT_GATEWAY_DEMO_GATEWAY_CA=$GATEWAY_CA "
115- " AGENT_GATEWAY_DEMO_MOCK_CA=$MOCK_CA "
116- " AGENT_GATEWAY_DEMO_SIDECAR_BIN=$SIDECAR_BIN "
117- " AGENT_GATEWAY_DEMO_STATE_DIR=$STATE_ROOT "
118- " AGENT_GATEWAY_TPM_USER_PIN=$USER_PIN "
119- " AGENT_GATEWAY_TPM_SO_PIN=$SO_PIN "
120- " AGENT_GATEWAY_RESET_TPM_STORE=false"
121- " CLAUDE_CODE_PROXY_RESOLVES_HOSTS=1"
122- " CURL_CA_BUNDLE=$MOCK_CA "
123- " NODE_EXTRA_CA_CERTS=$MOCK_CA "
124- " SSL_CERT_FILE=$MOCK_CA "
125- " TPM2_PKCS11_STORE=$TPM2_PKCS11_STORE "
126- )
188+ # ── Main ──────────────────────────────────────────────────────────────────────
127189
128190select_compose
129191require_cmd cargo
130192require_cmd openssl
131193require_cmd psql
132- require_cmd timeout
194+ require_cmd node
133195
134196cd " $REPO_ROOT "
135197
198+ if [[ " $RESET_MODE " == " true" ]]; then
199+ clear_enrollment
200+ enroll
201+ echo " Reset complete."
202+ exit 0
203+ fi
204+
136205echo " ==> Generating demo TLS certificates"
137206" $SCRIPT_DIR /generate-server-certs.sh"
138207
139208if [[ ! -f " $REPO_ROOT /config.toml" ]]; then
140209 echo " ==> Creating config.toml from config.example.toml"
141210 cp " $REPO_ROOT /config.example.toml" " $REPO_ROOT /config.toml"
142211fi
212+ # Ensure the gateway (running in Docker) sends OTLP to the collector service name,
213+ # not localhost (which would be the gateway container itself).
214+ sed -i ' s|otlp_endpoint = "http://localhost:4317"|otlp_endpoint = "http://otel-collector:4317"|' " $REPO_ROOT /config.toml"
143215
144216echo " ==> Building local sidecar"
145217cargo build -p agent_gateway_sidecar
@@ -152,49 +224,18 @@ compose up -d --force-recreate postgres mock-services
152224wait_for_postgres
153225apply_migrations
154226
155- echo " ==> Starting gateway"
156- compose up -d --force-recreate gateway
157-
158- echo " ==> Registering demo principal $PRINCIPAL "
159- env " ${demo_env[@]} " " $REPO_ROOT /registry-cli/register-principal-key.sh" " $PRINCIPAL "
160-
161- echo " ==> Granting demo scopes"
162- env " ${demo_env[@]} " " $REPO_ROOT /registry-cli/grant-principal-scope.sh" " $PRINCIPAL " docstore messaging api.anthropic.com
163-
164- echo " ==> Creating demo agent $HANDLE "
165- env " ${demo_env[@]} " " $SCRIPT_DIR /demo-agent.sh" create \
166- --identity " $IDENTITY " \
167- --handle " $HANDLE " \
168- --grant docstore \
169- --grant api.anthropic.com \
170- --grant messaging > /dev/null
171-
172- echo " ==> Verifying Claude Code HTTP requests through the gateway"
173- if ! timeout " $VERIFY_TIMEOUT_SECONDS " env " ${demo_env[@]} " " $SCRIPT_DIR /demo-agent.sh" prompt " $HANDLE " --prompt \
174- " Use the Bash tool to run exactly this command: curl -sS https://docstore/health
175- Return only the raw response body." ; then
176- cat >&2 << EOF
177- error: Claude Code could not fetch https://docstore/health through the demo gateway.
178-
179- Expected environment:
180- HTTPS_PROXY=http://127.0.0.1:3128
181- CURL_CA_BUNDLE=$MOCK_CA
182- NODE_EXTRA_CA_CERTS=$MOCK_CA
183- SSL_CERT_FILE=$MOCK_CA
184- CLAUDE_CODE_PROXY_RESOLVES_HOSTS=1
185- AGENT_GATEWAY_DEMO_SIDECAR_BIN=$SIDECAR_BIN
186-
187- EOF
188- print_verification_diagnostics
189- exit 1
190- fi
227+ echo " ==> Starting gateway, otel-collector, and dashboard"
228+ compose up -d --force-recreate gateway otel-collector dashboard
191229
192- rm -f " $( state_dir) /claude_started"
230+ enroll
231+ start_reset_server
193232
194233cat << EOF
195234
196235Demo is ready.
197236
237+ Dashboard: http://localhost:3000
238+
198239Mock service URLs available through the gateway:
199240 https://docstore/health
200241 https://docstore/documents
0 commit comments