fix(openbao): refuse an unreadable key before any change

The readability check of the TLS certificate and key ran after the role
had created the user and directories and installed the binary, so a
fresh host with a key the service user cannot read was changed and then
failed. It now runs in validation, from the files' owner, group and
mode against openbao_user and openbao_group, before anything changes;
prepare proves it on the fresh host.

Also from review:
- a seal status read that fails names the 127.0.0.1 IP SAN and
  openbao_tls_ca_file instead of a raw SSL error
- :: gets the loopback listener too: it reaches 127.0.0.1 only while
  net.ipv6.bindv6only is 0
- the listen address check rejects strings such as ... or :::
- the TLS-disabled warning is registered, and verify asserts it
- a missing binary under --skip-tags install fails with a clear message
- the README names openbao_user and openbao_group and says the always
  tagged prereqs run under --tags health too

Refs: #536
Assisted-by: Claude Code
This commit is contained in:
Defame1297 committed 2026-12-06 22:22:50 +00:00
1 parent 421e30c5da
commit c450cb7c37
9 files changed
+172 -67

No files matched your search

+8 -8
View File
@@ -12,8 +12,8 @@ Untested platforms: Debian 13 (trixie). The role uses nothing Ubuntu-specific, b
- Use it by its fully qualified name, `mortis.kamino.openbao`. - Use it by its fully qualified name, `mortis.kamino.openbao`.
- Role dependencies: none. - Role dependencies: none.
- Before the first run, deploy the listener's certificate (with its chain), its private key and the CA certificate that signed it to the host, and set `openbao_tls_cert_file`, `openbao_tls_key_file` and `openbao_tls_ca_file` to their paths. The role never creates or copies key material. Validation fails before any change when one is unset or does not exist; the key and certificate must also be readable by the `openbao` user, which the role checks before it writes the configuration. Create the `openbao` group first (a system group) and give it the key, for example `root:openbao` mode `0640`; the role finds the group and keeps it. - Before the first run, deploy the listener's certificate (with its chain), its private key and the CA certificate that signed it to the host, and set `openbao_tls_cert_file`, `openbao_tls_key_file` and `openbao_tls_ca_file` to their paths. The role never creates or copies key material. Validation fails before any change when one is unset, does not exist, or, for the certificate and key, is not readable by `openbao_user` (default `openbao`) judging by the file's owner, group and mode; the directories above the files are not checked. Create the `openbao_group` group (default `openbao`, a system group) before the first run and give it the key, for example `root:openbao` mode `0640`; the role finds the group and keeps it.
- The certificate must cover `127.0.0.1` as an IP subject alternative name: the role reads its own API at `https://127.0.0.1:<openbao_port>` and validates the certificate against `openbao_tls_ca_file`, so a certificate for the host name alone fails that check. - The certificate must cover `127.0.0.1` as an IP subject alternative name: the role reads its own API at `https://127.0.0.1:<openbao_port>` and validates the certificate against `openbao_tls_ca_file`, so a certificate for the host name alone fails that check, with a message naming the SAN and `openbao_tls_ca_file`.
- A firewall rule for `openbao_port` (clients) and `openbao_cluster_port` (raft peers) is the consumer's: the role opens no port. - A firewall rule for `openbao_port` (clients) and `openbao_cluster_port` (raft peers) is the consumer's: the role opens no port.
## Role variables ## Role variables
@@ -25,7 +25,7 @@ Untested platforms: Debian 13 (trixie). The role uses nothing Ubuntu-specific, b
| `openbao_tls_ca_file` | `""` (asserted unless `openbao_tls_disable`) | Path on the host of the CA certificate the role validates the API against. | | `openbao_tls_ca_file` | `""` (asserted unless `openbao_tls_disable`) | Path on the host of the CA certificate the role validates the API against. |
| `openbao_tls_min_version` | `tls12` | `tls12` or `tls13`. | | `openbao_tls_min_version` | `tls12` | `tls12` or `tls13`. |
| `openbao_tls_disable` | `false` | Serve plain HTTP; the TLS inputs are then not needed and the role warns on every run. | | `openbao_tls_disable` | `false` | Serve plain HTTP; the TLS inputs are then not needed and the role warns on every run. |
| `openbao_listen_address` | `0.0.0.0` | IPv4 or IPv6 listener address. Any address other than `0.0.0.0`, `::` or `127.0.0.1` gets a second listener on `127.0.0.1` for the role's own calls. | | `openbao_listen_address` | `0.0.0.0` | IPv4 or IPv6 listener address. Any address other than `0.0.0.0` or `127.0.0.1`, including `::` (which reaches IPv4 only while `net.ipv6.bindv6only` is 0), gets a second listener on `127.0.0.1` for the role's own calls. |
| `openbao_port` | `8200` | API port. | | `openbao_port` | `8200` | API port. |
| `openbao_cluster_port` | `8201` | Cluster port. | | `openbao_cluster_port` | `8201` | Cluster port. |
| `openbao_api_addr` | `https://<inventory_hostname>:<openbao_port>` | Address advertised to clients (`http://` with `openbao_tls_disable`). | | `openbao_api_addr` | `https://<inventory_hostname>:<openbao_port>` | Address advertised to clients (`http://` with `openbao_tls_disable`). |
@@ -35,14 +35,14 @@ Untested platforms: Debian 13 (trixie). The role uses nothing Ubuntu-specific, b
| `openbao_version` | pinned in `defaults/main.yml` | Release version, no leading `v`. | | `openbao_version` | pinned in `defaults/main.yml` | Release version, no leading `v`. |
| `openbao_sha256` | pinned, `amd64` and `arm64` | SHA-256 of the release tarball per architecture, from the release's `checksums.txt`. Update with the version. | | `openbao_sha256` | pinned, `amd64` and `arm64` | SHA-256 of the release tarball per architecture, from the release's `checksums.txt`. Update with the version. |
| `openbao_release_url` | github.com release directory of the version | URL of the directory holding `openbao_<version>_linux_<arch>.tar.gz`, no trailing slash. | | `openbao_release_url` | github.com release directory of the version | URL of the directory holding `openbao_<version>_linux_<arch>.tar.gz`, no trailing slash. |
| `openbao_user`, `openbao_group` | `openbao` | Service account, created with no login shell. | | `openbao_user`, `openbao_group` | `openbao` | Service account, created with no login shell. Create the group before the first run and give it the TLS key. |
| `openbao_bin_path` | `/usr/local/bin/bao` | Binary location; the file name must be `bao`. | | `openbao_bin_path` | `/usr/local/bin/bao` | Binary location; the file name must be `bao`. |
| `openbao_config_dir` | `/etc/openbao` | Configuration directory; the server reads `openbao.hcl` in it. | | `openbao_config_dir` | `/etc/openbao` | Configuration directory; the server reads `openbao.hcl` in it. |
| `openbao_data_dir` | `/var/lib/openbao` | Raft data directory, mode `0700`. | | `openbao_data_dir` | `/var/lib/openbao` | Raft data directory, mode `0700`. |
## Tags ## Tags
`openbao` (everything), `prereqs`, `install`, `configure`, `health`. The input checks and the `prereqs` tasks are also tagged `always`. `--tags health` checks the TLS files' readability, the service state and the seal status without writing the configuration or the unit. `openbao` (everything), `prereqs`, `install`, `configure`, `health`. The input checks (including the TLS files' existence and readability) and the `prereqs` tasks are also tagged `always`, so they run under any tag selection: `--tags health` still creates a missing user, group or directory, then checks the binary, the service state and the seal status without writing the configuration or the unit.
## Example play ## Example play
@@ -59,7 +59,7 @@ Untested platforms: Debian 13 (trixie). The role uses nothing Ubuntu-specific, b
## Tests ## Tests
The `default` molecule scenario runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). Prepare builds a throwaway CA and a server certificate covering `127.0.0.1` with the `openssl` CLI. The converge downloads the pinned release from GitHub and starts a real OpenBao server, left uninitialised and sealed. Verify asserts that the service is active with the unit's settings, the service user and the data directory, the installed version, the seal status over TLS validated against the test CA, a reload that keeps the server running, every input check (each failing with its own message and changing nothing), and the switch to plain HTTP and back. It runs `check` before the converge (a fresh host) and after it (a configured host), then idempotence. The `default` molecule scenario runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). Prepare builds a throwaway CA and a server certificate covering `127.0.0.1` with the `openssl` CLI. The converge downloads the pinned release from GitHub and starts a real OpenBao server, left uninitialised and sealed. Verify asserts that the service is active with the unit's settings, the service user and the data directory, the installed version, the seal status over TLS validated against the test CA, a reload that keeps the server running, every input check (each failing with its own message and changing nothing), a CA that did not sign the certificate, and the switch to plain HTTP and back with its warning. Prepare also runs the role on the fresh host with a key the service user cannot read and asserts that it changed nothing. It runs `check` before the converge (a fresh host) and after it (a configured host), then idempotence.
The unprivileged test container cannot set up the unit's namespace sandboxing or switch to the service user, so prepare adds a drop-in that resets those directives and runs the unit as root there; the unit's seccomp filters, signals and `MemorySwapMax` stay in force. The sandbox as a whole is therefore not covered by the scenario. The unprivileged test container cannot set up the unit's namespace sandboxing or switch to the service user, so prepare adds a drop-in that resets those directives and runs the unit as root there; the unit's seccomp filters, signals and `MemorySwapMax` stay in force. The sandbox as a whole is therefore not covered by the scenario.
@@ -68,9 +68,9 @@ The unprivileged test container cannot set up the unit's namespace sandboxing or
- Idempotent: yes. - Idempotent: yes.
- The role does not initialise or unseal the server. A new server stays uninitialised and sealed, and every restart seals it again; the role warns on each run while the server is uninitialised or sealed. - The role does not initialise or unseal the server. A new server stays uninitialised and sealed, and every restart seals it again; the role warns on each run while the server is uninitialised or sealed.
- A restart runs only when the configuration, the unit or the binary changed. A change to the certificate files needs no restart: `systemctl reload openbao` sends SIGHUP, which makes OpenBao read them again without sealing. - A restart runs only when the configuration, the unit or the binary changed. A change to the certificate files needs no restart: `systemctl reload openbao` sends SIGHUP, which makes OpenBao read them again without sealing.
- The binary is installed only when it is missing; `main` does not change the version of an installed binary. - The binary is installed only when it is missing; `main` does not change the version of an installed binary. With `--skip-tags install` on a host without it, the role fails with that message before writing the configuration.
- mlock was removed in OpenBao 2.0, so the unit sets no `CAP_IPC_LOCK` and the configuration no `disable_mlock`; `MemorySwapMax=0` keeps the server's memory out of swap and `LimitCORE=0` out of core dumps. The unit stops the server with SIGINT, runs with an empty capability set and `ProtectSystem=strict`, and may write only the data directory. - mlock was removed in OpenBao 2.0, so the unit sets no `CAP_IPC_LOCK` and the configuration no `disable_mlock`; `MemorySwapMax=0` keeps the server's memory out of swap and `LimitCORE=0` out of core dumps. The unit stops the server with SIGINT, runs with an empty capability set and `ProtectSystem=strict`, and may write only the data directory.
- A reverse proxy in front of OpenBao must re-encrypt to the listener rather than end TLS at the proxy: the proxy would see every token and secret in plain text, and TLS certificate authentication needs the client's TLS connection to reach OpenBao itself. - A reverse proxy in front of OpenBao must re-encrypt to the listener rather than end TLS at the proxy: the proxy would see every token and secret in plain text, and TLS certificate authentication needs the client's TLS connection to reach OpenBao itself.
- TLS can be turned off only through `openbao_tls_disable`, and the role warns on every such run. - TLS can be turned off only through `openbao_tls_disable`, and the role warns on every such run.
- Check mode: `--check` is the supported preview; a play-level `check_mode: true` is not supported. Under `--check` on a fresh host the download, the start and the seal status read are skipped, and the readability check of the TLS files is skipped while the `openbao` user is new. - Check mode: `--check` is the supported preview; a play-level `check_mode: true` is not supported. Under `--check` on a fresh host the download, the start and the seal status read are skipped.
- Not covered yet: multi-node raft (#528), auto-unseal (#529), configuration through OpenBao's API (#530), installing a CA into trust stores (#531) and certificate issuance (#532). - Not covered yet: multi-node raft (#528), auto-unseal (#529), configuration through OpenBao's API (#530), installing a CA into trust stores (#531) and certificate issuance (#532).
+3 -2
View File
@@ -70,8 +70,9 @@ argument_specs:
default: 0.0.0.0 default: 0.0.0.0
description: description:
- >- - >-
IPv4 or IPv6 address of the TCP listener; C(0.0.0.0) listens on every address. When it is neither a IPv4 or IPv6 address of the TCP listener; C(0.0.0.0) listens on every address. When it is neither
wildcard nor C(127.0.0.1), a second listener on C(127.0.0.1) is added for the role's own API calls. C(0.0.0.0) nor C(127.0.0.1), including C(::), a second listener on C(127.0.0.1) is added for the role's own
API calls.
openbao_port: openbao_port:
type: int type: int
default: 8200 default: 8200
@@ -110,3 +110,47 @@
owner: root owner: root
group: root group: root
mode: "0600" mode: "0600"
# For the failure case of a CA that did not sign the listener certificate.
- name: Create a second, unrelated CA
ansible.builtin.command:
argv: [openssl, req, -x509, -newkey, ec, -pkeyopt, "ec_paramgen_curve:prime256v1", -nodes,
-keyout, other-ca.key, -out, other-ca.crt, -days, "3", -subj, "/CN=Molecule unrelated CA",
-addext, "basicConstraints=critical,CA:TRUE", -addext, "keyUsage=critical,keyCertSign,cRLSign"]
chdir: "{{ openbao_test_tls_dir }}"
creates: other-ca.crt
# On the fresh host, before the converge: a key the service user cannot read stops the role
# before it changes anything.
- name: Refuse an unreadable key on a fresh host
hosts: all
gather_facts: false
tasks:
- name: Run the role with a root-only key
ansible.builtin.include_tasks: tasks/failed_run.yml
vars:
openbao_test_case:
name: fresh-host-key-unreadable
vars: {openbao_tls_key_file: /etc/molecule-tls/root-only.key}
expect: The user openbao could not read /etc/molecule-tls/root-only.key
- name: Read the service account
ansible.builtin.getent:
database: passwd
key: openbao
fail_key: false
- name: Stat what the role would create
ansible.builtin.stat:
path: "{{ openbao_test_path }}"
loop: [/etc/openbao, /var/lib/openbao, /usr/local/bin/bao, /etc/systemd/system/openbao.service]
loop_control:
loop_var: openbao_test_path
register: openbao_test_fresh
- name: The refused run changed nothing
ansible.builtin.assert:
that:
- ansible_facts.getent_passwd.openbao is none
- openbao_test_fresh.results | selectattr('stat.exists') | list | length == 0
quiet: true
@@ -28,8 +28,13 @@
ansible.builtin.fail: ansible.builtin.fail:
msg: The role accepted the input msg: The role accepted the input
rescue: rescue:
# A failed loop task reports its message per item.
- name: "The expected failure stopped the run, case {{ openbao_test_case.name }}" - name: "The expected failure stopped the run, case {{ openbao_test_case.name }}"
vars:
openbao_test_messages: >-
{{ (ansible_failed_result.msg | default('')) ~ ' '
~ (ansible_failed_result.results | default([]) | map(attribute='msg', default='') | join(' ')) }}
ansible.builtin.assert: ansible.builtin.assert:
that: openbao_test_case.expect in (ansible_failed_result.msg | default('')) that: openbao_test_case.expect in openbao_test_messages
fail_msg: "Expected '{{ openbao_test_case.expect }}', got: {{ ansible_failed_result.msg | default('') }}" fail_msg: "Expected '{{ openbao_test_case.expect }}', got: {{ openbao_test_messages }}"
quiet: true quiet: true
+19 -2
View File
@@ -109,7 +109,11 @@
expect: /etc/molecule-tls/absent.key do not exist expect: /etc/molecule-tls/absent.key do not exist
- name: tls-key-unreadable - name: tls-key-unreadable
vars: {openbao_tls_key_file: /etc/molecule-tls/root-only.key} vars: {openbao_tls_key_file: /etc/molecule-tls/root-only.key}
expect: The user openbao cannot read /etc/molecule-tls/root-only.key expect: The user openbao could not read /etc/molecule-tls/root-only.key
# Changes nothing: the CA file is read only by the role's own seal status call.
- name: ca-not-the-signer
vars: {openbao_tls_ca_file: /etc/molecule-tls/other-ca.crt}
expect: must cover 127.0.0.1 as an IP subject alternative name
- name: tls-min-version-unknown - name: tls-min-version-unknown
vars: {openbao_tls_min_version: tls10} vars: {openbao_tls_min_version: tls10}
expect: openbao_tls_min_version must be one of expect: openbao_tls_min_version must be one of
@@ -125,6 +129,12 @@
- name: listen-address-hostname - name: listen-address-hostname
vars: {openbao_listen_address: localhost} vars: {openbao_listen_address: localhost}
expect: openbao_listen_address must be an IPv4 or IPv6 address expect: openbao_listen_address must be an IPv4 or IPv6 address
- name: listen-address-dots
vars: {openbao_listen_address: "..."}
expect: openbao_listen_address must be an IPv4 or IPv6 address
- name: listen-address-triple-colon
vars: {openbao_listen_address: ":::"}
expect: openbao_listen_address must be an IPv4 or IPv6 address
- name: ports-equal - name: ports-equal
vars: {openbao_cluster_port: 8200} vars: {openbao_cluster_port: 8200}
expect: must be two different ports expect: must be two different ports
@@ -171,6 +181,11 @@
openbao_tls_key_file: "" openbao_tls_key_file: ""
openbao_tls_ca_file: "" openbao_tls_ca_file: ""
# The role registers the warning it gave; the next run replaces it.
- name: Keep the warning of the plain HTTP run
ansible.builtin.set_fact:
openbao_test_plain_warning: "{{ hostvars[inventory_hostname].__openbao_tls_warning }}"
- name: Read the seal status over plain HTTP - name: Read the seal status over plain HTTP
ansible.builtin.uri: ansible.builtin.uri:
url: http://127.0.0.1:8200/v1/sys/seal-status url: http://127.0.0.1:8200/v1/sys/seal-status
@@ -187,9 +202,11 @@
validate_certs: true validate_certs: true
register: openbao_test_tls_again register: openbao_test_tls_again
- name: The switch served plain HTTP and TLS came back - name: The switch warned, served plain HTTP, and TLS came back without the warning
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- "'openbao_tls_disable is true' in openbao_test_plain_warning.msg"
- openbao_test_plain.json.sealed - openbao_test_plain.json.sealed
- openbao_test_tls_again.json.sealed - openbao_test_tls_again.json.sealed
- hostvars[inventory_hostname].__openbao_tls_warning is skipped
quiet: true quiet: true
+14 -33
View File
@@ -1,39 +1,20 @@
--- ---
# The server reads the certificate and key as the service user and refuses to start without # Under --skip-tags install the binary may still be missing; say so instead of a systemd error.
# them; checking here names the file instead of leaving a failed unit. - name: Check that the OpenBao binary is installed
- name: Check that the service user can read the TLS files ansible.builtin.stat:
become: true path: "{{ openbao_bin_path }}"
ansible.builtin.command: register: __openbao_binary_now
# setpriv, unlike runuser or become_user, switches user without PAM or a temporary module file.
argv: [setpriv, "--reuid={{ openbao_user }}", "--regid={{ openbao_group }}", --init-groups, test, -r, "{{ __openbao_tls_file }}"]
loop:
- "{{ openbao_tls_cert_file }}"
- "{{ openbao_tls_key_file }}"
loop_control:
loop_var: __openbao_tls_file
register: __openbao_tls_readable
changed_when: false
failed_when: false
# Read-only: runs in --check too. A user that is new under --check does not exist yet.
check_mode: false
when:
- not (openbao_tls_disable | bool)
- not ansible_check_mode or __openbao_user_account is not changed
tags: [openbao, configure, health] tags: [openbao, configure, health]
- name: Require the TLS files to be readable by the service user - name: Fail if the OpenBao binary is missing
ansible.builtin.assert: ansible.builtin.fail:
that: __openbao_tls_unreadable | length == 0 msg: >-
fail_msg: >- The OpenBao binary {{ openbao_bin_path }} is missing, so the service cannot start. Run the role without
The user {{ openbao_user }} cannot read {{ __openbao_tls_unreadable | join(', ') }}. Give the file to the --skip-tags install (or with --tags install) to download it.
{{ openbao_group }} group (for example root:{{ openbao_group }}, mode 0640) and make its directories when:
searchable by that group. - not __openbao_binary_now.stat.exists
quiet: true # Nothing is downloaded under --check.
vars: - not ansible_check_mode
__openbao_tls_unreadable: >-
{{ __openbao_tls_readable.results | default([]) | selectattr('rc', 'defined') | rejectattr('rc', 'equalto', 0)
| map(attribute='__openbao_tls_file') | list }}
when: not (openbao_tls_disable | bool)
tags: [openbao, configure, health] tags: [openbao, configure, health]
- name: Write the OpenBao configuration - name: Write the OpenBao configuration
+26 -14
View File
@@ -3,23 +3,35 @@
# and validates the certificate against openbao_tls_ca_file: the certificate must cover # and validates the certificate against openbao_tls_ca_file: the certificate must cover
# 127.0.0.1. The endpoint needs no token. # 127.0.0.1. The endpoint needs no token.
- name: Read the OpenBao seal status - name: Read the OpenBao seal status
become: true
ansible.builtin.uri:
url: "{{ 'http' if openbao_tls_disable | bool else 'https' }}://127.0.0.1:{{ openbao_port }}/v1/sys/seal-status"
method: GET
validate_certs: true
ca_path: "{{ omit if openbao_tls_disable | bool else openbao_tls_ca_file }}"
status_code: [200]
register: __openbao_seal_status
# The listener opens a moment after systemd reports the unit started.
until: __openbao_seal_status.status | default(0) == 200
retries: 10
delay: 2
# Read-only GET: runs in --check too.
check_mode: false
# Under --check a new unit or binary is only simulated, so nothing listens yet. # Under --check a new unit or binary is only simulated, so nothing listens yet.
when: not ansible_check_mode or (__openbao_unit | default({}) is not changed and __openbao_installed) when: not ansible_check_mode or (__openbao_unit | default({}) is not changed and __openbao_installed)
tags: [openbao, configure, health] tags: [openbao, configure, health]
block:
- name: Read the seal status on loopback
become: true
ansible.builtin.uri:
url: "{{ 'http' if openbao_tls_disable | bool else 'https' }}://127.0.0.1:{{ openbao_port }}/v1/sys/seal-status"
method: GET
validate_certs: true
ca_path: "{{ omit if openbao_tls_disable | bool else openbao_tls_ca_file }}"
status_code: [200]
register: __openbao_seal_status
# The listener opens a moment after systemd reports the unit started.
until: __openbao_seal_status.status | default(0) == 200
retries: 10
delay: 2
# Read-only GET: runs in --check too.
check_mode: false
rescue:
# A raw SSL error does not say which input is wrong.
- name: Fail with the likely cause
ansible.builtin.fail:
msg: >-
OpenBao did not answer its seal status at {{ __openbao_seal_status.url | default('127.0.0.1') }}
({{ __openbao_seal_status.msg | default('no response') }}).
{{ 'Check journalctl -u openbao on the host.' if openbao_tls_disable | bool else
'The listener certificate must cover 127.0.0.1 as an IP subject alternative name and be signed by the CA in openbao_tls_ca_file ('
~ openbao_tls_ca_file ~ '); otherwise check journalctl -u openbao on the host.' }}
- name: Warn that OpenBao is not initialised - name: Warn that OpenBao is not initialised
ansible.builtin.debug: ansible.builtin.debug:
+49 -5
View File
@@ -50,11 +50,32 @@
whitespace or %; the three paths must be absolute, and the file name of openbao_bin_path must be bao. whitespace or %; the three paths must be absolute, and the file name of openbao_bin_path must be bao.
quiet: true quiet: true
- name: Require a listen address, ports and node id # Without a Collection dependency for an IP test: a dotted quad, or IPv6 in full or with one ::
# (no embedded IPv4), at most 8 groups in full form and 7 around a ::.
- name: Require an IP listen address
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- openbao_listen_address is string - openbao_listen_address is string
- openbao_listen_address is match('^[0-9A-Fa-f.:]+\\Z') - >-
openbao_listen_address is match(__openbao_ipv4_pattern)
or (openbao_listen_address is match(__openbao_ipv6_pattern)
and openbao_listen_address.split(':') | select | list | length
<= (7 if '::' in openbao_listen_address else 8))
fail_msg: >-
openbao_listen_address must be an IPv4 or IPv6 address (0.0.0.0 for every address), such as 192.0.2.10 or
2001:db8::10, with no brackets or port.
quiet: true
vars:
__openbao_octet: '(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])'
__openbao_ipv4_pattern: '^({{ __openbao_octet }}\.){3}{{ __openbao_octet }}\Z'
__openbao_hex: '[0-9A-Fa-f]{1,4}'
__openbao_ipv6_pattern: >-
^(({{ __openbao_hex }}:){7}{{ __openbao_hex }}|(({{ __openbao_hex }}:){0,6}{{ __openbao_hex }})?::(({{
__openbao_hex }}:){0,6}{{ __openbao_hex }})?)\Z
- name: Require ports and a node id
ansible.builtin.assert:
that:
- openbao_port | int(0) >= 1 - openbao_port | int(0) >= 1
- openbao_port | int(0) <= 65535 - openbao_port | int(0) <= 65535
- openbao_cluster_port | int(0) >= 1 - openbao_cluster_port | int(0) >= 1
@@ -63,9 +84,8 @@
- openbao_node_id is string - openbao_node_id is string
- openbao_node_id is match('^[A-Za-z0-9._-]+\\Z') - openbao_node_id is match('^[A-Za-z0-9._-]+\\Z')
fail_msg: >- fail_msg: >-
openbao_listen_address must be an IPv4 or IPv6 address (0.0.0.0 for every address); openbao_port and openbao_port and openbao_cluster_port must be two different ports from 1 to 65535; openbao_node_id must be
openbao_cluster_port must be two different ports from 1 to 65535; openbao_node_id must be letters, digits, letters, digits, dots, hyphens or underscores.
dots, hyphens or underscores.
quiet: true quiet: true
- name: Require API and cluster addresses - name: Require API and cluster addresses
@@ -125,9 +145,33 @@
| map(attribute='__openbao_tls_file') | list }} | map(attribute='__openbao_tls_file') | list }}
when: not (openbao_tls_disable | bool) when: not (openbao_tls_disable | bool)
# From the permission bits, because the service user may not exist yet: the server refuses to
# start without its certificate and key, and this fails before the role changes anything. The
# directories above the files are not checked.
- name: Require the certificate and key to be readable by the service user
ansible.builtin.assert:
that: >-
__openbao_mode[2] in '4567'
or (__openbao_tls_item.stat.gr_name == openbao_group and __openbao_mode[1] in '4567')
or (__openbao_tls_item.stat.pw_name == openbao_user and __openbao_mode[0] in '4567')
fail_msg: >-
The user {{ openbao_user }} could not read {{ __openbao_tls_item.__openbao_tls_file }}. Create the
{{ openbao_group }} system group before the role runs and give it the file (for example
root:{{ openbao_group }}, mode 0640), or make the file readable by everyone (a certificate, not a key).
quiet: true
vars:
__openbao_mode: "{{ __openbao_tls_item.stat.mode[-3:] }}"
loop: "{{ (__openbao_tls_stat.results | default([]))[:2] }}"
loop_control:
loop_var: __openbao_tls_item
label: "{{ __openbao_tls_item.__openbao_tls_file }}"
when: not (openbao_tls_disable | bool)
- name: Warn that TLS is disabled - name: Warn that TLS is disabled
ansible.builtin.debug: ansible.builtin.debug:
msg: >- msg: >-
WARNING: openbao_tls_disable is true, so OpenBao serves plain HTTP: tokens and secrets cross the network WARNING: openbao_tls_disable is true, so OpenBao serves plain HTTP: tokens and secrets cross the network
unencrypted. Use it only behind a listener address no one else can reach. unencrypted. Use it only behind a listener address no one else can reach.
# Registered so a caller (and the scenario) can see whether the warning was given.
register: __openbao_tls_warning
when: openbao_tls_disable | bool when: openbao_tls_disable | bool
+2 -1
View File
@@ -24,7 +24,8 @@ listener "tcp" {
cluster_address = {{ hostport(openbao_listen_address, openbao_cluster_port) | to_json }} cluster_address = {{ hostport(openbao_listen_address, openbao_cluster_port) | to_json }}
{{ tls() -}} {{ tls() -}}
} }
{% if openbao_listen_address not in ['0.0.0.0', '::', '127.0.0.1'] %} {# :: reaches 127.0.0.1 only while net.ipv6.bindv6only is 0, so it gets the loopback listener too. #}
{% if openbao_listen_address not in ['0.0.0.0', '127.0.0.1'] %}
# The role reads its own API on loopback. # The role reads its own API on loopback.
listener "tcp" { listener "tcp" {