Demo and CI: Postgres and SSH server for the dynamic engines

docker compose now runs a Postgres with sample tables and an SSH server
that trusts the CA in OpenBao's ssh/ engine. seed.sh configures the
database engine (dynamic and static roles), the ssh CA and a role, a few
live leases, and grants for alice and the platform group. CI gains a
Postgres service so the database engine and its admin-policy rules are
tested against a real database (skipped when BAO_PG_URL is unset).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
mattandClaude Sonnet 5.5 committed 2026-11-09 13:58:59 +00:00
1 parent 0eff098140
commit 11c9483a88
15 files changed
+399 -5

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
-- Sample database for the docker-compose demo (runs once, on first start). Throwaway: all names and
-- passwords here are fake. OpenBao's database engine connects as "openbao" and creates, rotates and
-- drops logins for the dynamic and static roles that docker/seed.sh configures.
-- The account OpenBao itself uses. CREATEROLE lets it make and drop the short-lived logins.
CREATE ROLE openbao WITH LOGIN PASSWORD 'openbao-sample' CREATEROLE;
-- A fixed login for the static role: OpenBao rotates its password on a schedule instead of creating it.
CREATE ROLE app_static WITH LOGIN PASSWORD 'initial-not-a-real-password';
GRANT app_static TO openbao WITH ADMIN OPTION;
CREATE TABLE customers (
id serial PRIMARY KEY,
name text NOT NULL,
email text NOT NULL UNIQUE,
created_at timestamptz NOT NULL DEFAULT now()
);
CREATE TABLE orders (
id serial PRIMARY KEY,
customer_id integer NOT NULL REFERENCES customers (id),
total_cents integer NOT NULL,
status text NOT NULL DEFAULT 'new',
placed_at timestamptz NOT NULL DEFAULT now()
);
INSERT INTO customers (name, email) VALUES
('Ada Example', 'ada@example.test'),
('Grace Sample', 'grace@example.test'),
('Linus Placeholder', 'linus@example.test');
INSERT INTO orders (customer_id, total_cents, status) VALUES
(1, 4200, 'shipped'),
(1, 1999, 'new'),
(2, 12500, 'shipped'),
(3, 800, 'cancelled');
-- OpenBao hands these out to the logins it creates, so it must hold them WITH GRANT OPTION.
GRANT CONNECT ON DATABASE app TO openbao;
GRANT USAGE ON SCHEMA public TO openbao WITH GRANT OPTION;
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO openbao WITH GRANT OPTION;
GRANT USAGE ON ALL SEQUENCES IN SCHEMA public TO openbao WITH GRANT OPTION;
-- What the static login may do.
GRANT CONNECT ON DATABASE app TO app_static;
GRANT USAGE ON SCHEMA public TO app_static;
GRANT SELECT, INSERT, UPDATE ON ALL TABLES IN SCHEMA public TO app_static;
GRANT USAGE ON ALL SEQUENCES IN SCHEMA public TO app_static;
+64
View File
@@ -37,6 +37,12 @@ path "secret/data/team-a/*" {
path "secret/metadata/team-a/*" {
capabilities = ["list"]
}
path "database/creds/readonly" {
capabilities = ["read"]
}
path "ssh/sign/demo" {
capabilities = ["update"]
}
POLICY
bao policy write envbao-user-bob - >/dev/null <<'POLICY'
@@ -58,6 +64,9 @@ path "secret/data/app/*" {
path "secret/metadata/app/*" {
capabilities = ["list"]
}
path "database/creds/*" {
capabilities = ["read"]
}
POLICY
# Hand-written, so EnvBao shows it read-only.
@@ -87,4 +96,59 @@ bao write identity/group name=platform member_entity_ids="$alice_id" policies=en
# --- A token ---
bao token create -display-name=ci-deploy -policy=envbao-user-bob -ttl=24h >/dev/null
# --- Dynamic secrets: database (Postgres service "postgres", see docker/postgres/init.sql) ---
bao secrets enable database >/dev/null
bao write database/config/app \
plugin_name=postgresql-database-plugin \
allowed_roles="readonly,readwrite,app-static" \
connection_url="postgresql://{{username}}:{{password}}@postgres:5432/app?sslmode=disable" \
username=openbao password=openbao-sample >/dev/null
# Statements are JSON on stdin because they contain quotes and semicolons.
bao write database/roles/readonly - >/dev/null <<'JSON'
{
"db_name": "app",
"creation_statements": [
"CREATE ROLE \"{{name}}\" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}';",
"GRANT SELECT ON ALL TABLES IN SCHEMA public TO \"{{name}}\";"
],
"default_ttl": "1h",
"max_ttl": "24h"
}
JSON
bao write database/roles/readwrite - >/dev/null <<'JSON'
{
"db_name": "app",
"creation_statements": [
"CREATE ROLE \"{{name}}\" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}';",
"GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO \"{{name}}\";",
"GRANT USAGE ON ALL SEQUENCES IN SCHEMA public TO \"{{name}}\";"
],
"default_ttl": "1h",
"max_ttl": "8h"
}
JSON
# A fixed login whose password OpenBao rotates, rather than a new login per request.
bao write database/static-roles/app-static db_name=app username=app_static rotation_period=24h >/dev/null
# --- Dynamic secrets: SSH certificates (the "sshd" service trusts this CA) ---
bao secrets enable ssh >/dev/null
bao write ssh/config/ca generate_signing_key=true >/dev/null
bao write ssh/roles/demo - >/dev/null <<'JSON'
{
"key_type": "ca",
"allow_user_certificates": true,
"allowed_users": "deploy,alice",
"default_user": "deploy",
"default_extensions": { "permit-pty": "" },
"ttl": "30m",
"max_ttl": "4h"
}
JSON
# A couple of live leases so the Leases tab has something to show (credentials discarded).
bao read database/creds/readonly >/dev/null
bao read database/creds/readwrite >/dev/null
echo "Sample data loaded. Sign in as alice, bob or carol with password: password123"
echo "Dynamic engines: database/ (Postgres) and ssh/ (certificates for the sshd service, port 2222)."
+21
View File
@@ -0,0 +1,21 @@
# A tiny SSH server for the docker-compose demo. It trusts certificates signed by the CA in OpenBao's ssh/
# engine: the entrypoint fetches the CA public key from OpenBao at start-up. Throwaway; not hardened for real use.
FROM alpine:3.22
RUN apk add --no-cache openssh-server curl \
&& ssh-keygen -A \
&& for u in deploy alice; do \
adduser -D -s /bin/sh "$u" \
# sshd refuses locked accounts even for key logins, so give each a random password (password logins are off).
&& echo "$u:$(head -c 24 /dev/urandom | base64)" | chpasswd; \
done
COPY sshd_config /etc/ssh/sshd_config
COPY sample-data/deploy/ /home/deploy/
COPY sample-data/alice/ /home/alice/
RUN chown -R deploy:deploy /home/deploy && chown -R alice:alice /home/alice
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
EXPOSE 22
ENTRYPOINT ["/entrypoint.sh"]
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
# Wait for OpenBao's SSH CA (generated by docker/seed.sh), trust it, then run sshd in the foreground.
set -eu
CA_URL="${BAO_ADDR:-http://openbao:8200}/v1/ssh/public_key"
i=0
until curl -fsS "$CA_URL" -o /etc/ssh/trusted-user-ca-keys.pem 2>/dev/null && [ -s /etc/ssh/trusted-user-ca-keys.pem ]; do
i=$((i + 1))
[ "$i" -le 60 ] || { echo "No SSH CA at $CA_URL after 60 tries" >&2; exit 1; }
echo "Waiting for the SSH CA at $CA_URL ..."
sleep 2
done
echo "Trusting the CA from $CA_URL"
exec /usr/sbin/sshd -D -e
+3
View File
@@ -0,0 +1,3 @@
Alice's notes (sample data)
- rotate the staging database password
- ask platform about the new SSH role
@@ -0,0 +1,2 @@
You are logged in as "deploy" on the EnvBao demo SSH server, using a certificate signed by OpenBao.
Everything in this container is sample data.
@@ -0,0 +1,6 @@
# sample application config (fake values)
service: orders-api
environment: demo
database:
host: postgres
name: app
+12
View File
@@ -0,0 +1,12 @@
# Certificate logins only: no passwords, no root.
Port 22
HostKey /etc/ssh/ssh_host_ed25519_key
HostKey /etc/ssh/ssh_host_rsa_key
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin no
PubkeyAuthentication yes
AllowUsers deploy alice
# Written by entrypoint.sh from OpenBao's ssh/ engine.
TrustedUserCAKeys /etc/ssh/trusted-user-ca-keys.pem
LogLevel VERBOSE