Skip to content

Commit 88dff03

Browse files
committed
update
1 parent ff7480b commit 88dff03

4 files changed

Lines changed: 87 additions & 16 deletions

File tree

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ RUST_LOG=pba_service=debug,tower_http=info
1010
HOST=0.0.0.0
1111
PORT=3030
1212
PG_DATA=.pg_data
13+
# Auth is disabled for local dev. Keycloak is disabled by default in
14+
# process-compose.yml; set this to true (and enable Keycloak) to test OIDC login.
15+
AUTH_ENABLED=false

README.md

Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,22 @@ The API is defined using [Smithy](https://smithy.io/) models under `model/`. A g
4242

4343
## Dev Setup
4444

45+
### First-time setup (TL;DR)
46+
47+
```bash
48+
git clone <repo-url> && cd purpose-bound-accounts
49+
50+
nix develop # 1. enter the dev shell (Rust, Postgres, TigerBeetle, just, ...)
51+
cp .env.example .env # 2. create your local config from the template
52+
just run # 3. start Postgres + TigerBeetle + the app
53+
```
54+
55+
Then open the **Admin Dashboard** at <http://localhost:3030/admin>.
56+
57+
The default `.env` runs with auth disabled (`AUTH_ENABLED=false`), so no
58+
Keycloak/OIDC provider is needed to get started. The sections below explain
59+
each piece in more detail.
60+
4561
### Prerequisites
4662

4763
The easiest way to get all dependencies is via [Nix](https://nixos.org/):
@@ -50,14 +66,35 @@ The easiest way to get all dependencies is via [Nix](https://nixos.org/):
5066
nix develop
5167
```
5268

53-
This provides Rust, PostgreSQL 16, TigerBeetle, Zig 0.14, just, sqlx-cli, cargo-watch, and Smithy CLI.
69+
This provides Rust 1.94, PostgreSQL 16, TigerBeetle, Zig 0.14, just, sqlx-cli,
70+
cargo-watch, cocogitto, process-compose, and the Smithy CLI — no other system
71+
setup required.
72+
73+
If you use [direnv](https://direnv.net/), run `direnv allow` once; the dev
74+
shell and your `.env` then load automatically whenever you `cd` into the repo.
5475

55-
Alternatively, install manually via Homebrew:
76+
Alternatively, install manually via Homebrew (macOS):
5677

5778
```bash
5879
just install-deps
5980
```
6081

82+
> **Docker is _not_ required** for the default dev flow. It is only needed if
83+
> you opt in to running Keycloak — see [Authentication](#authentication).
84+
85+
### Configure your environment
86+
87+
The service reads configuration from a `.env` file. It is git-ignored, so each
88+
clone needs its own — create one from the template:
89+
90+
```bash
91+
cp .env.example .env
92+
```
93+
94+
The defaults work out of the box for local development. The full list of
95+
variables is in [Configuration](#configuration); the key one for first-time
96+
setup is `AUTH_ENABLED=false`, which lets you run without an OIDC provider.
97+
6198
### Development workflow
6299

63100
**Start everything (Postgres + TigerBeetle + app):**
@@ -128,20 +165,46 @@ just smithy-build # regenerate the Rust client SDK
128165

129166
## Authentication
130167

131-
PBA uses Keycloak for authentication. `just run` starts Keycloak alongside other services.
168+
**Local dev runs with auth disabled.** The `.env.example` template sets
169+
`AUTH_ENABLED=false`, and the dev stack does **not** start an OIDC provider, so
170+
`just run` leaves the Admin UI and API open — just navigate to
171+
`http://localhost:3030/admin`.
172+
173+
### Enabling Keycloak (optional)
174+
175+
Keycloak is **not** bundled in the dev stack. To test the real OIDC login flow
176+
locally, run it standalone (requires Docker), then point the service at it:
132177

133-
**Admin UI:** Navigate to `http://localhost:3030/admin` — you'll be redirected to Keycloak to log in.
134-
Default credentials: `admin@pba.local` / `admin`
178+
1. Start Keycloak with the bundled realm:
135179

136-
**API access:** Use the `Authorization` header with a base64-encoded `client_id:client_secret`:
180+
```bash
181+
docker run --rm --name pba-keycloak \
182+
-p 8180:8080 -m 2g \
183+
-v "$(pwd)/keycloak/realm-export.json:/opt/keycloak/data/import/realm-export.json:ro" \
184+
-e KC_BOOTSTRAP_ADMIN_USERNAME=admin \
185+
-e KC_BOOTSTRAP_ADMIN_PASSWORD=admin \
186+
-e JAVA_OPTS_KC_HEAP="-XX:MaxRAMPercentage=50 -Xms256m -Xmx1024m -XX:UseSVE=0" \
187+
quay.io/keycloak/keycloak:26.0 \
188+
start-dev --import-realm
189+
```
190+
191+
> `-XX:UseSVE=0` works around a JVM crash on Apple Silicon (M-series); the
192+
> heap flags and `-m 2g` keep Keycloak from starving the rest of the stack.
193+
194+
2. Set `AUTH_ENABLED=true` in your `.env`.
195+
3. `just run` (or `just run-service`) — the service now uses Keycloak for auth.
196+
197+
**Admin UI:** Navigate to `http://localhost:3030/admin` — you'll be redirected
198+
to Keycloak to log in. Default credentials: `admin@pba.local` / `admin`
199+
200+
**API access:** Use the `Authorization` header with a base64-encoded
201+
`client_id:client_secret`:
137202

138203
```bash
139204
API_KEY=$(echo -n "pba-api:pba-api-secret" | base64)
140205
curl -H "Authorization: ApiKey $API_KEY" http://localhost:3030/purpose-types
141206
```
142207

143-
**Disable auth (development):** Set `AUTH_ENABLED=false` in your `.env` file.
144-
145208
## Configuration
146209

147210
Environment variables (loaded from `.env`):
@@ -158,10 +221,10 @@ Environment variables (loaded from `.env`):
158221
| `HOST` | `0.0.0.0` | Bind address |
159222
| `PORT` | `3030` | HTTP port |
160223
| `RUST_LOG` | `pba_service=debug,tower_http=info` | Log level (`tower_http=info` enables per-request access logs) |
161-
| `OIDC_ISSUER_URL` | `http://localhost:8180/realms/pba` | OIDC provider issuer URL (discovery via `.well-known/openid-configuration`) |
162-
| `OIDC_CLIENT_ID` | `pba-admin` | OIDC client ID for admin UI login flow |
224+
| `OIDC_ISSUER_URL` | `http://localhost:8180/realms/pba` | OIDC provider issuer URL (only used when `AUTH_ENABLED=true`) |
225+
| `OIDC_CLIENT_ID` | `pba-admin` | OIDC client ID for admin UI login flow (only used when `AUTH_ENABLED=true`) |
163226
| `COOKIE_SECRET` | _(dev default)_ | 32+ byte secret for session cookie signing |
164-
| `AUTH_ENABLED` | `true` | Set to `false` to disable auth |
227+
| `AUTH_ENABLED` | `true` (code) / `false` (dev `.env`) | Set to `false` to disable auth. `.env.example` ships with `false` for local dev |
165228
| `PATH_PREFIX` | _(empty)_ | URL prefix for reverse proxy / ingress (e.g., `/pba`) |
166229

167230
## Available just targets

justfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,15 @@ migrate-new name:
162162
# Install system dependencies (macOS via Homebrew, non-Nix)
163163
install-deps:
164164
@echo "Installing dependencies via Homebrew..."
165-
brew install rustup postgresql@16 just process-compose
166-
rustup-init -y --default-toolchain stable
165+
# process-compose lives in the maintainer's tap, not homebrew-core.
166+
brew install rustup postgresql@16 just f1bonacc1/tap/process-compose
167+
# Homebrew's rustup formula ships the self-managing `rustup` (no `rustup-init`).
168+
# rust-toolchain.toml pins the exact toolchain + clippy/rustfmt, which rustup
169+
# auto-installs on first cargo invocation inside the repo.
170+
rustup default stable
167171
cargo install sqlx-cli --no-default-features --features postgres
168172
cargo install cargo-watch
169173
cargo install cocogitto
170-
rustup component add clippy rustfmt
171174
@echo ""
172175
@echo "Dependencies installed. Run 'just run' to start everything."
173176

process-compose.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ processes:
2626
restart: "no"
2727

2828
keycloak:
29+
# Disabled by default — dev runs with AUTH_ENABLED=false, so no OIDC provider
30+
# is needed. Set this to false (and re-add the keycloak dependency under
31+
# pba-service) to test the Keycloak login flow.
32+
disabled: true
2933
command: |
3034
docker run --rm --name pba-keycloak \
3135
-p 8180:8080 \
@@ -69,8 +73,6 @@ processes:
6973
condition: process_completed_successfully
7074
tigerbeetle:
7175
condition: process_healthy
72-
keycloak:
73-
condition: process_healthy
7476
readiness_probe:
7577
http_get:
7678
host: 127.0.0.1

0 commit comments

Comments
 (0)