Skip to content

Read password from PassFile when connecting.#9810

Open
m000 wants to merge 1 commit intopgadmin-org:masterfrom
m000:passfile-fix
Open

Read password from PassFile when connecting.#9810
m000 wants to merge 1 commit intopgadmin-org:masterfrom
m000:passfile-fix

Conversation

@m000
Copy link
Copy Markdown

@m000 m000 commented Apr 1, 2026

Use PassFile to retrieve a password when one is not retrieved by other means. The PassFile setting was already passed to connect() but was never read.

Summary by CodeRabbit

  • Bug Fixes
    • PassFile-based passwords are now checked later in the credential flow, so decrypted credentials are evaluated first before falling back to external password files.
    • Reading a PassFile now reports explicit failures (I/O or encoding) with a localized error message instead of failing silently.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 1, 2026

Walkthrough

Reordered passfile handling in the psycopg3 connection routine: passfile is derived after credential decryption, and when password remains unset the code reads passfile content (UTF‑8) to populate password, returning False with a localized error on read/decode failures.

Changes

Cohort / File(s) Summary
Passfile credential handling
web/pgadmin/utils/driver/psycopg3/connection.py
Removed early extraction of passfile from kwargs; added from pathlib import Path; derive passfile = Path(...) after _decode_password(...); if password is unset and passfile exists, read passfile.read_text(encoding='utf-8').strip() into password; on OSError/UnicodeDecodeError return False with a localized “Failed to read PassFile” error. Existing fallback checks for manager-provided passfile/pgpass remain.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately describes the main change: implementing password reading from PassFile during connection establishment.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@web/pgadmin/utils/driver/psycopg3/connection.py`:
- Around line 317-320: The current logic creates a Path for kwargs['passfile']
and calls passfile.read_text() without validating that the value is non-empty
and points to a regular readable file; update the code around the passfile
handling so that if kwargs['passfile'] is an empty string it is treated as None,
then verify passfile.exists() and passfile.is_file() before calling
passfile.read_text(), and wrap the read_text() call in a try/except that catches
IsADirectoryError, FileNotFoundError, PermissionError, and UnicodeDecodeError
(and convert or re-raise them as a clear connection error or log appropriately)
so that reading failures do not propagate uncaught from the code that sets the
password variable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 340f95c2-cfcc-42e7-a15f-f262c72b2620

📥 Commits

Reviewing files that changed from the base of the PR and between d8a078a and 98234b0.

📒 Files selected for processing (1)
  • web/pgadmin/utils/driver/psycopg3/connection.py

@m000 m000 force-pushed the passfile-fix branch 2 times, most recently from 55cf4b6 to 50a03d5 Compare April 1, 2026 20:13
Use PassFile to retrieve a password when one is not retrieved by other means.
The PassFile setting was already passed to connect() but was never read.
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@web/pgadmin/utils/driver/psycopg3/connection.py`:
- Around line 316-317: The code constructs Path(kwargs['passfile']) whenever the
'passfile' key exists, which raises TypeError if its value is None; change the
guard so you only call Path(...) when the retrieved value is not None/empty
(e.g., use val = kwargs.get('passfile') and then passfile = Path(val) only if
val is truthy), ensuring the variable passfile remains None otherwise so
downstream exception handling around connect() or the passfile logic can run
safely.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a364471d-0bf2-4720-9580-b8a79cbfc2c3

📥 Commits

Reviewing files that changed from the base of the PR and between 50a03d5 and 7c9be2d.

📒 Files selected for processing (1)
  • web/pgadmin/utils/driver/psycopg3/connection.py

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.

1 participant