Files
Kamino/roles/openbao/molecule/default/verify.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

213 lines
8.4 KiB
YAML

---
- name: Verify the converged server
hosts: all
gather_facts: false
tasks:
- name: Ask systemd about the service
ansible.builtin.systemd_service:
name: openbao
register: openbao_test_service
- name: The service runs with the role's unit settings
ansible.builtin.assert:
that:
- openbao_test_service.status.ActiveState == 'active'
- openbao_test_service.status.UnitFileState == 'enabled'
- openbao_test_service.status.Type == 'notify'
- openbao_test_service.status.KillSignal == '2'
- openbao_test_service.status.MemorySwapMax == '0'
- openbao_test_service.status.NoNewPrivileges == 'yes'
- "'HUP' in openbao_test_service.status.ExecReload"
quiet: true
- name: Read the service account
ansible.builtin.getent:
database: passwd
key: openbao
- name: Stat the data directory and the configuration
ansible.builtin.stat:
path: "{{ openbao_test_path }}"
loop: [/var/lib/openbao, /etc/openbao/openbao.hcl]
loop_control:
loop_var: openbao_test_path
register: openbao_test_paths
- name: The service user has no shell and owns the private data directory
ansible.builtin.assert:
that:
- ansible_facts.getent_passwd.openbao[5] == '/usr/sbin/nologin'
- openbao_test_paths.results[0].stat.pw_name == 'openbao'
- openbao_test_paths.results[0].stat.mode == '0700'
- openbao_test_paths.results[1].stat.gr_name == 'openbao'
- openbao_test_paths.results[1].stat.mode == '0640'
quiet: true
- name: Ask the installed binary for its version
ansible.builtin.command:
argv: [/usr/local/bin/bao, version]
register: openbao_test_version
changed_when: false
# Over TLS on loopback, validated against the test CA: the listener serves the supplied
# certificate, and the server is left uninitialised and sealed on raft storage.
- name: Read the seal status over TLS
ansible.builtin.uri:
url: https://127.0.0.1:8200/v1/sys/seal-status
ca_path: "{{ openbao_tls_ca_file }}"
validate_certs: true
register: openbao_test_seal
- name: The pinned server answers uninitialised and sealed on raft
ansible.builtin.assert:
that:
- ('OpenBao v' ~ openbao_test_defaults.openbao_version ~ ' ') in openbao_test_version.stdout
- openbao_test_seal.json.version == openbao_test_defaults.openbao_version
- openbao_test_seal.json.storage_type == 'raft'
- not openbao_test_seal.json.initialized
- openbao_test_seal.json.sealed
quiet: true
- name: Reload the service
ansible.builtin.systemd_service:
name: openbao
state: reloaded
- name: Ask systemd about the service after the reload
ansible.builtin.systemd_service:
name: openbao
register: openbao_test_reloaded
- name: The reload signalled the running server instead of restarting it
ansible.builtin.assert:
that:
- openbao_test_reloaded.status.ActiveState == 'active'
- openbao_test_reloaded.status.MainPID == openbao_test_service.status.MainPID
quiet: true
- name: Verify the failure paths
hosts: all
gather_facts: false
tasks:
- name: Checksum the configuration before the failure cases
ansible.builtin.stat:
path: /etc/openbao/openbao.hcl
checksum_algorithm: sha256
register: openbao_test_config_before
- name: Run each case
ansible.builtin.include_tasks: tasks/failed_run.yml
loop:
- name: tls-cert-missing
vars: {openbao_tls_cert_file: ""}
expect: must be absolute paths of files on the host
- name: tls-ca-missing
vars: {openbao_tls_ca_file: ""}
expect: must be absolute paths of files on the host
- name: tls-key-absent
vars: {openbao_tls_key_file: /etc/molecule-tls/absent.key}
expect: /etc/molecule-tls/absent.key do not exist
- name: tls-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
# 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
vars: {openbao_tls_min_version: tls10}
expect: openbao_tls_min_version must be one of
- name: version-with-v
vars: {openbao_version: v2.7.3}
expect: openbao_version must be a release version
- name: sha256-not-hex
vars: {openbao_sha256: {amd64: not-a-hash, arm64: not-a-hash}}
expect: openbao_sha256 must map
- name: bin-path-not-bao
vars: {openbao_bin_path: /usr/local/bin/openbao}
expect: the file name of openbao_bin_path must be bao
- name: listen-address-hostname
vars: {openbao_listen_address: localhost}
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
vars: {openbao_cluster_port: 8200}
expect: must be two different ports
- name: node-id-with-space
vars: {openbao_node_id: "node one"}
expect: openbao_node_id must be letters
- name: cluster-addr-plain-http
vars: {openbao_cluster_addr: "http://127.0.0.1:8201"}
expect: openbao_cluster_addr an https:// URL
loop_control:
loop_var: openbao_test_case
label: "{{ openbao_test_case.name }}"
- name: Checksum the configuration after the failure cases
ansible.builtin.stat:
path: /etc/openbao/openbao.hcl
checksum_algorithm: sha256
register: openbao_test_config_after
- name: Ask systemd about the service after the failure cases
ansible.builtin.systemd_service:
name: openbao
register: openbao_test_after_failures
- name: The failures changed nothing and the server still runs
ansible.builtin.assert:
that:
- openbao_test_config_after.stat.checksum == openbao_test_config_before.stat.checksum
- openbao_test_after_failures.status.ActiveState == 'active'
- openbao_test_after_failures.status.MainPID == openbao_test_reloaded.status.MainPID
quiet: true
# Runs last: it rewrites the configuration and restarts the server, then the TLS run restores it.
- name: Verify the TLS switch
hosts: all
gather_facts: false
tasks:
- name: Run the role with TLS disabled and no TLS input
ansible.builtin.include_role:
name: mortis.kamino.openbao
vars:
openbao_tls_disable: true
openbao_tls_cert_file: ""
openbao_tls_key_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
ansible.builtin.uri:
url: http://127.0.0.1:8200/v1/sys/seal-status
register: openbao_test_plain
- name: Run the role with the scenario's TLS inputs again
ansible.builtin.include_role:
name: mortis.kamino.openbao
- name: Read the seal status over TLS again
ansible.builtin.uri:
url: https://127.0.0.1:8200/v1/sys/seal-status
ca_path: "{{ openbao_tls_ca_file }}"
validate_certs: true
register: openbao_test_tls_again
- name: The switch warned, served plain HTTP, and TLS came back without the warning
ansible.builtin.assert:
that:
- "'openbao_tls_disable is true' in openbao_test_plain_warning.msg"
- openbao_test_plain.json.sealed
- openbao_test_tls_again.json.sealed
- hostvars[inventory_hostname].__openbao_tls_warning is skipped
quiet: true