fix(openbao): follow TLS symlinks and keep :: on one listener
Build / build (pull_request) Successful in 21s
Lint / renovate-config (pull_request) Successful in 4s
Molecule / select (pull_request) Successful in 3s
Lint / lint (pull_request) Successful in 5m20s
Molecule / scenarios (pull_request) Successful in 37m31s
Molecule / Result (pull_request) Successful in 1s

Go opens a :: listener dual-stack, so it already serves 127.0.0.1 and a
second loopback listener failed to bind with "address already in use".
:: again gets no loopback listener.

The TLS file checks did not follow symlinks, so a certbot-style live/
path was refused as not a regular file; the stat now follows them, and
the scenario reaches its certificate and key through symlinks.

Also:
- an owner or group with no name gives the readability message, not a
  templating error
- openbao_port and openbao_cluster_port must be 1024 or higher: the
  unit grants no capability to bind a lower port
- SystemCallErrorNumber=EPERM, so a filtered syscall fails instead of
  killing the server with SIGSYS
- a warning when the installed binary differs from openbao_version,
  since main does not change an installed binary
- the TLS file inputs are type path in the argument spec

Refs: #536
Assisted-by: Claude Code
This commit is contained in:
Defame1297 committed 2026-12-06 22:51:40 +00:00
1 parent c450cb7c37
commit 7511d40ff8
10 files changed
+89 -26

No files matched your search

+6 -6
View File
@@ -12,7 +12,7 @@ Untested platforms: Debian 13 (trixie). The role uses nothing Ubuntu-specific, b
- Use it by its fully qualified name, `mortis.kamino.openbao`.
- 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, 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.
- 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 owner, group and mode of the file (behind a symlink, such as certbot's `live/` paths); 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, 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.
@@ -25,9 +25,9 @@ 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_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_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_cluster_port` | `8201` | Cluster port. |
| `openbao_listen_address` | `0.0.0.0` | IPv4 or IPv6 listener address. `::` listens on every IPv4 and IPv6 address, 127.0.0.1 included. 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_port` | `8200` | API port, 1024 or higher: the unit grants no capability to bind a lower one. |
| `openbao_cluster_port` | `8201` | Cluster port, 1024 or higher. |
| `openbao_api_addr` | `https://<inventory_hostname>:<openbao_port>` | Address advertised to clients (`http://` with `openbao_tls_disable`). |
| `openbao_cluster_addr` | `https://<inventory_hostname>:<openbao_cluster_port>` | Address advertised to raft peers, always `https://`. |
| `openbao_node_id` | `{{ inventory_hostname }}` | Raft node id. Do not change it on an initialised node. |
@@ -59,7 +59,7 @@ Untested platforms: Debian 13 (trixie). The role uses nothing Ubuntu-specific, b
## 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), 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 `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 role reaches the certificate and key through symlinks. 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, a different `openbao_version` (a warning, no change), 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.
@@ -68,7 +68,7 @@ The unprivileged test container cannot set up the unit's namespace sandboxing or
- 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.
- 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. With `--skip-tags install` on a host without it, the role fails with that message before writing the configuration.
- The binary is installed only when it is missing; `main` does not change the version of an installed binary, and warns when it differs from `openbao_version`. 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.
- 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.
+8 -8
View File
@@ -70,19 +70,19 @@ argument_specs:
default: 0.0.0.0
description:
- >-
IPv4 or IPv6 address of the TCP listener; C(0.0.0.0) listens on every address. When it is neither
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.
IPv4 or IPv6 address of the TCP listener; C(0.0.0.0) listens on every address. C(::) listens on every IPv4
and IPv6 address, C(127.0.0.1) included. For any other address than C(0.0.0.0), C(::) or C(127.0.0.1), a
second listener on C(127.0.0.1) is added for the role's own API calls.
openbao_port:
type: int
default: 8200
description:
- Port of the API listener.
- Port of the API listener, 1024 or higher (the unit grants no capability to bind a lower port).
openbao_cluster_port:
type: int
default: 8201
description:
- Port of the cluster listener, used by raft peers.
- Port of the cluster listener, used by raft peers, 1024 or higher.
openbao_api_addr:
type: str
description:
@@ -102,7 +102,7 @@ argument_specs:
Raft node id: letters, digits, dots, hyphens or underscores. The role default is a Jinja expression,
the C(inventory_hostname). Do not change it on an initialised node.
openbao_tls_cert_file:
type: str
type: path
default: ""
description:
- >-
@@ -110,14 +110,14 @@ argument_specs:
C(openbao_tls_disable) is true. It must cover C(127.0.0.1) as an IP subject alternative name, because the
role calls the API on loopback.
openbao_tls_key_file:
type: str
type: path
default: ""
description:
- >-
Absolute path of the listener's private key on the host, readable by C(openbao_user). Required unless
C(openbao_tls_disable) is true.
openbao_tls_ca_file:
type: str
type: path
default: ""
description:
- >-
+3 -2
View File
@@ -45,8 +45,9 @@ provisioner:
group_vars:
all:
openbao_test_tls_dir: /etc/molecule-tls
openbao_tls_cert_file: "{{ openbao_test_tls_dir }}/server.crt"
openbao_tls_key_file: "{{ openbao_test_tls_dir }}/server.key"
# Symlinks into the files, as in certbot's live/ layout.
openbao_tls_cert_file: "{{ openbao_test_tls_dir }}/live/server.crt"
openbao_tls_key_file: "{{ openbao_test_tls_dir }}/live/server.key"
openbao_tls_ca_file: "{{ openbao_test_tls_dir }}/ca.crt"
# The role's pinned version and checksums, for the failure cases that change other inputs.
openbao_test_defaults: "{{ lookup('ansible.builtin.file', playbook_dir ~ '/../../defaults/main.yml') | from_yaml }}"
@@ -101,6 +101,23 @@
group: openbao
mode: "0640"
# The scenario's certificate and key paths are symlinks: the role must judge the files behind
# them, not the links' own 0777 mode.
- name: Create the live directory
ansible.builtin.file:
path: "{{ openbao_test_tls_dir }}/live"
state: directory
mode: "0755"
- name: Link the certificate and key into the live directory
ansible.builtin.file:
src: "../{{ openbao_test_link }}"
dest: "{{ openbao_test_tls_dir }}/live/{{ openbao_test_link }}"
state: link
loop: [server.crt, server.key]
loop_control:
loop_var: openbao_test_link
# For the failure case of a key the service user cannot read.
- name: Copy the server key to a root-only file
ansible.builtin.copy:
@@ -17,8 +17,8 @@
openbao_cluster_port: "{{ openbao_test_case.vars.openbao_cluster_port | default(8201) }}"
openbao_node_id: "{{ openbao_test_case.vars.openbao_node_id | default(inventory_hostname) }}"
openbao_cluster_addr: "{{ openbao_test_case.vars.openbao_cluster_addr | default('https://' ~ inventory_hostname ~ ':8201') }}"
openbao_tls_cert_file: "{{ openbao_test_case.vars.openbao_tls_cert_file | default(openbao_test_tls_dir ~ '/server.crt') }}"
openbao_tls_key_file: "{{ openbao_test_case.vars.openbao_tls_key_file | default(openbao_test_tls_dir ~ '/server.key') }}"
openbao_tls_cert_file: "{{ openbao_test_case.vars.openbao_tls_cert_file | default(openbao_test_tls_dir ~ '/live/server.crt') }}"
openbao_tls_key_file: "{{ openbao_test_case.vars.openbao_tls_key_file | default(openbao_test_tls_dir ~ '/live/server.key') }}"
openbao_tls_ca_file: "{{ openbao_test_case.vars.openbao_tls_ca_file | default(openbao_test_tls_dir ~ '/ca.crt') }}"
openbao_tls_min_version: "{{ openbao_test_case.vars.openbao_tls_min_version | default('tls12') }}"
+17
View File
@@ -135,6 +135,9 @@
- name: listen-address-triple-colon
vars: {openbao_listen_address: ":::"}
expect: openbao_listen_address must be an IPv4 or IPv6 address
- name: port-privileged
vars: {openbao_port: 443}
expect: must be two different ports from 1024 to 65535
- name: ports-equal
vars: {openbao_cluster_port: 8200}
expect: must be two different ports
@@ -148,6 +151,20 @@
loop_var: openbao_test_case
label: "{{ openbao_test_case.name }}"
# Not a failure: the installed binary stays, and the role says so.
- name: Run the role with another openbao_version
ansible.builtin.include_role:
name: mortis.kamino.openbao
vars:
openbao_version: 2.7.2
- name: The role warned that it keeps the installed version
ansible.builtin.assert:
that:
- "'not openbao_version 2.7.2' in hostvars[inventory_hostname].__openbao_version_warning.msg"
- "('OpenBao v' ~ openbao_test_defaults.openbao_version) in hostvars[inventory_hostname].__openbao_version_warning.msg"
quiet: true
- name: Checksum the configuration after the failure cases
ansible.builtin.stat:
path: /etc/openbao/openbao.hcl
+24
View File
@@ -17,6 +17,30 @@
- not ansible_check_mode
tags: [openbao, configure, health]
- name: Ask the installed binary for its version
ansible.builtin.command:
argv: ["{{ openbao_bin_path }}", version]
register: __openbao_installed_version
changed_when: false
# Read-only: runs in --check too, where a new binary is not there yet.
check_mode: false
when: __openbao_binary_now.stat.exists
tags: [openbao, configure, health]
# Moving an installed server to another version needs a stop, a data copy and a rollback path,
# which this entry point does not do.
- name: Warn that the installed version differs from openbao_version
ansible.builtin.debug:
msg: >-
WARNING: {{ openbao_bin_path }} reports "{{ __openbao_installed_version.stdout_lines | first | default('') }}",
not openbao_version {{ openbao_version }}. The main entry point does not change the version of an installed
binary.
register: __openbao_version_warning
when:
- __openbao_installed_version.stdout is defined
- ('OpenBao v' ~ openbao_version ~ ' ') not in __openbao_installed_version.stdout
tags: [openbao, configure, health]
- name: Write the OpenBao configuration
become: true
ansible.builtin.template:
+8 -6
View File
@@ -76,16 +76,16 @@
- name: Require ports and a node id
ansible.builtin.assert:
that:
- openbao_port | int(0) >= 1
- openbao_port | int(0) >= 1024
- openbao_port | int(0) <= 65535
- openbao_cluster_port | int(0) >= 1
- openbao_cluster_port | int(0) >= 1024
- openbao_cluster_port | int(0) <= 65535
- openbao_port | int != openbao_cluster_port | int
- openbao_node_id is string
- openbao_node_id is match('^[A-Za-z0-9._-]+\\Z')
fail_msg: >-
openbao_port and openbao_cluster_port must be two different ports from 1 to 65535; openbao_node_id must be
letters, digits, dots, hyphens or underscores.
openbao_port and openbao_cluster_port must be two different ports from 1024 to 65535 (the unit grants no
capability to bind a lower one); openbao_node_id must be letters, digits, dots, hyphens or underscores.
quiet: true
- name: Require API and cluster addresses
@@ -120,6 +120,8 @@
become: true
ansible.builtin.stat:
path: "{{ __openbao_tls_file }}"
# A certbot-style live/ path is a symlink; the server reads the file behind it.
follow: true
loop:
- "{{ openbao_tls_cert_file }}"
- "{{ openbao_tls_key_file }}"
@@ -152,8 +154,8 @@
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')
or (__openbao_tls_item.stat.gr_name | default('') == openbao_group and __openbao_mode[1] in '4567')
or (__openbao_tls_item.stat.pw_name | default('') == 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
+2 -2
View File
@@ -24,8 +24,8 @@ listener "tcp" {
cluster_address = {{ hostport(openbao_listen_address, openbao_cluster_port) | to_json }}
{{ tls() -}}
}
{# :: 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'] %}
{# Go opens a :: listener dual-stack, so it already serves 127.0.0.1; a second one would not bind. #}
{% if openbao_listen_address not in ['0.0.0.0', '::', '127.0.0.1'] %}
# The role reads its own API on loopback.
listener "tcp" {
@@ -47,6 +47,8 @@ MemoryDenyWriteExecute=true
SystemCallArchitectures=native
SystemCallFilter=@system-service
SystemCallFilter=~@privileged @resources
# A filtered call fails with EPERM instead of killing the server with SIGSYS.
SystemCallErrorNumber=EPERM
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK
[Install]