feat(agent-relay): databaseGuard refuses wrong database credentials before install (chart 0.7.84)
Why
A sandbox rehearsal of a real customer install (EKS + RDS PG17, infra 13488a58, examples/aws) hand-filled examples/aws/secrets/01..05 with every database URL logging in as postgres, the RDS master, and never created the per-service logins. helm install succeeded, then one cause showed up as four unrelated-looking failures: relaycast-migrate exit 65 with a long FAIL list, relay-control-migrate's get_role_oid stack trace, hoopdb-migrate's runtime_role_missing, and everything else in CrashLoopBackOff. Working out that every URL used postgres took diagnose-install.py and a jq one-liner the next day.
What a customer sees now
helm install fails before anything is applied:
Error: INSTALLATION FAILED: execution error at (agent-relay/templates/db-guard.yaml:10:4):
AR_DB_LOGIN: the database credentials in this release's Secrets are wrong; nothing was installed or changed:
- agent-relay-secrets: database-url logs in as "postgres" (the RDS master user). Each service needs its own login.
- agent-relay-secrets: database-migrations-url logs in as "postgres" (the RDS master user). Each service needs its own login.
... (one line per URL, 10 on examples/aws)
Run scripts/selfhost/configure-rds.sh, which creates the logins and writes these Secrets, or see docs/self-hosted-rds-manual-setup.md §1.3 (https://agentrelay.com/docs/self-hosting/troubleshooting#database-logins). Then run helm again. (databaseGuard.enabled=false turns this check off, only for a setup it does not understand.)
When the render check passes but a login is still wrong (a master under another name, a login granted rds_superuser, a wrong password, an unreachable host, a CA mismatch), the pre-install hook stops the install. kubectl -n agent-relay logs job/agent-relay-db-guard shows:
Agent Relay database privilege check (databaseGuard.privilegeCheck)
FAIL agent-relay-secrets: database-url login=custom_admin logs in as "custom_admin", which has CREATEROLE: a database master/administrator login. Each service needs its own login (failed: not_createrole: role has CREATEROLE)
ok agent-relay-secrets: database-owner-url login=relaycast_owner relaycast owner identity
...
AR_DB_LOGIN: the database credentials in this release's Secrets are wrong; the install/upgrade was stopped before any workload changed:
- agent-relay-secrets: database-url logs in as "custom_admin", which has CREATEROLE: a database master/administrator login. Each service needs its own login.
Run scripts/selfhost/configure-rds.sh, ... Then run helm again.
Helm itself prints only failed pre-install: resource Job/agent-relay/agent-relay-db-guard not ready. status: Failed; the docs point to kubectl logs.
How
- Render time (
templates/_db-guard.tpl):lookupof every Secret the enabled components read a DB URL from. The targets are derived from values (relay-control, relaycast on postgres, external-HoopDb sessions-pipeline: worker, migrations, read API, ingest edge, search indexer and bootstrap), so thehoopdb-layout-values.yamloverlay and renamed Secrets are followed. It checks for a master login (databaseGuard.masterLogins), two jobs sharing one login, a missing Secret or key, and the wrong shape: a bare URL where{"hoopdb_url":ā¦}/{"supabase_url":ā¦}is expected, or JSON in a URL key. Exemptions: the HoopDb owner onrdsLayout: master-owner(the legacy layout) may be the master, and Secrets created by this release's ExternalSecrets may be absent.lookupis empty underhelm template, client--dry-runandhelm lint, so the check only runs whenkube-systemanswers.--dry-run=serverruns it. - Install time (
templates/db-guard.yaml,files/db-guard/check.mjs): a pre-install/pre-upgrade hook Job that runs in the relaycast-self-host image the release already pins, so there's no new image to mirror. It connects once per URL using relaycast's own verify-full TLS (postgresTlsOptions, therds-caConfigMap) and runs relaycast'sverifyIdentityfrom@relaycast/engine/adapters/postgres, the single source of truth with no copied SQL. Relaycast's two logins get the full owner/runtime checks. Every other login gets the attribute and privileged-membership checks (not_superuser,not_createrole,not_createdb,not_replication,not_bypassrls,no_privileged_memberships,login,session_user). The Job is read-only, mounts no SA token, mounts only the URL keys, and reports a missing Secret instead of leaving the pod Pending. Withbefore-hook-creation,hook-succeeded, a failed Job stays around to be read. - Opt-out:
databaseGuard.enabled=falseturns off both checks;databaseGuard.privilegeCheck.enabled=falseturns off only the hook. NOTES warns when the guard is off. - CI hook ban (
scripts/ci/charts.sh): non-test hooks are banned because Alchemy renders with--no-hooks. This hook is advisory, since the migrate Jobs enforce the same rules without it, so the ban now also admits pre-install/pre-upgrade hooks annotatedagentworkforce.dev/preflight: "true". Any other hook still fails. I checked both directions: the annotated hook passes, and the same objects without the annotation fail. Reviewer call: this is the first non-test hook in the umbrella.
Tests
ci/agent-relay/db-guard/kind.sh, wired into the newdb-guard-kindjob in lint.yml: an RDS-shaped PostgreSQL (rdsadmin superuser, master with CREATEROLE/CREATEDB in a NOLOGIN rds_superuser) with TLS from a test CA served asrds-ca, plus realhelm install. 13/13 pass. Cases: master in all 10 URLs, no release left behind, template and client dry-run are a no-op, opt-out, shared login, bare URL in 04, missing Secret, legacy master-owner layout, unnamed administrator caught by the hook, wrong password, correct logins over verify-full (install proceeds and the hook Job is deleted), and an upgrade regression.scripts/selfhost/tests/rds-setup-postgres-test.shwithDB_GUARD=1: the hook script runs against the logins the realrds-setup.sh precreates, and all 10 pass. The same Secrets rewritten to the master, with the name check off, all fail on live privileges, relaycast's owner checks included. 48/48 pass across PG 16/17/18 Ć psql 17/18. This test stays opt-in: it needs a sessions-pipeline checkout.- Also run:
scripts/ci/charts.sh static agent-relay(88 cases),ci/agent-relay/render.sh, allci/agent-relay/test_*.py, the registrycheckandtest.sh, the customer release gate (38), release consistency, support tests, and shellcheck on the new and changed scripts. Only pre-existing warnings remain. Chart.lock is unchanged.
Coordination
- This PR doesn't touch Chart.yaml dependency entries or the CA rendering. The hook mounts whatever
relaycast.postgresCanames, today the operator-createdrds-ca, withoptional: true. When the chart-owned RDS CA lands, a first install's pre-install hook runs before chart-rendered ConfigMaps exist: with no CA, the hook skips the live check for each URL and says so. After that lands, a follow-up should render a hook-weighted copy of the CA so first installs get the full check. - Part of a series: B (actionable migrate errors in relaycast / relay-control / sessions-pipeline), C (
helm teststatus table), and D (guided install as the primary path) follow.
š¤ Generated with Claude Code
Open in [code]smith Ā· Need help on this PR? Tag @codesmith-bot with what you need.
Summary by cubic
Adds databaseGuard to the agent-relay chart (0.7.84) so helm install and upgrade fail before deploying anything when a Secret's database URL is wrong. Previously, wrong credentials ā for example, every URL logging in as the RDS master postgres ā installed cleanly and surfaced later as unrelated migrate failures and CrashLoopBackOffs.
Behavior
- Refuses at render time a master login, two jobs sharing a login, a missing Secret or key, and a wrong value shape; the check is a no-op under
helm templateand client dry-run (--dry-run=serverruns it). The probe is namespaced, so the documented namespace-scoped operator Role works. - A pre-install/pre-upgrade hook Job connects once per URL over verify-full TLS and checks real privileges with relaycast's own
verifyIdentityrules. Each target uses its own component's CA (falling back torelaycast.postgresCa). - URLs are parsed with regexes, never
urlParse, whose errors would echo the URL and password. Render checks also refuse a URL with a login but no host. - Opt out with
databaseGuard.enabled=false(both checks) ordatabaseGuard.privilegeCheck.enabled=false(hook only); NOTES warns when the guard is off. scripts/ci/charts.shnow permits pre-install/pre-upgrade hooks annotatedagentworkforce.dev/preflight: "true"; other non-test hooks still fail.
Testing
- New kind end-to-end test with an RDS-shaped PostgreSQL and TLS (17 cases, including upgrades, opt-out, operator Role, hostless URL, shared key across roles, and migrations off).
- Opt-in
DB_GUARD=1mode in the RDS setup test runs the hook against the loginsrds-setup.sh precreates; 48/48 across PG 16/17/18 Ć psql 17/18.