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 <noreply@anthropic.com>
This commit is contained in:
mattandClaude Sonnet 5.5 committed 2026-10-20 12:07:39 +01:00
1 parent a63f7c0faa
commit fbe9cc9262
11 files changed
+1188 -169

No files matched your search

+42
View File
@@ -30,6 +30,14 @@ const state = (over: Partial<grants.GrantState> = {}): 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 "/"')
+81 -73
View File
@@ -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 (
<section aria-label={`Access for ${target.name}`} className="access-editor">
<h2>
Access: {target.kind} “{target.name}”
</h2>
<button type="button" onClick={onClose}>
Close
</button>
<header className="access-head">
<h2>
Access for <strong>{target.name}</strong> <span className="kind">{target.kind}</span>
</h2>
<button type="button" onClick={onClose}>
Close
</button>
</header>
{state.error && <p role="alert">{state.error.message}</p>}
{s && (
<>
<h3>Granted by EnvBao</h3>
{s.managed && !s.managed.editable && (
<p role="alert">
This policy was changed outside EnvBao and is read-only here: {s.managed.reasons.join('; ')}
</p>
)}
{s.managed?.grants.length ? (
<table aria-label="Granted by EnvBao">
<thead>
<tr>
<th>Path</th>
<th>Capabilities</th>
<th />
</tr>
</thead>
<tbody>
{s.managed.grants.map((g) => (
<tr key={g.path}>
<td>
<code>{g.path}</code>
</td>
<td>{g.capabilities.join(', ')}</td>
<td>
<button
type="button"
aria-label={`Revoke ${g.path}`}
disabled={!editable}
onClick={() => window.confirm(`Revoke ${g.capabilities.join(', ')} on ${g.path}?`) && revoke.mutate(g.path)}
>
Revoke
</button>
</td>
<div className="access-body">
<div className="access-current">
<div className="section-head">
<h3>Granted by EnvBao</h3>
{s.hcl && (
<button type="button" className="link" aria-expanded={showRaw} onClick={() => setShowRaw(!showRaw)}>
{showRaw ? 'Hide' : 'Show'} policy HCL ({s.policyName})
</button>
)}
</div>
{s.managed && !s.managed.editable && (
<p role="alert">
This policy was changed outside EnvBao and is read-only here: {s.managed.reasons.join('; ')}
</p>
)}
{showRaw && <pre>{s.hcl}</pre>}
{s.managed?.grants.length ? (
<table aria-label="Granted by EnvBao">
<thead>
<tr>
<th>Path</th>
<th>Capabilities</th>
<th />
</tr>
</thead>
<tbody>
{s.managed.grants.map((g) => (
<tr key={g.path}>
<td>
<code>{g.path}</code>
</td>
<td>{g.capabilities.join(', ')}</td>
<td>
<button
type="button"
aria-label={`Revoke ${g.path}`}
disabled={!editable}
onClick={() => window.confirm(`Revoke ${g.capabilities.join(', ')} on ${g.path}?`) && revoke.mutate(g.path)}
>
Revoke
</button>
</td>
</tr>
))}
</tbody>
</table>
) : (
<p className="hint">No access granted through EnvBao yet.</p>
)}
{revoke.error && <p role="alert">{revoke.error.message}</p>}
<h3>Other policies</h3>
<p className="hint">Set outside EnvBao, so they can only be viewed here.</p>
{s.otherPolicies.length ? (
<ul className="policy-list">
{s.otherPolicies.map((p) => (
<PolicyView key={p} client={client} name={p} />
))}
</tbody>
</table>
) : (
<p>No access granted through EnvBao yet.</p>
)}
{s.hcl && (
<p>
<button type="button" aria-expanded={showRaw} onClick={() => setShowRaw(!showRaw)}>
{showRaw ? 'Hide' : 'Show'} policy HCL ({s.policyName})
</button>
</p>
)}
{showRaw && <pre>{s.hcl}</pre>}
{revoke.error && <p role="alert">{revoke.error.message}</p>}
</ul>
) : (
<p className="hint">None.</p>
)}
</div>
{editable && (
<form onSubmit={submit} aria-label="Grant access">
<form onSubmit={submit} aria-label="Grant access" className="access-grant">
<h3>Grant access</h3>
<label>
Secrets engine
<select value={mount} onChange={(e) => setMount(e.target.value)}>
<select
value={mount}
onChange={(e) => {
setMount(e.target.value)
setSecretPath('')
}}
>
{mounts.data?.map((m) => (
<option key={m.path}>{m.path}</option>
))}
</select>
</label>
<label>
Secret path
<input value={secretPath} onChange={(e) => setSecretPath(e.target.value)} placeholder="app/db or app/*" />
</label>
<fieldset>
{mount && <PathPicker key={mount} client={client} mount={mount} value={secretPath} onChange={setSecretPath} />}
<fieldset className="caps">
<legend>Capabilities</legend>
{KV_CAPABILITIES.map((c) => (
<label key={c} className="check">
@@ -154,7 +174,6 @@ export function AccessEditor({ client, target, onClose }: Props) {
</fieldset>
<p className="hint">
Granting a path that already has a grant replaces its capabilities. “list” applies to the secret’s metadata path.
A trailing * matches everything below.
</p>
{(formError || grant.error) && <p role="alert">{formError ?? grant.error?.message}</p>}
<button type="submit" disabled={grant.isPending || !mount}>
@@ -162,18 +181,7 @@ export function AccessEditor({ client, target, onClose }: Props) {
</button>
</form>
)}
<h3>Other policies (not managed by EnvBao, read-only)</h3>
{s.otherPolicies.length ? (
<ul>
{s.otherPolicies.map((p) => (
<PolicyView key={p} client={client} name={p} />
))}
</ul>
) : (
<p>None.</p>
)}
</>
</div>
)}
</section>
)
+116
View File
@@ -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 (
<div className="path-picker">
<label>
Secret path
<input value={value} onChange={(e) => onChange(e.target.value)} placeholder="app/db or app/*" />
</label>
<p className="hint">
For a secret that doesn’t exist yet. A trailing * matches everything below.{' '}
<button type="button" className="link" onClick={() => setManual(false)}>
Browse secrets instead
</button>
</p>
</div>
)
}
const where = prefix ? `${mount}${prefix}` : mount
return (
<fieldset className="path-picker">
<legend>Secret</legend>
<nav aria-label="Folder" className="crumbs">
<button type="button" onClick={() => open('')}>
{mount}
</button>
{crumbs.map((c, i) => (
<button key={i} type="button" onClick={() => open(`${crumbs.slice(0, i + 1).join('/')}/`)}>
{c}/
</button>
))}
</nav>
{entries.isPending && <p className="hint">Loading…</p>}
{entries.error && <p role="alert">Can’t list secrets here: {entries.error.message}</p>}
{entries.data?.length === 0 && <p className="hint">Nothing in {where} yet.</p>}
{!!entries.data?.length && (
<ul className="entries" aria-label={`Contents of ${where}`}>
{entries.data.map((e) => (
<li key={e.path}>
{e.isFolder ? (
<button type="button" className="entry-folder" aria-label={`Open ${e.name}`} onClick={() => open(e.path)}>
{e.name}
<span aria-hidden="true">›</span>
</button>
) : (
<label className="entry-secret">
<input
type="radio"
name={`${id}-secret`}
checked={value === e.path}
disabled={wildcard}
onChange={() => onChange(e.path)}
/>
{e.name}
</label>
)}
</li>
))}
</ul>
)}
<label className="check">
<input type="checkbox" checked={wildcard} onChange={(e) => onChange(e.target.checked ? `${prefix}*` : '')} />
<span>
Everything inside <code>{where}</code>, including subfolders and new secrets
</span>
</label>
<p className="hint" aria-live="polite">
{value ? (
<>
Granting on <code>{wildcard ? `${where}*` : `${mount}${value}`}</code>.
</>
) : (
'Choose a secret or tick the box above.'
)}{' '}
<button type="button" className="link" onClick={() => setManual(true)}>
Type a path instead
</button>
</p>
</fieldset>
)
}
+11 -8
View File
@@ -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 (
<section>
<h1>Connection</h1>
<ConnectionSummary client={client} tokenInfo={tokenInfo} onDisconnect={disconnect} />
</section>
)
}
return (
<section>
<h1>Connect</h1>
{client && tokenInfo && (
<p role="status">
Connected to {client.baseUrl} as {tokenInfo.display_name || 'token'} (policies: {tokenInfo.policies.join(', ')}){' '}
<button type="button" onClick={disconnect}>
Disconnect
</button>
</p>
)}
<p className="hint">Connect to an OpenBao server to manage its identities and who can reach which secrets.</p>
<form onSubmit={submit}>
<label>
OpenBao URL
+100
View File
@@ -0,0 +1,100 @@
import { useQuery } from '@tanstack/react-query'
import type { BaoClient, TokenInfo } from '../../api/bao'
function formatRemaining(ms: number): string {
const minutes = Math.max(0, Math.round(ms / 60_000))
if (minutes < 1) return 'less than a minute'
const days = Math.floor(minutes / 1440)
const hours = Math.floor((minutes % 1440) / 60)
const mins = minutes % 60
if (days) return `${days}d ${hours}h`
if (hours) return `${hours}h ${mins}m`
return `${mins}m`
}
interface Props {
client: BaoClient
tokenInfo: TokenInfo
onDisconnect: () => void
}
/** What you're connected to and as whom. Shown instead of the connect form while a session is active. */
export function ConnectionSummary({ client, tokenInfo, onDisconnect }: Props) {
const health = useQuery({ queryKey: ['health', client.baseUrl], queryFn: () => client.health() })
// The session's tokenInfo is a snapshot from sign-in, so look the token up again for a current TTL.
const self = useQuery({ queryKey: ['token-self', client.baseUrl], queryFn: () => client.lookupSelf(), staleTime: 0 })
const info = self.data ?? tokenInfo
const remaining = `in ${formatRemaining(info.ttl * 1000)}`
const expires = info.ttl <= 0 ? 'Never' : self.data ? `${remaining} (${new Date(self.dataUpdatedAt + info.ttl * 1000).toLocaleString()})` : remaining
const h = health.data
return (
<div className="connection">
<div className="connection-head" role="status">
<p className="connection-state">
<span className="dot" aria-hidden="true" />
Connected to <code>{client.baseUrl}</code> as <strong>{info.display_name || 'token'}</strong>
</p>
<button type="button" onClick={onDisconnect}>
Disconnect
</button>
</div>
<div className="connection-grid">
<section aria-labelledby="conn-server">
<h2 id="conn-server">Server</h2>
{health.isPending && <p className="hint">Checking server…</p>}
{health.error && <p role="alert">{health.error.message}</p>}
{h && (
<dl>
<dt>Version</dt>
<dd>OpenBao {h.version}</dd>
<dt>Status</dt>
<dd>{!h.initialized ? 'Not initialised' : h.sealed ? 'Sealed' : 'Unsealed'}</dd>
<dt>Role</dt>
<dd>{h.standby ? 'Standby node' : 'Active node'}</dd>
{h.cluster_name && (
<>
<dt>Cluster</dt>
<dd>{h.cluster_name}</dd>
</>
)}
{h.server_time_utc != null && (
<>
<dt>Server time</dt>
<dd>{new Date(h.server_time_utc * 1000).toLocaleString(undefined, { timeZone: 'UTC', dateStyle: 'medium', timeStyle: 'medium' })} UTC</dd>
</>
)}
</dl>
)}
</section>
<section aria-labelledby="conn-session">
<h2 id="conn-session">Your session</h2>
<dl>
<dt>Signed in as</dt>
<dd>{info.display_name || 'token'}</dd>
<dt>Policies</dt>
<dd>
{info.policies.length ? (
<ul className="chips">
{info.policies.map((p) => (
<li key={p}>{p}</li>
))}
</ul>
) : (
'None'
)}
</dd>
<dt>Token expires</dt>
<dd>{expires}</dd>
<dt>Renewable</dt>
<dd>{info.renewable ? 'Yes' : 'No'}</dd>
</dl>
<p className="hint">The token is held in memory only. Reloading the page signs you out.</p>
</section>
</div>
</div>
)
}