-
-
Notifications
You must be signed in to change notification settings - Fork 537
Allow enabling https for Patroni REST API #1237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ca5fadd to
a440050
Compare
a440050 to
b0e7ba7
Compare
b0e7ba7 to
a76cb0e
Compare
|
The support for https is very initial, and will require manually enabling https on existing cluster, if switching from http to https, by configuring all parameters manually and reloading patroni. This is because the playbook will try to connect to https, before patroni accepts it. For my low-scale use it works, but changing the settings effectively on higher scale will require creating additional logic to switch from http to https. |
This change will be part of the upcoming 2.4 release, and we can highlight it in the release notes. For existing clusters, we can recommend explicitly setting |
24db962 to
56c8d51
Compare
This change introduces new variables: patroni_restapi_protocol patroni_restapi_certfile patroni_restapi_keyfile patroni_restapi_cafile With existing patroni_restapi_connect_addr and patroni_use_unix_socket_repl, it enables secure communication to the Patroni REST API. Resolves: #1234
The role sets default variables. Other playbooks have this role imported indirectly, but update_pgcluster doesn't import other roles, before variables are used. Related to: #1234
56c8d51 to
f8fb7b9
Compare
The location is different in Debian-based and RHEL-based. Related to: #1234
f5d6289 to
521dac2
Compare
Related to: #1234
Replace duplicate functionality with import_role. Related to: #1251
Replaces direct usage of patroni_restapi_cafile with a default to omit when not set, across all relevant Ansible playbooks, roles, and templates. This improves flexibility and prevents errors when the CA file is not provided for Patroni REST API connections.
|
The test with a self-signed certificate for the Patroni REST API was successful — it works. On the client side, you either need to specify the cacert or disable certificate verification (e.g., the -k option in curl). TODO: @vitabaks
|
Refactored the Patroni client to attempt HTTPS requests (with insecure TLS) before falling back to HTTP for monitoring and cluster info endpoints. Introduced a shared getJSON method to handle both protocols and updated GetMonitoringInfo and GetClusterInfo to use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enables HTTPS support for the Patroni REST API by introducing new configuration variables and updating the client code to support both HTTP and HTTPS protocols with automatic fallback.
- Adds HTTPS support with configurable protocol, certificate files, and CA certificate for secure Patroni REST API communication
- Implements automatic HTTPS-to-HTTP fallback in the Go client for backward compatibility
- Updates all Ansible playbooks and tasks to use the new protocol variables consistently across the codebase
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| console/service/pkg/patroni/client.go | Refactored client to support HTTPS with fallback to HTTP, added TLS configuration |
| automation/roles/patroni/templates/patroni.yml.j2 | Added conditional TLS certificate configuration to Patroni config template |
| automation/roles/common/defaults/main.yml | Defined new protocol and certificate variables with defaults |
| automation/roles/patroni/tasks/*.yml | Updated health check URLs to use configurable protocol and CA certificates |
| automation/roles/update/tasks/*.yml | Updated REST API calls to support HTTPS protocol and CA validation |
| automation/roles/upgrade/tasks/*.yml | Updated Patroni API calls to use new protocol variables |
| automation/playbooks/*.yml | Updated playbook API calls to use HTTPS-capable configuration |
| automation/molecule/tests/patroni/patroni.yml | Updated test to use configurable protocol |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
disable certificate verification by setting the tls_skip_verify field to true
Test: Consul service heath-checks & Partoni API with https
Doc: https://developer.hashicorp.com/consul/docs/register/health-check/vm#http-checks commit aba7655 result:
{
"service": {
"name": "test-pgcluster",
"id": "test-pgcluster-master",
"port": 6432,
"checks": [{"http": "https://10.172.0.20:8008/primary", "interval": "2s", "tls_skip_verify": true}, {"args": ["systemctl", "status", "pgbouncer"], "interval": "5s"}],
"tags": ["master", "primary"]
}
{
"service": {
"name": "test-pgcluster",
"id": "test-pgcluster-replica",
"port": 6432,
"checks": [{"http": "https://10.172.0.20:8008/replica?lag=100MB", "interval": "2s", "tls_skip_verify": true}, {"args": ["systemctl", "status", "pgbouncer"], "interval": "5s"}],
"tags": ["replica"]
}
}check: connect: passed |



This change introduces new variables:
patroni_restapi_protocol
patroni_restapi_certfile
patroni_restapi_keyfile
patroni_restapi_cafile
With existing patroni_restapi_connect_addr and patroni_use_unix_socket_repl, it enables secure communication to the Patroni REST API.
Resolves: #1234