Visitar URL original
ssl: align key file permission check with libpq by harinath001 · Pull Request #3952 · pgjdbc/pgjdbc · GitHub
Skip to content

ssl: align key file permission check with libpq - #3952

Merged
davecramer merged 1 commit into
pgjdbc:masterfrom
harinath001:640_fix
Mar 10, 2026
Merged

davecramer merged 1 commit into
pgjdbc:masterfrom
harinath001:640_fix

Conversation

@harinath001

Copy link
Copy Markdown
Contributor

Context

pgjdbc currently refuses to connect if a private key file has any group or other permissions —
it strictly requires 0600. That's a safe default, but it's stricter than what libpq (the
reference PostgreSQL C client) actually enforces.

libpq makes a practical distinction: if the key file is owned by root, it allows group-read
(0640). This matters in real deployments where a system administrator owns the certificates
and grants read access to a service account via group membership. With pgjdbc's current behavior,
those setups break — even though psql and every other libpq-based client works just fine with
them.

For non-root-owned files, libpq is strict: no group or other access. pgjdbc agrees on that part.
The gap is only for root-owned files, and that's what this PR closes.

The relevant check in libpq's fe-secure-openssl.c is:

if (buf.st_uid == 0 ?
    buf.st_mode & (S_IWGRP | S_IXGRP | S_IRWXO) :
    buf.st_mode & (S_IRWXG | S_IRWXO))

Changes to Existing Features:

  • The only behavioral change is that root-owned key files with GROUP_READ (0640) are now
    accepted instead of rejected, matching libpq. All other permission checks remain unchanged.

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Does ./gradlew styleCheck pass ?
  3. Have you added your new test classes to an existing test suite in alphabetical order?

Root-owned key files with GROUP_READ (0640) are now accepted,
matching the behavior of libpq and psql. Non-root-owned files
still require 0600 or stricter.

Splits validatePosixPermissions into isFileOwnedByRoot and
hasInsecurePosixPermissions for clarity. Adds four tests covering
the permission matrix, skipped on non-POSIX systems.
@davecramer

Copy link
Copy Markdown
Member

I don't see any issues with this. Will merge if no objections

@harinath001

Copy link
Copy Markdown
Contributor Author

@davecramer yeah, this change will be very helpful in many environments !! Waiting for the merge and release , thank you !!

@davecramer
davecramer merged commit d45f279 into pgjdbc:master Mar 10, 2026
17 checks passed
@tonirevert

tonirevert commented May 19, 2026 •

Copy link
Copy Markdown

After this change, the certificates that we use in our company started to fail on DBeaver because of the permission checks...

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.

3 participants