Skip to content

fix(slm): database URLs encode their credentials, in one helper (#19812) - #20424

Closed
mrveiss wants to merge 2 commits into
mainfrom
issue-19812-dsn-encoding
Closed

mrveiss wants to merge 2 commits into
mainfrom
issue-19812-dsn-encoding

Conversation

@mrveiss

@mrveiss mrveiss commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

Thinking Path

autobot-admin.py get_db_url put the password straight into the connection URL, so one containing @, :, / or % broke it, and the CLI connected to the wrong host or failed to parse. user_management/config.py _build_url had the same defect, so this fixes the class once rather than each copy.

What Changed

  • New autobot_shared/postgres_dsn.py build_postgres_dsn percent-encodes user and password. No existing helper did this. autobot-admin.py, both user_management/config.py copies and autobot_shared/db_url.py call it.
  • Ansible: the postgresql role's env file and task use one db_url_credentials default; provision-backend-db-single-box.yml encodes in place. urlencode leaves / raw (checked on the local Ansible), so both add replace('/', '%2F').
  • pre_migration_backup.yml: the shell cannot encode, so the discrete-vars branch passes credentials as PGUSER/PGPASSWORD instead of in the URL.
  • api/code_sync.py: pg_dump got the password from urlparse without decoding, which an encoded URL would have broken. It now decodes the password and user.
  • migrations/utils.py parse_db_url: the SLM migration runner passed the URL's credentials to psycopg2 undecoded, the same failure on update. It decodes both now. nl_database_service.py reads external URLs from the secrets manager, not these, so it is not affected by this change; its own bug is bug(nl-db): the MySQL path passes the URL's password still percent-encoded #20428.

Not fixed: docker-compose.yml:596-600 builds three URLs by interpolation, and compose cannot encode. docker/generate-secrets.sh generates hex by default, so only a hand-set password breaks. So this PR says Refs.

Verification

postgres_dsn_19812_test.py, db_url_test.py, postgres_url_credentials_encoded_19812_test.py and test_code_sync_deploy_bugs.py were run locally; CI reads the rest. The @:/% password test through get_db_url is in test_admin_db_credentials_19407.py. SQLAlchemy's make_url and render_as_string round-trip the password (test). No connection to a real Postgres was made.

Worth reviewing:

  • autobot-admin.py imports it from autobot_shared, which slm_manager syncs under the install root. A pinned standalone copy without the updated package hits the existing import-error message, which names where it looked.
  • A password already percent-encoded by hand in an env file would now be encoded twice. The role generates letters and digits, for which encoding changes nothing, and compose generates hex. On the local install slm-secrets.env has no % in its password or URL lines; db-credentials.env and the backend env are not readable by this session, so they were not checked.

Model Used

Claude Opus 5.5

Refs #19812

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 3 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between f88cd37 and 8c8fb56.

Files selected for processing: 17
  • autobot-backend/user_management/config.py
  • autobot-slm-backend/ansible/_shared/tasks/pre_migration_backup.yml
  • autobot-slm-backend/ansible/playbooks/provision-backend-db-single-box.yml
  • autobot-slm-backend/ansible/roles/postgresql/defaults/main.yml
  • autobot-slm-backend/ansible/roles/postgresql/tasks/databases.yml
  • autobot-slm-backend/ansible/roles/postgresql/templates/db-credentials.env.j2
  • autobot-slm-backend/api/code_sync.py
  • autobot-slm-backend/migrations/utils.py
  • autobot-slm-backend/migrations/utils_encoded_url_19812_test.py
  • autobot-slm-backend/scripts/autobot-admin.py
  • autobot-slm-backend/tests/api/test_pg_dump_encoded_url_19812.py
  • autobot-slm-backend/tests/services/test_admin_db_credentials_19407.py
  • autobot-slm-backend/user_management/config.py
  • autobot_shared/db_url.py
  • autobot_shared/postgres_dsn.py
  • autobot_shared/postgres_dsn_19812_test.py
  • repo_tests/postgres_url_credentials_encoded_19812_test.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

✅ SSOT Configuration Compliance: Passing

🎉 No new hardcoded values of either class — ssot and other both block.

Known backlog in pipeline-scripts/hardcoded_values_baseline.txt is suppressed and tracked in #14371.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Notice: 29 open PRs — past the runaway threshold (25)

This is not a request to defer this PR. There is no cap on open PRs (#19397) -- nothing blocks opening or pushing a PR.

This notice only means the count is high enough to be worth a glance for a runaway — something opening PRs in a loop, or a merge pipeline that has stalled so nothing is draining.

Currently open:

If the queue is draining normally, ignore this. Otherwise:

  1. Check whether CI is dispatching at all — see the ci-dispatch-watchdog status on these PRs
  2. Approved PRs land through the merge train the coordinator sequences (merge commits, never squash) -- check the open chore(merge-train) PR is moving, not each PR on its own
  3. Look for a loop opening near-identical PRs

Warn-only runaway detector — .github/workflows/pr-queue-gate.yml. It never blocks a merge.

@mrveiss

mrveiss commented Nov 1, 2026

Copy link
Copy Markdown
Owner Author

Code review on PR #20424 (head ea73398): approve. Delta since ede6e36, read only: the SLM migration parser decodes user and password, with a test. Compose is the only raw URL writer left, recorded on #19812; it stays Refs. No real Postgres connection has been made, and the host env files were not read.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Auto-sync: merging main into issue-19812-dsn-encoding conflicts

The sync aborted the merge and pushed nothing. Conflicts are information, so it never resolves one itself. Below, for each conflicted file, are the commits that touched it on each side since the merge base 04c4ed7994. Merge main in yourself and push; the label clears on the first run that finds this branch 0 behind.

repo_tests/chunk_identity_single_home_18142_test.py

side commit subject issue refs
main f83312d05 chore(guards): re-pin the reach floors the pre-push gate reported stale (#20264) #20264
this branch 2d9fef863 chore(guards): re-pin the reach floors main's growth left stale (#19812) #19812

repo_tests/direct_secrets_service_callers_17773_test.py

side commit subject issue refs
main f83312d05 chore(guards): re-pin the reach floors the pre-push gate reported stale (#20264) #20264
this branch 2d9fef863 chore(guards): re-pin the reach floors main's growth left stale (#19812) #19812

@mrveiss mrveiss added the phase:M1.4 Wizard and SLM: choose a mode, apply it, default models work label Nov 1, 2026
@mrveiss

mrveiss commented Nov 1, 2026

Copy link
Copy Markdown
Owner Author

Landed via the merge train (PR #20458), main 0dbb02f.

@mrveiss

mrveiss commented Nov 1, 2026

Copy link
Copy Markdown
Owner Author

Closed: 0 changed files; the content is on main via the merge train (PR #20458).

@mrveiss mrveiss closed this Nov 1, 2026
@mrveiss
mrveiss deleted the issue-19812-dsn-encoding branch November 1, 2026 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

phase:M1.4 Wizard and SLM: choose a mode, apply it, default models work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant