Files
Kamino/roles/openbao/molecule/default/prepare.yml
T
Defame1297 7511d40ff8
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
fix(openbao): follow TLS symlinks and keep :: on one listener
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
2026-12-06 22:51:40 +00:00

174 lines
6.8 KiB
YAML

---
# systemd's sandboxing directives that need a mount or UTS namespace need CAP_SYS_ADMIN, which the
# unprivileged test container lacks, so without this drop-in the unit fails with status
# 226/NAMESPACE. The drop-in resets only those directives; the seccomp filters, Type, signals,
# MemorySwapMax and ExecStart under test are the role's own. The namespace sandbox itself is
# therefore not covered by this scenario.
#
# User and Group are reset too, as in the traefik scenario: the switch to the service user fails in
# the unprivileged container, so the unit runs as root here. Root then needs the capabilities the
# role's empty bounding set removes, to enter the 0700 data directory it does not own. The service
# user, the directory ownership and the key's readability by that user are still asserted.
- name: Prepare
hosts: all
gather_facts: false
tasks:
- name: Install openssl
ansible.builtin.apt:
name: openssl
update_cache: true
- name: Create the unit drop-in directory
ansible.builtin.file:
path: /etc/systemd/system/openbao.service.d
state: directory
mode: "0755"
- name: Disable the namespace-based sandboxing for the unprivileged container
ansible.builtin.copy:
dest: /etc/systemd/system/openbao.service.d/molecule.conf
mode: "0644"
content: |
[Service]
ProtectSystem=no
ProtectHome=no
PrivateTmp=no
PrivateDevices=no
ProtectKernelModules=no
ProtectKernelTunables=no
ProtectKernelLogs=no
ProtectControlGroups=no
ProtectClock=no
ProtectHostname=no
ReadWritePaths=
User=
Group=
CapabilityBoundingSet=CAP_DAC_OVERRIDE CAP_DAC_READ_SEARCH CAP_FOWNER CAP_CHOWN
# A consumer deploys the key for the service group before the role runs, so the group
# exists first here too; the role finds it and leaves it as it is.
- name: Create the openbao group
ansible.builtin.group:
name: openbao
system: true
- name: Create the TLS directory
ansible.builtin.file:
path: "{{ openbao_test_tls_dir }}"
state: directory
mode: "0755"
# A throwaway CA and a server certificate covering 127.0.0.1, with the openssl CLI so the
# scenario needs no crypto collection. The extensions satisfy Python's strict verification.
- name: Create the test CA
ansible.builtin.command:
argv: [openssl, req, -x509, -newkey, ec, -pkeyopt, "ec_paramgen_curve:prime256v1", -nodes,
-keyout, ca.key, -out, ca.crt, -days, "3", -subj, "/CN=Molecule OpenBao test CA",
-addext, "basicConstraints=critical,CA:TRUE", -addext, "keyUsage=critical,keyCertSign,cRLSign"]
chdir: "{{ openbao_test_tls_dir }}"
creates: ca.crt
- name: Write the server certificate extensions
ansible.builtin.copy:
dest: "{{ openbao_test_tls_dir }}/server.ext"
mode: "0644"
content: |
basicConstraints=critical,CA:FALSE
keyUsage=critical,digitalSignature
extendedKeyUsage=serverAuth
subjectAltName=IP:127.0.0.1,DNS:{{ inventory_hostname }}
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid
- name: Create the server key and request
ansible.builtin.command:
argv: [openssl, req, -new, -newkey, ec, -pkeyopt, "ec_paramgen_curve:prime256v1", -nodes,
-keyout, server.key, -out, server.csr, -subj, "/CN={{ inventory_hostname }}"]
chdir: "{{ openbao_test_tls_dir }}"
creates: server.csr
- name: Sign the server certificate
ansible.builtin.command:
argv: [openssl, x509, -req, -in, server.csr, -CA, ca.crt, -CAkey, ca.key, -CAcreateserial,
-out, server.crt, -days, "3", -extfile, server.ext]
chdir: "{{ openbao_test_tls_dir }}"
creates: server.crt
- name: Give the server key to the openbao group
ansible.builtin.file:
path: "{{ openbao_test_tls_dir }}/server.key"
owner: root
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:
src: "{{ openbao_test_tls_dir }}/server.key"
dest: "{{ openbao_test_tls_dir }}/root-only.key"
remote_src: true
owner: root
group: root
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