docker compose now runs a Postgres with sample tables and an SSH server that trusts the CA in OpenBao's ssh/ engine. seed.sh configures the database engine (dynamic and static roles), the ssh CA and a role, a few live leases, and grants for alice and the platform group. CI gains a Postgres service so the database engine and its admin-policy rules are tested against a real database (skipped when BAO_PG_URL is unset). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
30 lines
1.3 KiB
TypeScript
30 lines
1.3 KiB
TypeScript
import type { DraftValue } from '../api/engines/roles'
|
|
|
|
/**
|
|
* A Postgres for the database-engine integration tests, from BAO_PG_URL, e.g.
|
|
* postgresql://postgres:secret@postgres:5432/app?sslmode=disable. The host must be reachable from OpenBao (not
|
|
* necessarily from the test process). The user needs CREATEROLE. Returns null when unset, so tests can skip.
|
|
*/
|
|
export function pgTarget(): { values: Record<string, DraftValue>; creationStatements: string } | null {
|
|
const raw = process.env.BAO_PG_URL
|
|
if (!raw) return null
|
|
const u = new URL(raw)
|
|
const db = u.pathname.slice(1)
|
|
return {
|
|
values: {
|
|
plugin_name: 'postgresql-database-plugin',
|
|
// OpenBao substitutes the admin login into the template, so the password never sits in the URL it stores.
|
|
connection_url: `${u.protocol}//{{username}}:{{password}}@${u.host}${u.pathname}${u.search}`,
|
|
allowed_roles: '*',
|
|
username: decodeURIComponent(u.username),
|
|
password: decodeURIComponent(u.password),
|
|
verify_connection: true,
|
|
},
|
|
// Two statements separated by a blank line, which is how the form takes them.
|
|
creationStatements: [
|
|
`CREATE ROLE "{{name}}" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}';`,
|
|
`GRANT CONNECT ON DATABASE "${db}" TO "{{name}}";`,
|
|
].join('\n\n'),
|
|
}
|
|
}
|