hirosystems / stacks-blockchain-api

API for the Stacks blockchain
https://stacks-blockchain-api.vercel.app
GNU General Public License v3.0
178 stars 114 forks source link

api-writer fails to connect zalando postgres database #2145

Closed josedev-union closed 3 weeks ago

josedev-union commented 3 weeks ago

Describe the bug We use zalando postgres database for our central database. Api-reader works with this cluster but api-writer fails with the following error.

(node:1) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
(Use `node --trace-warnings ...` to show where the warning was created)
{"level":"info","time":"2024-10-28T09:06:23.033Z","pid":1,"hostname":"stacks-blockchain-api-writer-0","name":"stacks-blockchain-api","component":"core-api","msg":"PgNotifier connected, listening on channel: stacks-api-pg-notifier"}

{"level":"error","time":"2024-10-28T09:06:23.141Z","pid":1,"hostname":"stacks-blockchain-api-writer-0","name":"stacks-blockchain-api","component":"core-api","msg":"could not connect to postgres: error: pg_hba.conf rejects connection for host \"192.168.133.183\", user \"stacks-blockchain-api-new\", database \"stacks_blockchain_api\", SSL off\n    at Parser.parseErrorMessage (/app/node_modules/pg-protocol/src/parser.ts:369:69)\n    at Parser.handlePacket (/app/node_modules/pg-protocol/src/parser.ts:188:21)\n    at Parser.parse (/app/node_modules/pg-protocol/src/parser.ts:103:30)\n    at Socket.<anonymous> (/app/node_modules/pg-protocol/src/index.ts:7:48)\n    at Socket.emit (node:events:519:28)\n    at addChunk (node:internal/streams/readable:559:12)\n    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)\n    at Socket.Readable.push (node:internal/streams/readable:390:5)\n    at TCP.onStreamRead (node:internal/stream_base_commons:191:23) {\n  length: 197,\n  severity: 'FATAL',\n  code: '28000',\n  detail: undefined,\n  hint: undefined,\n  position: undefined,\n  internalPosition: undefined,\n  internalQuery: undefined,\n  where: undefined,\n  schema: undefined,\n  table: undefined,\n  column: undefined,\n  dataType: undefined,\n  constraint: undefined,\n  file: 'auth.c',\n  line: '427',\n  routine: 'ClientAuthentication'\n}"}

{"level":"error","time":"2024-10-28T09:06:23.141Z","pid":1,"hostname":"stacks-blockchain-api-writer-0","name":"stacks-blockchain-api","component":"core-api","err":{"type":"DatabaseError","message":"pg_hba.conf rejects connection for host \"192.168.133.183\", user \"stacks-blockchain-api-new\", database \"stacks_blockchain_api\", SSL off","stack":"error: pg_hba.conf rejects connection for host \"192.168.133.183\", user \"stacks-blockchain-api-new\", database \"stacks_blockchain_api\", SSL off\n    at Parser.parseErrorMessage (/app/node_modules/pg-protocol/src/parser.ts:369:69)\n    at Parser.handlePacket (/app/node_modules/pg-protocol/src/parser.ts:188:21)\n    at Parser.parse (/app/node_modules/pg-protocol/src/parser.ts:103:30)\n    at Socket.<anonymous> (/app/node_modules/pg-protocol/src/index.ts:7:48)\n    at Socket.emit (node:events:519:28)\n    at addChunk (node:internal/streams/readable:559:12)\n    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)\n    at Socket.Readable.push (node:internal/streams/readable:390:5)\n    at TCP.onStreamRead (node:internal/stream_base_commons:191:23)","length":197,"name":"error","severity":"FATAL","code":"28000","file":"auth.c","line":"427","routine":"ClientAuthentication"},"msg":"app failed to start"}

This stacks-api is deployed on K8s cluster using helm chart and zalando PG is deployed using zalando operator. This issue happens in all pg versions, 12, 13, 14, and 15.

To Reproduce Steps to reproduce the behavior:

  1. Create a new user, database and schema in zalando postgres server for stacks-api
  2. Deploy stacks-blockchain-api helm chart (use the credential of the user created at the 1st step)
  3. After Helm release is installed, check pod status
  4. api-reader is running without errors, but api-writer is failing.

Expected behavior Api writer should work.

Screenshots If applicable, add screenshots to help explain your problem.

Console log If applicable, add console log to help explain your problem.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context

zone117x commented 3 weeks ago

This looks like a postgres config issue on your deployment. From the error log it looks like user stacks-blockchain-api-new@192.168.133.183 does not have permission to connect to database named stacks_blockchain_api.

Closing because this doesn't look like an issue with this repo.

josedev-union commented 3 weeks ago

This looks like a postgres config issue on your deployment. From the error log it looks like user stacks-blockchain-api-new@192.168.133.183 does not have permission to connect to database named stacks_blockchain_api.

Closing because this doesn't look like an issue with this repo.

@zone117x as i mentioned, api reader works ok with the same database. Also as you can see the writer's log, pgNotifier connected without any issue

{... "name":"stacks-blockchain-api","component":"core-api","msg":"PgNotifier connected, listening on channel: stacks-api-pg-notifier"}

So i opened this issue because it is not a simple pg config related issue