Repository navigation
fix(proxy-extras): accept unencoded DB passwords in the v2 migration lock and redact its errors - #46592
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
|
|
@greptileai please review this PR at 66a77fe |
[Critical impact] The PR appears safe to merge; no actionable issue remains. SummaryThis PR makes database URLs with spaces or quotes in credentials usable by the migration coordinator.
Both earlier, unnumbered findings are addressed. No new actionable issue was found. The full PR diff was reviewed because the rebased head did not pass the previous-review ancestry checks. Tests were inspected but not run. Reviews (4) · Last reviewed commit: "fix(proxy-extras): accept unencoded DB p..." · Reviewed by Greptile |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
66a77fe to
8fd989a
Compare
|
@greptileai please re-review at 8fd989a82e, TLS and certificate errors no longer get the P1001 label |
|
@greptileai please re-review at 5022e26, TLS markers now ignore quoted hostnames so unreachable hosts keep P1001 |
8fd989a to
5022e26
Compare
…lock and redact its errors Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
5022e26 to
2fe5c14
Compare
|
@greptileai review at 2fe5c14 after rebasing onto main |
|
@litereview code-review |
✅ code-review5/5 · Ready for human reviewScope: full · Full PR review. Completed · Some checks not run. No correctness findings. Checks and execution details
View review · Reviewed |
TLDR
Problem this solves:
How it solves it:
User Flow
Before: an operator whose DB password has a space or quote cannot boot the proxy, and the error shows the password
--use_v2_migration_resolverandDATABASE_URL=postgresql://user:wr ong'pw9@host:5432/dbunexpected spaces found in "wr ong'pw9"even though the database is upAfter: the same URL boots, and failures name the cause without the password
DATABASE_URLP1001: Can't reach database server at host:portand no passwordFiles changed
litellm-proxy-extras/litellm_proxy_extras/utils.py_strip_prisma_query_paramsnow re-encodes the user and password for libpq, also when the URL has no query string. The redaction helpers moved out to_redaction.pyand are imported backlitellm-proxy-extras/litellm_proxy_extras/_redaction.pymigration_lock.pycan use them without importingutils.py(which imports it)litellm-proxy-extras/litellm_proxy_extras/migration_lock.pyP1001: Can't reach database server at host:portunder the existing message prefixWhen
--use_v2_migration_resolverrunsprisma migrate deploy, it first opens a psycopg connection to hold the coordinator lock (added in #46368). psycopg parses the URL itself and rejects an unencoded password that Prisma accepts, before any socket is opened, and the raw psycopg message went straight into the boot error. Prisma never ran, so P1001 was never printed eitherThe URL fix lives in
_strip_prisma_query_params, so the other psycopg legs that already go through it (migration ledger reads, the Lens safety check, request log index build) accept the same passwords tooAffected release
Regression from #46368, on main only
Linear ticket
Resolves LIT-9639
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreScreenshots / Proof of Fix
Same commands on both sides against a local Postgres 16.
PYTHONPATHpoints at this checkout, and the build is identified by whetherlitellm_proxy_extras.migration_lockexposes_redact_credentials(False at the base, True at the tip). After rebasing onto 84e8204 the unreachable, reachable and wrong-password legs were re-run on both sides with the same results as below (base exits 2 with the password in the error for both the closed port and the live database, the tip prints P1001 for the closed port, applies all 219 migrations on the live database and exits 0, and keeps the wrong-password failure free of P1001 and of every password fragment). The passwordwr ong'pw9is a throwaway test value for a throwaway roleBefore (84e8204, merge base)
Unreachable database
DATABASE_URL="postgresql://lit9639:wr ong'pw9@127.0.0.1:41127/lit9639" litellm --config /tmp/lit9639.yaml --use_v2_migration_resolver --skip_server_startupReachable database, same password
DATABASE_URL="postgresql://lit9639:wr ong'pw9@localhost:5432/lit9639" litellm --config /tmp/lit9639.yaml --use_v2_migration_resolver --skip_server_startupWrong password
Not run at the base, since the base rejects this URL shape before authentication like the case above
After (2fe5c14)
Unreachable database
Reachable database, same password
python litellm/proxy/proxy_cli.py --config /tmp/lit9639_proxy.yaml --port 4000 --use_v2_migration_resolver, modelopenai/gpt-5.4-mini), then a real calladminwith the master key, pickgpt-5.4-mini, sendReply with the single word: pong. The reply comes back through the proxy that booted from the unencoded-password URLWrong password
DATABASE_URL="postgresql://lit9639:wr ong'pw8@localhost:5432/lit9639" litellm --config /tmp/lit9639.yaml --use_v2_migration_resolver --skip_server_startupTLS failure on a reachable database
DATABASE_URL="postgresql://lit9639:wr ong'pw9@localhost:5432/lit9639?sslmode=verify-full&sslrootcert=/nonexistent"with the same commandP1001: Can't reach database server at 127.0.0.1:5432before the certificate detail. Now the label is gone, the detail stays, exit 2certificate-db.invalidprintsP1001: Can't reach database server at certificate-db.invalid:5432, exit 2?sslmode=requirestill prints P1001 and exits 2, and the reachable database without sslmode still exits 0Tests:
tests/integration/database/test_v1_migration_error_logging.py::test_v2_resolver_unreachable_database_exits_2_and_names_p1001(the CI failure from the ticket) now passes unchanged, and new cases cover the reachable boot, the wrong password, the libpq URL rewrite and the lock error. Mutation checks: dropping the userinfo encoding, the redaction, the P1001 branch, or theFATAL:guard each fails at least one of themTaxonomy audit (A-BB) on the final diff
M3 fixed: the
FATAL:check ran on redacted text, so a password containingFATALcould turn an auth failure into P1001. It now reads the raw psycopg text, with a regression testM1 fixed:
raise ... from exckept the raw psycopg error in__cause__, so a traceback printed the password. Both wrappers now usefrom None, and the integration test asserts the formatted traceback has no password fragmentH5, H6 not changed:
_REDACTEDwas already a module constant inutils.pyand moved as is.litellm-proxy-extrasis a separate package and cannot importlitellm.constantsF3 covered: the other psycopg legs (ledger reads, Lens check, request log index build) already go through
_strip_prisma_query_params, so they get the same URL handlingGreptile P2 fixed: a reachable server with a TLS or certificate error was labeled P1001. Messages carrying
SSLorcertificatenow keep the plain detail, with unit tests for three TLS shapes and aConnection refusedcontrolGreptile P2 fixed: a hostname such as
certificate-db.internalhid the P1001 label. The markers are now matched with quoted segments removed, since libpq and psycopg quote hosts, users and file pathsU3, U6 checked: userinfo is decoded then re-encoded, so already-encoded passwords keep their meaning, and URLs built by
construct_database_url_from_env_varswithquote_plusreach libpq exactly as beforeT1-T5, T17 checked: no assertion was removed under
tests/relative to the merge base, and the core integration case fails at the baseEvery other item was judged not applicable to this diff
Type
🐛 Bug Fix
Caveats (if any)
Low
FATAL:,SSL,certificatetextlc_messagescould show P1001 for an auth failureFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/d7f3f94494444264a7f763ef1a2907ea
Open in Devin Desktop: https://app.devin.ai/desktop/session/d7f3f94494444264a7f763ef1a2907ea?variant=devin
Requested by: @yassin-berriai