Share PostgreSQL with Substrate - #2708
iplay88keys wants to merge 6 commits into
Conversation
Configure embedded Substrate to use Kagent's selected PostgreSQL database through a shared Secret and a separate schema. Support bundled, external, shared existing, and independently configured Substrate databases, with examples for each installation mode. Signed-off-by: Jeremy Alvis <jeremy.alvis@solo.io>
Signed-off-by: Jeremy Alvis <jeremy.alvis@solo.io>
…tgres-with-substrate Signed-off-by: Jeremy Alvis <jeremy.alvis@solo.io>
|
Three gaps after this PR. --postgres-schema defaults to public, and atepg.go assigns RuntimeParams["search_path"] unconditionally after parsing the DSN. In the shared-Secret setup this PR documents, a connection string carrying search_path=agents is therefore overridden to public on the ate-api-server side, silently, unless the flag is set to match. Migrations cannot use a separate identity. RunUp runs in-process on the same connection string before the pool opens, so the role serving traffic must also hold DDL rights on its own schema, and every migrated object ends up owned by it. A schema owner distinct from its runtime consumer is not expressible. Rotation has no input left. POSTGRES_DATABASE_URL is an env var, frozen for the life of the process. urlFile was the only input a rotation system could write to, and passfile is no substitute because ParseConfig resolves that once too. Is rotation meant to work another way? |
|
@smeegoan, thanks for taking a look! Just updating this PR and reviewing your comment. Just a heads up that Codex helped put together this response, though I reviewed it.
This PR defaults
Kagent already supports this operationally. An operator can create the schema/grants and run On the Substrate side, even if we added a way to pre-apply and skip startup migrations, that would not provide complete DDL/DML separation. Operators can configure Substrate with a separate connection Secret and role, even when it points to the same PostgreSQL server and database. This keeps Substrate’s DDL privileges off Kagent’s runtime role, but Substrate currently has no supported mechanism for separating its own migration/DDL and runtime/DML identities. Additional Substrate work would be required for that stricter separation.
So the PR does not remove an existing Kagent credential-separation or live-rotation capability. The real follow-up is adding equivalent migration-role separation to Substrate if that is required for shared production databases. |
…tgres-with-substrate Signed-off-by: Jeremy Alvis <jeremy.alvis@solo.io>
…t's role Signed-off-by: Jeremy Alvis <jeremy.alvis@solo.io>
Signed-off-by: Jeremy Alvis <jeremy.alvis@solo.io>
Important
This PR requires a Substrate chart containing kagent-dev/substrate#32. The Kagent dependency must also be bumped after that chart is released.
Summary
substrateschema.database.postgres.urlor Kagent's bundled PostgreSQL URL.database.postgres.urlFilewith the Kubernetes-nativedatabase.postgres.secretRef.{name,key}configuration.database.postgres.*, while embedded Substrate readssubstrate.postgres.*.Configuration
The default development configuration shares Kagent's bundled database and uses separate schemas:
For an external database with separate Kagent, Substrate runtime, and Substrate DDL accounts:
Both Substrate connections may point to Kagent's PostgreSQL server and database. The dedicated schema prevents the generic Substrate runtime grants from covering Kagent tables. The DDL role owns and migrates the Substrate schema; the runtime role receives only the table and sequence access needed by ateapi.
Omitting the DDL connection preserves single-connection operation. Existing Secrets can also be shared by setting the same name and key under
database.postgres.secretRefandsubstrate.postgres.connectionStringSecretRef.