Access: grant and inspect access to dynamic engine roles
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>
This commit is contained in:
1 parent
48ee757e8d
commit
85a318c351
14 files changed
+642
-22
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import type { Capability } from '../../model/policy'
|
||||
import type { Mount } from '../secrets'
|
||||
import { isKvV2 } from '../secrets'
|
||||
|
||||
@@ -37,6 +38,8 @@ export interface CredKind {
|
||||
method: 'GET' | 'POST'
|
||||
/** Request parameters; only sent for POST. */
|
||||
inputs: FieldDef[]
|
||||
/** ACL capabilities a token needs on `path` to make this request (and so what "generate" grants). */
|
||||
capabilities: Capability[]
|
||||
}
|
||||
|
||||
/** A one-off call on a config, e.g. rotating the root credentials. */
|
||||
@@ -107,7 +110,7 @@ const DATABASE_ROLE: RoleKind = {
|
||||
{ key: 'default_ttl', label: 'Default TTL', type: 'ttl' },
|
||||
{ key: 'max_ttl', label: 'Max TTL', type: 'ttl' },
|
||||
],
|
||||
creds: [{ id: 'creds', label: 'Generate credentials', path: (r) => `creds/${encodeURIComponent(r)}`, method: 'GET', inputs: [] }],
|
||||
creds: [{ id: 'creds', label: 'Generate credentials', path: (r) => `creds/${encodeURIComponent(r)}`, method: 'GET', inputs: [], capabilities: ['read'] }],
|
||||
}
|
||||
|
||||
const DATABASE_STATIC_ROLE: RoleKind = {
|
||||
@@ -121,7 +124,7 @@ const DATABASE_STATIC_ROLE: RoleKind = {
|
||||
{ key: 'rotation_period', label: 'Rotation period', type: 'ttl' },
|
||||
],
|
||||
creds: [
|
||||
{ id: 'static-creds', label: 'Read current credentials', path: (r) => `static-creds/${encodeURIComponent(r)}`, method: 'GET', inputs: [] },
|
||||
{ id: 'static-creds', label: 'Read current credentials', path: (r) => `static-creds/${encodeURIComponent(r)}`, method: 'GET', inputs: [], capabilities: ['read'] },
|
||||
],
|
||||
}
|
||||
|
||||
@@ -152,6 +155,7 @@ const AWS_ROLE: RoleKind = {
|
||||
label: 'Generate credentials',
|
||||
path: (r) => `creds/${encodeURIComponent(r)}`,
|
||||
method: 'POST',
|
||||
capabilities: ['read', 'update'],
|
||||
inputs: [
|
||||
{ key: 'ttl', label: 'TTL', type: 'ttl', help: 'For STS credentials.' },
|
||||
{ key: 'role_arn', label: 'Role ARN', type: 'text', help: 'Only when the role allows several.' },
|
||||
@@ -181,6 +185,7 @@ const SSH_ROLE: RoleKind = {
|
||||
label: 'Sign a public key (CA)',
|
||||
path: (r) => `sign/${encodeURIComponent(r)}`,
|
||||
method: 'POST',
|
||||
capabilities: ['update'],
|
||||
inputs: [
|
||||
{ key: 'public_key', label: 'Public key', type: 'textarea', required: true },
|
||||
{ key: 'valid_principals', label: 'Valid principals', type: 'text', help: 'Comma separated.' },
|
||||
@@ -193,6 +198,7 @@ const SSH_ROLE: RoleKind = {
|
||||
label: 'Generate an OTP',
|
||||
path: (r) => `creds/${encodeURIComponent(r)}`,
|
||||
method: 'POST',
|
||||
capabilities: ['update'],
|
||||
inputs: [
|
||||
{ key: 'ip', label: 'Target IP', type: 'text', required: true },
|
||||
{ key: 'username', label: 'Username', type: 'text' },
|
||||
|
||||
@@ -3,7 +3,11 @@ import { BaoClient } from '../bao'
|
||||
import { readConfig, runAction, writeConfig, deleteConfig } from './config'
|
||||
import { generateCreds } from './creds'
|
||||
import { listLeases, lookupLease, renewLease, revokeLease, revokePrefix } from './leases'
|
||||
import { listMounts } from '../secrets'
|
||||
import { accessForPath } from '../../model/graph'
|
||||
import { dynamicGrantRules, renderManagedPolicy } from '../../model/managed'
|
||||
import { pathMatches } from '../../model/policy'
|
||||
import { capabilitiesSelf, listMounts } from '../secrets'
|
||||
import { createToken, revokeToken } from '../tokens'
|
||||
import { ENGINES } from './registry'
|
||||
import { deleteRole, draftFromRole, emptyDraft, listRoles, payloadFromDraft, readRole, writeRole } from './roles'
|
||||
|
||||
@@ -126,3 +130,48 @@ describe('dynamic engine config and credentials', () => {
|
||||
expect(await readConfig(client, awsMount, lease)).toMatchObject({ lease: '30m0s', lease_max: '2h0m0s' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('grants on dynamic roles match what OpenBao enforces', () => {
|
||||
const polName = `it-dyn-${sfx}`
|
||||
const ca = ENGINES.ssh.configs[0]
|
||||
let token: Awaited<ReturnType<typeof createToken>>
|
||||
|
||||
beforeAll(async () => {
|
||||
const role = emptyDraft(kind)
|
||||
role.values.allow_user_certificates = true
|
||||
role.values.allowed_users = '*'
|
||||
role.values.default_user = 'alice'
|
||||
for (const name of ['granted', 'other']) await writeRole(client, mount, kind, name, payloadFromDraft(kind, role))
|
||||
await runAction(client, mount, ca.actions![0])
|
||||
|
||||
const grants = dynamicGrantRules(kind, mount, 'granted', ['generate', 'manage']).filter((g) => g.capabilities.length)
|
||||
await client.request('PUT', `sys/policies/acl/${polName}`, { policy: renderManagedPolicy('user', 'x', grants) })
|
||||
token = await createToken(client, { displayName: polName, policies: [polName], renewable: false, orphan: false })
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await revokeToken(client, token.accessor).catch(() => {})
|
||||
await client.request('DELETE', `sys/policies/acl/${polName}`).catch(() => {})
|
||||
})
|
||||
|
||||
test('capabilities-self agrees with the access model for granted and other roles', async () => {
|
||||
const as = client.withToken(token.token)
|
||||
const hcl = renderManagedPolicy('user', 'x', dynamicGrantRules(kind, mount, 'granted', ['generate', 'manage']).filter((g) => g.capabilities.length))
|
||||
const who = [{ kind: 'user' as const, name: 'x', policies: [polName] }]
|
||||
for (const role of ['granted', 'other']) {
|
||||
for (const path of [`${mount}sign/${role}`, `${mount}creds/${role}`, `${mount}roles/${role}`]) {
|
||||
const real = (await capabilitiesSelf(as, path)).filter((c) => c !== 'deny').sort()
|
||||
const modelled = accessForPath(who, [{ name: polName, hcl }], path, pathMatches).flatMap((e) => e.capabilities).sort()
|
||||
expect(modelled, path).toEqual(real)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
test('the granted token can sign with its role and not with another', async () => {
|
||||
const as = client.withToken(token.token)
|
||||
const out = await generateCreds(as, mount, kind.creds[0], 'granted', { public_key: PUBLIC_KEY })
|
||||
expect(String(out.data.signed_key)).toContain('cert-v01')
|
||||
await expect(generateCreds(as, mount, kind.creds[0], 'other', { public_key: PUBLIC_KEY })).rejects.toThrow()
|
||||
expect(await listRoles(as, mount, kind)).toEqual(expect.arrayContaining(['granted']))
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user