9 Commits

Author SHA1 Message Date
6e7800721f feat: restrict access to postgres socket
Some checks failed
Continuous Delivery / build_n_upload (push) Has been cancelled
2026-02-24 13:37:10 +01:00
fe30792dbf fix: chown sock directory
Some checks failed
Continuous Delivery / build_n_upload (push) Has been cancelled
2026-02-23 00:16:05 +01:00
0483f61904 fix: create sock directory if not existing
Some checks failed
Continuous Delivery / build_n_upload (push) Has been cancelled
2026-02-23 00:05:14 +01:00
ac5a23350d fix: add systemctl restart
Some checks failed
Continuous Delivery / build_n_upload (push) Has been cancelled
2026-02-22 22:57:20 +01:00
5870da6249 fix: create db users after service start
Some checks failed
Continuous Delivery / build_n_upload (push) Has been cancelled
2026-02-22 22:42:53 +01:00
5bf84b3719 fix: add drop-in directory in spec file
Some checks failed
Continuous Delivery / build_n_upload (push) Has been cancelled
2026-02-22 22:35:06 +01:00
c55e4199e8 fix: postgresql conf quotes
Some checks failed
Continuous Delivery / build_n_upload (push) Has been cancelled
2026-02-22 22:28:21 +01:00
fde6b4b621 fix: override execstart
Some checks failed
Continuous Delivery / build_n_upload (push) Has been cancelled
2026-02-22 21:58:30 +01:00
98dbfe8da5 feat: add db users
Some checks failed
Continuous Delivery / build_n_upload (push) Has been cancelled
2026-02-22 16:24:16 +01:00
4 changed files with 26 additions and 15 deletions

View File

@@ -18,7 +18,7 @@ jobs:
env:
GIT_REFERENCE: ${{ github.ref }}
- name: Build rpm package
run: rpmbuild -ba "%(make name).spec"
run: rpmbuild -ba "$(make name).spec"
- name: Upload rpm package
run: make upload
env:

View File

@@ -5,7 +5,7 @@
#-------------------------------------------------------------------------------
# Change pg_hba location
hba_file = "/etc/postgres/pg_hba.conf"
hba_file = '/etc/postgres/pg_hba.conf'
#-------------------------------------------------------------------------------
@@ -16,7 +16,10 @@ hba_file = "/etc/postgres/pg_hba.conf"
# Empty listen addresses to disable listening via TCP/IP
# because we want only uni socket connections
listen_addresses = ""
listen_addresses = ''
# Forbide access to users not in group postgres
unix_socket_permissions = 0770
#-------------------------------------------------------------------------------
@@ -26,4 +29,4 @@ listen_addresses = ""
#-------------------------------------------------------------------------------
# Redirect logs to stderr to be managed by journald
log_destination = "stderr"
log_destination = 'stderr'

View File

@@ -1,2 +1,3 @@
[Service]
ExecStart=
ExecStart=/usr/bin/postgres -D ${PGDATA} -c config_file=/etc/postgres/postgresql.conf

View File

@@ -22,25 +22,32 @@ Install the database management system called postgresql with a predefined confi
%make_install
%post
# Create databases and users from DB_USERS variable (separator is ",") if not existing
echo "$DB_USERS" | IFS="," read -ra users
for user in "${users[@]}"; do
if ! runuser --user=postgres -- psql --quiet --tuples-only --command='\du' | grep --invert-match postgres | grep --quiet "$user"; then
runuser --user=postgres -- createuser "$user"
runuser --user=postgres -- createdb --owner="$user" "$user"
fi
done
# Create sock directory if not existing
mkdir --parents --mode 755 "%{_rundir}/postgresql"
chown postgres:postgres "%{_rundir}/postgresql"
# Restart services
systemctl daemon-reload
systemctl reenable --now postgresql.service
systemctl reenable postgresql.service
systemctl restart postgresql.service
# Create databases and users from DB_USERS variable (separator is ",") if not existing
IFS="," read -ra users <<< "$DB_USERS";
for user in "${users[@]}"; do
usermod --append --groups postgres "$user";
if ! runuser --user=postgres -- psql --quiet --tuples-only --command='\du' | grep --quiet "$user"; then
runuser --user=postgres -- createuser "$user"
runuser --user=postgres -- createdb --owner="$user" "$user"
fi
done
%files
%attr(755, root, root) %{_sysconfdir}/postgres
%dir %attr(755, root, root) %{_sysconfdir}/postgres
%attr(644, root, root) %{_sysconfdir}/postgres/postgresql.conf
%attr(644, root, root) %{_sysconfdir}/postgres/pg_hba.conf
%dir %attr(755, root, root) %{_unitdir}/postgresql.service.d
%attr(644, root, root) %{_unitdir}/postgresql.service.d/postgres.conf
%changelog
%autochangelog