Skip to content

Commit 3519359

Browse files
committed
feat: add support for Raft HA in OpenBao
Add support for deploying `OpenBao` with Raft storage backend configured in a high available manner.
1 parent 9870125 commit 3519359

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

roles/openbao/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Role variables
2323
* `openbao_cluster_name`: OpenBao cluster name (e.g. "prod_cluster")
2424
* `openbao_config_dir`: Directory into which to bind mount OpenBao configuration
2525
* Optional
26-
* `openbao_bind_address`: Which IP address should OpenBao bind to (default: "127.0.0.1")
26+
* `openbao_bind_addr`: Which IP address should OpenBao bind to (default: "127.0.0.1")
2727
* `openbao_api_addr`: OpenBao [API addr](https://openbao.org/docs/configuration/#high-availability-parameters) - Full URL including protocol and port (default: "http://127.0.0.1:8200")
2828
* `openbao_init_addr`: OpenBao init addr (used only for initialisation purposes) - full URL including protocol and port (default: "http://127.0.0.1:8200")
2929
* `openbao_docker_name`: Docker - under which name to run the OpenBao image (default: "bao")
@@ -38,6 +38,7 @@ Role variables
3838
* `openbao_write_keys_file`: Whether to write the root token and unseal keys to a file. Default `false`
3939
* `openbao_write_keys_file_host`: Host on which to write root token and unseal keys. Default `localhost`
4040
* `openbao_write_keys_file_path`: Path of file to write root token and unseal keys. Default `bao-keys.json`
41+
* `openbao_raft_leaders`: List of IPs belonging to Raft leaders. Expected that the first and only entry is the IP address of the first OpenBao instance as this would be initialised whereas as the others will not.
4142

4243
Root and unseal keys
4344
--------------------

roles/openbao/defaults/main.yml

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,52 @@ openbao_docker_name: "openbao"
77
openbao_docker_image: "openbao/openbao"
88
openbao_docker_tag: "latest"
99

10+
openbao_config_dir: ""
11+
1012
openbao_cluster_name: ""
11-
openbao_protocol: "{{ 'https' if openbao_tls_key and openbao_tls_cert else 'http' }}"
12-
# Allow openbao_vip_url and openbao_vip_address for backwards compatibility.
13-
openbao_vip_address: "{{ openbao_vip_url | default(openbao_bind_address) }}"
14-
openbao_api_addr: "{{ openbao_protocol ~ '://' ~ openbao_vip_address ~ ':8200' }}"
15-
openbao_bind_address: "127.0.0.1"
16-
openbao_init_addr: "http://127.0.0.1:8200"
13+
1714
openbao_tls_key: ""
1815
openbao_tls_cert: ""
1916

20-
openbao_config_dir: ""
17+
openbao_protocol: "{{ 'https' if openbao_tls_key and openbao_tls_cert else 'http' }}"
18+
19+
openbao_api_addr: "{{ openbao_bind_addr ~ ':' ~ openbao_api_port }}"
20+
openbao_bind_addr: "127.0.0.1"
21+
openbao_init_addr: "{{ openbao_api_addr }}"
22+
openbao_cluster_addr: "{{ openbao_bind_addr ~ ':' ~ openbao_cluster_port }}"
23+
24+
openbao_api_port: 8200
25+
openbao_cluster_port: 8201
26+
27+
openbao_raft_leaders: []
2128

2229
openbao_config: >
2330
{
2431
"cluster_name": "{{ openbao_cluster_name }}",
2532
"ui": false,
26-
"api_addr": "{{ openbao_api_addr }}",
27-
"cluster_addr": "http://127.0.0.1:8201",
33+
"api_addr": "{{ openbao_protocol }}://{{ openbao_api_addr }}",
34+
"cluster_addr": "{{ openbao_protocol }}://{{ openbao_cluster_addr }}",
2835
"listener": [{
2936
"tcp": {
30-
"address": "{{ openbao_bind_address }}:8200",
37+
"address": "{{ openbao_bind_addr }}:{{ openbao_api_port }}",
3138
{% if openbao_tls_key and openbao_tls_cert %}
3239
"tls_min_version": "tls12",
3340
"tls_key_file": "/openbao/config/{{ openbao_tls_key }}",
3441
"tls_cert_file": "/openbao/config/{{ openbao_tls_cert }}"
3542
{% else %}
3643
"tls_disable": "true"
3744
{% endif %}
38-
}{% if openbao_bind_address != '127.0.0.1' %},
39-
},
40-
{
41-
"tcp": {
42-
"address": "127.0.0.1:8200",
43-
"tls_disable": "true"
4445
}
45-
{% endif %}
4646
}],
4747
"storage": {
48-
"raft": {
49-
"node_id": "raft_{{ ansible_facts.nodename }}",
50-
"path": "/openbao/file"
48+
"raft": {
49+
"node_id": "raft_{{ ansible_facts.nodename }}",
50+
"path": "/openbao/file",
51+
{% if openbao_raft_leaders | length > 0 %}
52+
"retry_join": {
53+
"leader_api_addr": "{{ openbao_protocol }}://{{ openbao_raft_leaders | first }}:{{ openbao_api_port }}"
54+
}
55+
{% endif %}
5156
}
5257
},
5358
"telemetry": {

tests/test_openbao.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
vars:
66
openbao_config_dir: "/etc/openbao"
77
openbao_log_keys: true
8-
openbao_api_addr: "{{ 'http' ~ '://' ~ '127.0.0.1' ~ ':8200' }}"
8+
openbao_bind_addr: "{{ 'http' ~ '://' ~ '127.0.0.1' ~ ':8200' }}"
99
openbao_set_keys_fact: true
1010
openbao_write_keys_file: true
1111
tasks:

0 commit comments

Comments
 (0)