Author SHA1 Message Date
Defame1297 7511d40ff8 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
2026-12-06 22:51:40 +00:00
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
Defame1297 421e30c5da test(openbao): add the default molecule scenario
Runs the role against a real OpenBao 2.7.3 on the noble and resolute
containers, with check before and after converge and idempotence.

Prepare builds a throwaway CA and a server certificate covering
127.0.0.1 with the openssl CLI, so no crypto collection is needed, and
adds a drop-in that resets the namespace sandboxing and the service user,
which the unprivileged container cannot provide.

Verify asserts the effect on the host: the service is active with the
unit's type, stop signal, MemorySwapMax and reload; the service user and
the private data directory; the installed version; seal status over TLS
on loopback reporting uninitialised and sealed; a reload that keeps the
same process. Every input check has a negative case matched on its
message, and the run ends with the switch to plain HTTP and back.

Refs: #536
Assisted-by: Claude Code
2026-12-06 21:38:40 +00:00
Defame1297 eda69bcbf5 feat(openbao): add the role's main entry point
A consumer gets a running single-node OpenBao server on integrated raft
storage, listening on TLS they supply, left uninitialised and sealed.

The role installs the pinned 2.7.3 release tarball, checked by get_url
against the sha256 of each architecture from the release's checksums.txt
(its GPG signature checks out against OpenBao's release key). It creates
its own system user, data directory, configuration and sandboxed unit:
Type=notify, SIGINT stop, MemorySwapMax=0 instead of mlock, an empty
capability set, ProtectSystem=strict with the data directory writable,
and ExecReload sending SIGHUP. The directive set was tried against the
real binary under systemd before it was kept.

TLS certificate, key and CA paths are required unless openbao_tls_disable
is true, which warns; validation fails before any change when a file is
missing, and the role checks the service user can read the key and
certificate before writing the config. It reads its seal status over
https://127.0.0.1 validated against the CA file, so an address other
than a wildcard or loopback gets a second loopback listener.

The tasks are split by job (validate, prereqs, install, configure,
seal_status) so the init, unseal, audit and update work can reuse them.

Refs: #536
Assisted-by: Claude Code
2026-12-06 21:19:15 +00:00
Defame1297 ddfb1c6d0a Merge pull request 'docs(roles): allow a no_log output fact from an opt-in entry point; list openbao on the Roadmap' (#533) from docs/openbao-role-decisions into main
Renovate / renovate (push) Successful in 33s
Reviewed-on: #533
2026-12-06 20:41:43 +00:00
Defame1297 b2d29df657 docs(security): accept unseal keys in vaulted inventory for openbao
Build / build (pull_request) Successful in 23s
Lint / renovate-config (pull_request) Successful in 5s
Molecule / select (pull_request) Successful in 4s
Molecule / scenarios (pull_request) Skipped
Molecule / Result (pull_request) Successful in 1s
Lint / lint (pull_request) Successful in 2m0s
Assisted-by: Claude Code
2026-12-06 20:38:48 +00:00
Defame1297 2f2d980ef7 Merge branch 'main' into docs/openbao-role-decisions
Build / build (pull_request) Successful in 34s
Molecule / select (pull_request) Successful in 4s
Molecule / scenarios (pull_request) Skipped
Lint / renovate-config (pull_request) Successful in 7s
Molecule / Result (pull_request) Successful in 1s
Lint / lint (pull_request) Successful in 2m42s
2026-12-06 20:30:37 +00:00
Defame1297 fbdee5f778 docs(roles): count a no_log output fact from an opt-in entry point as handed to the consumer's store
Build / build (pull_request) Successful in 45s
Lint / lint (pull_request) Successful in 3m12s
Molecule / select (pull_request) Canceled after 0s
Molecule / scenarios (pull_request) Canceled after 0s
Molecule / Result (pull_request) Canceled after 0s
Lint / renovate-config (pull_request) Canceled after 7s
Also list openbao on the Roadmap, ahead of the role that removes it.

Assisted-by: Claude Code
2026-12-06 20:16:59 +00:00
26 changed files with 1369 additions and 6 deletions

No files matched your search

+1 -1
View File
@@ -28,7 +28,7 @@ jobs:
timeout-minutes: 30
# The ci image (images/ci, built by image.yml): tag for the release, digest enforced.
container:
image: git.rkdr.net/mortis/ci:0.2.55@sha256:a20f7e4154aaba15a3dd5b2d42e5e84b307bab1128c9dc4cd4e54d55d6b64d60
image: git.rkdr.net/mortis/ci:0.2.54@sha256:2742be4ba03f71f00b06f1d2b318e8fd3866a800247bbd7e52508dfb0da6312c
env:
PIP_DISABLE_PIP_VERSION_CHECK: "1"
steps:
+1 -1
View File
@@ -44,7 +44,7 @@ jobs:
# The ci image (images/ci, built by image.yml), at the pin of lint.yml: tag for the
# release, digest enforced. Only its /opt/venv Python (with PyYAML) is used here.
container:
image: git.rkdr.net/mortis/ci:0.2.55@sha256:a20f7e4154aaba15a3dd5b2d42e5e84b307bab1128c9dc4cd4e54d55d6b64d60
image: git.rkdr.net/mortis/ci:0.2.54@sha256:2742be4ba03f71f00b06f1d2b318e8fd3866a800247bbd7e52508dfb0da6312c
steps:
# The container has no Node, so JavaScript actions such as actions/checkout
# cannot run; clone with git and the job token.
+1 -1
View File
@@ -31,7 +31,7 @@ jobs:
# The tag says which release, the digest is what is enforced (bump both together
# when image.yml publishes a new version).
container:
image: git.rkdr.net/mortis/ci:0.2.55@sha256:a20f7e4154aaba15a3dd5b2d42e5e84b307bab1128c9dc4cd4e54d55d6b64d60
image: git.rkdr.net/mortis/ci:0.2.54@sha256:2742be4ba03f71f00b06f1d2b318e8fd3866a800247bbd7e52508dfb0da6312c
env:
PIP_DISABLE_PIP_VERSION_CHECK: "1"
PRE_COMMIT_HOME: /opt/pre-commit
+2 -2
View File
@@ -2,10 +2,10 @@
An Ansible Collection of reusable, hardened roles for a self-hosted home lab:
`cloudflared`, `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`,
`nfs_client`, `pihole`, `pve_lxc`, `pve_vm`, `sshd`, `system_baseline`, `systemd_hardening`, `tailscale`, `traefik`,
`nfs_client`, `openbao`, `pihole`, `pve_lxc`, `pve_vm`, `sshd`, `system_baseline`, `systemd_hardening`, `tailscale`, `traefik`,
`ufw` and `user_management`, plus the internal `_binary_update`. Roles still to come are listed under [Roadmap](#roadmap).
Status: roles arrive in waves. Release 3.5.0 holds the `cloudflared`, `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`, `nfs_client`, `pihole`, `pve_lxc`, `pve_vm`, `sshd`, `system_baseline`, `systemd_hardening`, `tailscale`, `traefik`, `ufw` and `user_management` roles (and the internal `_binary_update`, which `cloudflared`, `gitea`, `gitea_runner` and `traefik` call).
Status: roles arrive in waves. Release 3.5.0 holds the `cloudflared`, `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`, `nfs_client`, `pihole`, `pve_lxc`, `pve_vm`, `sshd`, `system_baseline`, `systemd_hardening`, `tailscale`, `traefik`, `ufw` and `user_management` roles (and the internal `_binary_update`, which `cloudflared`, `gitea`, `gitea_runner` and `traefik` call). `openbao` is on `main` for the next release.
## Consuming
+10
View File
@@ -126,3 +126,13 @@ reduction. A later decision that accepts a risk adds an entry here.
- **Trigger:** the pull request that moves `molecule.yml` to a new `molecule-controller` image
fails Molecule because of a changed image input.
- **Planned reduction:** none for now.
### Unseal keys in vaulted inventory
- **Risk:** the planned `openbao` role can unseal a Shamir-sealed OpenBao from unseal keys the
consumer keeps in vaulted inventory (`openbao_unseal_keys`), so whoever holds the Ansible
vault password can unseal alone. This weakens the split knowledge Shamir's scheme gives.
- **Why accepted:** it keeps restarts and updates unattended, and the Collection already keeps
secrets in vaulted inventory. The keys are optional: without them the role leaves the node
sealed and warns.
- **Trigger and planned reduction:** auto-unseal, tracked in #529.
+8
View File
@@ -0,0 +1,8 @@
---
minor_changes:
- >-
openbao - New role. Installs a single OpenBao server on integrated raft storage from the pinned release
tarball, checked against a sha256 pinned in the role defaults, with its own system user, data directory,
configuration and sandboxed systemd unit. The listener uses the certificate, key and CA files the consumer
supplies (required unless ``openbao_tls_disable`` is true, which warns). The role reads the seal status over TLS
on ``127.0.0.1`` and leaves a new server uninitialised and sealed.
+1 -1
View File
@@ -7,7 +7,7 @@ authors:
- Defame1297
description: >-
Reusable, hardened Ansible roles for a self-hosted home lab (cloudflared, docker, fail2ban,
gitea, gitea_runner, network_interfaces, nfs_client, pihole, pve_lxc, pve_vm, sshd, system_baseline,
gitea, gitea_runner, network_interfaces, nfs_client, openbao, pihole, pve_lxc, pve_vm, sshd, system_baseline,
systemd_hardening, tailscale, traefik, ufw, user_management; _binary_update is internal).
license:
- GPL-3.0-or-later
+5
View File
@@ -68,6 +68,11 @@ names a check that does not exist yet and its backlog issue.
- **Secrets.** Never in plaintext in the repository, a role's defaults, task output or a file on
the controller; `no_log: true` on every task that carries one; a secret is a required input
with no default; a role generates one only straight into a secret store the consumer names.
A secret returned as a `no_log`, non-cacheable output fact from an opt-in entry point, for the
calling play to persist (for example vault-encrypted into inventory), counts as handed straight
to the consumer's store, as the gitea and cloudflared `mint` entry points do. Such an entry point
has a confirm flag, refuses under CI environment variables, sets `no_log` on every task, blanks
its intermediates, skips under `--check` and does nothing when the secret already exists.
Keys a host generates for itself and keeps (SSH host keys) are not covered. The README line
"`no_log` is not used: the role handles no secrets" stays only where true. *Why:* nothing leaks
today and a role writing to a secret store stays possible. *Held:* review.
+76
View File
@@ -0,0 +1,76 @@
# openbao
Installs a single OpenBao server on integrated raft storage as a sandboxed systemd service, listening on TLS the consumer supplies. The role installs the pinned release tarball after checking it against a sha256 pinned in its defaults, creates its own system user, data directory, configuration and unit, starts the service and reads its seal status over TLS on loopback. It leaves a new server uninitialised and sealed. Variables and their types are defined in [`meta/argument_specs.yml`](meta/argument_specs.yml), which is the source of truth.
## Supported platforms
Ubuntu 24.04 (noble) and 26.04 (resolute), the platforms the molecule scenario runs on, on amd64 or arm64; the role needs `systemd`. The target needs outbound access to github.com for the release download.
Untested platforms: Debian 13 (trixie). The role uses nothing Ubuntu-specific, but no Debian test image exists yet, so it is not declared in `meta/main.yml`.
## Requirements and run order
- 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 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.
## Role variables
| Variable | Default | Description |
|---|---|---|
| `openbao_tls_cert_file` | `""` (asserted unless `openbao_tls_disable`) | Path of the listener certificate on the host; must cover `127.0.0.1`. |
| `openbao_tls_key_file` | `""` (asserted unless `openbao_tls_disable`) | Path of the listener key on the host, readable by `openbao_user`. |
| `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. `::` 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. |
| `openbao_ui` | `false` | Serve the web UI. |
| `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_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. 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_config_dir` | `/etc/openbao` | Configuration directory; the server reads `openbao.hcl` in it. |
| `openbao_data_dir` | `/var/lib/openbao` | Raft data directory, mode `0700`. |
## Tags
`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
```yaml
- name: Run OpenBao
hosts: secret_store
roles:
- role: mortis.kamino.openbao
vars:
openbao_tls_cert_file: /etc/ssl/openbao/server.crt
openbao_tls_key_file: /etc/ssl/openbao/server.key
openbao_tls_ca_file: /etc/ssl/openbao/ca.crt
```
## 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 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.
## Notes
- 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, 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.
- 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).
+34
View File
@@ -0,0 +1,34 @@
---
# The sha256 values are those of the release's checksums.txt, whose GPG signature checks out
# against OpenBao's release key. Pin the version and both hashes together in inventory to move
# ahead of the role's pin.
openbao_version: "2.7.3"
openbao_sha256:
amd64: "131df9a21cf3dd2dff47107110b369c9974cbdaa482bcbc723b81b3403c68ecd"
arm64: "b505b07af4206fdf0e81b747fcb7e9e63f2c2b05e26ead973cce62d0ed07d0e0"
# The release directory; the role appends openbao_<version>_linux_<arch>.tar.gz.
openbao_release_url: "https://github.com/openbao/openbao/releases/download/v{{ openbao_version }}"
openbao_user: "openbao"
openbao_group: "openbao"
openbao_bin_path: "/usr/local/bin/bao"
openbao_config_dir: "/etc/openbao"
openbao_data_dir: "/var/lib/openbao"
openbao_listen_address: "0.0.0.0"
openbao_port: 8200
openbao_cluster_port: 8201
openbao_api_addr: "{{ 'http' if openbao_tls_disable | bool else 'https' }}://{{ inventory_hostname }}:{{ openbao_port }}"
openbao_cluster_addr: "https://{{ inventory_hostname }}:{{ openbao_cluster_port }}"
openbao_node_id: "{{ inventory_hostname }}"
# Paths on the host. The role never creates or copies key material: it asserts that these files
# exist and that the service user can read them. Required unless openbao_tls_disable is true.
openbao_tls_cert_file: ""
openbao_tls_key_file: ""
openbao_tls_ca_file: ""
openbao_tls_min_version: "tls12"
# Plain HTTP on the listener; the role accepts it with a warning.
openbao_tls_disable: false
openbao_ui: false
+143
View File
@@ -0,0 +1,143 @@
---
argument_specs:
main:
short_description: Install and run a single OpenBao server on integrated raft storage, over TLS
description:
- >-
Validates the inputs, then creates the C(openbao) system user and group, the configuration directory and the
raft data directory, downloads the pinned release tarball and checks it against C(openbao_sha256) when the
binary is missing, writes the server configuration and a sandboxed systemd unit, and starts the service.
- >-
TLS on the listener is required: C(openbao_tls_cert_file), C(openbao_tls_key_file) and
C(openbao_tls_ca_file) must name files that already exist on the host, unless C(openbao_tls_disable) is true,
which the role accepts with a warning. The role never creates or copies key material.
- >-
Finally it reads the seal status from C(https://127.0.0.1:<openbao_port>), validating the certificate
against C(openbao_tls_ca_file), and warns when the server is uninitialised or sealed. This entry point
neither initialises nor unseals the server.
options:
openbao_version:
type: str
default: "2.7.3"
description:
- >-
OpenBao release version, with no leading C(v). Pin it in inventory together with C(openbao_sha256) to
move ahead of the role's pin. The binary is installed only when it is missing; an installed binary is
not changed.
openbao_sha256:
type: dict
default:
amd64: "131df9a21cf3dd2dff47107110b369c9974cbdaa482bcbc723b81b3403c68ecd"
arm64: "b505b07af4206fdf0e81b747fcb7e9e63f2c2b05e26ead973cce62d0ed07d0e0"
description:
- >-
SHA-256 of the release tarball per architecture (C(amd64), C(arm64)), from the release's
C(checksums.txt). Only the entry of the host's architecture is read, and it must be 64 hex digits.
openbao_release_url:
type: str
description:
- >-
URL of the directory that holds the release tarball, with no trailing slash; the role appends
C(openbao_<version>_linux_<arch>.tar.gz). The role default is a Jinja expression, the github.com release
directory of C(openbao_version).
openbao_user:
type: str
default: openbao
description:
- System user that runs the service and owns the data directory. Created with no login shell.
openbao_group:
type: str
default: openbao
description:
- Group of the service user; it owns the configuration. Give the TLS key file to this group.
openbao_bin_path:
type: path
default: /usr/local/bin/bao
description:
- Absolute path of the C(bao) binary. Its file name must be C(bao).
openbao_config_dir:
type: path
default: /etc/openbao
description:
- Absolute path of the configuration directory; the server configuration is C(openbao.hcl) in it.
openbao_data_dir:
type: path
default: /var/lib/openbao
description:
- Absolute path of the raft data directory, mode C(0700), owned by the service user.
openbao_listen_address:
type: str
default: 0.0.0.0
description:
- >-
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, 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, 1024 or higher.
openbao_api_addr:
type: str
description:
- >-
Address the server advertises to clients. The role default is a Jinja expression,
C(https://<inventory_hostname>:<openbao_port>), or C(http://) when C(openbao_tls_disable) is true.
openbao_cluster_addr:
type: str
description:
- >-
Address the server advertises to raft peers, always C(https://). The role default is a Jinja expression,
C(https://<inventory_hostname>:<openbao_cluster_port>).
openbao_node_id:
type: str
description:
- >-
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: path
default: ""
description:
- >-
Absolute path of the listener's certificate (with its chain) on the host. Required unless
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: 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: path
default: ""
description:
- >-
Absolute path on the host of the CA certificate that signed the listener's certificate; the role
validates the API's certificate against it. Required unless C(openbao_tls_disable) is true.
openbao_tls_min_version:
type: str
default: tls12
choices: [tls12, tls13]
description:
- Lowest TLS version the listener accepts.
openbao_tls_disable:
type: bool
default: false
description:
- >-
Serve plain HTTP on the listener. The role then needs no TLS input and warns on every run. Tokens and
secrets cross the network unencrypted.
openbao_ui:
type: bool
default: false
description:
- Serve the web UI on the listener.
+19
View File
@@ -0,0 +1,19 @@
---
galaxy_info:
role_name: openbao
namespace: mortis
author: Defame1297
license: GPL-3.0-or-later
description: Install and run a single OpenBao server on raft storage, from a checksum-verified release, with a sandboxed unit and the consumer's TLS.
min_ansible_version: "2.22"
platforms:
- name: Ubuntu
versions:
- noble
- resolute
galaxy_tags:
- openbao
- secrets
- vault
- systemd
dependencies: []
@@ -0,0 +1,8 @@
---
# Role variables come from the inventory group_vars in molecule.yml, so the idempotence step
# reruns converge with identical configuration. Facts are off: the role gathers the one it reads.
- name: Converge
hosts: all
gather_facts: false
roles:
- role: mortis.kamino.openbao
@@ -0,0 +1,72 @@
---
# Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404
# (MOLECULE_IMAGE) and molecule-ubuntu2604 (MOLECULE_IMAGE_2604) images, pinned in
# .gitea/workflows/molecule.yml. Needs outbound network: prepare installs openssl with apt and the
# converge downloads the pinned OpenBao release from GitHub. prepare.yml builds a throwaway CA and
# server certificate. The container runs systemd as PID 1 with a writable cgroup; no privileged mode.
driver:
name: docker
platforms:
- name: ${KAMINO_RUN_ID:-local}-openbao-instance
labels:
net.rkdr.mortis.molecule-run: "${KAMINO_RUN_ID:-local}"
image: ${MOLECULE_IMAGE}
pre_build_image: true
pull: true
command: /sbin/init
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
tmpfs:
- /run
- /run/lock
security_opts:
- apparmor=unconfined
- name: ${KAMINO_RUN_ID:-local}-openbao-2604-instance
labels:
net.rkdr.mortis.molecule-run: "${KAMINO_RUN_ID:-local}"
image: ${MOLECULE_IMAGE_2604}
pre_build_image: true
pull: true
command: /sbin/init
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
tmpfs:
- /run
- /run/lock
security_opts:
- apparmor=unconfined
provisioner:
name: ansible
# One source for every play, so a verify play that runs the role again renders the same
# configuration and the idempotence step reruns converge with identical inputs.
inventory:
group_vars:
all:
openbao_test_tls_dir: /etc/molecule-tls
# 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 }}"
verifier:
name: ansible
scenario:
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
# A check runs before the converge (fresh host) and after it (configured host).
test_sequence:
- dependency
- cleanup
- syntax
- create
- prepare
- check
- converge
- check
- idempotence
- side_effect
- verify
- cleanup
+173
View File
@@ -0,0 +1,173 @@
---
# 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
@@ -0,0 +1,40 @@
---
# One failing run: runs the main entry point with the inputs of the case and asserts that the
# expected message, not something else, stopped it. Input: openbao_test_case (name, vars,
# expect). Task vars cannot come from a template as a whole, so each input a case may change is
# passed with its scenario value as the default.
- name: "Run the role, case {{ openbao_test_case.name }}"
block:
- name: "Include the role, case {{ openbao_test_case.name }}"
ansible.builtin.include_role:
name: mortis.kamino.openbao
vars:
openbao_version: "{{ openbao_test_case.vars.openbao_version | default(openbao_test_defaults.openbao_version) }}"
openbao_sha256: "{{ openbao_test_case.vars.openbao_sha256 | default(openbao_test_defaults.openbao_sha256) }}"
openbao_bin_path: "{{ openbao_test_case.vars.openbao_bin_path | default('/usr/local/bin/bao') }}"
openbao_listen_address: "{{ openbao_test_case.vars.openbao_listen_address | default('0.0.0.0') }}"
openbao_port: "{{ openbao_test_case.vars.openbao_port | default(8200) }}"
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 ~ '/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') }}"
# Only reached when the include returned. The message must not contain the expected
# text, so the rescue below cannot mistake it for the failure under test.
- name: "Fail because the include returned, case {{ openbao_test_case.name }}"
ansible.builtin.fail:
msg: The role accepted the input
rescue:
# A failed loop task reports its message per item.
- 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:
that: openbao_test_case.expect in openbao_test_messages
fail_msg: "Expected '{{ openbao_test_case.expect }}', got: {{ openbao_test_messages }}"
quiet: true
+229
View File
@@ -0,0 +1,229 @@
---
- 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: 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
- 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 }}"
# 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
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
+97
View File
@@ -0,0 +1,97 @@
---
# Under --skip-tags install the binary may still be missing; say so instead of a systemd error.
- name: Check that the OpenBao binary is installed
ansible.builtin.stat:
path: "{{ openbao_bin_path }}"
register: __openbao_binary_now
tags: [openbao, configure, health]
- name: Fail if the OpenBao binary is missing
ansible.builtin.fail:
msg: >-
The OpenBao binary {{ openbao_bin_path }} is missing, so the service cannot start. Run the role without
--skip-tags install (or with --tags install) to download it.
when:
- not __openbao_binary_now.stat.exists
# Nothing is downloaded under --check.
- 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:
src: openbao.hcl.j2
dest: "{{ openbao_config_dir }}/openbao.hcl"
owner: root
group: "{{ openbao_group }}"
mode: "0640"
register: __openbao_config
tags: [openbao, configure]
- name: Write the OpenBao systemd unit
become: true
ansible.builtin.template:
src: openbao.service.j2
dest: /etc/systemd/system/openbao.service
owner: root
group: root
mode: "0644"
register: __openbao_unit
tags: [openbao, configure]
# A restart seals the server, so it runs only when the configuration, the unit or the binary
# changed; a sealed server stays sealed until it is unsealed again.
- name: Enable and start OpenBao
become: true
ansible.builtin.systemd_service:
name: openbao
enabled: true
state: "{{ 'restarted' if __openbao_restart else 'started' }}"
daemon_reload: "{{ __openbao_unit is changed }}"
vars:
__openbao_restart: "{{ __openbao_config is changed or __openbao_unit is changed or not __openbao_installed }}"
# Under --check a new unit or binary is only simulated, so systemd would not find it.
when: not ansible_check_mode or (__openbao_unit is not changed and __openbao_installed)
tags: [openbao, configure]
- name: Check the OpenBao service status
become: true
ansible.builtin.systemd_service:
name: openbao
register: __openbao_service_status
tags: [openbao, configure, health]
- name: Fail if OpenBao is not running
ansible.builtin.fail:
msg: >-
The openbao service is {{ __openbao_service_status.status.ActiveState }}. See journalctl -u openbao on the
host.
when:
- __openbao_service_status.status.ActiveState != "active"
# The start above is skipped under --check for a new unit or binary.
- not ansible_check_mode or (__openbao_unit | default({}) is not changed and __openbao_installed)
tags: [openbao, configure, health]
+39
View File
@@ -0,0 +1,39 @@
---
# get_url checks the pinned sha256 before it keeps the archive, so a tampered or replaced asset
# never reaches the extraction. Only bao is extracted: the archive also holds the licence,
# README and changelog, which do not belong in a bin directory.
# Skipped under --check: tempfile and the extraction of a gzipped tarball cannot run in check
# mode, and nothing is downloaded.
- name: Download, verify and extract OpenBao
become: true
when: not ansible_check_mode
tags: [openbao, install]
block:
- name: Create a download directory
ansible.builtin.tempfile:
state: directory
suffix: .openbao
register: __openbao_download_dir
- name: Download and verify the OpenBao archive
ansible.builtin.get_url:
url: "{{ openbao_release_url }}/openbao_{{ openbao_version }}_linux_{{ __openbao_arch }}.tar.gz"
dest: "{{ __openbao_download_dir.path }}/openbao.tar.gz"
checksum: "sha256:{{ openbao_sha256[__openbao_arch] }}"
mode: "0600"
- name: Extract the bao binary
ansible.builtin.unarchive:
src: "{{ __openbao_download_dir.path }}/openbao.tar.gz"
dest: "{{ openbao_bin_path | dirname }}"
remote_src: true
include: [bao]
owner: root
group: root
mode: "0755"
always:
- name: Remove the download directory
ansible.builtin.file:
path: "{{ __openbao_download_dir.path }}"
state: absent
when: __openbao_download_dir.path is defined
+34
View File
@@ -0,0 +1,34 @@
---
# The download and the sha256 pick depend on the CPU architecture; a play with gather_facts off
# has none, so the smallest subset is gathered here.
- name: Gather the architecture fact
ansible.builtin.setup:
gather_subset: [min]
when: ansible_facts.architecture is undefined
tags: [openbao, always]
- name: Map the architecture to the release name
ansible.builtin.set_fact:
__openbao_arch: "{{ {'x86_64': 'amd64', 'aarch64': 'arm64'}.get(ansible_facts.architecture, ansible_facts.architecture) }}"
tags: [openbao, always]
- name: Validate the role inputs
ansible.builtin.import_tasks: validate.yml
tags: [openbao, always]
- name: Include prerequisites
ansible.builtin.include_tasks: prereqs.yml
tags: [openbao, prereqs, always]
- name: Install OpenBao if missing
ansible.builtin.include_tasks: install.yml
when: not __openbao_installed
tags: [openbao, install]
- name: Configure and start OpenBao
ansible.builtin.include_tasks: configure.yml
tags: [openbao, configure, health]
- name: Read the seal status
ansible.builtin.include_tasks: seal_status.yml
tags: [openbao, configure, health]
+51
View File
@@ -0,0 +1,51 @@
---
- name: Create the OpenBao group
become: true
ansible.builtin.group:
name: "{{ openbao_group }}"
system: true
register: __openbao_group_account
tags: [openbao, prereqs, always]
- name: Create the OpenBao user
become: true
ansible.builtin.user:
name: "{{ openbao_user }}"
group: "{{ openbao_group }}"
shell: /usr/sbin/nologin
home: "{{ openbao_data_dir }}"
comment: "OpenBao secret store"
system: true
create_home: false
register: __openbao_user_account
tags: [openbao, prereqs, always]
# The config holds no secret, but the service user reads it and no one else needs to.
- name: Create the OpenBao directories
become: true
ansible.builtin.file:
path: "{{ __openbao_dir.path }}"
state: directory
owner: "{{ __openbao_dir.owner }}"
group: "{{ openbao_group }}"
mode: "{{ __openbao_dir.mode }}"
loop:
- {path: "{{ openbao_config_dir }}", owner: root, mode: "0750"}
- {path: "{{ openbao_data_dir }}", owner: "{{ openbao_user }}", mode: "0700"}
loop_control:
loop_var: __openbao_dir
label: "{{ __openbao_dir.path }}"
# Under --check a new account is only simulated, so a directory cannot be chowned to it.
when: not ansible_check_mode or (__openbao_group_account is not changed and __openbao_user_account is not changed)
tags: [openbao, prereqs, always]
- name: Check if the OpenBao binary exists
ansible.builtin.stat:
path: "{{ openbao_bin_path }}"
register: __openbao_binary
tags: [openbao, prereqs, always]
- name: Set the OpenBao install fact
ansible.builtin.set_fact:
__openbao_installed: "{{ __openbao_binary.stat.exists }}"
tags: [openbao, prereqs, always]
+55
View File
@@ -0,0 +1,55 @@
---
# Reads the seal status on loopback, so it depends neither on DNS nor on the listen address,
# and validates the certificate against openbao_tls_ca_file: the certificate must cover
# 127.0.0.1. The endpoint needs no token.
- name: Read the OpenBao seal status
# 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)
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
ansible.builtin.debug:
msg: >-
WARNING: OpenBao on {{ inventory_hostname }} is not initialised and stays sealed. Initialise it before use;
until then it serves no secret.
when:
- __openbao_seal_status.json is defined
- not __openbao_seal_status.json.initialized
tags: [openbao, configure, health]
- name: Warn that OpenBao is sealed
ansible.builtin.debug:
msg: >-
WARNING: OpenBao on {{ inventory_hostname }} is sealed and serves no secret until it is unsealed with the
unseal keys.
when:
- __openbao_seal_status.json is defined
- __openbao_seal_status.json.initialized
- __openbao_seal_status.json.sealed
tags: [openbao, configure, health]
+179
View File
@@ -0,0 +1,179 @@
---
# 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) >= 1024
- openbao_port | int(0) <= 65535
- 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 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
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 }}"
# 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 }}"
- "{{ 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 | 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
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
+35
View File
@@ -0,0 +1,35 @@
{{ ansible_managed | comment }}
{% macro hostport(address, port) %}{{ ('[' ~ address ~ ']') if ':' in address else address }}:{{ port }}{% endmacro %}
{% macro tls() %}
{% if openbao_tls_disable | bool %}
tls_disable = true
{% else %}
tls_cert_file = {{ openbao_tls_cert_file | to_json }}
tls_key_file = {{ openbao_tls_key_file | to_json }}
tls_min_version = {{ openbao_tls_min_version | to_json }}
{% endif %}
{% endmacro %}
ui = {{ openbao_ui | bool | lower }}
api_addr = {{ openbao_api_addr | to_json }}
cluster_addr = {{ openbao_cluster_addr | to_json }}
storage "raft" {
path = {{ openbao_data_dir | to_json }}
node_id = {{ openbao_node_id | to_json }}
}
listener "tcp" {
address = {{ hostport(openbao_listen_address, openbao_port) | to_json }}
cluster_address = {{ hostport(openbao_listen_address, openbao_cluster_port) | to_json }}
{{ tls() -}}
}
{# 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" {
address = {{ hostport('127.0.0.1', openbao_port) | to_json }}
{{ tls() -}}
}
{% endif %}
@@ -0,0 +1,55 @@
{{ ansible_managed | comment }}
[Unit]
Description=OpenBao secret store
Documentation=https://openbao.org/docs/
Wants=network-online.target
After=network-online.target
ConditionFileNotEmpty={{ openbao_config_dir }}/openbao.hcl
[Service]
Type=notify
User={{ openbao_user }}
Group={{ openbao_group }}
ExecStart={{ openbao_bin_path }} server -config={{ openbao_config_dir }}/openbao.hcl
# SIGHUP reloads the listener certificates and the log level without sealing the server. The
# shell's own kill, because the kill binary (procps) is not on every host.
ExecReload=/bin/sh -c 'kill -HUP "$MAINPID"'
KillMode=process
KillSignal=SIGINT
TimeoutStopSec=30
Restart=on-failure
RestartSec=5
LimitNOFILE=65536
# OpenBao has no mlock since 2.0: keep its memory out of swap and out of core dumps instead.
MemorySwapMax=0
LimitCORE=0
UMask=0077
NoNewPrivileges=true
CapabilityBoundingSet=
AmbientCapabilities=
ProtectSystem=strict
ReadWritePaths={{ openbao_data_dir }}
ProtectHome=true
PrivateTmp=true
PrivateDevices=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectKernelLogs=true
ProtectControlGroups=true
ProtectClock=true
ProtectHostname=true
RestrictNamespaces=true
RestrictRealtime=true
RestrictSUIDSGID=true
LockPersonality=true
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]
WantedBy=multi-user.target
+1
View File
@@ -107,6 +107,7 @@ declare -A last_seconds=(
[roles/gitea_runner/molecule/default]=398
[roles/docker/molecule/default]=352
[roles/cloudflared/molecule/default]=305
[roles/openbao/molecule/default]=300
[roles/tailscale/molecule/default]=220
[roles/fail2ban/molecule/default]=161
[roles/gitea/molecule/default]=137