Skip to content

fix(cubejs): match checkSqlAuth signature to Cube.js v1.6#41

Merged
acmeguy merged 1 commit intomainfrom
fix/check-sql-auth-signature
Apr 20, 2026
Merged

fix(cubejs): match checkSqlAuth signature to Cube.js v1.6#41
acmeguy merged 1 commit intomainfrom
fix/check-sql-auth-signature

Conversation

@acmeguy
Copy link
Copy Markdown

@acmeguy acmeguy commented Apr 20, 2026

Summary

  • Fix checkSqlAuth callback signature — Cube.js v1.6 passes (request, user, password) as three positional args; our code expected (_, user) and treated the username string as the password.
  • Unblocks Postgres / MySQL wire auth against the CubeJS SQL API.

Root cause

@cubejs-backend/api-gateway/dist/src/sql-server.js:291,105 wraps the callback and always calls it with three positional args. When a Postgres client connects (e.g. psql -U e0m19ghdz9), Cube hands us:

request  = { protocol: "postgres", method: "password", apiType: "sql" }
user     = "e0m19ghdz9"
password = "<client-supplied>"

The existing code:

const checkSqlAuth = async (_, user) => {
  const password = typeof user === "string" ? user : user?.password;
  const username = typeof user === "string" ? _    : user?.username;
  ...
  const sqlCredentials = await findSqlCredentials(username || user);
}

With user being a string, this assigned the username string to password and the request object to username. findSqlCredentials then called Hasura with an object variable:

parsing Text failed, expected String, but encountered Object
path: $.selectionSet.sql_credentials.args.where.username._eq

Every SQL login failed before the password was ever compared. Reproduced with psql -h <cubejs> -p 15432 -U <valid> -d db28P01 FATAL: password authentication failed.

Fix

  • Declare the callback with the v1.6 signature: (request, userArg, passwordArg).
  • Keep a defensive branch for the legacy object-shape ({ username, password }) to not break anyone still on the old path.
  • Reject non-string username before the Hasura lookup so a misrouted request surfaces as Incorrect user name or password rather than a 503 with a GraphQL parse error.

Test plan

  • Build new container image; update data/synmetrix/overlays/dev/kustomization.yaml to the new tag
  • Deploy and verify psql -h dbx.fraios.dev -p 15432 -U <valid_sql_user> -d db authenticates
  • Verify JWT-as-password path still works (psql -U <datasource_id> -d db with a FraiOS JWT in PGPASSWORD)
  • Verify a bad password still returns 28P01

🤖 Generated with Claude Code

Cube.js v1.6 invokes checkSqlAuth as (request, user, password) — three
positional args — see
@cubejs-backend/api-gateway/dist/src/sql-server.js:291,105.

Our implementation declared (_, user) and did:
  password = typeof user === "string" ? user : user?.password
  username = typeof user === "string" ? _     : user?.username

With the v1.6 wire server, user arrives as a plain string (the Postgres
username), so the code took the username as the password AND used the
request metadata object as the username. findSqlCredentials then
received the {protocol, method, apiType} object, and Hasura rejected
the query with:

  parsing Text failed, expected String, but encountered Object
  path: $.selectionSet.sql_credentials.args.where.username._eq

Every SQL API login failed before any password comparison ran
(reproduced via `psql -U <valid> -h <cubejs>` → 28P01).

Fix: match the documented v1.6 signature and keep a defensive branch
for the legacy object-shape call. Also reject non-string username
early so the Hasura GraphQL layer cannot receive a non-string variable.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@akshaykumar2505 akshaykumar2505 self-requested a review April 20, 2026 16:16
@acmeguy acmeguy merged commit ed6915a into main Apr 20, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants