Secrets: list all mounts and group dynamic engines by type

Adds listMounts and an engine registry (database, aws, ssh, generic
fallback). The Secrets page groups mounts by engine; KV v2 keeps the
path browser and dynamic mounts get a placeholder EngineView.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
mattandClaude Sonnet 5.5 committed 2026-11-09 13:20:40 +00:00
1 parent eba7c97de6
commit 6daed8d388
5 files changed
+149 -24

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
import { engineFor } from '../../api/engines/registry'
import type { Mount } from '../../api/secrets'
/** Roles / Config / Leases for a dynamic secrets engine. Filled in by later phases. */
export function EngineView({ mount }: { mount: Mount }) {
const engine = engineFor(mount.type)
return (
<p className="secret-placeholder">
{engine.label} engine at {mount.path}: role management is coming soon.
</p>
)
}
+30 -2
View File
@@ -14,7 +14,7 @@ import { SecretsPage } from './SecretsPage'
vi.mock('../../api/grants')
vi.mock('../../api/identities')
vi.mock('../../api/secrets', async (orig) => ({ ...(await orig<typeof api>()), listKvMounts: vi.fn(), listSecrets: vi.fn(), readPolicyHcl: vi.fn() }))
vi.mock('../../api/secrets', async (orig) => ({ ...(await orig<typeof api>()), listMounts: vi.fn(), listSecrets: vi.fn(), readPolicyHcl: vi.fn() }))
vi.mock('../../api/tokens')
const client = new BaoClient('http://b', 't')
@@ -29,7 +29,7 @@ function Connected() {
}
beforeEach(() => {
vi.mocked(api.listKvMounts).mockResolvedValue([{ path: 'secret/' }])
vi.mocked(api.listMounts).mockResolvedValue([{ path: 'secret/', type: 'kv', version: '2' }])
vi.mocked(api.listSecrets).mockImplementation(async (_c, _m, prefix) =>
prefix === ''
? [{ name: 'app/', path: 'app/', isFolder: true }]
@@ -127,6 +127,34 @@ test('shows why a grant failed and keeps the form open', async () => {
expect(screen.getByRole('form', { name: 'Grant access to this secret' })).toBeInTheDocument()
})
test('groups mounts by engine and shows the engine view for a dynamic mount', async () => {
vi.mocked(api.listMounts).mockResolvedValue([
{ path: 'database/', type: 'database' },
{ path: 'secret/', type: 'kv', version: '2' },
{ path: 'cubbyhole/', type: 'cubbyhole' },
])
render(
<QueryClientProvider client={new QueryClient({ defaultOptions: { queries: { retry: false } } })}>
<SessionProvider>
<MemoryRouter>
<Connected />
<SecretsPage />
</MemoryRouter>
</SessionProvider>
</QueryClientProvider>,
)
const user = userEvent.setup()
await user.click(screen.getByRole('button', { name: 'go' }))
const select = await screen.findByLabelText('Mount')
expect(within(select).getByRole('group', { name: 'KV' })).toBeInTheDocument()
expect(within(select).getByRole('group', { name: 'Database' })).toBeInTheDocument()
expect(within(select).queryByText('cubbyhole/')).not.toBeInTheDocument()
await user.selectOptions(select, 'database/')
expect(await screen.findByText(/Database engine at database\//)).toBeInTheDocument()
expect(api.listSecrets).not.toHaveBeenCalled()
})
test('asks to connect first', () => {
render(
<QueryClientProvider client={new QueryClient()}>
+55 -19
View File
@@ -1,21 +1,28 @@
import { useQuery } from '@tanstack/react-query'
import { useState } from 'react'
import type { BaoClient } from '../../api/bao'
import { listKvMounts, listSecrets } from '../../api/secrets'
import { engineFor, mountKind } from '../../api/engines/registry'
import { listMounts, listSecrets } from '../../api/secrets'
import { RequireConnection } from '../shared/RequireConnection'
import { AccessPanel } from './AccessPanel'
import { EngineView } from './EngineView'
function Browser({ client }: { client: BaoClient }) {
const mounts = useQuery({ queryKey: ['kv-mounts'], queryFn: () => listKvMounts(client) })
const mounts = useQuery({
queryKey: ['mounts'],
queryFn: async () => (await listMounts(client)).filter((m) => mountKind(m) !== null),
})
const [mountChoice, setMount] = useState<string | null>(null)
const [prefix, setPrefix] = useState('')
const [selected, setSelected] = useState<string | null>(null)
const mount = mountChoice ?? mounts.data?.[0]?.path ?? null
const current = mounts.data?.find((m) => m.path === mountChoice) ?? mounts.data?.[0] ?? null
const mount = current?.path ?? null
const isKv = current !== null && mountKind(current) === 'kv'
const entries = useQuery({
queryKey: ['kv-list', mount, prefix],
queryFn: () => listSecrets(client, mount!, prefix),
enabled: mount !== null,
enabled: isKv,
})
const crumbs = prefix.split('/').filter(Boolean)
@@ -26,28 +33,57 @@ function Browser({ client }: { client: BaoClient }) {
if (mounts.error) return <p role="alert">{mounts.error.message}</p>
if (mounts.isPending) return <p>Loading…</p>
if (!mount) return <p>No KV v2 secrets engines are mounted.</p>
if (!current || !mount) return <p>No secrets engines are mounted.</p>
const where = prefix ? `${mount}${prefix}` : mount
const kv = mounts.data.filter((m) => mountKind(m) === 'kv')
const dynamic = mounts.data.filter((m) => mountKind(m) === 'dynamic')
const mountSelect = mounts.data.length > 1 && (
<select
aria-label="Mount"
value={mount}
onChange={(e) => {
setMount(e.target.value)
go('')
}}
>
{kv.length > 0 && (
<optgroup label="KV">
{kv.map((m) => (
<option key={m.path}>{m.path}</option>
))}
</optgroup>
)}
{[...new Set(dynamic.map((m) => m.type))].map((type) => (
<optgroup key={type} label={engineFor(type).label}>
{dynamic
.filter((m) => m.type === type)
.map((m) => (
<option key={m.path}>{m.path}</option>
))}
</optgroup>
))}
</select>
)
if (!isKv) {
return (
<div className="secrets-layout">
<div className="secrets-browser">
<nav aria-label="Path" className="crumbs">
{mountSelect}
</nav>
</div>
<EngineView mount={current} />
</div>
)
}
return (
<div className="secrets-layout">
<div className="secrets-browser">
<nav aria-label="Path" className="crumbs">
{mounts.data.length > 1 && (
<select
aria-label="Mount"
value={mount}
onChange={(e) => {
setMount(e.target.value)
go('')
}}
>
{mounts.data.map((m) => (
<option key={m.path}>{m.path}</option>
))}
</select>
)}
{mountSelect}
<button type="button" onClick={() => go('')}>
{mount}
</button>