SELinux
ps -eo label,pid,user,comm,args | grep '[p]ostgres'Expected output
system_u:system_r:unconfined_service_t:s0"unconfined_service_t" means that PostgreSQL is not running in its own restricted domain.
dnf install policycoreutils-python-utils selinux-policy-doc setools-console
semanage fcontext -a -t postgresql_exec_t '/usr/pgsql-16/bin/(postgres|postmaster|pg_ctl|initdb)'Apply the rule
restorecon -v "/usr/pgsql-16/bin/postgres" "/usr/pgsql-16/bin/pg_ctl" "/usr/pgsql-16/bin/initdb"Verification
ls -lZ "/usr/pgsql-16/bin/postgres" "/usr/pgsql-16/bin/pg_ctl" "/usr/pgsql-16/bin/initdb" matchpathcon -V "/usr/pgsql-16/bin/postgres" "/usr/pgsql-16/bin/pg_ctl" "/usr/pgsql-16/bin/initdb"Expected type
postgresql_exec_t
systemctl stop postgresql-16.serviceAdd a persistent rule
semanage fcontext -a -t postgresql_db_t '/app/postgres/data(/.*)?'Apply the rule to existing data
restorecon -Rv "/app/postgres/data"Verification
ls -ldZ "/app/postgres/data" find "/app/postgres/data" -maxdepth 2 -printf '%Z %p\n' | head -50 matchpathcon -V "/app/postgres/data"Expected data type
postgresql_db_t
namei -l "/app/postgres/data"
ls -ldZ \
/app \
/app/postgres \
/app/postgres/data
systemctl start postgresql-16.service systemctl status postgresql-16.service --no-pagerCheck the processes
ps -eo label,pid,user,comm,args | grep '[p]ostgres'Expected output
system_u:system_r:postgresql_t:s0Data directory
ls -ldZ "/app/postgres/data"The expected result contains
system_u:object_r:postgresql_db_t:s0A typical correct combination is therefore
binary: postgresql_exec_t process: postgresql_t data: postgresql_db_t