Rework Graph page: node cards, key, toolbar bar and details card
CI / integration (push) Successful in 12s
CI / check (push) Successful in 15s

- Custom graph nodes with identity kind tags and per-column colours; wider
  text, styled edge labels, "full access" for everything grants.
- Filters, refresh and the key share one bar above the canvas.
- Details card restructured into sections with capability chips, a collapsible
  policy HCL and a red Revoke button; shared CapabilityChips component.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
mattandClaude Sonnet 5.5 committed 2026-10-20 12:16:02 +01:00
1 parent 68e564eb6c
commit d67a9c9b62
7 files changed
+441 -110

No files matched your search

+117 -45
View File
@@ -3,6 +3,7 @@ import type { BaoClient } from '../../api/bao'
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'
export type Selection = { kind: 'node'; id: string } | { kind: 'edge'; id: string }
@@ -17,65 +18,125 @@ interface Props {
const nodeById = (g: AccessGraph, id: string) => g.nodes.find((n) => n.id === id)
const label = (n: GraphNode | undefined) => n?.label ?? '?'
/** An identity's name with its kind, so "alice" the user and "alice" the entity read differently. */
function Who({ node }: { node: GraphNode | undefined }) {
return (
<>
<span>{label(node)}</span>
{node?.type === 'identity' && <span className="tag">{node.kind}</span>}
</>
)
}
function Warnings({ items }: { items: string[] | undefined }) {
return items?.map((w) => (
<p key={w} className="note-warn">
{w}
</p>
))
}
function NodeDetails({ node, full, policies }: { node: GraphNode; full: AccessGraph; policies: PolicyInput[] }) {
const out = full.edges.filter((e) => e.source === node.id)
const into = full.edges.filter((e) => e.target === node.id)
const caps = (e: GraphEdge) => (e.capabilities?.length ? ` (${e.capabilities.join(', ')})` : '')
if (node.type === 'identity') {
return (
<>
<h2>{node.label}</h2>
<p>{node.kind}</p>
<header className="detail-head">
<h2>{node.label}</h2>
<span className="tag">{node.kind}</span>
</header>
<h3>Policies</h3>
<ul>{out.map((e) => <li key={e.id}>{label(nodeById(full, e.target))}</li>)}</ul>
</>
)
}
if (node.type === 'policy') {
const hcl = policies.find((p) => p.name === node.label)?.hcl
return (
<>
<h2>{node.label}</h2>
<p>
{node.missing ? 'Attached but does not exist.' : node.managed ? 'Managed by EnvBao.' : 'Not managed by EnvBao (read-only).'}
</p>
{node.warnings.length > 0 && (
<ul>
{node.warnings.map((w) => (
<li key={w}>⚠ {w}</li>
{out.length ? (
<ul className="rows">
{out.map((e) => (
<li key={e.id}>
<code>{label(nodeById(full, e.target))}</code>
</li>
))}
</ul>
) : (
<p className="hint">No policies attached.</p>
)}
<h3>Used by</h3>
<ul>{into.map((e) => <li key={e.id}>{label(nodeById(full, e.source))}</li>)}</ul>
<h3>Grants</h3>
<ul>
{out.map((e) => (
<li key={e.id}>
<code>{label(nodeById(full, e.target))}</code>
{caps(e)}
</li>
))}
</ul>
{hcl && <pre>{hcl}</pre>}
</>
)
}
if (node.type === 'policy') {
const hcl = policies.find((p) => p.name === node.label)?.hcl
const status = node.missing ? 'Attached but does not exist' : node.managed ? 'Managed by EnvBao' : 'Not managed by EnvBao (read-only)'
return (
<>
<header className="detail-head">
<h2>{node.label}</h2>
</header>
<p className="hint">{status}.</p>
<Warnings items={node.warnings} />
<h3>Used by</h3>
{into.length ? (
<ul className="rows">
{into.map((e) => (
<li key={e.id}>
<Who node={nodeById(full, e.source)} />
</li>
))}
</ul>
) : (
<p className="hint">Not attached to anything.</p>
)}
<h3>Grants</h3>
{out.length ? (
<ul className="rows">
{out.map((e) => (
<li key={e.id}>
<code>{label(nodeById(full, e.target))}</code>
{e.capabilities && <CapabilityChips capabilities={e.capabilities} />}
</li>
))}
</ul>
) : (
<p className="hint">No grants.</p>
)}
{hcl && (
<details>
<summary>Policy HCL</summary>
<pre>{hcl}</pre>
</details>
)}
</>
)
}
// path: who reaches it, via which policy
return (
<>
<h2>
<code>{node.label}</code>
</h2>
<header className="detail-head">
<h2>
<code>{node.label}</code>
</h2>
</header>
<h3>Reached through</h3>
<ul>
<ul className="rows">
{into.map((e) => {
const users = full.edges.filter((x) => x.target === e.source).map((x) => label(nodeById(full, x.source)))
const users = full.edges.filter((x) => x.target === e.source).map((x) => nodeById(full, x.source))
return (
<li key={e.id}>
{label(nodeById(full, e.source))}
{caps(e)}: {users.join(', ') || 'no identity'}
<li key={e.id} className="stacked">
<div className="row-main">
<code>{label(nodeById(full, e.source))}</code>
{e.capabilities && <CapabilityChips capabilities={e.capabilities} />}
</div>
{users.length ? (
<ul className="people">
{users.map((u, i) => (
<li key={i}>
<Who node={u} />
</li>
))}
</ul>
) : (
<p className="hint">No identity uses this policy.</p>
)}
</li>
)
})}
@@ -104,16 +165,27 @@ function EdgeDetails({ client, edge, full, policies, onRevoked }: { client: BaoC
return (
<>
<h2>
{label(from)} → {label(to)}
</h2>
{edge.capabilities && <p>Capabilities: {edge.capabilities.join(', ')}</p>}
{edge.warnings?.map((w) => <p key={w}>⚠ {w}</p>)}
<header className="detail-head">
<h2>
<Who node={from} />
</h2>
</header>
<p className="edge-to">
<span aria-hidden="true">→</span> <code>{label(to)}</code>
</p>
{edge.capabilities && (
<>
<h3>Capabilities</h3>
<CapabilityChips capabilities={edge.capabilities} />
</>
)}
<Warnings items={edge.warnings} />
{isGrant && (
<>
{managed?.editable && ownerMatch ? (
<button
type="button"
className="danger"
onClick={() =>
window.confirm(`Revoke access to ${to!.label} from ${ownerMatch[1]} "${ownerMatch[2]}"? Other policies are unaffected.`) &&
revoke.mutate()
@@ -133,7 +205,7 @@ function EdgeDetails({ client, edge, full, policies, onRevoked }: { client: BaoC
}
export function Details({ client, full, policies, selection, onRevoked }: Props) {
let body = <p className="hint">Click a node or an edge for details.</p>
let body = <p className="detail-empty">Select a node or a line to see what it grants.</p>
if (selection?.kind === 'node') {
const node = nodeById(full, selection.id)
if (node) body = <NodeDetails node={node} full={full} policies={policies} />
+14
View File
@@ -0,0 +1,14 @@
import { Handle, Position, type NodeProps } from '@xyflow/react'
/** One box in the access graph: identities show their kind, so "alice" the user and "alice" the entity differ. */
export function GraphNodeCard({ data }: NodeProps) {
const { label, kind } = data as { label: string; kind?: string }
return (
<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>
<Handle type="source" position={Position.Right} isConnectable={false} />
</div>
)
}
+3 -1
View File
@@ -119,7 +119,9 @@ test('node details show who reaches a path', async () => {
const user = await open()
await user.click(screen.getByRole('button', { name: 'node secret/data/app/*' }))
const d = screen.getByRole('complementary', { name: 'Details' })
expect(within(d).getByText(/envbao-user-alice \(read\): alice/)).toBeInTheDocument()
expect(within(d).getByText('envbao-user-alice')).toBeInTheDocument()
expect(within(d).getByText('read')).toBeInTheDocument()
expect(within(d).getByText('alice')).toBeInTheDocument()
})
test('revokes a grant from a managed policy edge', async () => {
+51 -21
View File
@@ -17,13 +17,25 @@ import { layoutColumns } from '../../model/layout'
import { RequireConnection } from '../shared/RequireConnection'
import { useAccessInputs } from '../shared/useAccessInputs'
import { Details, type Selection } from './Details'
import { GraphNodeCard } from './GraphNode'
// Defined once, outside the component, so React Flow doesn't re-register node types on every render.
const nodeTypes = { gnode: GraphNodeCard }
// A grant with everything is easier to read as one word than as seven.
const FULL = ['create', 'read', 'update', 'delete', 'list', 'sudo']
function capabilityLabel(caps: string[] | undefined): string | undefined {
if (!caps?.length) return undefined
return FULL.every((c) => caps.includes(c)) ? 'full access' : caps.join(', ')
}
function toFlow(graph: AccessGraph, selected: Selection | null): { nodes: Node[]; edges: Edge[] } {
const pos = layoutColumns(graph)
const nodes: Node[] = graph.nodes.map((n) => ({
id: n.id,
position: pos.get(n.id)!,
data: { label: n.label },
type: 'gnode',
data: { label: n.label, kind: n.type === 'identity' ? n.kind : undefined },
className: [
'gnode',
`gnode-${n.type}`,
@@ -38,7 +50,10 @@ function toFlow(graph: AccessGraph, selected: Selection | null): { nodes: Node[]
id: e.id,
source: e.source,
target: e.target,
label: e.capabilities?.join(', '),
label: capabilityLabel(e.capabilities),
labelStyle: { fill: 'var(--ink-soft)', fontSize: 12 },
labelBgStyle: { fill: 'var(--surface-sunken)' },
labelBgPadding: [6, 3],
markerEnd: { type: MarkerType.ArrowClosed },
selected: selected?.kind === 'edge' && selected.id === e.id,
}))
@@ -69,31 +84,45 @@ function GraphView({ client }: { client: BaoClient }) {
return (
<>
<div className="graph-toolbar">
<label>
Identity
<input value={identity} onChange={(e) => setIdentity(e.target.value)} placeholder="filter identities" />
</label>
<label>
Path
<input value={path} onChange={(e) => setPath(e.target.value)} placeholder="filter paths" />
</label>
<label className="check">
<input type="checkbox" checked={hideDefault} onChange={(e) => setHideDefault(e.target.checked)} /> Hide the default policy
</label>
<button type="button" onClick={() => qc.invalidateQueries({ queryKey: ['access-inputs'] })} disabled={inputs.isFetching}>
{inputs.isFetching ? 'Refreshing…' : 'Refresh'}
</button>
<div className="graph-bar">
<div className="graph-toolbar">
<label>
Identity
<input value={identity} onChange={(e) => setIdentity(e.target.value)} placeholder="Filter identities" />
</label>
<label>
Path
<input value={path} onChange={(e) => setPath(e.target.value)} placeholder="Filter paths" />
</label>
<label className="check">
<input type="checkbox" checked={hideDefault} onChange={(e) => setHideDefault(e.target.checked)} /> Hide the default policy
</label>
<button type="button" onClick={() => qc.invalidateQueries({ queryKey: ['access-inputs'] })} disabled={inputs.isFetching}>
{inputs.isFetching ? 'Refreshing…' : 'Refresh'}
</button>
</div>
<ul className="graph-legend" aria-label="Key">
<li>
<span className="swatch swatch-identity" /> Identity
</li>
<li>
<span className="swatch swatch-policy" /> Policy
</li>
<li>
<span className="swatch swatch-path" /> Path
</li>
<li>
<strong>Bold</strong> policy: managed by EnvBao
</li>
<li>Dashed: policy is attached but missing</li>
<li className="grow">Identities include policies inherited through entities and groups.</li>
</ul>
</div>
{inputs.data.notes.map((n) => (
<p key={n} role="alert">
Incomplete: could not read {n}
</p>
))}
<div className="graph-legend" aria-hidden="true">
<span>Identities → Policies → Paths</span>
<span>Identity→policy edges include policies inherited via entities and groups.</span>
</div>
{shown.nodes.length === 0 ? (
<p>Nothing matches.</p>
) : (
@@ -102,6 +131,7 @@ function GraphView({ client }: { client: BaoClient }) {
<ReactFlow
nodes={flow.nodes}
edges={flow.edges}
nodeTypes={nodeTypes}
fitView
nodesDraggable={false}
nodesConnectable={false}
+2 -16
View File
@@ -2,6 +2,7 @@ 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'
interface Props {
@@ -10,9 +11,6 @@ interface Props {
secret: string
}
// Capabilities that let someone change or remove the secret, or bypass policy checks.
const RISKY = new Set(['delete', 'sudo'])
export function AccessPanel({ client, mount, secret }: Props) {
const data = useAccessInputs(client)
const path = dataPath(mount, secret)
@@ -60,19 +58,7 @@ function Entries({ data, path }: { data: NonNullable<ReturnType<typeof useAccess
<code>{e.policy}</code>
</td>
<td>
{e.policy === 'root' ? (
<ul className="chips">
<li className="risky">full access</li>
</ul>
) : (
<ul className="chips">
{e.capabilities.map((c) => (
<li key={c} className={RISKY.has(c) ? 'risky' : undefined}>
{c}
</li>
))}
</ul>
)}
<CapabilityChips capabilities={e.capabilities} />
</td>
</tr>
))}
+20
View File
@@ -0,0 +1,20 @@
// Capabilities that let someone change or remove data, or bypass policy checks.
const RISKY = new Set(['delete', 'sudo'])
/** A grant's capabilities as chips; the risky ones are red. Everything-plus-sudo reads as "full access". */
export function CapabilityChips({ capabilities }: { capabilities: readonly string[] }) {
const full = ['create', 'read', 'update', 'delete', 'list', 'sudo'].every((c) => capabilities.includes(c))
return (
<ul className="chips">
{full ? (
<li className="risky">full access</li>
) : (
capabilities.map((c) => (
<li key={c} className={RISKY.has(c) ? 'risky' : undefined}>
{c}
</li>
))
)}
</ul>
)
}