Skip to content

Commit

Permalink
Add basic security for Patroni REST API (#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
rcknr authored May 3, 2024
1 parent 5f8c073 commit 0384a32
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions roles/patroni/config/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
ansible.builtin.uri:
url: http://{{ inventory_hostname }}:{{ patroni_restapi_port }}/config
method: PATCH
user: "{{ patroni_restapi_username | default(omit) }}"
password: "{{ patroni_restapi_password | default(omit) }}"
body: '{"postgresql":{"parameters":{"{{ item.option }}":"{{ item.value }}"}}}'
body_format: json
loop: "{{ postgresql_parameters }}"
Expand All @@ -53,6 +55,8 @@
ansible.builtin.uri:
url: http://{{ inventory_hostname }}:{{ patroni_restapi_port }}/config
method: PATCH
user: "{{ patroni_restapi_username | default(omit) }}"
password: "{{ patroni_restapi_password | default(omit) }}"
body: '{"postgresql":{"parameters":{"{{ item.option }}":null}}}'
body_format: json
loop: "{{ postgresql_parameters }}"
Expand Down
6 changes: 6 additions & 0 deletions roles/patroni/templates/patroni.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ restapi:
connect_address: {{ inventory_hostname }}:{{ patroni_restapi_port }}
# certfile: /etc/ssl/certs/ssl-cert-snakeoil.pem
# keyfile: /etc/ssl/private/ssl-cert-snakeoil.key
{% if patroni_restapi_password | default('') | length > 0 %}
authentication:
username: {{ patroni_restapi_username | default('patroni') }}
password: {{ patroni_restapi_password }}
{% else %}
# authentication:
# username: username
# password: password
{% endif %}

{% if not dcs_exists|bool and dcs_type == 'etcd' %}
etcd3:
Expand Down
2 changes: 2 additions & 0 deletions roles/update/tasks/switchover.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
ansible.builtin.uri:
url: http://{{ inventory_hostname }}:{{ patroni_restapi_port }}/switchover
method: POST
user: "{{ patroni_restapi_username | default(omit) }}"
password: "{{ patroni_restapi_password | default(omit) }}"
body: '{"leader":"{{ ansible_hostname }}"}'
body_format: json
register: patroni_switchover_result
Expand Down
2 changes: 2 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ pgbouncer_pools:
# Extended variables (optional)
patroni_restapi_listen_addr: "0.0.0.0" # Listen on all interfaces. Or use "{{ inventory_hostname }}" to listen on a specific IP address.
patroni_restapi_port: 8008
patroni_restapi_username: "patroni"
patroni_restapi_password: "restapi-pass" # please change password
patroni_ttl: 30
patroni_loop_wait: 10
patroni_retry_timeout: 10
Expand Down

0 comments on commit 0384a32

Please sign in to comment.