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:
1 parent
a63f7c0faa
commit
fbe9cc9262
11 files changed
+1188
-169
No files matched your search
@@ -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 "/"')
|
||||
|
||||
@@ -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>
|
||||
)
|
||||
|
||||
@@ -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>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user