Default new tokens to the default policy only (ENB-21)
CI / integration (push) Successful in 13s
CI / check (push) Successful in 16s

OpenBao copies the creator's policies when none are sent, so a token created
with nothing ticked while signed in as root was itself root. The New token form
now starts with `default` ticked, and createToken sends ['default'] for an
empty selection.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
mattandClaude Sonnet 5.5 committed 2026-10-20 12:52:13 +01:00
1 parent 0a2054eb41
commit b55259c492
4 files changed
+44 -9

No files matched your search

+15 -1
View File
@@ -47,6 +47,20 @@ test('lists tokens with a human TTL', async () => {
expect(within(row).getByText('2h')).toBeInTheDocument()
})
test('a new token starts with only the default policy ticked', async () => {
setup()
await userEvent.setup().click(await screen.findByRole('button', { name: 'New token' }))
expect(await screen.findByLabelText('default')).toBeChecked()
expect(screen.getByLabelText('dev')).not.toBeChecked()
})
test('explains what an empty policy selection means', async () => {
const user = setup()
await user.click(await screen.findByRole('button', { name: 'New token' }))
await user.click(await screen.findByLabelText('default'))
expect(screen.getByText(/gets only the default policy/)).toBeInTheDocument()
})
test('creates a token and shows its value once', async () => {
vi.mocked(api.createToken).mockResolvedValue({ token: 'hvs.SECRET', accessor: 'x', policies: ['dev'] })
const user = setup()
@@ -58,7 +72,7 @@ test('creates a token and shows its value once', async () => {
expect(api.createToken).toHaveBeenCalledWith(client, {
displayName: 'ci',
policies: ['dev'],
policies: ['default', 'dev'],
ttl: '24h',
renewable: true,
orphan: false,
+3 -7
View File
@@ -16,7 +16,8 @@ interface Draft {
orphan: boolean
}
const empty: Draft = { displayName: '', policies: [], ttl: '', renewable: true, orphan: false }
// Least privilege by default: a new token starts with the default policy only.
const empty: Draft = { displayName: '', policies: ['default'], ttl: '', renewable: true, orphan: false }
function formatTtl(seconds: number): string {
if (!seconds) return 'no expiry'
@@ -161,12 +162,7 @@ export function TokensTab({ client }: { client: BaoClient }) {
</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>
)}
{draft.policies.length === 0 && <p className="hint">No policies selected: the token gets only the default policy.</p>}
{create.error && <p role="alert">{create.error.message}</p>}
<div className="form-actions">
<button type="submit" disabled={create.isPending}>