|
| 1 | +This role deploys and initializes OpenBao with a Raft backend. |
| 2 | + |
| 3 | +Requirements |
| 4 | +------------ |
| 5 | + |
| 6 | +`ansible-modules-hashivault` Python package installed on the Ansible control host |
| 7 | +`hvac` Python package installed on the remote hosts |
| 8 | + |
| 9 | +Note that since version `4.6.4`, `ansible-modules-hashivault` requires |
| 10 | +`ansible>4`. |
| 11 | + |
| 12 | +Role variables |
| 13 | +-------------- |
| 14 | + |
| 15 | +* Common variables |
| 16 | + * Optional |
| 17 | + * `openbao_registry_url`: Address of the Docker registry used to authenticate (default: "") |
| 18 | + * `openbao_registry_username`: Username used to authenticate with the Docker registry (default: "") |
| 19 | + * `openbao_registry_password`: Password used to authenticate with the Docker registry (default: "") |
| 20 | + |
| 21 | +* OpenBao |
| 22 | + * Mandatory |
| 23 | + * `openbao_cluster_name`: OpenBao cluster name (e.g. "prod_cluster") |
| 24 | + * `openbao_config_dir`: Directory into which to bind mount OpenBao configuration |
| 25 | + * Optional |
| 26 | + * `openbao_bind_address`: Which IP address should OpenBao bind to (default: "127.0.0.1") |
| 27 | + * `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") |
| 28 | + * `openbao_init_addr`: OpenBao init addr (used only for initialisation purposes) - full URL including protocol and port (default: "http://127.0.0.1:8200") |
| 29 | + * `openbao_docker_name`: Docker - under which name to run the OpenBao image (default: "bao") |
| 30 | + * `openbao_docker_image`: Docker image for OpenBao (default: "openbao/openbao") |
| 31 | + * `openbao_docker_tag`: Docker image tag for OpenBao (default: "latest") |
| 32 | + * `openbao_extra_volumes`: List of `"<host_location>:<container_mountpoint>"` |
| 33 | + * `openbao_ca_cert`: Path to CA certificate used to verify OpenBao server TLS cert |
| 34 | + * `openbao_tls_key`: Path to TLS key to use by OpenBao |
| 35 | + * `openbao_tls_cert`: Path to TLS cert to use by OpenBao |
| 36 | + * `openbao_log_keys`: Whether to log the root token and unseal keys in the Ansible output. Default `false` |
| 37 | + * `openbao_set_keys_fact`: Whether to set a `openbao_keys` fact containing the root token and unseal keys. Default `false` |
| 38 | + * `openbao_write_keys_file`: Whether to write the root token and unseal keys to a file. Default `false` |
| 39 | + * `openbao_write_keys_file_host`: Host on which to write root token and unseal keys. Default `localhost` |
| 40 | + * `openbao_write_keys_file_path`: Path of file to write root token and unseal keys. Default `bao-keys.json` |
| 41 | + |
| 42 | +Root and unseal keys |
| 43 | +-------------------- |
| 44 | + |
| 45 | +After OpenBao has been initialised, a root token and a set of unseal keys are emitted. |
| 46 | +It is very important to store these keys safely and securely. |
| 47 | +This role provides several mechanisms for extracting the root token and unseal keys: |
| 48 | + |
| 49 | +1. Print to Ansible log output (`openbao_log_keys`) |
| 50 | +1. Set a `openbao_keys` fact (`openbao_set_keys_fact`) |
| 51 | +1. Write to a file (`openbao_write_keys_file`) |
| 52 | + |
| 53 | +In each case, the output will contain the following: |
| 54 | + |
| 55 | +```json |
| 56 | +{ |
| 57 | + "keys": [ |
| 58 | + "...", |
| 59 | + "..." |
| 60 | + ], |
| 61 | + "keys_base64": [ |
| 62 | + "...", |
| 63 | + "..." |
| 64 | + ], |
| 65 | + "root_token": "..." |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | +Example playbook (used with OpenStack Kayobe) |
| 70 | +--------------------------------------------- |
| 71 | + |
| 72 | +``` |
| 73 | +--- |
| 74 | +- name: Prepare for OpenBao role |
| 75 | + any_errors_fatal: True |
| 76 | + gather_facts: True |
| 77 | + hosts: consul |
| 78 | + tasks: |
| 79 | + - name: Ensure /opt/kayobe/bao exists |
| 80 | + file: |
| 81 | + path: /opt/kayobe/bao |
| 82 | + state: directory |
| 83 | +
|
| 84 | + - name: Template out tls key and cert |
| 85 | + vars: |
| 86 | + tls_files: |
| 87 | + - content: "{{ secrets_external_tls_cert }}" |
| 88 | + dest: "tls.cert" |
| 89 | + - content: "{{ secrets_external_tls_key }}" |
| 90 | + dest: "tls.key" |
| 91 | + copy: |
| 92 | + content: "{{ item.content }}" |
| 93 | + dest: "/opt/kayobe/bao/{{ item.dest }}" |
| 94 | + owner: 100 |
| 95 | + group: 1001 |
| 96 | + mode: 0600 |
| 97 | + loop: "{{ tls_files }}" |
| 98 | + no_log: True |
| 99 | + become: true |
| 100 | +
|
| 101 | +- name: Run OpenBao role |
| 102 | + any_errors_fatal: True |
| 103 | + gather_facts: True |
| 104 | + hosts: consul |
| 105 | + roles: |
| 106 | + - role: stackhpc.hashicorp.openbao |
| 107 | + openbao_bind_address: "{{ external_net_ips[inventory_hostname] }}" |
| 108 | + openbao_api_addr: "https://{{ external_net_fqdn }}:8200" |
| 109 | + openbao_config_dir: "/opt/kayobe/bao" |
| 110 | +``` |
| 111 | + |
| 112 | +Example post-config playbook to enable secrets engines: |
| 113 | +``` |
| 114 | +--- |
| 115 | +- name: OpenBao post deployment config |
| 116 | + any_errors_fatal: True |
| 117 | + gather_facts: True |
| 118 | + hosts: bao |
| 119 | + tasks: |
| 120 | + - name: Enable bao secrets engines |
| 121 | + hashivault_secret_engine: |
| 122 | + url: "https://vault.example.com:8200" |
| 123 | + token: "{{ secrets_openbao_keys.root_token }}" |
| 124 | + name: pki |
| 125 | + backend: pki |
| 126 | + run_once: True |
| 127 | +``` |
| 128 | + |
| 129 | +NOTE: secrets_external_tls_cert/key are variables in Kayobe's secrets.yml |
0 commit comments