From fbe9cc9262e6335bb35df75f2644969becd4ceb1 Mon Sep 17 00:00:00 2001 From: Matthew Daubney Date: Tue, 20 Oct 2026 12:07:39 +0100 Subject: [PATCH] Design sweep: tokens and base styles, connection summary, secret picker, access panel layout, sample data - Add a token-based design system (light/dark colours, type and spacing scales) and style buttons, forms, tables, tabs and the app shell. - Show a server and session summary (version, status, cluster, server time, token expiry) instead of the connect form while connected. - Replace the free-text secret path in the Access panel with a browsable picker and an "everything inside" tickbox; typing a path is still available. - Re-lay out the Access panel: header bar, current access beside the grant form. - Seed the docker-compose stack with sample secrets, users, entities, a group, policies and a token via docker/seed.sh (safe to re-run). Co-Authored-By: Claude Sonnet 5.5 --- README.md | 2 + docker-compose.yml | 8 +- docker/seed.sh | 90 +++ src/api/bao.ts | 2 + src/docs.test.ts | 4 +- src/features/access/AccessEditor.test.tsx | 42 ++ src/features/access/AccessEditor.tsx | 154 ++-- src/features/access/PathPicker.tsx | 116 +++ src/features/connect/ConnectPage.tsx | 19 +- src/features/connect/ConnectionSummary.tsx | 100 +++ src/index.css | 820 ++++++++++++++++++--- 11 files changed, 1188 insertions(+), 169 deletions(-) create mode 100755 docker/seed.sh create mode 100644 src/features/access/PathPicker.tsx create mode 100644 src/features/connect/ConnectionSummary.tsx diff --git a/README.md b/README.md index f51412e..f468145 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ docker compose up --build Open http://localhost:8080 and connect to `http://localhost:8200` with token `root`. This starts a throwaway in-memory OpenBao dev server (CORS pre-configured for the UI and for OpenBao's own web UI at `:8200`) and the UI. Not for production. +The stack also loads sample data from [`docker/seed.sh`](docker/seed.sh): five secrets under `secret/` (`app/`, `shared/`, `team-a/`), userpass users `alice`, `bob` and `carol` (password `password123`), entities for alice and bob, a `platform` group, a few grants, and a `ci-deploy` token. Edit the script to change it. If you already have the stack running, `docker compose down` first: the setup step only runs on a fresh start. + To run just the UI image: `docker build -t envbao-admin . && docker run -p 8080:80 envbao-admin`. ## OpenBao setup diff --git a/docker-compose.yml b/docker-compose.yml index e0ce559..88cbb2b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,8 +15,8 @@ services: interval: 2s retries: 15 - # One-shot: allow the UI origin to call OpenBao from the browser. OpenBao's own - # web UI (:8200) is same-origin but still sends an Origin header, so it is listed too. + # One-shot: allow the UI origin to call OpenBao from the browser, then load sample + # secrets, users, entities, a group and a token (see docker/seed.sh). openbao-setup: image: openbao/openbao:latest depends_on: @@ -25,7 +25,9 @@ services: environment: BAO_ADDR: http://openbao:8200 BAO_TOKEN: root - entrypoint: ["bao", "write", "sys/config/cors", "enabled=true", "allowed_origins=http://localhost:8080,http://localhost:8200", "allowed_headers=X-Vault-Token,Content-Type"] + volumes: + - ./docker/seed.sh:/seed.sh:ro + entrypoint: ["sh", "/seed.sh"] restart: "no" ui: diff --git a/docker/seed.sh b/docker/seed.sh new file mode 100755 index 0000000..9e216d5 --- /dev/null +++ b/docker/seed.sh @@ -0,0 +1,90 @@ +#!/bin/sh +# Sample data for the docker-compose demo. Throwaway: the dev server is in-memory, so this +# runs fresh on every `docker compose up`. All passwords and secret values here are fake. +# Expects BAO_ADDR and BAO_TOKEN in the environment. +set -eu + +# Allow the UI origin to call OpenBao from the browser. OpenBao's own web UI (:8200) is +# same-origin but still sends an Origin header, so it is listed too. +bao write sys/config/cors enabled=true \ + allowed_origins="http://localhost:8080,http://localhost:8200" \ + allowed_headers="X-Vault-Token,Content-Type" + +# Compose re-runs this when other services are rebuilt; don't load the data twice. +if bao read sys/auth/userpass >/dev/null 2>&1; then + echo "Sample data already loaded." + exit 0 +fi + +# --- Secrets (KV v2 at secret/ is mounted by dev mode) --- +put() { path=$1; shift; bao kv put "secret/$path" "$@" >/dev/null; } +put app/database host=db.internal user=app password=sample-not-a-real-secret +put app/api-keys stripe=sk_test_sample sendgrid=SG.sample +put shared/smtp host=smtp.internal user=mailer password=sample-not-a-real-secret +put team-a/deploy ssh_key=sample-not-a-real-key +put team-a/staging/database host=staging-db.internal password=sample-not-a-real-secret + +# --- Policies --- +# The envbao-* ones are written the way EnvBao writes them (see src/model/managed.ts), so +# they show up as editable grants in the Access panel and in the graph. +bao policy write envbao-user-alice - >/dev/null <<'POLICY' +# Managed by EnvBao. Changes made outside EnvBao may be overwritten. +# envbao-owner: user:alice + +path "secret/data/team-a/*" { + capabilities = ["read", "update"] +} +path "secret/metadata/team-a/*" { + capabilities = ["list"] +} +POLICY + +bao policy write envbao-user-bob - >/dev/null <<'POLICY' +# Managed by EnvBao. Changes made outside EnvBao may be overwritten. +# envbao-owner: user:bob + +path "secret/data/shared/smtp" { + capabilities = ["read"] +} +POLICY + +bao policy write envbao-group-platform - >/dev/null <<'POLICY' +# Managed by EnvBao. Changes made outside EnvBao may be overwritten. +# envbao-owner: group:platform + +path "secret/data/app/*" { + capabilities = ["read"] +} +path "secret/metadata/app/*" { + capabilities = ["list"] +} +POLICY + +# Hand-written, so EnvBao shows it read-only. +bao policy write ops-readonly - >/dev/null <<'POLICY' +path "sys/health" { + capabilities = ["read"] +} +path "secret/metadata/*" { + capabilities = ["list"] +} +POLICY + +# --- Users --- +bao auth enable userpass >/dev/null +bao write auth/userpass/users/alice password=password123 policies=envbao-user-alice >/dev/null +bao write auth/userpass/users/bob password=password123 policies=envbao-user-bob >/dev/null +bao write auth/userpass/users/carol password=password123 policies=ops-readonly >/dev/null + +# --- Entities, aliases and a group --- +accessor=$(bao read -field=accessor sys/auth/userpass) +alice_id=$(bao write -field=id identity/entity name=alice) +bob_id=$(bao write -field=id identity/entity name=bob) +bao write identity/entity-alias name=alice canonical_id="$alice_id" mount_accessor="$accessor" >/dev/null +bao write identity/entity-alias name=bob canonical_id="$bob_id" mount_accessor="$accessor" >/dev/null +bao write identity/group name=platform member_entity_ids="$alice_id" policies=envbao-group-platform >/dev/null + +# --- A token --- +bao token create -display-name=ci-deploy -policy=envbao-user-bob -ttl=24h >/dev/null + +echo "Sample data loaded. Sign in as alice, bob or carol with password: password123" diff --git a/src/api/bao.ts b/src/api/bao.ts index 78d81d7..6d7fae6 100644 --- a/src/api/bao.ts +++ b/src/api/bao.ts @@ -20,6 +20,8 @@ export interface BaoHealth { standby: boolean version: string cluster_name?: string + /** Unix seconds. */ + server_time_utc?: number } export interface TokenInfo { diff --git a/src/docs.test.ts b/src/docs.test.ts index a32a618..a1c5a24 100644 --- a/src/docs.test.ts +++ b/src/docs.test.ts @@ -7,8 +7,8 @@ test('README embeds the tested admin policy verbatim', () => { }) test('README documents every origin the docker-compose setup allows', () => { - const compose = readFileSync('docker-compose.yml', 'utf8') - const origins = /allowed_origins=([^"]+)"/.exec(compose)![1].split(',') + const seed = readFileSync('docker/seed.sh', 'utf8') + const origins = /allowed_origins="([^"]+)"/.exec(seed)![1].split(',') const readme = readFileSync('README.md', 'utf8') for (const o of origins) expect(readme).toContain(o) }) diff --git a/src/features/access/AccessEditor.test.tsx b/src/features/access/AccessEditor.test.tsx index 0e13051..a6a9aa1 100644 --- a/src/features/access/AccessEditor.test.tsx +++ b/src/features/access/AccessEditor.test.tsx @@ -30,6 +30,14 @@ const state = (over: Partial = {}): grants.GrantState => ({ beforeEach(() => { vi.mocked(grants.getGrantState).mockResolvedValue(state()) vi.mocked(secrets.listKvMounts).mockResolvedValue([{ path: 'secret/' }]) + vi.mocked(secrets.listSecrets).mockImplementation(async (_c, _m, prefix) => + prefix === '' + ? [ + { name: 'app/', path: 'app/', isFolder: true }, + { name: 'shared', path: 'shared', isFolder: false }, + ] + : [{ name: 'db', path: 'app/db', isFolder: false }], + ) vi.mocked(secrets.readPolicyHcl).mockResolvedValue('path "x" { capabilities = ["read"] }') }) afterEach(() => vi.resetAllMocks()) @@ -54,6 +62,7 @@ test('shows managed grants and read-only other policies', async () => { test('grants KV access split into data and metadata rules', async () => { vi.mocked(grants.grantAccess).mockResolvedValue() const user = setup() + await user.click(await screen.findByRole('button', { name: 'Type a path instead' })) await user.type(await screen.findByLabelText('Secret path'), 'db/*') await user.click(screen.getByLabelText('update')) await user.click(screen.getByLabelText('list')) @@ -64,8 +73,41 @@ test('grants KV access split into data and metadata rules', async () => { ]) }) +test('grants a secret chosen from the browser', async () => { + vi.mocked(grants.grantAccess).mockResolvedValue() + const user = setup() + await user.click(await screen.findByRole('button', { name: 'Open app/' })) + await user.click(await screen.findByLabelText('db')) + await user.click(screen.getByRole('button', { name: 'Grant' })) + expect(grants.grantAccess).toHaveBeenCalledWith(client, target, [ + { path: 'secret/data/app/db', capabilities: ['read'] }, + { path: 'secret/metadata/app/db', capabilities: [] }, + ]) +}) + +test('ticking "everything inside" grants the folder wildcard', async () => { + vi.mocked(grants.grantAccess).mockResolvedValue() + const user = setup() + await user.click(await screen.findByRole('button', { name: 'Open app/' })) + await user.click(await screen.findByLabelText(/Everything inside/)) + expect(screen.getByLabelText('db')).toBeDisabled() + await user.click(screen.getByRole('button', { name: 'Grant' })) + expect(grants.grantAccess).toHaveBeenCalledWith(client, target, [ + { path: 'secret/data/app/*', capabilities: ['read'] }, + { path: 'secret/metadata/app/*', capabilities: [] }, + ]) +}) + +test('asks for a choice before granting', async () => { + const user = setup() + await user.click(await screen.findByRole('button', { name: 'Grant' })) + expect(await screen.findByRole('alert')).toHaveTextContent('Path is required') + expect(grants.grantAccess).not.toHaveBeenCalled() +}) + test('validates the path and capabilities before calling the API', async () => { const user = setup() + await user.click(await screen.findByRole('button', { name: 'Type a path instead' })) await user.type(await screen.findByLabelText('Secret path'), '/bad') await user.click(screen.getByRole('button', { name: 'Grant' })) expect(await screen.findByRole('alert')).toHaveTextContent('must not start with "/"') diff --git a/src/features/access/AccessEditor.tsx b/src/features/access/AccessEditor.tsx index 63a62de..7f5c1f8 100644 --- a/src/features/access/AccessEditor.tsx +++ b/src/features/access/AccessEditor.tsx @@ -4,6 +4,7 @@ import type { BaoClient } from '../../api/bao' import { getGrantState, grantAccess, revokeAccess, type Target } from '../../api/grants' import { listKvMounts, readPolicyHcl } from '../../api/secrets' import { KV_CAPABILITIES, kvGrantRules, validateGrantPath, type KvCapability } from '../../model/managed' +import { PathPicker } from './PathPicker' interface Props { client: BaoClient @@ -66,80 +67,99 @@ export function AccessEditor({ client, target, onClose }: Props) { return (
-

- Access: {target.kind} “{target.name}” -

- +
+

+ Access for {target.name} {target.kind} +

+ +
{state.error &&

{state.error.message}

} {s && ( - <> -

Granted by EnvBao

- {s.managed && !s.managed.editable && ( -

- This policy was changed outside EnvBao and is read-only here: {s.managed.reasons.join('; ')} -

- )} - {s.managed?.grants.length ? ( - - - - - - - - - {s.managed.grants.map((g) => ( - - - - +
+
+
+

Granted by EnvBao

+ {s.hcl && ( + + )} +
+ {s.managed && !s.managed.editable && ( +

+ This policy was changed outside EnvBao and is read-only here: {s.managed.reasons.join('; ')} +

+ )} + {showRaw &&
{s.hcl}
} + {s.managed?.grants.length ? ( +
PathCapabilities -
- {g.path} - {g.capabilities.join(', ')} - -
+ + + + + + + + {s.managed.grants.map((g) => ( + + + + + + ))} + +
PathCapabilities
+ {g.path} + {g.capabilities.join(', ')} + +
+ ) : ( +

No access granted through EnvBao yet.

+ )} + {revoke.error &&

{revoke.error.message}

} + +

Other policies

+

Set outside EnvBao, so they can only be viewed here.

+ {s.otherPolicies.length ? ( +
    + {s.otherPolicies.map((p) => ( + ))} - - - ) : ( -

    No access granted through EnvBao yet.

    - )} - {s.hcl && ( -

    - -

    - )} - {showRaw &&
    {s.hcl}
    } - {revoke.error &&

    {revoke.error.message}

    } +
+ ) : ( +

None.

+ )} + {editable && ( -
+

Grant access

- -
+ {mount && } +
Capabilities {KV_CAPABILITIES.map((c) => (

Granting a path that already has a grant replaces its capabilities. “list” applies to the secret’s metadata path. - A trailing * matches everything below.

{(formError || grant.error) &&

{formError ?? grant.error?.message}

} )} - -

Other policies (not managed by EnvBao, read-only)

- {s.otherPolicies.length ? ( -
    - {s.otherPolicies.map((p) => ( - - ))} -
- ) : ( -

None.

- )} - + )}
) diff --git a/src/features/access/PathPicker.tsx b/src/features/access/PathPicker.tsx new file mode 100644 index 0000000..08bd063 --- /dev/null +++ b/src/features/access/PathPicker.tsx @@ -0,0 +1,116 @@ +import { useQuery } from '@tanstack/react-query' +import { useId, useState } from 'react' +import type { BaoClient } from '../../api/bao' +import { listSecrets } from '../../api/secrets' + +interface Props { + client: BaoClient + mount: string + /** Path within the mount: a secret ("app/db"), or a folder wildcard ("app/*", "*"). */ + value: string + onChange: (path: string) => void +} + +/** + * Pick a secret by browsing the mount, or tick "everything inside" to grant a whole folder. + * Lists names only; secret values are never read. + */ +export function PathPicker({ client, mount, value, onChange }: Props) { + const id = useId() + const [prefix, setPrefix] = useState('') + const [manual, setManual] = useState(false) + const entries = useQuery({ queryKey: ['secrets', mount, prefix], queryFn: () => listSecrets(client, mount, prefix) }) + + const wildcard = value === `${prefix}*` + const crumbs = prefix.split('/').filter(Boolean) + + function open(next: string) { + setPrefix(next) + // Keep the "everything inside" intent while moving between folders. + onChange(wildcard ? `${next}*` : '') + } + + if (manual) { + return ( +
+ +

+ For a secret that doesn’t exist yet. A trailing * matches everything below.{' '} + +

+
+ ) + } + + const where = prefix ? `${mount}${prefix}` : mount + + return ( +
+ Secret + + + {entries.isPending &&

Loading…

} + {entries.error &&

Can’t list secrets here: {entries.error.message}

} + {entries.data?.length === 0 &&

Nothing in {where} yet.

} + {!!entries.data?.length && ( +
    + {entries.data.map((e) => ( +
  • + {e.isFolder ? ( + + ) : ( + + )} +
  • + ))} +
+ )} + + + +

+ {value ? ( + <> + Granting on {wildcard ? `${where}*` : `${mount}${value}`}. + + ) : ( + 'Choose a secret or tick the box above.' + )}{' '} + +

+
+ ) +} diff --git a/src/features/connect/ConnectPage.tsx b/src/features/connect/ConnectPage.tsx index 2533ade..e0ae891 100644 --- a/src/features/connect/ConnectPage.tsx +++ b/src/features/connect/ConnectPage.tsx @@ -1,6 +1,7 @@ import { useState, type FormEvent } from 'react' import { BaoClient, BaoError, type BaoHealth } from '../../api/bao' import { useSession } from '../../api/useSession' +import { ConnectionSummary } from './ConnectionSummary' type Mode = 'token' | 'userpass' @@ -43,17 +44,19 @@ export function ConnectPage() { } } + if (client && tokenInfo) { + return ( +
+

Connection

+ +
+ ) + } + return (

Connect

- {client && tokenInfo && ( -

- Connected to {client.baseUrl} as {tokenInfo.display_name || 'token'} (policies: {tokenInfo.policies.join(', ')}){' '} - -

- )} +

Connect to an OpenBao server to manage its identities and who can reach which secrets.