dynamicGrantRules expands a grant on a role into the credential paths its requests need (generate) and the role CRUD paths (manage); unticked access comes back empty so writing it revokes. Roles get an Access panel showing who can generate credentials or manage them, and the identity Access editor can pick dynamic mounts and roles. Checked against capabilities-self and a real token in the integration tests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
121 lines
3.4 KiB
TypeScript
121 lines
3.4 KiB
TypeScript
import { useState } from 'react'
|
|
import type { BaoClient } from '../../api/bao'
|
|
import { dataPath } from '../../api/secrets'
|
|
import { accessForPath } from '../../model/graph'
|
|
import { pathMatches } from '../../model/policy'
|
|
import { CapabilityChips } from '../shared/CapabilityChips'
|
|
import { useAccessInputs } from '../shared/useAccessInputs'
|
|
import { GrantHere } from './GrantHere'
|
|
|
|
interface Props {
|
|
client: BaoClient
|
|
mount: string
|
|
secret: string
|
|
}
|
|
|
|
export function AccessPanel({ client, mount, secret }: Props) {
|
|
const data = useAccessInputs(client)
|
|
const path = dataPath(mount, secret)
|
|
const [granting, setGranting] = useState(false)
|
|
const [granted, setGranted] = useState<string | null>(null)
|
|
|
|
return (
|
|
<section aria-label="Access" className="secret-detail">
|
|
<header>
|
|
<div>
|
|
<h2>{secret}</h2>
|
|
<code>{path}</code>
|
|
</div>
|
|
{!granting && (
|
|
<button
|
|
type="button"
|
|
disabled={!data.data}
|
|
onClick={() => {
|
|
setGranted(null)
|
|
setGranting(true)
|
|
}}
|
|
>
|
|
Grant access
|
|
</button>
|
|
)}
|
|
</header>
|
|
{granted && (
|
|
<p role="status" className="note-ok">
|
|
{granted}
|
|
</p>
|
|
)}
|
|
{granting && data.data && (
|
|
<GrantHere
|
|
client={client}
|
|
mount={mount}
|
|
secret={secret}
|
|
identities={data.data.identities}
|
|
onClose={() => setGranting(false)}
|
|
onGranted={(message) => {
|
|
setGranting(false)
|
|
setGranted(message)
|
|
}}
|
|
/>
|
|
)}
|
|
{data.isPending && <p className="hint">Loading access…</p>}
|
|
{data.error && <p role="alert">Could not load access: {data.error.message}</p>}
|
|
{data.data && <Entries data={data.data} path={path} />}
|
|
</section>
|
|
)
|
|
}
|
|
|
|
/** Who can reach `path`, from every identity's effective policies. */
|
|
export function Entries({
|
|
data,
|
|
path,
|
|
label = 'Who can access this secret',
|
|
empty = 'No identity can reach this secret.',
|
|
}: {
|
|
data: NonNullable<ReturnType<typeof useAccessInputs>['data']>
|
|
path: string
|
|
label?: string
|
|
empty?: string
|
|
}) {
|
|
const entries = accessForPath(data.identities, data.policies, path, pathMatches)
|
|
return (
|
|
<>
|
|
{data.notes.map((n) => (
|
|
<p key={n} role="alert">
|
|
Incomplete: could not read {n}
|
|
</p>
|
|
))}
|
|
{entries.length === 0 ? (
|
|
<p>{empty}</p>
|
|
) : (
|
|
<table aria-label={label}>
|
|
<thead>
|
|
<tr>
|
|
<th>Identity</th>
|
|
<th>Via policy</th>
|
|
<th>Can</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{entries.map((e) => (
|
|
<tr key={`${e.identity.kind}:${e.identity.name}:${e.policy}`}>
|
|
<td>
|
|
<span>{e.identity.name}</span> <span className="tag">{e.identity.kind}</span>
|
|
</td>
|
|
<td data-label="Via policy">
|
|
<code>{e.policy}</code>
|
|
</td>
|
|
<td data-label="Can">
|
|
<CapabilityChips capabilities={e.capabilities} />
|
|
</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
)}
|
|
<p className="hint">
|
|
Only the most specific matching policy path applies, as in OpenBao. Parameter constraints and templated paths are approximated.
|
|
</p>
|
|
</>
|
|
)
|
|
}
|