Polish pass: identity forms, confirm dialogs, policy chips, merged grants, narrow screens
- Tokens: bigger show-once token with primary Copy; warn when no policies are selected (OpenBao then inherits the creator's policies). - Identity forms get headings, wider cards and two-column policy lists. - Replace window.confirm with an in-app confirm dialog (falls back to window.confirm without a provider). - Show policies, aliases and members as chips in the identity tables. - Access panel: one row per secret instead of separate data/metadata rules. - Stack graph details below 60rem; phone-width rules for tables, nav, toolbar. - New favicon and page title; label the root "*" path as "everything". Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d67a9c9b62
commit
0a2054eb41
19 files changed
+545
-61
No files matched your search
+2
-1
@@ -4,7 +4,8 @@
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>envbao-admin</title>
|
||||
<meta name="theme-color" content="#0b7a6e" />
|
||||
<title>EnvBao Admin</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
+5
-1
@@ -1 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="46" fill="none" viewBox="0 0 48 46"><path fill="#863bff" d="M25.946 44.938c-.664.845-2.021.375-2.021-.698V33.937a2.26 2.26 0 0 0-2.262-2.262H10.287c-.92 0-1.456-1.04-.92-1.788l7.48-10.471c1.07-1.497 0-3.578-1.842-3.578H1.237c-.92 0-1.456-1.04-.92-1.788L10.013.474c.214-.297.556-.474.92-.474h28.894c.92 0 1.456 1.04.92 1.788l-7.48 10.471c-1.07 1.498 0 3.579 1.842 3.579h11.377c.943 0 1.473 1.088.89 1.83L25.947 44.94z" style="fill:#863bff;fill:color(display-p3 .5252 .23 1);fill-opacity:1"/><mask id="a" width="48" height="46" x="0" y="0" maskUnits="userSpaceOnUse" style="mask-type:alpha"><path fill="#000" d="M25.842 44.938c-.664.844-2.021.375-2.021-.698V33.937a2.26 2.26 0 0 0-2.262-2.262H10.183c-.92 0-1.456-1.04-.92-1.788l7.48-10.471c1.07-1.498 0-3.579-1.842-3.579H1.133c-.92 0-1.456-1.04-.92-1.787L9.91.473c.214-.297.556-.474.92-.474h28.894c.92 0 1.456 1.04.92 1.788l-7.48 10.471c-1.07 1.498 0 3.578 1.842 3.578h11.377c.943 0 1.473 1.088.89 1.832L25.843 44.94z" style="fill:#000;fill-opacity:1"/></mask><g mask="url(#a)"><g filter="url(#b)"><ellipse cx="5.508" cy="14.704" fill="#ede6ff" rx="5.508" ry="14.704" style="fill:#ede6ff;fill:color(display-p3 .9275 .9033 1);fill-opacity:1" transform="matrix(.00324 1 1 -.00324 -4.47 31.516)"/></g><g filter="url(#c)"><ellipse cx="10.399" cy="29.851" fill="#ede6ff" rx="10.399" ry="29.851" style="fill:#ede6ff;fill:color(display-p3 .9275 .9033 1);fill-opacity:1" transform="matrix(.00324 1 1 -.00324 -39.328 7.883)"/></g><g filter="url(#d)"><ellipse cx="5.508" cy="30.487" fill="#7e14ff" rx="5.508" ry="30.487" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(89.814 -25.913 -14.639)scale(1 -1)"/></g><g filter="url(#e)"><ellipse cx="5.508" cy="30.599" fill="#7e14ff" rx="5.508" ry="30.599" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(89.814 -32.644 -3.334)scale(1 -1)"/></g><g filter="url(#f)"><ellipse cx="5.508" cy="30.599" fill="#7e14ff" rx="5.508" ry="30.599" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="matrix(.00324 1 1 -.00324 -34.34 30.47)"/></g><g filter="url(#g)"><ellipse cx="14.072" cy="22.078" fill="#ede6ff" rx="14.072" ry="22.078" style="fill:#ede6ff;fill:color(display-p3 .9275 .9033 1);fill-opacity:1" transform="rotate(93.35 24.506 48.493)scale(-1 1)"/></g><g filter="url(#h)"><ellipse cx="3.47" cy="21.501" fill="#7e14ff" rx="3.47" ry="21.501" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(89.009 28.708 47.59)scale(-1 1)"/></g><g filter="url(#i)"><ellipse cx="3.47" cy="21.501" fill="#7e14ff" rx="3.47" ry="21.501" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(89.009 28.708 47.59)scale(-1 1)"/></g><g filter="url(#j)"><ellipse cx=".387" cy="8.972" fill="#7e14ff" rx="4.407" ry="29.108" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(39.51 .387 8.972)"/></g><g filter="url(#k)"><ellipse cx="47.523" cy="-6.092" fill="#7e14ff" rx="4.407" ry="29.108" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(37.892 47.523 -6.092)"/></g><g filter="url(#l)"><ellipse cx="41.412" cy="6.333" fill="#47bfff" rx="5.971" ry="9.665" style="fill:#47bfff;fill:color(display-p3 .2799 .748 1);fill-opacity:1" transform="rotate(37.892 41.412 6.333)"/></g><g filter="url(#m)"><ellipse cx="-1.879" cy="38.332" fill="#7e14ff" rx="4.407" ry="29.108" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(37.892 -1.88 38.332)"/></g><g filter="url(#n)"><ellipse cx="-1.879" cy="38.332" fill="#7e14ff" rx="4.407" ry="29.108" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(37.892 -1.88 38.332)"/></g><g filter="url(#o)"><ellipse cx="35.651" cy="29.907" fill="#7e14ff" rx="4.407" ry="29.108" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(37.892 35.651 29.907)"/></g><g filter="url(#p)"><ellipse cx="38.418" cy="32.4" fill="#47bfff" rx="5.971" ry="15.297" style="fill:#47bfff;fill:color(display-p3 .2799 .748 1);fill-opacity:1" transform="rotate(37.892 38.418 32.4)"/></g></g><defs><filter id="b" width="60.045" height="41.654" x="-19.77" y="16.149" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17158" stdDeviation="7.659"/></filter><filter id="c" width="90.34" height="51.437" x="-54.613" y="-7.533" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17158" stdDeviation="7.659"/></filtLine truncated
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
|
||||
<rect width="32" height="32" rx="7" fill="#0b7a6e"/>
|
||||
<circle cx="16" cy="13" r="5" fill="#fff"/>
|
||||
<path d="M13.5 16h5l2.2 9h-9.4z" fill="#fff"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 9.3 KiB After Width: | Height: | Size: 241 B |
@@ -2,6 +2,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { createBrowserRouter, RouterProvider } from 'react-router'
|
||||
import { SessionGuard } from './api/SessionGuard'
|
||||
import { SessionProvider } from './api/session'
|
||||
import { ConfirmProvider } from './features/shared/ConfirmProvider'
|
||||
import { routes } from './routes'
|
||||
|
||||
const queryClient = new QueryClient()
|
||||
@@ -11,8 +12,10 @@ function App() {
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<SessionProvider>
|
||||
<ConfirmProvider>
|
||||
<SessionGuard />
|
||||
<RouterProvider router={router} />
|
||||
</ConfirmProvider>
|
||||
</SessionProvider>
|
||||
</QueryClientProvider>
|
||||
)
|
||||
|
||||
@@ -53,7 +53,7 @@ function setup() {
|
||||
|
||||
test('shows managed grants and read-only other policies', async () => {
|
||||
const user = setup()
|
||||
expect(await screen.findByText('secret/data/app/*')).toBeInTheDocument()
|
||||
expect(await screen.findByText('secret/app/*')).toBeInTheDocument()
|
||||
const other = screen.getByText('default').closest('li')!
|
||||
await user.click(within(other).getByRole('button', { name: 'View default' }))
|
||||
expect(await within(other).findByText(/capabilities/)).toBeInTheDocument()
|
||||
@@ -118,9 +118,9 @@ test('revoke asks for confirmation', async () => {
|
||||
vi.mocked(grants.revokeAccess).mockResolvedValue()
|
||||
const user = setup()
|
||||
const confirm = vi.spyOn(window, 'confirm').mockReturnValueOnce(false).mockReturnValueOnce(true)
|
||||
await user.click(await screen.findByRole('button', { name: 'Revoke secret/data/app/*' }))
|
||||
await user.click(await screen.findByRole('button', { name: 'Revoke secret/app/*' }))
|
||||
expect(grants.revokeAccess).not.toHaveBeenCalled()
|
||||
await user.click(screen.getByRole('button', { name: 'Revoke secret/data/app/*' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Revoke secret/app/*' }))
|
||||
expect(grants.revokeAccess).toHaveBeenCalledWith(client, target, ['secret/data/app/*'])
|
||||
confirm.mockRestore()
|
||||
})
|
||||
|
||||
@@ -4,7 +4,10 @@ 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 { groupGrants } from '../../model/grantRows'
|
||||
import { CapabilityChips } from '../shared/CapabilityChips'
|
||||
import { PathPicker } from './PathPicker'
|
||||
import { useConfirm } from '../shared/useConfirm'
|
||||
|
||||
interface Props {
|
||||
client: BaoClient
|
||||
@@ -28,6 +31,7 @@ function PolicyView({ client, name }: { client: BaoClient; name: string }) {
|
||||
|
||||
export function AccessEditor({ client, target, onClose }: Props) {
|
||||
const qc = useQueryClient()
|
||||
const confirm = useConfirm()
|
||||
const stateKey = ['grant-state', target.kind, target.name]
|
||||
const state = useQuery({ queryKey: stateKey, queryFn: () => getGrantState(client, target) })
|
||||
const mounts = useQuery({ queryKey: ['kv-mounts'], queryFn: () => listKvMounts(client) })
|
||||
@@ -53,7 +57,7 @@ export function AccessEditor({ client, target, onClose }: Props) {
|
||||
return done()
|
||||
},
|
||||
})
|
||||
const revoke = useMutation({ mutationFn: (path: string) => revokeAccess(client, target, [path]), onSuccess: done })
|
||||
const revoke = useMutation({ mutationFn: (paths: string[]) => revokeAccess(client, target, paths), onSuccess: done })
|
||||
|
||||
function submit(e: FormEvent) {
|
||||
e.preventDefault()
|
||||
@@ -63,6 +67,7 @@ export function AccessEditor({ client, target, onClose }: Props) {
|
||||
}
|
||||
|
||||
const s = state.data
|
||||
const rows = groupGrants(s?.managed?.grants ?? [], mounts.data?.map((m) => m.path) ?? [])
|
||||
const editable = !s?.managed || s.managed.editable
|
||||
|
||||
return (
|
||||
@@ -93,28 +98,38 @@ export function AccessEditor({ client, target, onClose }: Props) {
|
||||
</p>
|
||||
)}
|
||||
{showRaw && <pre>{s.hcl}</pre>}
|
||||
{s.managed?.grants.length ? (
|
||||
{rows.length ? (
|
||||
<table aria-label="Granted by EnvBao">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Path</th>
|
||||
<th>Capabilities</th>
|
||||
<th>Secret</th>
|
||||
<th>Can</th>
|
||||
<th />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{s.managed.grants.map((g) => (
|
||||
<tr key={g.path}>
|
||||
{rows.map((row) => (
|
||||
<tr key={row.display}>
|
||||
<td>
|
||||
<code>{g.path}</code>
|
||||
<code>{row.display}</code>
|
||||
{row.wildcard && <span className="tag">everything inside</span>}
|
||||
</td>
|
||||
<td>
|
||||
<CapabilityChips capabilities={row.capabilities} />
|
||||
</td>
|
||||
<td>{g.capabilities.join(', ')}</td>
|
||||
<td>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Revoke ${g.path}`}
|
||||
aria-label={`Revoke ${row.display}`}
|
||||
disabled={!editable}
|
||||
onClick={() => window.confirm(`Revoke ${g.capabilities.join(', ')} on ${g.path}?`) && revoke.mutate(g.path)}
|
||||
onClick={async () => {
|
||||
const ok = await confirm({
|
||||
title: `Revoke access to ${row.display}?`,
|
||||
message: `Removes ${row.capabilities.join(', ')} from ${target.kind} “${target.name}”.`,
|
||||
confirmLabel: 'Revoke',
|
||||
})
|
||||
if (ok) revoke.mutate(row.paths)
|
||||
}}
|
||||
>
|
||||
Revoke
|
||||
</button>
|
||||
|
||||
@@ -4,6 +4,7 @@ import { revokeAccess } from '../../api/grants'
|
||||
import type { AccessGraph, GraphEdge, GraphNode, PolicyInput } from '../../model/graph'
|
||||
import { parseManagedPolicy, type GrantTarget } from '../../model/managed'
|
||||
import { CapabilityChips } from '../shared/CapabilityChips'
|
||||
import { useConfirm } from '../shared/useConfirm'
|
||||
|
||||
export type Selection = { kind: 'node'; id: string } | { kind: 'edge'; id: string }
|
||||
|
||||
@@ -147,6 +148,7 @@ function NodeDetails({ node, full, policies }: { node: GraphNode; full: AccessGr
|
||||
|
||||
function EdgeDetails({ client, edge, full, policies, onRevoked }: { client: BaoClient; edge: GraphEdge; full: AccessGraph } & Pick<Props, 'policies' | 'onRevoked'>) {
|
||||
const qc = useQueryClient()
|
||||
const confirm = useConfirm()
|
||||
const from = nodeById(full, edge.source)
|
||||
const to = nodeById(full, edge.target)
|
||||
const isGrant = from?.type === 'policy' && to?.type === 'path'
|
||||
@@ -186,10 +188,14 @@ function EdgeDetails({ client, edge, full, policies, onRevoked }: { client: BaoC
|
||||
<button
|
||||
type="button"
|
||||
className="danger"
|
||||
onClick={() =>
|
||||
window.confirm(`Revoke access to ${to!.label} from ${ownerMatch[1]} "${ownerMatch[2]}"? Other policies are unaffected.`) &&
|
||||
revoke.mutate()
|
||||
}
|
||||
onClick={async () => {
|
||||
const ok = await confirm({
|
||||
title: `Revoke access to ${to!.label}?`,
|
||||
message: `Removes it from ${ownerMatch[1]} “${ownerMatch[2]}”. Other policies are unaffected.`,
|
||||
confirmLabel: 'Revoke',
|
||||
})
|
||||
if (ok) revoke.mutate()
|
||||
}}
|
||||
disabled={revoke.isPending}
|
||||
>
|
||||
Revoke
|
||||
|
||||
@@ -7,7 +7,7 @@ export function GraphNodeCard({ data }: NodeProps) {
|
||||
<div className="gnode-card">
|
||||
<Handle type="target" position={Position.Left} isConnectable={false} />
|
||||
{kind && <span className="gnode-kind">{kind}</span>}
|
||||
<span className="gnode-label">{label}</span>
|
||||
<span className="gnode-label">{label === '*' ? 'everything (*)' : label}</span>
|
||||
<Handle type="source" position={Position.Right} isConnectable={false} />
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -5,6 +5,8 @@ import { addAlias, deleteAlias, deleteEntity, listEntities, saveEntity, userpass
|
||||
import { AccessEditor } from '../access/AccessEditor'
|
||||
import { ListState } from '../shared/ListState'
|
||||
import { PolicyPicker } from '../shared/PolicyPicker'
|
||||
import { useConfirm } from '../shared/useConfirm'
|
||||
import { NameChips, PolicyChips } from '../shared/PolicyChips'
|
||||
|
||||
interface Draft {
|
||||
name: string
|
||||
@@ -15,6 +17,7 @@ interface Draft {
|
||||
|
||||
export function EntitiesTab({ client }: { client: BaoClient }) {
|
||||
const qc = useQueryClient()
|
||||
const confirm = useConfirm()
|
||||
const entities = useQuery({ queryKey: ['entities'], queryFn: () => listEntities(client) })
|
||||
const [draft, setDraft] = useState<Draft | null>(null)
|
||||
const [accessFor, setAccessFor] = useState<string | null>(null)
|
||||
@@ -71,19 +74,26 @@ export function EntitiesTab({ client }: { client: BaoClient }) {
|
||||
{entities.data?.map((e) => (
|
||||
<tr key={e.id}>
|
||||
<td>{e.name}</td>
|
||||
<td>{e.aliases.map((a) => a.name).join(', ') || '—'}</td>
|
||||
<td>{e.policies.join(', ') || '—'}</td>
|
||||
<td>
|
||||
<NameChips names={e.aliases.map((a) => a.name)} />
|
||||
</td>
|
||||
<td>
|
||||
<PolicyChips policies={e.policies} />
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" aria-label={`Access ${e.name}`} onClick={() => setAccessFor(e.name)}>
|
||||
Access
|
||||
</button>{' '}
|
||||
</button>
|
||||
<button type="button" aria-label={`Edit ${e.name}`} onClick={() => setDraft({ name: e.name, policies: e.policies, isNew: false, entity: e })}>
|
||||
Edit
|
||||
</button>{' '}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Delete ${e.name}`}
|
||||
onClick={() => window.confirm(`Delete entity "${e.name}" and its aliases?`) && remove.mutate(e.name)}
|
||||
onClick={async () => {
|
||||
if (await confirm({ title: `Delete entity “${e.name}”?`, message: 'Its aliases are deleted too. This cannot be undone.', confirmLabel: 'Delete' }))
|
||||
remove.mutate(e.name)
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
@@ -107,10 +117,10 @@ export function EntitiesTab({ client }: { client: BaoClient }) {
|
||||
</label>
|
||||
<PolicyPicker client={client} value={draft.policies} onChange={(policies) => setDraft({ ...draft, policies })} />
|
||||
{save.error && <p role="alert">{save.error.message}</p>}
|
||||
<div>
|
||||
<div className="form-actions">
|
||||
<button type="submit" disabled={save.isPending}>
|
||||
Save
|
||||
</button>{' '}
|
||||
</button>
|
||||
<button type="button" onClick={() => setDraft(null)}>
|
||||
Cancel
|
||||
</button>
|
||||
@@ -121,7 +131,13 @@ export function EntitiesTab({ client }: { client: BaoClient }) {
|
||||
{draft.entity.aliases.map((a) => (
|
||||
<div key={a.id}>
|
||||
{a.name}{' '}
|
||||
<button type="button" onClick={() => window.confirm(`Remove alias "${a.name}"?`) && detach.mutate(a.id)}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={async () => {
|
||||
if (await confirm({ title: `Remove alias “${a.name}”?`, message: 'The userpass user is no longer linked to this entity.', confirmLabel: 'Remove' }))
|
||||
detach.mutate(a.id)
|
||||
}}
|
||||
>
|
||||
Remove
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -5,6 +5,8 @@ import { deleteGroup, listEntities, listGroups, saveGroup } from '../../api/iden
|
||||
import { AccessEditor } from '../access/AccessEditor'
|
||||
import { ListState } from '../shared/ListState'
|
||||
import { PolicyPicker } from '../shared/PolicyPicker'
|
||||
import { useConfirm } from '../shared/useConfirm'
|
||||
import { NameChips, PolicyChips } from '../shared/PolicyChips'
|
||||
|
||||
interface Draft {
|
||||
name: string
|
||||
@@ -15,6 +17,7 @@ interface Draft {
|
||||
|
||||
export function GroupsTab({ client }: { client: BaoClient }) {
|
||||
const qc = useQueryClient()
|
||||
const confirm = useConfirm()
|
||||
const groups = useQuery({ queryKey: ['groups'], queryFn: () => listGroups(client) })
|
||||
const entities = useQuery({ queryKey: ['entities'], queryFn: () => listEntities(client) })
|
||||
const [draft, setDraft] = useState<Draft | null>(null)
|
||||
@@ -54,20 +57,26 @@ export function GroupsTab({ client }: { client: BaoClient }) {
|
||||
{groups.data?.map((g) => (
|
||||
<tr key={g.id}>
|
||||
<td>{g.name}</td>
|
||||
<td>{g.member_entity_ids.map(nameOf).join(', ') || '—'}</td>
|
||||
<td>{g.policies.join(', ') || '—'}</td>
|
||||
<td>
|
||||
<NameChips names={g.member_entity_ids.map(nameOf)} />
|
||||
</td>
|
||||
<td>
|
||||
<PolicyChips policies={g.policies} />
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" aria-label={`Access ${g.name}`} onClick={() => setAccessFor(g.name)}>
|
||||
Access
|
||||
</button>{' '}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Edit ${g.name}`}
|
||||
onClick={() => setDraft({ name: g.name, policies: g.policies, members: g.member_entity_ids, isNew: false })}
|
||||
>
|
||||
Edit
|
||||
</button>{' '}
|
||||
<button type="button" aria-label={`Delete ${g.name}`} onClick={() => window.confirm(`Delete group "${g.name}"?`) && remove.mutate(g.name)}>
|
||||
</button>
|
||||
<button type="button" aria-label={`Delete ${g.name}`} onClick={async () => {
|
||||
if (await confirm({ title: `Delete group “${g.name}”?`, message: 'This cannot be undone.', confirmLabel: 'Delete' })) remove.mutate(g.name)
|
||||
}}>
|
||||
Delete
|
||||
</button>
|
||||
</td>
|
||||
@@ -88,7 +97,7 @@ export function GroupsTab({ client }: { client: BaoClient }) {
|
||||
Name
|
||||
<input value={draft.name} disabled={!draft.isNew} onChange={(e) => setDraft({ ...draft, name: e.target.value })} required />
|
||||
</label>
|
||||
<fieldset>
|
||||
<fieldset className="pick-grid">
|
||||
<legend>Member entities</legend>
|
||||
{entities.data?.map((e) => (
|
||||
<label key={e.id} className="check">
|
||||
@@ -106,10 +115,10 @@ export function GroupsTab({ client }: { client: BaoClient }) {
|
||||
</fieldset>
|
||||
<PolicyPicker client={client} value={draft.policies} onChange={(policies) => setDraft({ ...draft, policies })} />
|
||||
{save.error && <p role="alert">{save.error.message}</p>}
|
||||
<div>
|
||||
<div className="form-actions">
|
||||
<button type="submit" disabled={save.isPending}>
|
||||
Save
|
||||
</button>{' '}
|
||||
</button>
|
||||
<button type="button" onClick={() => setDraft(null)}>
|
||||
Cancel
|
||||
</button>
|
||||
|
||||
@@ -5,6 +5,8 @@ import { createToken, listTokens, revokeToken, type CreatedToken } from '../../a
|
||||
import { useSession } from '../../api/useSession'
|
||||
import { ListState } from '../shared/ListState'
|
||||
import { PolicyPicker } from '../shared/PolicyPicker'
|
||||
import { useConfirm } from '../shared/useConfirm'
|
||||
import { PolicyChips } from '../shared/PolicyChips'
|
||||
|
||||
interface Draft {
|
||||
displayName: string
|
||||
@@ -25,6 +27,7 @@ function formatTtl(seconds: number): string {
|
||||
|
||||
export function TokensTab({ client }: { client: BaoClient }) {
|
||||
const qc = useQueryClient()
|
||||
const confirm = useConfirm()
|
||||
const { tokenInfo } = useSession()
|
||||
const tokens = useQuery({ queryKey: ['tokens'], queryFn: () => listTokens(client) })
|
||||
const [draft, setDraft] = useState<Draft | null>(null)
|
||||
@@ -68,14 +71,16 @@ export function TokensTab({ client }: { client: BaoClient }) {
|
||||
<p>
|
||||
<strong>Copy this token now. It will not be shown again.</strong>
|
||||
</p>
|
||||
<code>{created.token}</code>{' '}
|
||||
<button type="button" onClick={copy}>
|
||||
<code className="token-value">{created.token}</code>
|
||||
<div className="form-actions">
|
||||
<button type="button" className="primary" onClick={copy}>
|
||||
{copied ? 'Copied' : 'Copy'}
|
||||
</button>{' '}
|
||||
</button>
|
||||
<button type="button" onClick={() => setCreated(null)}>
|
||||
Done
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<ListState query={tokens} empty="No tokens." />
|
||||
{!!tokens.data?.length && (
|
||||
@@ -98,7 +103,9 @@ export function TokensTab({ client }: { client: BaoClient }) {
|
||||
{t.display_name || '—'}
|
||||
{isSelf ? ' (you)' : ''}
|
||||
</td>
|
||||
<td>{t.policies.join(', ') || '—'}</td>
|
||||
<td>
|
||||
<PolicyChips policies={t.policies} />
|
||||
</td>
|
||||
<td>{formatTtl(t.ttl)}</td>
|
||||
<td>
|
||||
<code>{t.accessor.slice(0, 8)}…</code>
|
||||
@@ -109,10 +116,14 @@ export function TokensTab({ client }: { client: BaoClient }) {
|
||||
aria-label={`Revoke ${t.display_name || t.accessor}`}
|
||||
disabled={isSelf}
|
||||
title={isSelf ? 'This is the token you are signed in with' : undefined}
|
||||
onClick={() =>
|
||||
window.confirm(`Revoke token "${t.display_name || t.accessor}"? Tokens created from it are revoked too.`) &&
|
||||
revoke.mutate(t.accessor)
|
||||
}
|
||||
onClick={async () => {
|
||||
const ok = await confirm({
|
||||
title: `Revoke token “${t.display_name || t.accessor}”?`,
|
||||
message: 'Tokens created from it are revoked too.',
|
||||
confirmLabel: 'Revoke',
|
||||
})
|
||||
if (ok) revoke.mutate(t.accessor)
|
||||
}}
|
||||
>
|
||||
Revoke
|
||||
</button>
|
||||
@@ -130,7 +141,8 @@ export function TokensTab({ client }: { client: BaoClient }) {
|
||||
</button>
|
||||
)}
|
||||
{draft && (
|
||||
<form onSubmit={submit} aria-label="New token">
|
||||
<form onSubmit={submit} aria-label="New token" className="wide">
|
||||
<h3>New token</h3>
|
||||
<label>
|
||||
Display name
|
||||
<input value={draft.displayName} onChange={(e) => setDraft({ ...draft, displayName: e.target.value })} />
|
||||
@@ -143,15 +155,23 @@ export function TokensTab({ client }: { client: BaoClient }) {
|
||||
<input type="checkbox" checked={draft.renewable} onChange={(e) => setDraft({ ...draft, renewable: e.target.checked })} /> Renewable
|
||||
</label>
|
||||
<label className="check">
|
||||
<input type="checkbox" checked={draft.orphan} onChange={(e) => setDraft({ ...draft, orphan: e.target.checked })} /> Orphan
|
||||
(outlives the token you are signed in with; requires sudo)
|
||||
<input type="checkbox" checked={draft.orphan} onChange={(e) => setDraft({ ...draft, orphan: e.target.checked })} />
|
||||
<span>
|
||||
Orphan <span className="hint">(outlives the token you are signed in with; requires sudo)</span>
|
||||
</span>
|
||||
</label>
|
||||
<PolicyPicker client={client} value={draft.policies} onChange={(policies) => setDraft({ ...draft, policies })} />
|
||||
{draft.policies.length === 0 && (
|
||||
<p className="note-warn">
|
||||
No policies selected: OpenBao gives the new token the same policies as yours
|
||||
{tokenInfo?.policies.length ? ` (${tokenInfo.policies.join(', ')})` : ''}.
|
||||
</p>
|
||||
)}
|
||||
{create.error && <p role="alert">{create.error.message}</p>}
|
||||
<div>
|
||||
<div className="form-actions">
|
||||
<button type="submit" disabled={create.isPending}>
|
||||
Create
|
||||
</button>{' '}
|
||||
</button>
|
||||
<button type="button" onClick={() => setDraft(null)}>
|
||||
Cancel
|
||||
</button>
|
||||
|
||||
@@ -5,6 +5,8 @@ import { deleteUser, listUsers, saveUser } from '../../api/identities'
|
||||
import { AccessEditor } from '../access/AccessEditor'
|
||||
import { ListState } from '../shared/ListState'
|
||||
import { PolicyPicker } from '../shared/PolicyPicker'
|
||||
import { useConfirm } from '../shared/useConfirm'
|
||||
import { PolicyChips } from '../shared/PolicyChips'
|
||||
|
||||
interface Draft {
|
||||
name: string
|
||||
@@ -18,6 +20,7 @@ const empty: Draft = { name: '', password: '', policies: [], ttl: '', isNew: tru
|
||||
|
||||
export function UsersTab({ client }: { client: BaoClient }) {
|
||||
const qc = useQueryClient()
|
||||
const confirm = useConfirm()
|
||||
const users = useQuery({ queryKey: ['users'], queryFn: () => listUsers(client) })
|
||||
const [draft, setDraft] = useState<Draft | null>(null)
|
||||
const [accessFor, setAccessFor] = useState<string | null>(null)
|
||||
@@ -55,18 +58,22 @@ export function UsersTab({ client }: { client: BaoClient }) {
|
||||
{users.data?.map((u) => (
|
||||
<tr key={u.name}>
|
||||
<td>{u.name}</td>
|
||||
<td>{u.policies.join(', ') || '—'}</td>
|
||||
<td>
|
||||
<PolicyChips policies={u.policies} />
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" aria-label={`Access ${u.name}`} onClick={() => setAccessFor(u.name)}>
|
||||
Access
|
||||
</button>{' '}
|
||||
</button>
|
||||
<button type="button" aria-label={`Edit ${u.name}`} onClick={() => setDraft({ ...u, password: '', ttl: u.ttl ? `${u.ttl}s` : '', isNew: false })}>
|
||||
Edit
|
||||
</button>{' '}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Delete ${u.name}`}
|
||||
onClick={() => window.confirm(`Delete user "${u.name}"? This cannot be undone.`) && remove.mutate(u.name)}
|
||||
onClick={async () => {
|
||||
if (await confirm({ title: `Delete user “${u.name}”?`, message: 'This cannot be undone.', confirmLabel: 'Delete' })) remove.mutate(u.name)
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
@@ -105,10 +112,10 @@ export function UsersTab({ client }: { client: BaoClient }) {
|
||||
</label>
|
||||
<PolicyPicker client={client} value={draft.policies} onChange={(policies) => setDraft({ ...draft, policies })} />
|
||||
{save.error && <p role="alert">{save.error.message}</p>}
|
||||
<div>
|
||||
<div className="form-actions">
|
||||
<button type="submit" disabled={save.isPending}>
|
||||
Save
|
||||
</button>{' '}
|
||||
</button>
|
||||
<button type="button" onClick={() => setDraft(null)}>
|
||||
Cancel
|
||||
</button>
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import { fireEvent, render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { useState } from 'react'
|
||||
import { expect, test } from 'vitest'
|
||||
import { ConfirmProvider } from './ConfirmProvider'
|
||||
import { useConfirm } from './useConfirm'
|
||||
|
||||
function Trigger() {
|
||||
const confirm = useConfirm()
|
||||
const [answer, setAnswer] = useState('none')
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
onClick={async () =>
|
||||
setAnswer(
|
||||
(await confirm({ title: 'Delete user “alice”?', message: 'This cannot be undone.', confirmLabel: 'Delete' })) ? 'yes' : 'no',
|
||||
)
|
||||
}
|
||||
>
|
||||
ask
|
||||
</button>
|
||||
<output>{answer}</output>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
function setup() {
|
||||
render(
|
||||
<ConfirmProvider>
|
||||
<Trigger />
|
||||
</ConfirmProvider>,
|
||||
)
|
||||
return userEvent.setup()
|
||||
}
|
||||
|
||||
test('shows the question and resolves true on confirm', async () => {
|
||||
const user = setup()
|
||||
await user.click(screen.getByRole('button', { name: 'ask' }))
|
||||
const dialog = await screen.findByRole('dialog', { name: 'Delete user “alice”?' })
|
||||
expect(dialog).toHaveTextContent('This cannot be undone.')
|
||||
await user.click(screen.getByRole('button', { name: 'Delete' }))
|
||||
expect(await screen.findByText('yes')).toBeInTheDocument()
|
||||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('resolves false on cancel, and Cancel has focus first', async () => {
|
||||
const user = setup()
|
||||
await user.click(screen.getByRole('button', { name: 'ask' }))
|
||||
expect(await screen.findByRole('button', { name: 'Cancel' })).toHaveFocus()
|
||||
await user.click(screen.getByRole('button', { name: 'Cancel' }))
|
||||
expect(await screen.findByText('no')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('resolves false when the dialog is cancelled', async () => {
|
||||
const user = setup()
|
||||
await user.click(screen.getByRole('button', { name: 'ask' }))
|
||||
// Browsers fire "cancel" on a modal dialog for Escape; jsdom does not, so send it directly.
|
||||
fireEvent(await screen.findByRole('dialog'), new Event('cancel', { cancelable: true }))
|
||||
expect(await screen.findByText('no')).toBeInTheDocument()
|
||||
})
|
||||
@@ -0,0 +1,59 @@
|
||||
import { useCallback, useEffect, useRef, useState, type MouseEvent, type ReactNode } from 'react'
|
||||
import { ConfirmContext, type Confirm, type ConfirmOptions } from './useConfirm'
|
||||
|
||||
interface Pending {
|
||||
options: ConfirmOptions
|
||||
resolve: (ok: boolean) => void
|
||||
}
|
||||
|
||||
/** Renders one modal confirmation dialog for the whole app; open it with useConfirm(). */
|
||||
export function ConfirmProvider({ children }: { children: ReactNode }) {
|
||||
const [pending, setPending] = useState<Pending | null>(null)
|
||||
const dialog = useRef<HTMLDialogElement>(null)
|
||||
|
||||
const confirm = useCallback<Confirm>((options) => new Promise((resolve) => setPending({ options, resolve })), [])
|
||||
|
||||
useEffect(() => {
|
||||
const el = dialog.current
|
||||
if (!pending || !el) return
|
||||
// showModal gives focus trapping, Escape and an inert page; fall back to a plain open dialog without it.
|
||||
if (typeof el.showModal === 'function') el.showModal()
|
||||
else el.setAttribute('open', '')
|
||||
}, [pending])
|
||||
|
||||
function settle(ok: boolean) {
|
||||
pending?.resolve(ok)
|
||||
setPending(null)
|
||||
}
|
||||
|
||||
return (
|
||||
<ConfirmContext value={confirm}>
|
||||
{children}
|
||||
{pending && (
|
||||
<dialog
|
||||
ref={dialog}
|
||||
className="confirm-dialog"
|
||||
aria-labelledby="confirm-title"
|
||||
aria-describedby={pending.options.message ? 'confirm-message' : undefined}
|
||||
onCancel={(e) => {
|
||||
e.preventDefault()
|
||||
settle(false)
|
||||
}}
|
||||
// A click on the backdrop lands on the dialog element itself, not on its content.
|
||||
onClick={(e: MouseEvent<HTMLDialogElement>) => e.target === e.currentTarget && settle(false)}
|
||||
>
|
||||
<h2 id="confirm-title">{pending.options.title}</h2>
|
||||
{pending.options.message && <p id="confirm-message">{pending.options.message}</p>}
|
||||
<div className="confirm-actions">
|
||||
<button type="button" autoFocus onClick={() => settle(false)}>
|
||||
Cancel
|
||||
</button>
|
||||
<button type="button" className="danger-solid" onClick={() => settle(true)}>
|
||||
{pending.options.confirmLabel}
|
||||
</button>
|
||||
</div>
|
||||
</dialog>
|
||||
)}
|
||||
</ConfirmContext>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { isManagedPolicy } from '../../model/graph'
|
||||
|
||||
function Empty() {
|
||||
return <span className="hint">None</span>
|
||||
}
|
||||
|
||||
/** Policy names as chips; the ones EnvBao manages are tinted. */
|
||||
export function PolicyChips({ policies }: { policies: readonly string[] }) {
|
||||
if (policies.length === 0) return <Empty />
|
||||
return (
|
||||
<ul className="chips plain">
|
||||
{policies.map((p) => (
|
||||
<li key={p} className={isManagedPolicy(p) ? 'managed' : undefined}>
|
||||
{p}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
|
||||
/** Plain names (aliases, members) as neutral chips. */
|
||||
export function NameChips({ names }: { names: readonly string[] }) {
|
||||
if (names.length === 0) return <Empty />
|
||||
return (
|
||||
<ul className="chips plain">
|
||||
{names.map((n) => (
|
||||
<li key={n}>{n}</li>
|
||||
))}
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
@@ -13,7 +13,7 @@ export function PolicyPicker({ client, value, onChange }: Props) {
|
||||
// Keep policies that are attached but no longer exist selectable, so editing doesn't drop them silently.
|
||||
const names = [...new Set([...(data ?? []), ...value])].filter((n) => n !== 'root').sort()
|
||||
return (
|
||||
<fieldset>
|
||||
<fieldset className="pick-grid">
|
||||
<legend>Policies</legend>
|
||||
{error && <p role="alert">Could not load policies: {error.message}</p>}
|
||||
{names.map((n) => (
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { createContext, useContext } from 'react'
|
||||
|
||||
export interface ConfirmOptions {
|
||||
title: string
|
||||
message?: string
|
||||
/** Label of the confirming button, e.g. "Delete". */
|
||||
confirmLabel: string
|
||||
}
|
||||
|
||||
export type Confirm = (options: ConfirmOptions) => Promise<boolean>
|
||||
|
||||
export const ConfirmContext = createContext<Confirm | null>(null)
|
||||
|
||||
/** Ask before a destructive action. Falls back to the browser's confirm() when no provider is mounted. */
|
||||
export function useConfirm(): Confirm {
|
||||
const confirm = useContext(ConfirmContext)
|
||||
return confirm ?? (async (o) => window.confirm(o.message ? `${o.title}\n${o.message}` : o.title))
|
||||
}
|
||||
+163
-5
@@ -20,6 +20,7 @@
|
||||
--accent-soft: light-dark(#e2f3f0, #12302c);
|
||||
--danger: light-dark(#b42318, #ff8a7a);
|
||||
--danger-soft: light-dark(#fdecea, #3a1815);
|
||||
--danger-ink: light-dark(#ffffff, #2a0b07);
|
||||
--warn: light-dark(#8a5a00, #f2c14e);
|
||||
--warn-soft: light-dark(#fff4d6, #3a2d0c);
|
||||
|
||||
@@ -898,7 +899,7 @@ td:last-child button + button {
|
||||
}
|
||||
|
||||
@media (max-width: 48rem) {
|
||||
.shell nav {
|
||||
.shell > nav {
|
||||
flex-wrap: wrap;
|
||||
padding: 0 var(--s4);
|
||||
}
|
||||
@@ -906,10 +907,6 @@ td:last-child button + button {
|
||||
.shell main {
|
||||
padding: var(--s5) var(--s4);
|
||||
}
|
||||
|
||||
.graph-layout {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
@@ -1158,3 +1155,164 @@ button.link:hover:not(:disabled) {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- Identity forms ---------- */
|
||||
|
||||
form.wide {
|
||||
max-width: 36rem;
|
||||
}
|
||||
|
||||
form > h3 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
gap: var(--s2);
|
||||
}
|
||||
|
||||
/* Checkbox lists (policies, members) run in columns instead of one long stack. */
|
||||
.pick-grid {
|
||||
grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
|
||||
}
|
||||
|
||||
.pick-grid legend,
|
||||
.pick-grid > p {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
form .note-warn {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
button.primary {
|
||||
background: var(--accent);
|
||||
border-color: var(--accent);
|
||||
color: var(--accent-ink);
|
||||
}
|
||||
|
||||
button.primary:hover:not(:disabled) {
|
||||
background: var(--accent);
|
||||
border-color: var(--accent);
|
||||
filter: brightness(1.08);
|
||||
}
|
||||
|
||||
/* The one-time token: large, selectable, impossible to mistake for table content. */
|
||||
.secret-once p {
|
||||
margin: 0 0 var(--s3);
|
||||
}
|
||||
|
||||
.token-value {
|
||||
display: block;
|
||||
margin-bottom: var(--s3);
|
||||
padding: var(--s3) var(--s4);
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--warn);
|
||||
border-radius: var(--radius);
|
||||
font-size: var(--text);
|
||||
overflow-wrap: anywhere;
|
||||
user-select: all;
|
||||
}
|
||||
|
||||
/* ---------- Narrow screens ---------- */
|
||||
|
||||
@media (max-width: 60rem) {
|
||||
.graph-layout {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.graph-canvas {
|
||||
height: 60vh;
|
||||
}
|
||||
|
||||
.graph-details {
|
||||
max-height: none;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 40rem) {
|
||||
/* Wide tables scroll sideways inside themselves rather than widening the page. */
|
||||
table {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.shell > nav .whoami {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.graph-toolbar label:not(.check),
|
||||
.graph-toolbar input:not([type='checkbox']) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.graph-toolbar button {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.graph-legend .grow {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.access-head,
|
||||
.connection-head {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- Confirm dialog ---------- */
|
||||
|
||||
.confirm-dialog {
|
||||
width: min(28rem, calc(100% - 2rem));
|
||||
padding: var(--s5);
|
||||
background: var(--surface);
|
||||
color: var(--ink);
|
||||
border: 1px solid var(--line-strong);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: 0 12px 40px rgb(0 0 0 / 0.35);
|
||||
}
|
||||
|
||||
.confirm-dialog::backdrop {
|
||||
background: rgb(0 0 0 / 0.55);
|
||||
}
|
||||
|
||||
.confirm-dialog h2 {
|
||||
margin: 0 0 var(--s2);
|
||||
font-size: var(--text-lg);
|
||||
}
|
||||
|
||||
.confirm-dialog p {
|
||||
margin: 0 0 var(--s5);
|
||||
color: var(--ink-soft);
|
||||
}
|
||||
|
||||
.confirm-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: var(--s2);
|
||||
}
|
||||
|
||||
button.danger-solid {
|
||||
background: var(--danger);
|
||||
border-color: var(--danger);
|
||||
color: var(--danger-ink);
|
||||
}
|
||||
|
||||
button.danger-solid:hover:not(:disabled) {
|
||||
background: var(--danger);
|
||||
border-color: var(--danger);
|
||||
filter: brightness(1.08);
|
||||
}
|
||||
|
||||
/* Policy and name chips in tables: neutral, with EnvBao-managed policies tinted. */
|
||||
.chips.plain li {
|
||||
background: var(--surface-sunken);
|
||||
border: 1px solid var(--line);
|
||||
color: var(--ink-soft);
|
||||
}
|
||||
|
||||
.chips.plain li.managed {
|
||||
background: var(--accent-soft);
|
||||
border-color: transparent;
|
||||
color: var(--accent);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { expect, test } from 'vitest'
|
||||
import { groupGrants } from './grantRows'
|
||||
|
||||
test('folds a KV data rule and its metadata rule into one row', () => {
|
||||
const rows = groupGrants(
|
||||
[
|
||||
{ path: 'secret/data/team-a/*', capabilities: ['read', 'update'] },
|
||||
{ path: 'secret/metadata/team-a/*', capabilities: ['list'] },
|
||||
],
|
||||
['secret/'],
|
||||
)
|
||||
expect(rows).toEqual([
|
||||
{
|
||||
display: 'secret/team-a/*',
|
||||
wildcard: true,
|
||||
capabilities: ['read', 'update', 'list'],
|
||||
paths: ['secret/data/team-a/*', 'secret/metadata/team-a/*'],
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
test('a secret with only a data rule is one row', () => {
|
||||
const [row] = groupGrants([{ path: 'secret/data/app/db', capabilities: ['read'] }], ['secret/'])
|
||||
expect(row).toMatchObject({ display: 'secret/app/db', wildcard: false, paths: ['secret/data/app/db'] })
|
||||
})
|
||||
|
||||
test('paths outside a known KV mount keep their raw path', () => {
|
||||
const [row] = groupGrants([{ path: 'sys/health', capabilities: ['read'] }], ['secret/'])
|
||||
expect(row).toMatchObject({ display: 'sys/health', paths: ['sys/health'] })
|
||||
})
|
||||
|
||||
test('keeps different secrets and mounts apart', () => {
|
||||
const rows = groupGrants(
|
||||
[
|
||||
{ path: 'secret/data/a', capabilities: ['read'] },
|
||||
{ path: 'kv/data/a', capabilities: ['read'] },
|
||||
],
|
||||
['secret/', 'kv/'],
|
||||
)
|
||||
expect(rows.map((r) => r.display)).toEqual(['secret/a', 'kv/a'])
|
||||
})
|
||||
@@ -0,0 +1,35 @@
|
||||
import type { Grant } from './managed'
|
||||
import { CAPABILITIES, type Capability } from './policy'
|
||||
|
||||
/** One line in the "granted by EnvBao" list: a secret path with everything granted on it. */
|
||||
export interface GrantRow {
|
||||
/** Where the grant applies as a user thinks of it, e.g. "secret/app/*" (not "secret/data/app/*"). */
|
||||
display: string
|
||||
wildcard: boolean
|
||||
capabilities: Capability[]
|
||||
/** The policy paths behind this row; revoking the row removes all of them. */
|
||||
paths: string[]
|
||||
}
|
||||
|
||||
/**
|
||||
* KV v2 grants are stored as a `data/` rule and a `metadata/` rule per secret. Fold each pair into one row
|
||||
* keyed by the secret's own path; grants outside a known KV mount keep their raw path.
|
||||
*/
|
||||
export function groupGrants(grants: Grant[], mounts: string[]): GrantRow[] {
|
||||
const rows = new Map<string, GrantRow>()
|
||||
for (const g of grants) {
|
||||
let display = g.path
|
||||
for (const m of mounts) {
|
||||
const mount = m.endsWith('/') ? m : `${m}/`
|
||||
for (const kind of ['data', 'metadata']) {
|
||||
const prefix = `${mount}${kind}/`
|
||||
if (g.path.startsWith(prefix)) display = mount + g.path.slice(prefix.length)
|
||||
}
|
||||
}
|
||||
const row = rows.get(display) ?? { display, wildcard: display.endsWith('*'), capabilities: [], paths: [] }
|
||||
row.capabilities = CAPABILITIES.filter((c) => row.capabilities.includes(c) || g.capabilities.includes(c))
|
||||
row.paths.push(g.path)
|
||||
rows.set(display, row)
|
||||
}
|
||||
return [...rows.values()]
|
||||
}
|
||||
Reference in new issue
Block a user