Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Barbacane image version to pull from ghcr.io/barbacane-dev
# Set to a specific release tag (e.g. 0.12.3) to pin the playground to that version.
# Use "latest" to always pull the most recent release.
BARBACANE_VERSION=0.12.3
# The playground needs 1.0.0-rc.1 or later. `latest` is the most recent stable
# release, which release candidates do not move.
BARBACANE_VERSION=1.0.0-rc.1

# Admin token for the control plane. Since 0.8 the control plane refuses to
# start without a non-empty token. This is a demo default — change it for any
# Admin token for the control plane, at least 32 bytes: the control plane
# refuses to start without one. This is a demo default: change it for any
# non-local use.
BARBACANE_CONTROL_ADMIN_TOKEN=playground-admin-token
BARBACANE_CONTROL_ADMIN_TOKEN=playground-admin-token-change-me-0123456789
23 changes: 13 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ on:
push:
branches: [main]
schedule:
# Nightly, against the `latest` gateway image, to catch upstream drift.
# Nightly, against the `latest` gateway image (or a newer pre-release pin),
# to catch upstream drift.
- cron: '0 5 * * *'
workflow_dispatch:
inputs:
Expand All @@ -19,9 +20,9 @@ concurrency:
cancel-in-progress: true

jobs:
# Resolve which gateway image tag this run tests: the nightly schedule uses
# `latest`, a manual run uses its input, everything else uses the .env.example
# pin.
# Resolve which gateway image tag this run tests: a manual run uses its input,
# the nightly schedule uses `latest` unless the .env.example pin is a
# pre-release (which `latest` does not move to), everything else uses the pin.
version:
runs-on: ubuntu-latest
outputs:
Expand All @@ -30,12 +31,13 @@ jobs:
- uses: actions/checkout@v5
- id: pick
run: |
if [ "${{ github.event_name }}" = "schedule" ]; then
TAG=latest
elif [ -n "${{ github.event.inputs.version }}" ]; then
PIN="$(grep '^BARBACANE_VERSION=' .env.example | cut -d= -f2)"
if [ -n "${{ github.event.inputs.version }}" ]; then
TAG="${{ github.event.inputs.version }}"
elif [ "${{ github.event_name }}" = "schedule" ] && [ "${PIN#*-}" = "$PIN" ]; then
TAG=latest
else
TAG="$(grep '^BARBACANE_VERSION=' .env.example | cut -d= -f2)"
TAG="$PIN"
fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "Testing Barbacane image tag: $TAG"
Expand Down Expand Up @@ -63,8 +65,9 @@ jobs:
- name: Start the stack
# The observability viewers (Grafana/Loki/Tempo/Alloy) are not needed for
# the smoke test; bring up only the gateway, its upstreams, the asset
# seeder and Prometheus. Compose pulls in each service's dependencies.
run: docker compose up -d --pull always barbacane prometheus rustfs-init
# seeder, the control plane and Prometheus. Compose pulls in each
# service's dependencies.
run: docker compose up -d --pull always barbacane control-plane prometheus rustfs-init

- name: Run the smoke test
run: bash scripts/smoke.sh
Expand Down
61 changes: 25 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Barbacane Playground

A complete demonstration environment for the Barbacane API Gateway featuring a realistic Train Travel API, full observability stack (logs, metrics, traces), control plane UI, S3 object storage proxy, and mock backend services.
A complete demonstration environment for the Barbacane API Gateway featuring a realistic Train Travel API, full observability stack (logs, metrics, traces), signed artifacts, the control plane API, S3 object storage proxy, and mock backend services.

## Quick Start

Expand All @@ -19,25 +19,29 @@ docker compose ps
curl http://localhost:8080/stations
```

That's it! The API specs are compiled automatically before the gateway starts.
That's it! The API specs are compiled and signed automatically before the gateway starts.

## Version

By default the playground pulls the `latest` images from [GitHub Container Registry](https://github.com/orgs/barbacane-dev/packages). To pin a specific release, copy `.env.example` and set the version:
The playground pulls the Barbacane release `docker-compose.yml` pins (`1.0.0-rc.1`) from [GitHub Container Registry](https://github.com/orgs/barbacane-dev/packages). It needs 1.0.0-rc.1 or later. To run another release, copy `.env.example` and set the version:

```bash
cp .env.example .env
# Edit .env and set BARBACANE_VERSION=0.12.3 (or any release tag)
# Edit .env and set BARBACANE_VERSION to a release tag
docker compose pull
docker compose up -d
```

## Signed artifacts

The gateway loads only artifacts signed by the key it pins. On the first start, the `keygen` init container creates an Ed25519 signing key in the `signing_key` volume and writes its public key to the `trusted_key` volume. The `compiler` signs the artifact with the private key (`BARBACANE_SIGNING_KEY`), and the gateway pins the public key (`BARBACANE_TRUSTED_PUBKEY`) and never sees the private one. The key is kept across restarts; `docker compose down -v` deletes it with the other volumes, and the next start creates a new one.

## Services

| Service | URL | Description |
|---------|-----|-------------|
| **Gateway** | http://localhost:8080 | Barbacane API Gateway (Data Plane) |
| **Control Plane** | http://localhost:3001 | Web UI for managing APIs |
| **Control Plane** | http://localhost:9091 | REST API for projects, specs, artifacts and deployments (admin token) |
| **Grafana** | http://localhost:3000 | Dashboards (admin/admin) |
| **Prometheus** | http://localhost:9090 | Metrics |
| **NATS** | nats://localhost:4222 | Message broker ([monitoring](http://localhost:8222)) |
Expand All @@ -57,31 +61,6 @@ All requests are in **[playground.http](playground.http)** — open it with the
| Events | `POST /events/trips/delayed`, `/events/bookings/confirmed`, `/events/payments/succeeded` | Public |
| S3 proxy | `PUT/GET/DELETE /storage/{bucket}/{key+}` | OIDC |
| Asset CDN | `GET /assets/{key+}` | Public (rate-limited) |
| MCP Server | `POST /__barbacane/mcp` | JSON-RPC 2.0 |

### MCP Server (Model Context Protocol)

The Train Travel API is exposed as an MCP server. AI agents can connect to `POST /__barbacane/mcp` to discover and call API operations via JSON-RPC 2.0.

```bash
# Initialize a session
curl -s http://localhost:8080/__barbacane/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' \
-D -

# List available tools (use the Mcp-Session-Id from the response above)
curl -s http://localhost:8080/__barbacane/mcp \
-H "Content-Type: application/json" \
-H "Mcp-Session-Id: <session-id>" \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/list"}'

# Call a tool
curl -s http://localhost:8080/__barbacane/mcp \
-H "Content-Type: application/json" \
-H "Mcp-Session-Id: <session-id>" \
-d '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"listStations"}}'
```

### Bookings — OIDC flow

Expand Down Expand Up @@ -266,12 +245,22 @@ Distributed tracing is available in Grafana (Explore > Tempo).

## Control Plane

The Control Plane UI at http://localhost:3001 provides:
- API specification management
- Gateway configuration
- Plugin management
The control plane's REST API is at http://localhost:9091: projects, specs, compilations, artifacts, plugins, data planes and deployments. Every request but `GET /health` carries the admin token, `BARBACANE_CONTROL_ADMIN_TOKEN` (the demo default is in `.env.example`):

```bash
TOKEN=playground-admin-token-change-me-0123456789
curl http://localhost:9091/projects -H "Authorization: Bearer $TOKEN"
```

The `barbacane` CLI calls the same API with `barbacane control <resource> <command>` (see the [CLI reference](https://github.com/barbacane-dev/barbacane/blob/main/docs/reference/cli.md#barbacane-control)):

```bash
export BARBACANE_CONTROL_URL=http://localhost:9091
export BARBACANE_CONTROL_ADMIN_TOKEN=playground-admin-token-change-me-0123456789
barbacane control projects list
```

The Control Plane API is available at http://localhost:9091.
The API describes itself at http://localhost:9091/openapi.

## WireMock Admin

Expand Down Expand Up @@ -350,7 +339,7 @@ docker compose down -v
│ │
│ ┌───────────────┐ │
│ │ Control Plane │ │
│ │ :3001 │ │
│ │ :9091 │ │
│ └───────┬───────┘ │
│ │ │
│ ▼ │
Expand Down
8 changes: 4 additions & 4 deletions configs/grafana/provisioning/dashboards/barbacane.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"targets": [
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "sum(rate(barbacane_requests_total_total[1m]))",
"expr": "sum(rate(barbacane_requests_total[1m]))",
"refId": "A"
}
],
Expand Down Expand Up @@ -111,7 +111,7 @@
"targets": [
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "sum(rate(barbacane_requests_total_total{status=~\"5..\"}[5m])) / sum(rate(barbacane_requests_total_total[5m])) * 100",
"expr": "sum(rate(barbacane_requests_total{status=~\"5..\"}[5m])) / sum(rate(barbacane_requests_total[5m])) * 100",
"refId": "A"
}
],
Expand Down Expand Up @@ -203,7 +203,7 @@
"targets": [
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "sum by (method, path) (rate(barbacane_requests_total_total[1m]))",
"expr": "sum by (method, path) (rate(barbacane_requests_total[1m]))",
"legendFormat": "{{method}} {{path}}",
"refId": "A"
}
Expand Down Expand Up @@ -258,7 +258,7 @@
"targets": [
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "sum by (status) (rate(barbacane_requests_total_total[1m]))",
"expr": "sum by (status) (rate(barbacane_requests_total[1m]))",
"legendFormat": "{{status}}",
"refId": "A"
}
Expand Down
72 changes: 54 additions & 18 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
# Then visit:
# - Gateway: http://localhost:8080
# - Control Plane UI: http://localhost:3001
# - Control Plane API: http://localhost:9091
# - Grafana: http://localhost:3000 (admin/admin)
# - Prometheus: http://localhost:9090
# - NATS: nats://localhost:4222
Expand All @@ -16,32 +16,62 @@
# - RustFS console: http://localhost:9001 (playground/playground-secret)

services:
# ==========================================================================
# Signing key (init container - creates the artifact signing key once)
# ==========================================================================
# The private key stays in signing_key, which only the compiler mounts; the
# public key goes to trusted_key, which the gateway pins. The key survives
# restarts; removing the volumes replaces it.
keygen:
image: ghcr.io/barbacane-dev/barbacane-standalone:${BARBACANE_VERSION:-1.0.0-rc.1}
user: "0:0"
entrypoint: ["/bin/sh", "-c"]
command:
- |
set -e
[ -f /keys/private/signing.pk8 ] || barbacane key generate --out /keys/private/signing.pk8 > /dev/null
barbacane key public --key /keys/private/signing.pk8 > /keys/public/signing.pub
volumes:
- signing_key:/keys/private
- trusted_key:/keys/public
restart: "no"

# ==========================================================================
# Spec Compiler (init container - compiles specs before gateway starts)
# ==========================================================================
compiler:
image: ghcr.io/barbacane-dev/barbacane-standalone:${BARBACANE_VERSION:-0.12.3}
image: ghcr.io/barbacane-dev/barbacane-standalone:${BARBACANE_VERSION:-1.0.0-rc.1}
command: ["compile", "--spec", "/specs/train-travel-api.yaml", "--spec", "/specs/train-events.yaml", "--spec", "/specs/s3-proxy.yaml", "--spec", "/specs/waf-demo.yaml", "--manifest", "/manifest/barbacane.yaml", "--output", "/output/api.bca", "--allow-plaintext"]
# Run as root so the init container can write the shared artifact volume,
# which is root-owned by default. The gateway mounts it read-only.
# Root, to write the shared artifact volume (root-owned) and read the
# signing key (owner-only). The gateway mounts the artifact read-only.
user: "0:0"
environment:
BARBACANE_SIGNING_KEY: /keys/signing.pk8
volumes:
- ./specs:/specs:ro
- ./barbacane.yaml:/manifest/barbacane.yaml:ro
- artifact_data:/output
- signing_key:/keys:ro
depends_on:
keygen:
condition: service_completed_successfully
# Only run once, then exit
restart: "no"

# ==========================================================================
# API Gateway (Data Plane)
# ==========================================================================
barbacane:
image: ghcr.io/barbacane-dev/barbacane-standalone:${BARBACANE_VERSION:-0.12.3}
image: ghcr.io/barbacane-dev/barbacane-standalone:${BARBACANE_VERSION:-1.0.0-rc.1}
# serve loads only artifacts signed by the key BARBACANE_TRUSTED_PUBKEY
# pins: here, the public key the keygen container wrote.
# --admin-bind on 0.0.0.0 exposes the admin API (/health, /metrics,
# /provenance) to Prometheus and the host. It defaults to loopback, which
# other containers cannot reach. The admin endpoints are unauthenticated;
# keep this on an internal network in production.
command: ["serve", "--artifact", "/config/api.bca", "--allow-plaintext-upstream", "--admin-bind", "0.0.0.0:8082"]
entrypoint: ["/bin/sh", "-c"]
command:
- BARBACANE_TRUSTED_PUBKEY="$$(cat /keys/signing.pub)" exec barbacane serve --artifact /config/api.bca --allow-plaintext-upstream --admin-bind 0.0.0.0:8082
ports:
- "8080:8080"
- "8443:8443"
Expand All @@ -51,15 +81,20 @@ services:
- "127.0.0.1:8082:8082"
volumes:
- artifact_data:/config:ro
- trusted_key:/keys:ro
environment:
RUST_LOG: info
OTEL_EXPORTER_OTLP_ENDPOINT: http://tempo:4317
OTEL_SERVICE_NAME: barbacane-playground
# Since 0.8 an SSRF guard blocks upstream calls to internal/private hosts
# by default (fail closed). The playground's upstreams (wiremock, rustfs,
# mock-oauth, nats) are all internal Docker services, so opt in. Do NOT
# enable this in production unless your upstreams are genuinely internal.
# The SSRF guard blocks upstream calls to internal/private hosts by
# default. The playground's upstreams (wiremock, rustfs, mock-oauth, nats)
# are all internal Docker services, so opt in. Do NOT enable this in
# production unless your upstreams are genuinely internal.
BARBACANE_ALLOW_INTERNAL_EGRESS: "true"
# specs/s3-proxy.yaml gives the s3 dispatcher's secret_access_key as
# env://S3_SECRET_ACCESS_KEY, resolved when the gateway loads the artifact.
# It must match RUSTFS_SECRET_KEY below.
S3_SECRET_ACCESS_KEY: playground-secret
# The compiler is an init container that writes the .bca before the gateway
# loads it. compose runtimes that don't strictly honor
# service_completed_successfully can start the gateway mid-write; retry so it
Expand All @@ -85,19 +120,18 @@ services:
- "logging=alloy"

# ==========================================================================
# Control Plane (Web UI + API)
# Control Plane (REST API)
# ==========================================================================
control-plane:
image: ghcr.io/barbacane-dev/barbacane-control:${BARBACANE_VERSION:-0.12.3}
image: ghcr.io/barbacane-dev/barbacane-control:${BARBACANE_VERSION:-1.0.0-rc.1}
ports:
- "3001:80" # Web UI
- "9091:9090" # Control Plane API
- "9091:9090" # Control Plane API (Prometheus has 9090 on the host)
environment:
DATABASE_URL: postgres://barbacane:barbacane@postgres:5432/barbacane
# Since 0.8 the control plane fails closed: it refuses to start without a
# non-empty admin token (it can mint API keys, upload plugin WASM, and
# deploy artifacts). This is a demo value — set your own in production.
BARBACANE_CONTROL_ADMIN_TOKEN: ${BARBACANE_CONTROL_ADMIN_TOKEN:-playground-admin-token}
# The control plane refuses to start without an admin token of at least
# 32 bytes (it can mint API keys, upload plugin WASM, and deploy
# artifacts). This is a demo value: set your own in production.
BARBACANE_CONTROL_ADMIN_TOKEN: ${BARBACANE_CONTROL_ADMIN_TOKEN:-playground-admin-token-change-me-0123456789}
depends_on:
postgres:
condition: service_healthy
Expand Down Expand Up @@ -340,3 +374,5 @@ volumes:
tempo_data:
grafana_data:
rustfs_data:
signing_key:
trusted_key:
Loading
Loading