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>
)
}
+234 -27
View File
@@ -23,6 +23,11 @@
--warn: light-dark(#8a5a00, #f2c14e);
--warn-soft: light-dark(#fff4d6, #3a2d0c);
/* Graph node kinds. */
--node-identity: light-dark(#2a6fdb, #6ea8ff);
--node-policy: light-dark(#7a4bc2, #b794f4);
--node-path: light-dark(#0b7a6e, #3cc2af);
--font: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
--mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
@@ -263,13 +268,15 @@ button[type='submit']:hover:not(:disabled) {
/* Destructive actions. */
button[aria-label^='Delete'],
button[aria-label^='Revoke'],
button[aria-label^='Remove'] {
button[aria-label^='Remove'],
button.danger {
color: var(--danger);
}
button[aria-label^='Delete']:hover:not(:disabled),
button[aria-label^='Revoke']:hover:not(:disabled),
button[aria-label^='Remove']:hover:not(:disabled) {
button[aria-label^='Remove']:hover:not(:disabled),
button.danger:hover:not(:disabled) {
background: var(--danger-soft);
border-color: var(--danger);
}
@@ -613,40 +620,92 @@ td:last-child button + button {
/* ---------- Graph ---------- */
/* One bar above the canvas: filters and refresh on top, the key underneath. */
.graph-bar {
display: grid;
gap: var(--s3);
margin-bottom: var(--s3);
padding: var(--s3) var(--s4);
background: var(--surface);
border: 1px solid var(--line);
border-radius: var(--radius);
}
.graph-toolbar {
display: flex;
flex-wrap: wrap;
gap: var(--s4);
gap: var(--s3) var(--s4);
align-items: flex-end;
margin-bottom: var(--s3);
}
.graph-toolbar label:not(.check) {
display: grid;
gap: var(--s1);
color: var(--ink-soft);
font-size: var(--text-sm);
font-weight: 500;
}
.graph-toolbar input:not([type='checkbox']) {
width: 15rem;
}
.graph-toolbar .check {
min-height: 2.25rem;
}
.graph-toolbar button {
margin-left: auto;
min-height: 2.25rem;
}
.graph-legend {
display: flex;
gap: var(--s5);
margin-bottom: var(--s2);
flex-wrap: wrap;
align-items: center;
gap: var(--s2) var(--s5);
margin: 0;
padding: var(--s3) 0 0;
border-top: 1px solid var(--line);
list-style: none;
color: var(--ink-faint);
font-size: var(--text-sm);
}
.graph-legend .grow {
margin-left: auto;
}
.swatch {
display: inline-block;
width: 0.6rem;
height: 0.6rem;
margin-right: var(--s1);
border-radius: 2px;
background: var(--node-colour);
}
.swatch-identity {
--node-colour: var(--node-identity);
}
.swatch-policy {
--node-colour: var(--node-policy);
}
.swatch-path {
--node-colour: var(--node-path);
}
.graph-layout {
display: grid;
grid-template-columns: 1fr 22rem;
grid-template-columns: minmax(0, 1fr) 22rem;
gap: var(--s4);
}
.graph-canvas {
height: 70vh;
height: calc(100vh - 21rem);
min-height: 28rem;
background: var(--surface-sunken);
border: 1px solid var(--line);
border-radius: var(--radius);
@@ -654,40 +713,188 @@ td:last-child button + button {
}
.graph-details {
max-height: calc(100vh - 21rem);
overflow: auto;
max-height: 70vh;
padding: var(--s4) var(--s5);
background: var(--surface);
border: 1px solid var(--line);
border-radius: var(--radius);
}
.gnode {
width: 300px;
font-size: 12px;
border-width: 2px;
.detail-head {
display: flex;
flex-wrap: wrap;
align-items: baseline;
gap: var(--s2);
margin-bottom: var(--s2);
}
.gnode-identity {
border-color: #2d7ff9;
.detail-head h2,
.graph-details h2 {
margin: 0;
font-size: var(--text-lg);
overflow-wrap: anywhere;
}
.gnode-policy {
border-color: #8e44ad;
}
.gnode-managed {
border-style: solid;
.graph-details h3 {
margin: var(--s5) 0 var(--s2);
color: var(--ink-soft);
font-size: var(--text-sm);
font-weight: 600;
}
.gnode-missing {
border-style: dashed;
opacity: 0.7;
.graph-details p {
margin: 0 0 var(--s2);
}
.graph-details code {
overflow-wrap: anywhere;
}
.detail-empty {
padding: var(--s6) var(--s3);
color: var(--ink-faint);
text-align: center;
}
.edge-to {
color: var(--ink-soft);
}
/* Label/value rows: one entry per line, hairline between. */
.rows,
.people {
margin: 0;
padding: 0;
list-style: none;
}
.rows > li {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--s1) var(--s3);
padding: var(--s2) 0;
border-bottom: 1px solid var(--line);
}
.rows > li:last-child {
border-bottom: 0;
}
.rows > li.stacked {
display: block;
}
.row-main {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--s1) var(--s3);
}
.people {
margin-top: var(--s1);
padding-left: var(--s3);
}
.people li {
padding: 1px 0;
}
.graph-details details {
margin-top: var(--s5);
}
.graph-details summary {
color: var(--accent);
cursor: pointer;
}
.graph-details pre {
margin: var(--s2) 0 0;
}
.note-warn {
padding: var(--s2) var(--s3);
background: var(--warn-soft);
border-radius: var(--radius);
color: var(--warn);
font-size: var(--text-sm);
}
/* Nodes. The wrapper carries state classes; the card is what you see. */
.gnode {
--node-colour: var(--ink-faint);
width: 260px;
}
.gnode-identity {
--node-colour: var(--node-identity);
}
.gnode-policy {
--node-colour: var(--node-policy);
}
.gnode-path {
border-color: #27ae60;
--node-colour: var(--node-path);
}
.gnode-selected {
box-shadow: 0 0 0 3px var(--warn);
.gnode-card {
display: flex;
align-items: baseline;
gap: var(--s2);
padding: var(--s2) var(--s3);
background: var(--surface);
color: var(--ink);
border: 1px solid var(--line-strong);
border-left: 4px solid var(--node-colour);
border-radius: var(--radius);
font-size: 14px;
line-height: 1.3;
}
.gnode-path .gnode-label {
font-family: var(--mono);
font-size: 13px;
}
.gnode-label {
overflow-wrap: anywhere;
}
.gnode-kind {
flex: none;
padding: 0 var(--s2);
background: var(--surface-sunken);
border-radius: 999px;
color: var(--ink-soft);
font-size: 11px;
}
.gnode-managed .gnode-label {
font-weight: 650;
}
.gnode-missing .gnode-card {
border-style: dashed;
border-left-style: solid;
opacity: 0.75;
}
.gnode-selected .gnode-card {
box-shadow: 0 0 0 2px var(--accent);
}
/* Handles anchor the edges but aren't interactive. */
.gnode-card .react-flow__handle {
width: 1px;
height: 1px;
min-width: 0;
min-height: 0;
opacity: 0;
border: 0;
}
@media (max-width: 48rem) {