Skip to content

Verify the server certificate against the host name in utilities run over an SSH tunnel. #10861 - #10915

Merged
dpage merged 1 commit into
pgadmin-org:masterfrom
dpage:fix/issue-10861-tunnel-hostaddr
Dec 1, 2026
Merged

dpage merged 1 commit into
pgadmin-org:masterfrom
dpage:fix/issue-10861-tunnel-hostaddr

Conversation

@dpage

@dpage dpage commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Backup, restore, maintenance, import/export and the materialised view refresh passed the tunnel's local address (127.0.0.1) as the host, so with sslmode=verify-full libpq checked the certificate against that address and the utility failed.
  • They now get the server's host name as --host (or PGHOST) with the tunnel's local port, and BatchProcess._set_env_variables() sets PGHOSTADDR to the tunnel's local address in place of dropping it, matching the interactive connection (create_connection_string() already uses host plus hostaddr). PGHOSTADDR is inherited by the pg_dump processes pg_dumpall starts, so they route through the tunnel too.
  • The Processes list now shows the server's host name with the tunnel's local port rather than 127.0.0.1.

Test plan

  • New utils.tests.test_utility_ssh_tunnel: --host/--port for backup, pg_restore and plain restore, and PGHOSTADDR in the utility environment, with and without a tunnel; 5 of its scenarios fail on master.
  • misc.bgprocess.tests, tools.backup.tests, tools.restore.tests, tools.maintenance.tests, tools.import_export.tests, utils.tests.test_utility_conninfo_call_sites
  • Checked by hand that psql -h db.example.invalid with PGHOSTADDR=127.0.0.1 connects through the given address, and with PGSSLMODE=verify-full goes on to certificate verification.
  • pycodestyle

Closes #10861

Summary by CodeRabbit

  • Bug Fixes
    • Database utilities now use the configured database hostname when connecting through an SSH tunnel, while continuing to use the tunnel’s local port.
    • SSH-tunneled background processes now use the tunnel address for connection routing. Server-name reporting also consistently shows the configured hostname.
  • Tests
    • Added coverage for connection arguments and environment settings with and without SSH tunnels.

…over an SSH tunnel. pgadmin-org#10861

Backup, restore, maintenance, import/export and the materialised view
refresh were given the tunnel's local address as their host, so with
sslmode=verify-full libpq checked the server certificate against
127.0.0.1 and the utility failed. They now get the database host name
and the tunnel's local port, and reach the local end of the tunnel
through PGHOSTADDR, as the interactive connection does.

Closes pgadmin-org#10861
@dpage dpage self-assigned this Dec 1, 2026
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

For SSH-tunneled connections, utility invocations now use the configured database host while retaining the tunnel’s local port. Background processes set PGHOSTADDR to the tunnel’s local address. Tests cover utility arguments and environment values with and without tunnels.

Changes

Utility Connections Through SSH Tunnels

Layer / File(s) Summary
Utility host and port arguments
web/pgadmin/browser/server_groups/servers/databases/schemas/views/__init__.py, web/pgadmin/tools/backup/__init__.py, web/pgadmin/tools/import_export/__init__.py, web/pgadmin/tools/maintenance/__init__.py, web/pgadmin/tools/restore/__init__.py, web/pgadmin/utils/tests/test_utility_ssh_tunnel.py
Utility arguments and server-name reporting use the configured database host. Tunnel-aware port selection remains in place. Tests check backup, restore, and plain-restore arguments with and without a tunnel.
Tunnel address environment
web/pgadmin/misc/bgprocess/processes.py, web/pgadmin/utils/tests/test_utility_ssh_tunnel.py
Tunneled processes set PGHOSTADDR to the tunnel’s local address. Tests check tunnel and non-tunnel environment values.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: rohitbhati8269, asheshv

Merge Risk: Minimal · up to 457a1

Utilities run over SSH tunnels now verify the certificate against the database host name while routing through the tunnel. No material merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: utilities run over an SSH tunnel now verify the server certificate against the database host name. The raw summary shows backup, restore, maintenance, import/export, a…
Linked Issues check Passed [#10861] The issue requires that utilities over an SSH tunnel verify the certificate against the database host name, with the tunnel's local address used for routing. The diffs at the reviewed head im…
Out of Scope Changes check Passed All changed areas relate to #10861. They are the utility host and port selection in backup, restore, maintenance, import/export and the materialised view refresh, the PGHOSTADDR handling in BatchPro…
Full details: Title check

Explanation

The title names the main change: utilities run over an SSH tunnel now verify the server certificate against the database host name. The raw summary shows backup, restore, maintenance, import/export, and the materialised-view refresh now pass server.host for --host/PGHOST/PGHOSTADDR-related routing, with the tunnel's local port kept. The title matches the linked issue #10861 and the PR objectives. It is specific and not vague, though it does not mention the PGHOSTADDR environment change. The title is 95 characters, slightly over a typical short title length, but it is still a single clear sentence.

Full details: Linked Issues check

Explanation

[#10861] The issue requires that utilities over an SSH tunnel verify the certificate against the database host name, with the tunnel's local address used for routing. The diffs at the reviewed head implement this:

  • backup (web/pgadmin/tools/backup/init.py): --host and the server name use s.host/server.host. --port uses manager.local_bind_port when a tunnel is active.
  • BatchProcess._set_env_variables (web/pgadmin/misc/bgprocess/processes.py): when manager_obj.use_ssh_tunnel is set, PGHOSTADDR is set to manager_obj.local_bind_host instead of being removed. This matches the issue's host plus hostaddr approach.
  • The PR description states the same host and port handling for restore, maintenance, import/export and the materialised view refresh. The summaries for those files show the same pattern: the host is the server host and the port is tunnel-aware.
    The new tests in utils.tests.test_utility_ssh_tunnel cover --host/--port and PGHOSTADDR with and without a tunnel. I did not run the tests. I checked the source diffs for processes.py and backup only. The other files rely on the summary, which is consistent with the same pattern.
Full details: Out of Scope Changes check

Explanation

All changed areas relate to #10861. They are the utility host and port selection in backup, restore, maintenance, import/export and the materialised view refresh, the PGHOSTADDR handling in BatchProcess._set_env_variables, the Processes list server-name display, and the new tests for these paths. No unrelated refactoring or feature change appears in the summary or the inspected diffs.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • 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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4129152 and 457a1d8.

Files selected for processing: 7

  • web/pgadmin/browser/server_groups/servers/databases/schemas/views/__init__.py
  • web/pgadmin/misc/bgprocess/processes.py
  • web/pgadmin/tools/backup/__init__.py
  • web/pgadmin/tools/import_export/__init__.py
  • web/pgadmin/tools/maintenance/__init__.py
  • web/pgadmin/tools/restore/__init__.py
  • web/pgadmin/utils/tests/test_utility_ssh_tunnel.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@dpage
dpage merged commit ef2e40f into pgadmin-org:master Dec 1, 2026
32 checks passed
@dpage
dpage deleted the fix/issue-10861-tunnel-hostaddr branch December 1, 2026 12:01
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.

Utilities over an SSH tunnel fail sslmode=verify-full

1 participant