Skip to content

Commit

Permalink
Generate TLS cert only on PGBouncer role
Browse files Browse the repository at this point in the history
  • Loading branch information
klention committed Dec 17, 2024
1 parent a641891 commit 2c84108
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 29 deletions.
21 changes: 0 additions & 21 deletions automation/roles/patroni/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -816,27 +816,6 @@
(existing_pgcluster is not defined or not existing_pgcluster|bool)
tags: patroni

# Generating TLS Certificates
- block:
- name: Generate a private key for TLS (if not exist)
become: true
become_user: postgres
community.crypto.openssl_privatekey:
path: "{{ postgresql_conf_dir }}/server.key"
size: '4096'
mode: '0400'

- name: Generate a self-signed certificate for Postgres (if not exist)
community.crypto.x509_certificate:
path: "{{ postgresql_conf_dir }}/server.crt"
privatekey_path: "{{ postgresql_conf_dir }}/server.key"
owner: postgres
group: postgres
mode: '0644'
provider: selfsigned
entrust_not_after: "+1000d"
when: (postgresql_parameters | selectattr('option', 'equalto', 'ssl') | map(attribute='value') | first | default('off')) == 'on'

- block: # start patroni on master
- name: Start patroni service on the Master server
ansible.builtin.systemd:
Expand Down
12 changes: 6 additions & 6 deletions automation/roles/pgbouncer/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,24 +126,24 @@

# Generating TLS Certificates
- block:
- name: Generate a private key for TLS
- name: Generate a private TLS key for PostgreSQL & PGBouncer
become: true
become_user: postgres
community.crypto.openssl_privatekey:
path: "{{ pgbouncer_conf_dir }}/server.key"
size: '4096'
mode: '0400'
size: "4096"
mode: "0400"

- name: Generate a self-signed certificate for PGBouncer
- name: Generate a self-signed TLS certificate for PostgreSQL & PGBouncer
community.crypto.x509_certificate:
path: "{{ pgbouncer_conf_dir }}/server.crt"
privatekey_path: "{{ pgbouncer_conf_dir }}/server.key"
owner: postgres
group: postgres
mode: '0644'
mode: "0644"
provider: selfsigned
entrust_not_after: "+1000d"
when: pgbouncer_server_tls_sslmode | default('disable') != 'disable'
when: (pgbouncer_server_tls_sslmode | default('disable') != 'disable') or ((postgresql_parameters | selectattr('option', 'equalto', 'ssl') | map(attribute='value') | first | default('off')) == 'on')

Check failure on line 146 in automation/roles/pgbouncer/tasks/main.yml

View workflow job for this annotation

GitHub Actions / build

yaml[line-length]

Line too long (200 > 160 characters)

Check failure on line 146 in automation/roles/pgbouncer/tasks/main.yml

View workflow job for this annotation

GitHub Actions / build

146:161 [line-length] line too long (200 > 160 characters)

- name: Configure pgbouncer.ini
ansible.builtin.template:
Expand Down
4 changes: 2 additions & 2 deletions automation/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ postgresql_parameters:
- { option: "superuser_reserved_connections", value: "5" }
- { option: "password_encryption", value: "{{ postgresql_password_encryption_algorithm }}" }
- { option: "ssl", value: "on"}
- { option: "ssl_cert_file", value: "{{ postgresql_conf_dir }}/server.crt"}
- { option: "ssl_key_file", value: "{{ postgresql_conf_dir }}/server.key"}
- { option: "ssl_cert_file", value: "{{ pgbouncer_conf_dir }}/server.crt"}
- { option: "ssl_key_file", value: "{{ pgbouncer_conf_dir }}/server.key"}
- { option: "ssl_min_protocol_version", value: "TLSv1.2"}
- { option: "max_locks_per_transaction", value: "512" }
- { option: "max_prepared_transactions", value: "0" }
Expand Down

0 comments on commit 2c84108

Please sign in to comment.