Skip to content

Commit 9faf7fc

Browse files
committed
Restrict PostgreSQL listen_addresses to localhost and IOP gateway
1 parent dae6d89 commit 9faf7fc

13 files changed

Lines changed: 40 additions & 10 deletions

File tree

development/playbooks/deploy-dev/deploy-dev.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
- role: pre_install
4646
- role: systemd_target
4747
- role: certificates
48+
- role: iop_network
49+
when:
50+
- "enabled_features | has_feature('iop')"
4851
- role: postgresql
4952
- role: valkey
5053
- role: candlepin

development/playbooks/remote-database/remote-database.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
certificates_ca_password: "CHANGEME"
1111
postgresql_ssl_crt: "{{ certificates_ca_directory }}/certs/{{ ansible_facts['fqdn'] }}.crt"
1212
postgresql_ssl_key: "{{ certificates_ca_directory }}/private/{{ ansible_facts['fqdn'] }}.key"
13+
# Dedicated DB host must accept connections from the application host.
14+
postgresql_publish:
15+
- "5432:5432"
1316
vars_files:
1417
- "../../../src/vars/defaults.yml"
1518
- "../../../src/vars/flavors/{{ flavor }}.yml"

docs/iop.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ Advisor and vulnerability frontend assets are extracted from container images an
9696

9797
### Databases
9898

99-
IOP creates five PostgreSQL databases, all accessible to containers via `host.containers.internal:5432`:
99+
IOP creates five PostgreSQL databases, all accessible to containers via the
100+
`postgresql` container on `iop-core-network` (`postgresql:5432`):
100101

101102
| Database | User |
102103
|----------|------|

src/playbooks/deploy/deploy.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
certificate_checks_certificate: "{{ server_certificate }}"
2727
certificate_checks_key: "{{ server_key }}"
2828
certificate_checks_ca: "{{ server_ca_certificate }}"
29+
# IOP network must exist before Postgres joins it when IOP is enabled.
30+
- role: iop_network
31+
when:
32+
- "enabled_features | has_feature('iop')"
33+
- database_mode == 'internal'
2934
- role: postgresql
3035
when:
3136
- database_mode == 'internal'

src/roles/iop_advisor/defaults/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ iop_advisor_container_tag: "foreman-3.18"
55
iop_advisor_database_name: advisor_db
66
iop_advisor_database_user: advisor_user
77
iop_advisor_database_password: "{{ undef(hint='Set a secure database password') }}"
8-
iop_advisor_database_host: host.containers.internal
8+
iop_advisor_database_host: "{{ iop_database_host | default('postgresql') }}"
99
iop_advisor_database_port: 5432

src/roles/iop_inventory/defaults/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ iop_inventory_container_tag: "foreman-3.18"
55
iop_inventory_database_name: inventory_db
66
iop_inventory_database_user: inventory_admin
77
iop_inventory_database_password: "{{ undef(hint='Set a secure database password') }}"
8-
iop_inventory_database_host: host.containers.internal
8+
iop_inventory_database_host: "{{ iop_database_host | default('postgresql') }}"
99
iop_inventory_database_port: 5432

src/roles/iop_remediation/defaults/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ iop_remediation_container_tag: "foreman-3.18"
55
iop_remediation_database_name: remediations_db
66
iop_remediation_database_user: remediations_user
77
iop_remediation_database_password: "{{ undef(hint='Set a secure database password') }}"
8-
iop_remediation_database_host: "host.containers.internal"
8+
iop_remediation_database_host: "{{ iop_database_host | default('postgresql') }}"
99
iop_remediation_database_port: "5432"

src/roles/iop_vmaas/defaults/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ iop_vmaas_container_tag: "foreman-3.18"
55
iop_vmaas_database_name: vmaas_db
66
iop_vmaas_database_user: vmaas_admin
77
iop_vmaas_database_password: "{{ undef(hint='Set a secure database password') }}"
8-
iop_vmaas_database_host: "host.containers.internal"
8+
iop_vmaas_database_host: "{{ iop_database_host | default('postgresql') }}"
99
iop_vmaas_database_port: "5432"
1010

1111
iop_vmaas_client_ca_certificate: "/var/lib/foremanctl/certs/certs/ca.crt"

src/roles/iop_vulnerability/defaults/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ iop_vulnerability_container_tag: "foreman-3.18"
55
iop_vulnerability_database_name: vulnerability_db
66
iop_vulnerability_database_user: vulnerability_admin
77
iop_vulnerability_database_password: "{{ undef(hint='Set a secure database password') }}"
8-
iop_vulnerability_database_host: "host.containers.internal"
8+
iop_vulnerability_database_host: "{{ iop_database_host | default('postgresql') }}"
99
iop_vulnerability_database_port: "5432"
1010

1111
# Taskomatic configuration

src/roles/postgresql/defaults/main.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
postgresql_container_image: quay.io/sclorg/postgresql-16-c10s
33
postgresql_container_tag: "latest"
44
postgresql_container_name: postgresql
5-
postgresql_network: host
65
postgresql_restart_policy: always
76

87
postgresql_data_dir: /var/lib/pgsql/data
@@ -13,4 +12,11 @@ postgresql_max_connections: 500
1312
postgresql_shared_buffers: 512MB
1413
postgresql_effective_cache_size: 1GB
1514

15+
# Bridge networking + localhost publish keeps 5432 off the LAN. When IOP is
16+
# enabled, also join iop-core-network so IOP containers can reach this
17+
# container by name instead of host.containers.internal.
18+
postgresql_networks: "{{ [iop_network_name | default('iop-core-network')] if (enabled_features | default([]) | has_feature('iop')) else [] }}"
19+
postgresql_publish:
20+
- "127.0.0.1:5432:5432"
21+
1622
postgresql_upgrade: "hardlink"

0 commit comments

Comments
 (0)