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

+34
View File
@@ -0,0 +1,34 @@
import type { Mount } from '../secrets'
import { isKvV2 } from '../secrets'
/** Describes a dynamic secrets engine the UI can manage. Grows in later phases (role fields, creds, config). */
export interface EngineDef {
/** Engine type as reported by sys/mounts. */
type: string
label: string
/** Path, relative to the mount, that roles are listed/written under. */
rolesPath: string
}
export const ENGINES: Record<string, EngineDef> = {
database: { type: 'database', label: 'Database', rolesPath: 'roles' },
aws: { type: 'aws', label: 'AWS', rolesPath: 'roles' },
ssh: { type: 'ssh', label: 'SSH', rolesPath: 'roles' },
}
/** Engine types that are managed as plain secret stores or by the system, not as dynamic engines. */
const NOT_DYNAMIC = new Set(['kv', 'generic', 'cubbyhole', 'system', 'identity'])
/** Known engine definition, or a generic fallback (raw JSON roles) for any other dynamic engine type. */
export function engineFor(type: string): EngineDef {
return ENGINES[type] ?? { type, label: type, rolesPath: 'roles' }
}
export type MountKind = 'kv' | 'dynamic'
/** KV v2 mounts use the path-tree browser; every other non-system engine is treated as dynamic. */
export function mountKind(m: Mount): MountKind | null {
if (isKvV2(m)) return 'kv'
if (NOT_DYNAMIC.has(m.type)) return null
return 'dynamic'
}
+18 -3
View File
@@ -14,17 +14,32 @@ export interface SecretEntry {
isFolder: boolean
}
export async function listKvMounts(c: BaoClient): Promise<KvMount[]> {
export interface Mount {
/** Mount path with trailing slash, e.g. "database/". */
path: string
/** Engine type as reported by sys/mounts, e.g. "kv", "database", "aws", "ssh". */
type: string
/** KV version ("1" | "2") when the engine is KV. */
version?: string
}
/** Every secrets engine mount visible to the token, sorted by path. */
export async function listMounts(c: BaoClient): Promise<Mount[]> {
const res = await c.request<{ data: Record<string, { type: string; options?: { version?: string } | null }> }>(
'GET',
'sys/mounts',
)
return Object.entries(res.data)
.filter(([, m]) => m.type === 'kv' && m.options?.version === '2')
.map(([path]) => ({ path }))
.map(([path, m]) => ({ path, type: m.type, version: m.options?.version }))
.sort((a, b) => a.path.localeCompare(b.path))
}
export const isKvV2 = (m: Mount) => m.type === 'kv' && m.version === '2'
export async function listKvMounts(c: BaoClient): Promise<KvMount[]> {
return (await listMounts(c)).filter(isKvV2).map(({ path }) => ({ path }))
}
/** Lists metadata only; secret values are never read. `prefix` is "" or ends with "/". */
export async function listSecrets(c: BaoClient, mount: string, prefix: string): Promise<SecretEntry[]> {
const keys = await c.list(`${mount}metadata/${enc(prefix)}`)
+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>