fix: handle 'role does not exist' error for PG gateway connection test#5802
Conversation
When testing DB connectivity via gateway with a dummy role, PostgreSQL returns different errors depending on the pg_hba.conf auth method: - md5/password/trust: 'role does not exist' (was NOT handled) - scram-sha-256: 'password authentication failed' (was already handled) Both errors confirm successful connectivity to the target database. Added handling for the 'role does not exist' case so connection validation succeeds regardless of the PG auth configuration. Co-Authored-By: saif <[email protected]>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Greptile SummaryThis PR fixes a narrow but impactful bug: when testing Postgres connectivity via the PAM gateway, the code previously only accepted
Confidence Score: 5/5
Important Files Changed
|
…and rotateAccountCredentials Extends the role-not-exist error handling to the credential validation and rotation paths, so users on md5/password/trust PG auth configs get the friendly 'Username or password incorrect' / 'Management credentials invalid' messages instead of a generic error. Co-Authored-By: saif <[email protected]>
Co-Authored-By: saif <[email protected]>
Context
When adding a PAM resource via gateway, we test connectivity to the target PostgreSQL database using a dummy role
infisical-gateway-connection-test. The test intentionally expects an auth failure as proof that the DB is reachable.However, PostgreSQL returns different errors depending on the
pg_hba.confauth method for the matching connection rule:scram-sha-256password authentication failed for user "..."md5/password/trustrole "..." does not existThe difference is that
scram-sha-256doesn't reveal whether a role exists, whilemd5/password/trustlooks up the role first and returns the "does not exist" error before attempting authentication.This was hitting users who run the gateway and DB on the same host (matching a
trustormd5rule inpg_hba.conffor localhost connections).Fix: Add
role "..." does not existas an additional accepted error across all three Postgres error-handling paths insql-resource-factory.ts:connectOnly=true(connection validation) — treat the error as proof of connectivity, same as "password authentication failed"validateAccountCredentials— map to friendly "Account credentials invalid: Username or password incorrect" messagerotateAccountCredentials— map to friendly "Management credentials invalid: Username or password incorrect" messageSteps to verify the change
md5ortrustauth inpg_hba.conffor the connecting hostHuman review checklist
role "..." does not existmatches the actual PostgreSQL error format across supported PG versions (9.x through 16+)connectOnly=truepath still does not allow real auth failures to pass silentlyvalidateAccountCredentialsandrotateAccountCredentialscorrectly surface the friendly error for both "password auth failed" and "role does not exist" casesType
Checklist
type(scope): short descriptionLink to Devin session: https://app.devin.ai/sessions/b0c07121154642f288d196702da9503a