Files
Kamino/roles/openbao/tasks/validate.yml
T
Defame1297 c450cb7c37 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
2026-12-06 22:22:50 +00:00

178 lines
7.6 KiB
YAML

---
# Input checks. Imported first in main.yml with tags: always, so a bad input fails before any
# change, whatever tags the run selects.
- name: Require a plain openbao_version
ansible.builtin.assert:
that:
- openbao_version is string
- openbao_version is match('^[0-9]+\\.[0-9]+\\.[0-9]+\\Z')
fail_msg: >-
openbao_version must be a release version such as 2.7.3, with no leading v: it is used in the
download URL.
quiet: true
- name: Require a supported architecture
ansible.builtin.assert:
that: __openbao_arch in ['amd64', 'arm64']
fail_msg: >-
OpenBao release tarballs are installed for amd64 and arm64 only; this host reports
{{ ansible_facts.architecture }}.
quiet: true
- name: Require a sha256 for this architecture
ansible.builtin.assert:
that:
- openbao_sha256 is mapping
- openbao_sha256[__openbao_arch] | default('') is string
- openbao_sha256[__openbao_arch] | default('') is match('^[0-9a-fA-F]{64}\\Z')
fail_msg: >-
openbao_sha256 must map {{ __openbao_arch }} to the 64-digit hex sha256 of
openbao_{{ openbao_version }}_linux_{{ __openbao_arch }}.tar.gz, as listed in the release's checksums.txt.
quiet: true
# The values land in the systemd unit and in file paths: a newline or % would inject or expand
# unit directives, and a space would split ReadWritePaths.
- name: Require plain service account names and absolute paths
ansible.builtin.assert:
that:
- openbao_user is string
- openbao_group is string
- openbao_bin_path is string
- openbao_config_dir is string
- openbao_data_dir is string
- (openbao_user ~ openbao_group ~ openbao_bin_path ~ openbao_config_dir ~ openbao_data_dir) is not search('[\\s%]')
- openbao_bin_path is match('/')
- openbao_bin_path | basename == 'bao'
- openbao_config_dir is match('/')
- openbao_data_dir is match('/')
fail_msg: >-
openbao_user, openbao_group, openbao_bin_path, openbao_config_dir and openbao_data_dir must not contain
whitespace or %; the three paths must be absolute, and the file name of openbao_bin_path must be bao.
quiet: true
# 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:
that:
- openbao_listen_address is string
- >-
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) <= 65535
- openbao_cluster_port | int(0) >= 1
- 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.
quiet: true
- name: Require API and cluster addresses
ansible.builtin.assert:
that:
- openbao_api_addr is string
- openbao_api_addr is match('^https?://[^\\s"]+\\Z')
- openbao_cluster_addr is string
- openbao_cluster_addr is match('^https://[^\\s"]+\\Z')
fail_msg: >-
openbao_api_addr must be an http:// or https:// URL and openbao_cluster_addr an https:// URL (cluster
traffic is always TLS), with no whitespace or quote.
quiet: true
- name: Require the TLS files unless TLS is disabled
ansible.builtin.assert:
that:
- openbao_tls_cert_file is string
- openbao_tls_key_file is string
- openbao_tls_ca_file is string
- openbao_tls_cert_file is match('/')
- openbao_tls_key_file is match('/')
- openbao_tls_ca_file is match('/')
fail_msg: >-
openbao_tls_cert_file, openbao_tls_key_file and openbao_tls_ca_file must be absolute paths of files on the
host: the role does not create key material. Set them, or set openbao_tls_disable to true to serve plain
HTTP.
quiet: true
when: not (openbao_tls_disable | bool)
- name: Stat the TLS files
become: true
ansible.builtin.stat:
path: "{{ __openbao_tls_file }}"
loop:
- "{{ openbao_tls_cert_file }}"
- "{{ openbao_tls_key_file }}"
- "{{ openbao_tls_ca_file }}"
loop_control:
loop_var: __openbao_tls_file
register: __openbao_tls_stat
# Read-only: runs in --check too, so a missing file is caught in the preview.
check_mode: false
when: not (openbao_tls_disable | bool)
- name: Require the TLS files to exist
ansible.builtin.assert:
that: __openbao_tls_missing | length == 0
fail_msg: >-
The TLS file(s) {{ __openbao_tls_missing | join(', ') }} do not exist or are not regular files on the host.
Deploy the certificate, key and CA file before running the role.
quiet: true
vars:
__openbao_tls_missing: >-
{{ __openbao_tls_stat.results | rejectattr('stat.exists') | map(attribute='__openbao_tls_file') | list
+ __openbao_tls_stat.results | selectattr('stat.exists') | rejectattr('stat.isreg')
| map(attribute='__openbao_tls_file') | list }}
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
ansible.builtin.debug:
msg: >-
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.
# Registered so a caller (and the scenario) can see whether the warning was given.
register: __openbao_tls_warning
when: openbao_tls_disable | bool