Mounts: API, path validation and mountable engine types

Adds create/tune/delete for secrets engine mounts, the KV v2 settings
that live on the mount, and an impact summary for deletes. Mount lists
now carry description and explicit lease TTLs: sys/mounts/<path>/tune
reports the effective value, which would pin the system default if it
were saved back, so edits prefill from the list instead.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
mattandClaude Sonnet 5.5 committed 2026-11-09 14:21:22 +00:00
1 parent fd20caa525
commit 66aa86028a
6 files changed
+376 -5

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
import { expect, test } from 'vitest'
import { policiesReferencing, validateMountPath } from './mounts'
const existing = ['secret/', 'database/', 'team/kv/']
test('accepts ordinary and nested paths, with or without slashes', () => {
for (const p of ['scratch', 'my-store_2', 'scratch/', 'apps/payments', '9lives']) expect(validateMountPath(p, existing), p).toBeNull()
})
test('rejects empty, oddly-formed and uppercase paths', () => {
expect(validateMountPath('', existing)).toBe('Path is required.')
expect(validateMountPath('/', existing)).toBe('Path is required.')
expect(validateMountPath(' x', existing)).toMatch(/spaces/)
for (const p of ['My Store', 'Upper', 'a//b', '-lead', 'dot.ted', 'a/_b', 'ünï']) expect(validateMountPath(p, existing), p).toMatch(/lowercase/)
})
test('rejects the names OpenBao reserves, also as a prefix', () => {
for (const p of ['sys', 'auth', 'identity', 'cubbyhole', 'sys/x', 'auth/kv']) expect(validateMountPath(p, existing), p).toMatch(/reserved/)
})
test('rejects a path equal to, inside or containing an existing mount', () => {
expect(validateMountPath('secret', existing)).toMatch(/already a secrets engine/)
expect(validateMountPath('secret/', existing)).toMatch(/already/)
expect(validateMountPath('secret/inner', existing)).toMatch(/inside the existing mount "secret\/"/)
expect(validateMountPath('team', existing)).toMatch(/contain the existing mount "team\/kv\/"/)
expect(validateMountPath('secrets', existing)).toBeNull() // shares a prefix, not a path segment
})
test('finds policies with rules under a mount, however the mount is written', () => {
const policies = [
{ name: 'b-uses', hcl: 'path "secret/data/app/*" { capabilities = ["read"] }' },
{ name: 'a-uses', hcl: 'path "secret/metadata/*" { capabilities = ["list"] }\npath "x/y" { capabilities = ["read"] }' },
{ name: 'other', hcl: 'path "secrets/data/x" { capabilities = ["read"] }' },
{ name: 'unreadable', hcl: null },
{ name: 'broken', hcl: 'path "secret/x" {' },
]
expect(policiesReferencing(policies, 'secret/')).toEqual(['a-uses', 'b-uses'])
expect(policiesReferencing(policies, 'secret')).toEqual(['a-uses', 'b-uses'])
expect(policiesReferencing(policies, 'nothing/')).toEqual([])
})
+44
View File
@@ -0,0 +1,44 @@
import { parsePolicy } from './policy'
/** Prefixes OpenBao reserves for itself; a secrets engine cannot be mounted at or under them. */
const RESERVED = ['sys', 'auth', 'identity', 'cubbyhole']
const SEGMENT = /^[a-z0-9][a-z0-9_-]*$/
const norm = (p: string) => p.replace(/^\/+|\/+$/g, '')
/**
* Error message for a mount path that can't be used, or null. `existing` are the current mounts (with or without
* trailing slashes). Nested paths such as "team/kv" are fine, but a mount can't sit inside another or contain one.
*/
export function validateMountPath(path: string, existing: string[]): string | null {
const p = norm(path)
if (!p) return 'Path is required.'
if (path !== path.trim()) return 'Path must not start or end with spaces.'
if (!p.split('/').every((s) => SEGMENT.test(s))) {
return 'Use lowercase letters, digits, "-" and "_", starting each part with a letter or digit. Parts are separated by "/".'
}
const first = p.split('/')[0]
if (RESERVED.includes(first)) return `"${first}" is reserved by OpenBao.`
for (const e of existing.map(norm)) {
if (e === p) return `"${p}/" is already a secrets engine.`
if (p.startsWith(`${e}/`)) return `"${p}/" would sit inside the existing mount "${e}/".`
if (e.startsWith(`${p}/`)) return `"${p}/" would contain the existing mount "${e}/".`
}
return null
}
export interface PolicyText {
name: string
/** Null when the policy could not be read. */
hcl: string | null
}
/** Policies with a rule on a path under `mount`, which would be left pointing at nothing if it were deleted. */
export function policiesReferencing(policies: PolicyText[], mount: string): string[] {
const m = mount.endsWith('/') ? mount : `${mount}/`
return policies
.filter((p) => p.hcl !== null && parsePolicy(p.hcl).rules.some((r) => r.path.startsWith(m)))
.map((p) => p.name)
.sort((a, b) => a.localeCompare(b))
}