fix: restore defaults to /var/lib/postgresql #1901
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Security Analysis of /var/lib/postgresql/ Permissions
What was there BEFORE commit 388c2da (Oct 22, 2025)?
The directory had NO explicit mode set, meaning it got default permissions from the system when created:
So yes, it was effectively 0755 before the refactor.
What's in /var/lib/postgresql/?
Based on the codebase:
Security Implications
Setting /var/lib/postgresql/ to 0755 is safe because:
- Real data is in /data/pgdata (mode 0750, secure)
- /var/lib/postgresql/data is just a symlink to /data/pgdata
- Traversing through 0755 directory to reach a symlink doesn't bypass the target's permissions
- Nix profile binaries (already public in /usr/bin/)
- .bashrc (just environment variables)
- Extension files (no credentials)
- Database files (in /data/pgdata with 0750)
- Connection passwords (in /etc/postgresql/)
- SSL keys (in /etc/ssl/private/ with 0750)
The October refactor (388c2da) introduced a regression
The refactor changed the behavior from:
This broke symlinks without improving security.
Best Practice Recommendation
Recommended solution: Set /var/lib/postgresql/ to 0755
Security boundaries are correct:
Analysis of documented practices
PostgreSQL Directory Permissions - Security Documentation
Executive Summary
This document provides evidence that setting
/var/lib/postgresql/to 0755 permissions is the standard practice for PostgreSQL installations across major Linux distributions, and explains why this is secure.Problem Statement
After commit
388c2da4a(October 22, 2025), which refactored ansible tasks to meet modern ansible-lint standards, the/var/lib/postgresql/directory was inadvertently set to 0750 permissions. This broke symlink traversal for PostgreSQL binaries, preventing users from executing commands likepsqlthrough symlinks in/usr/bin/.Security Analysis
Critical Distinction: Parent Directory vs Data Directory
PostgreSQL's security model distinguishes between:
Parent/Home Directory (
/var/lib/postgresql/)Data Directory (
/var/lib/postgresql/data→/data/pgdata)Official PostgreSQL Requirements
From PostgreSQL official documentation (v11+):
Important: This requirement applies to the PGDATA directory (
/var/lib/postgresql/data), not the parent directory.Distribution Survey Results
We tested actual PostgreSQL installations across major Linux distributions to document standard practices:
/var/lib/postgresql/var/lib/postgresql/var/lib/postgresql/var/lib/pgsqlTest Commands Used
Analysis of Distribution Choices
Conclusion: Debian-based distributions (which we use) standardize on 0755 for the parent directory.
Our Directory Structure
What's Exposed with 0755 on /var/lib/postgresql/?
Safe to be World-Readable:
/usr/bin/symlinks.bashrc) - Just environment variables (LANG, LOCALE_ARCHIVE)lscommandsNOT Exposed (Still Protected):
/data/pgdatawith strict 0750 permissions/etc/postgresql/and encrypted in database/etc/ssl/private/with 0750 permissionsSecurity Boundaries
PostgreSQL's security model relies on multiple layers:
Opening Layer 1 does NOT compromise Layers 2-4.
Recommended Solution
Set
/var/lib/postgresql/to 0755This is implemented in
ansible/tasks/setup-postgres.yml:Why This is Safe
/data/pgdataremains 0750Testing and Validation
We added comprehensive permission checks in
ansible/files/permission_check.py:This test runs during AMI builds and will fail if any directory has incorrect permissions.
Historical Context
Before October 22, 2025 (Commit 388c2da)
Result:
/var/lib/postgresqlhad 0755 (system default)After October 22, 2025 (Commit 388c2da)
Result: Both
/var/lib/postgresqland/var/lib/postgresql/datagot 0750Regression: Broke symlink traversal without improving security
References
Official Documentation
Distribution Packages
postgresql-commonpostgresqlpostgresql-serverRelated Commits
388c2da4a- "refactor(ansible): bring our ansible up to modern ansible-lint standards" (Oct 22, 2025)/var/lib/postgresqlto 0755Conclusion
Setting
/var/lib/postgresql/to 0755 is:fix to be submitted
root ownership analysis
Evidence from Distribution Survey:
FHS (Filesystem Hierarchy Standard) Requirements:
Why postgres:postgres Was Wrong:
Why root:root Is Correct:
This Commit Was Correct:
Verdict: Keep this change. It fixes a security and compliance issue.
The symlink ownership doesn't affect functionality (symlinks are always traversable regardless of ownership), but having user-owned files in /usr/bin is: