Skip to content

Commit 70cae4c

Browse files
committed
Add explicit demo setup and teardown commands
1 parent b362ecf commit 70cae4c

3 files changed

Lines changed: 111 additions & 46 deletions

File tree

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ sudo apt-get install libtss2-dev swtpm tpm2-tools pkg-config
2121

2222
```bash
2323
export AGENT_GATEWAY_DEMO_GATEWAY_IMAGE=ghcr.io/sl5taskforce/agent-gateway:main
24-
./demo/setup.sh
24+
./demo/demo.sh setup
2525
```
2626

27-
The setup script generates demo TLS material, creates `config.toml` when needed,
27+
The setup command generates demo TLS material, creates `config.toml` when needed,
2828
starts Postgres and static HTTPS mock services with Podman Compose or Docker Compose, applies the
2929
database migration, starts the configured gateway image, enrolls a demo principal,
3030
grants access to `docstore` and `messaging`, creates a demo agent handle, and
@@ -40,7 +40,7 @@ that public key and identity extension. The gateway does not trust a client CA
4040
bundle; it authorizes the exact subject public key recorded in signed Postgres
4141
permission rows.
4242

43-
`demo/setup.sh` keeps its tpm2-pkcs11 state under the demo state directory by
43+
`demo/demo.sh setup` keeps its tpm2-pkcs11 state under the demo state directory by
4444
default. Override `AGENT_GATEWAY_DEMO_TPM2_PKCS11_STORE` only when you
4545
intentionally want the demo principal to use another store.
4646

@@ -61,6 +61,13 @@ revokes its database permissions, and removes local state:
6161
./demo/demo-agent.sh delete agent-alpha
6262
```
6363

64+
Reset all demo services, volumes, generated certificates, `config.toml`, and
65+
local demo state with:
66+
67+
```bash
68+
./demo/demo.sh teardown
69+
```
70+
6471
Pass a custom policy identity when creating an agent with
6572
`./demo/demo-agent.sh create --identity agent-beta ...`. The identity must match
6673
`permission_registry.subject_identity` in an active signed permission row.
@@ -135,7 +142,7 @@ Register a principal signing key from the TPM owner machine with:
135142

136143
The script creates or reuses a non-exportable TPM-backed P-256 key through `tpm2_ptool` and PKCS#11, stores only the public key in `principal_signing_keys`, and uses the friendly `key_id` (`org-alice`, `org-bob`, etc.) for the registry row. Run it on the machine that owns the TPM, with `AGENT_GATEWAY_DATABASE_URL` or `DATABASE_URL` pointing at Postgres.
137144

138-
For a manual demo without `./demo/setup.sh`, use three windows:
145+
For a manual demo without `./demo/demo.sh setup`, use three windows:
139146

140147
```bash
141148
# Principal shell: enroll the principal TPM public key.

demo/demo-agent.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ cmd_prompt() {
584584
ensure_runtime "$dir"
585585
[[ -f "$DEFAULT_MOCK_CA" ]] || {
586586
echo "error: mock service CA file not found: $DEFAULT_MOCK_CA" >&2
587-
echo "hint: run ./demo/generate-server-certs.sh or ./demo/setup.sh first" >&2
587+
echo "hint: run ./demo/generate-server-certs.sh or ./demo/demo.sh setup first" >&2
588588
exit 1
589589
}
590590
export NODE_EXTRA_CA_CERTS="$DEFAULT_MOCK_CA"

demo/setup.sh renamed to demo/demo.sh

Lines changed: 99 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ VERIFY_TIMEOUT_SECONDS="${AGENT_GATEWAY_DEMO_VERIFY_TIMEOUT_SECONDS:-120}"
2626
export COMPOSE_PROJECT_NAME
2727
export AGENT_GATEWAY_DEMO_GATEWAY_IMAGE="$GATEWAY_IMAGE"
2828

29+
usage() {
30+
cat >&2 <<'EOF'
31+
Usage:
32+
demo.sh setup
33+
demo.sh teardown
34+
35+
Commands:
36+
setup Start and verify the full local demo.
37+
teardown Delete demo agents, state, generated files, containers, and volumes.
38+
EOF
39+
}
40+
2941
require_cmd() {
3042
command -v "$1" >/dev/null 2>&1 || {
3143
echo "error: required command not found: $1" >&2
@@ -127,54 +139,55 @@ demo_env=(
127139
"TPM2_PKCS11_STORE=$TPM2_PKCS11_STORE"
128140
)
129141

130-
select_compose
131-
require_cmd cargo
132-
require_cmd openssl
133-
require_cmd psql
134-
require_cmd timeout
142+
cmd_setup() {
143+
select_compose
144+
require_cmd cargo
145+
require_cmd openssl
146+
require_cmd psql
147+
require_cmd timeout
135148

136-
cd "$REPO_ROOT"
149+
cd "$REPO_ROOT"
137150

138-
echo "==> Generating demo TLS certificates"
139-
"$SCRIPT_DIR/generate-server-certs.sh"
151+
echo "==> Generating demo TLS certificates"
152+
"$SCRIPT_DIR/generate-server-certs.sh"
140153

141-
if [[ ! -f "$REPO_ROOT/config.toml" ]]; then
142-
echo "==> Creating config.toml from config.example.toml"
143-
cp "$REPO_ROOT/config.example.toml" "$REPO_ROOT/config.toml"
144-
fi
154+
if [[ ! -f "$REPO_ROOT/config.toml" ]]; then
155+
echo "==> Creating config.toml from config.example.toml"
156+
cp "$REPO_ROOT/config.example.toml" "$REPO_ROOT/config.toml"
157+
fi
145158

146-
echo "==> Building local sidecar"
147-
cargo build -p agent_gateway_sidecar
159+
echo "==> Building local sidecar"
160+
cargo build -p agent_gateway_sidecar
148161

149-
echo "==> Using gateway image $GATEWAY_IMAGE"
162+
echo "==> Using gateway image $GATEWAY_IMAGE"
150163

151-
echo "==> Starting Postgres and mock HTTPS services"
152-
compose up -d --force-recreate postgres mock-services
153-
wait_for_postgres
154-
apply_migrations
164+
echo "==> Starting Postgres and mock HTTPS services"
165+
compose up -d --force-recreate postgres mock-services
166+
wait_for_postgres
167+
apply_migrations
155168

156-
echo "==> Starting gateway"
157-
compose up -d --force-recreate gateway otel-collector dashboard
169+
echo "==> Starting gateway"
170+
compose up -d --force-recreate gateway otel-collector dashboard
158171

159-
echo "==> Registering demo principal $PRINCIPAL"
160-
env "${demo_env[@]}" "$REPO_ROOT/registry-cli/register-principal-key.sh" "$PRINCIPAL"
172+
echo "==> Registering demo principal $PRINCIPAL"
173+
env "${demo_env[@]}" "$REPO_ROOT/registry-cli/register-principal-key.sh" "$PRINCIPAL"
161174

162-
echo "==> Granting demo scopes"
163-
env "${demo_env[@]}" "$REPO_ROOT/registry-cli/grant-principal-scope.sh" "$PRINCIPAL" docstore messaging api.anthropic.com
175+
echo "==> Granting demo scopes"
176+
env "${demo_env[@]}" "$REPO_ROOT/registry-cli/grant-principal-scope.sh" "$PRINCIPAL" docstore messaging api.anthropic.com
164177

165-
echo "==> Creating demo agent $HANDLE"
166-
env "${demo_env[@]}" "$SCRIPT_DIR/demo-agent.sh" create \
167-
--identity "$IDENTITY" \
168-
--handle "$HANDLE" \
169-
--grant docstore \
170-
--grant api.anthropic.com \
171-
--grant messaging >/dev/null
178+
echo "==> Creating demo agent $HANDLE"
179+
env "${demo_env[@]}" "$SCRIPT_DIR/demo-agent.sh" create \
180+
--identity "$IDENTITY" \
181+
--handle "$HANDLE" \
182+
--grant docstore \
183+
--grant api.anthropic.com \
184+
--grant messaging >/dev/null
172185

173-
echo "==> Verifying Claude Code HTTP requests through the gateway"
174-
if ! timeout "$VERIFY_TIMEOUT_SECONDS" env "${demo_env[@]}" "$SCRIPT_DIR/demo-agent.sh" prompt "$HANDLE" --prompt \
175-
"Access https://docstore/health using curl and return only the raw response body.
186+
echo "==> Verifying Claude Code HTTP requests through the gateway"
187+
if ! timeout "$VERIFY_TIMEOUT_SECONDS" env "${demo_env[@]}" "$SCRIPT_DIR/demo-agent.sh" prompt "$HANDLE" --prompt \
188+
"Access https://docstore/health using curl and return only the raw response body.
176189
Return only the raw response body."; then
177-
cat >&2 <<EOF
190+
cat >&2 <<EOF
178191
error: Claude Code could not fetch https://docstore/health through the demo gateway.
179192
180193
Expected environment:
@@ -186,13 +199,13 @@ Expected environment:
186199
AGENT_GATEWAY_DEMO_SIDECAR_BIN=$SIDECAR_BIN
187200
188201
EOF
189-
print_verification_diagnostics
190-
exit 1
191-
fi
202+
print_verification_diagnostics
203+
exit 1
204+
fi
192205

193-
rm -f "$(state_dir)/claude_started"
206+
rm -f "$(state_dir)/claude_started"
194207

195-
cat <<EOF
208+
cat <<EOF
196209
197210
Demo is ready.
198211
@@ -211,7 +224,52 @@ Prompt the demo agent with:
211224
Delete the demo agent when finished:
212225
./demo/demo-agent.sh delete "$HANDLE"
213226
227+
Reset the entire demo with:
228+
./demo/demo.sh teardown
229+
214230
Useful logs:
215231
$COMPOSE_DISPLAY -p "$COMPOSE_PROJECT_NAME" -f docker-compose.demo.yml logs -f gateway
216232
$(state_dir)/sidecar.log
217233
EOF
234+
}
235+
236+
delete_demo_agents() {
237+
[[ -d "$STATE_ROOT" ]] || return
238+
239+
local dir handle
240+
for dir in "$STATE_ROOT"/*; do
241+
[[ -d "$dir" ]] || continue
242+
[[ -f "$dir/identity" && -f "$dir/client/machine-client-spki.der" ]] || continue
243+
244+
handle="${dir##*/}"
245+
echo "==> Deleting demo agent $handle"
246+
if ! env "${demo_env[@]}" "$SCRIPT_DIR/demo-agent.sh" delete "$handle"; then
247+
echo "warning: failed to delete demo agent $handle; continuing teardown" >&2
248+
fi
249+
done
250+
}
251+
252+
cmd_teardown() {
253+
select_compose
254+
cd "$REPO_ROOT"
255+
256+
delete_demo_agents
257+
258+
echo "==> Stopping compose services and deleting volumes"
259+
compose down -v --remove-orphans
260+
261+
echo "==> Removing demo state and generated files"
262+
rm -rf -- "$STATE_ROOT" "$REPO_ROOT/certs"
263+
rm -f -- "$REPO_ROOT/config.toml"
264+
265+
echo "Demo teardown complete."
266+
}
267+
268+
[[ $# -eq 1 ]] || { usage; exit 2; }
269+
270+
case "$1" in
271+
setup) cmd_setup ;;
272+
teardown) cmd_teardown ;;
273+
-h|--help) usage ;;
274+
*) echo "Unknown command: $1" >&2; usage; exit 2 ;;
275+
esac

0 commit comments

Comments
 (0)