SELinux Security Policy Adjustment
SELinux (Security-Enhanced Linux) is a Linux kernel security module that enforces mandatory access control policies, enhancing security by restricting user and process actions based on predefined rules. It adds an extra layer of protection by limiting the impact of vulnerabilities and attacks.
It is important to properly configure SELinux to ensure that the PostgreSYS Platform services work correctly.
Below are some steps to adjust SELinux security policies for PostgreSQL:
-
Check SELinux status
Terminal inputsestatus
-
Adjust SELinux policies to allow network connections for PostgreSQL
Terminal inputsudo setsebool -P <BOOLEAN> <VALOR>
noteReplace
<BOOLEAN>
with the name of the SELinux policy boolean to be configured (e.g.,postgresql_can_network_connect
) and<VALOR>
with 1 (enable) or 0 (disable) -
Add security contexts to PostgreSQL directories
-
Generic command to add a security context (Replace
<DIRETORIO>
with the directory path and<CONTEXTO>
with the desired context)Terminal inputsudo semanage fcontext -a -t <CONTEXTO> "<DIRETORIO>"
-
Apply the security context
Terminal inputsudo restorecon -Rv <DIRETORIO>
-
-
Configure SELinux to allow network connections and add security contexts to PostgreSQL directories
-
Allow network connections for PostgreSQL
Terminal inputsudo setsebool -P postgresql_can_network_connect 1
-
Add security context for PostgreSQL directories
Terminal inputDIRETORIOS=("/var/lib/pgsql" "/var/lib/pgsql/data")
for DIR in "${DIRETORIOS[@]}"; do
sudo semanage fcontext -a -t postgresql_db_t "${DIR}(/.*)?"
sudo restorecon -Rv ${DIR}
done
-