Secrets: engine config editors and one-time credential generation
Adds Config tab (database connections with rotate/reset, aws root and lease, ssh CA with generate/import) and a Generate action on roles (database/static creds, aws creds, ssh sign and OTP). Secret inputs are write-only: never prefilled and omitted when blank so the stored value is kept. Issued credentials live only in a gcTime-0 mutation and are shown once, with revoke-now for leased credentials. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4fa7ff1497
commit
48746e2150
15 files changed
+1089
-18
No files matched your search
@@ -1,5 +1,8 @@
|
||||
import { afterAll, beforeAll, describe, expect, test } from 'vitest'
|
||||
import { BaoClient } from '../bao'
|
||||
import { readConfig, runAction, writeConfig, deleteConfig } from './config'
|
||||
import { generateCreds } from './creds'
|
||||
import { revokeLease } from './leases'
|
||||
import { listMounts } from '../secrets'
|
||||
import { ENGINES } from './registry'
|
||||
import { deleteRole, draftFromRole, emptyDraft, listRoles, payloadFromDraft, readRole, writeRole } from './roles'
|
||||
@@ -8,13 +11,23 @@ const client = new BaoClient(process.env.BAO_ADDR ?? 'http://127.0.0.1:8200', pr
|
||||
const sfx = Math.random().toString(36).slice(2, 8)
|
||||
const mount = `it-ssh-${sfx}/`
|
||||
const kind = ENGINES.ssh.roleKinds[0]
|
||||
const awsMount = `it-aws-${sfx}/`
|
||||
// Not every OpenBao build bundles the AWS engine (some ship it as an external plugin).
|
||||
let awsAvailable = false
|
||||
// A throwaway public key made only for this test; there is no matching private key anywhere.
|
||||
const PUBLIC_KEY = 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDI/MhHH9Rd3dBZwAa4gQOkxfuw0ogMWlO2G4rlINbfv it'
|
||||
|
||||
beforeAll(async () => {
|
||||
await client.request('POST', `sys/mounts/${mount.slice(0, -1)}`, { type: 'ssh' })
|
||||
awsAvailable = await client
|
||||
.request('POST', `sys/mounts/${awsMount.slice(0, -1)}`, { type: 'aws' })
|
||||
.then(() => true)
|
||||
.catch(() => false)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await client.request('DELETE', `sys/mounts/${mount.slice(0, -1)}`).catch(() => {})
|
||||
await client.request('DELETE', `sys/mounts/${awsMount.slice(0, -1)}`).catch(() => {})
|
||||
})
|
||||
|
||||
describe('dynamic engine roles (ssh)', () => {
|
||||
@@ -47,3 +60,49 @@ describe('dynamic engine roles (ssh)', () => {
|
||||
expect(await listRoles(client, mount, kind)).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('dynamic engine config and credentials', () => {
|
||||
const ca = ENGINES.ssh.configs[0]
|
||||
|
||||
test('an unconfigured CA reads as null, then generate, sign and delete', async () => {
|
||||
expect(await readConfig(client, mount, ca)).toBeNull()
|
||||
|
||||
await runAction(client, mount, ca.actions![0])
|
||||
const cfg = await readConfig(client, mount, ca)
|
||||
expect(cfg?.public_key).toMatch(/^ssh-rsa /)
|
||||
|
||||
const role = emptyDraft(kind)
|
||||
role.values.allow_user_certificates = true
|
||||
role.values.allowed_users = '*'
|
||||
role.values.default_user = 'alice'
|
||||
role.values.ttl = '10m'
|
||||
await writeRole(client, mount, kind, 'signer', payloadFromDraft(kind, role))
|
||||
|
||||
const sign = kind.creds[0]
|
||||
const out = await generateCreds(client, mount, sign, 'signer', { public_key: PUBLIC_KEY })
|
||||
expect(String(out.data.signed_key)).toMatch(/^ssh-ed25519-cert-v01@openssh.com /)
|
||||
|
||||
await deleteConfig(client, mount, ca)
|
||||
expect(await readConfig(client, mount, ca)).toBeNull()
|
||||
})
|
||||
|
||||
test('OTP credentials come with a lease that can be revoked', async () => {
|
||||
const role = emptyDraft(kind)
|
||||
role.values.key_type = 'otp'
|
||||
role.values.default_user = 'alice'
|
||||
role.values.cidr_list = '10.0.0.0/8'
|
||||
await writeRole(client, mount, kind, 'otp', payloadFromDraft(kind, role))
|
||||
|
||||
const out = await generateCreds(client, mount, kind.creds[1], 'otp', { ip: '10.1.2.3' })
|
||||
expect(out.leaseId).toContain('/creds/otp/')
|
||||
expect(out.data.key).toBeTruthy()
|
||||
await revokeLease(client, out.leaseId)
|
||||
})
|
||||
|
||||
test('single-endpoint config round-trips (aws lease)', async (ctx) => {
|
||||
if (!awsAvailable) ctx.skip()
|
||||
const lease = ENGINES.aws.configs[1]
|
||||
await writeConfig(client, awsMount, lease, { lease: '30m', lease_max: '2h' })
|
||||
expect(await readConfig(client, awsMount, lease)).toMatchObject({ lease: '30m0s', lease_max: '2h0m0s' })
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user