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
This commit is contained in:
1 parent
ddfb1c6d0a
commit
eda69bcbf5
16 files changed
+762
-4
No files matched your search
@@ -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
|
||||
|
||||
@@ -42,7 +42,6 @@ when its own prerequisites (tests, a safe cutover wherever the role already runs
|
||||
Still to come:
|
||||
|
||||
- Wave 3: `rke2`, `proxmox_host`.
|
||||
- Not yet in a wave: `openbao`.
|
||||
|
||||
Will not be extracted (they serve one lab or install that lab's own tool pins):
|
||||
`k8s_manage`, `k8s_localhost`, `k8s_lint_tools`, `minecraft_server`, `dragonwilds_server`,
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -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 or does not exist; the key and certificate must also be readable by the `openbao` user, which the role checks before it writes the configuration. Create the `openbao` group first (a system group) 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.
|
||||
- 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. 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. |
|
||||
| `openbao_cluster_port` | `8201` | Cluster port. |
|
||||
| `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. |
|
||||
| `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 and the `prereqs` tasks are also tagged `always`. `--tags health` checks the TLS files' readability, 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 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), and the switch to plain HTTP and back. 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.
|
||||
- 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, and the readability check of the TLS files is skipped while the `openbao` user is new.
|
||||
- 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).
|
||||
@@ -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
|
||||
@@ -0,0 +1,142 @@
|
||||
---
|
||||
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. When it is neither a
|
||||
wildcard nor 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.
|
||||
openbao_cluster_port:
|
||||
type: int
|
||||
default: 8201
|
||||
description:
|
||||
- Port of the cluster listener, used by raft peers.
|
||||
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: str
|
||||
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: str
|
||||
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
|
||||
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.
|
||||
@@ -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,92 @@
|
||||
---
|
||||
# The server reads the certificate and key as the service user and refuses to start without
|
||||
# them; checking here names the file instead of leaving a failed unit.
|
||||
- name: Check that the service user can read the TLS files
|
||||
become: true
|
||||
ansible.builtin.command:
|
||||
# setpriv, unlike runuser or become_user, switches user without PAM or a temporary module file.
|
||||
argv: [setpriv, "--reuid={{ openbao_user }}", "--regid={{ openbao_group }}", --init-groups, test, -r, "{{ __openbao_tls_file }}"]
|
||||
loop:
|
||||
- "{{ openbao_tls_cert_file }}"
|
||||
- "{{ openbao_tls_key_file }}"
|
||||
loop_control:
|
||||
loop_var: __openbao_tls_file
|
||||
register: __openbao_tls_readable
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
# Read-only: runs in --check too. A user that is new under --check does not exist yet.
|
||||
check_mode: false
|
||||
when:
|
||||
- not (openbao_tls_disable | bool)
|
||||
- not ansible_check_mode or __openbao_user_account is not changed
|
||||
tags: [openbao, configure, health]
|
||||
|
||||
- name: Require the TLS files to be readable by the service user
|
||||
ansible.builtin.assert:
|
||||
that: __openbao_tls_unreadable | length == 0
|
||||
fail_msg: >-
|
||||
The user {{ openbao_user }} cannot read {{ __openbao_tls_unreadable | join(', ') }}. Give the file to the
|
||||
{{ openbao_group }} group (for example root:{{ openbao_group }}, mode 0640) and make its directories
|
||||
searchable by that group.
|
||||
quiet: true
|
||||
vars:
|
||||
__openbao_tls_unreadable: >-
|
||||
{{ __openbao_tls_readable.results | default([]) | selectattr('rc', 'defined') | rejectattr('rc', 'equalto', 0)
|
||||
| map(attribute='__openbao_tls_file') | list }}
|
||||
when: not (openbao_tls_disable | bool)
|
||||
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]
|
||||
@@ -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
|
||||
@@ -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]
|
||||
@@ -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]
|
||||
@@ -0,0 +1,43 @@
|
||||
---
|
||||
# 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
|
||||
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
|
||||
# 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]
|
||||
|
||||
- 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]
|
||||
@@ -0,0 +1,133 @@
|
||||
---
|
||||
# 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
|
||||
|
||||
- name: Require a listen address, ports and node id
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- openbao_listen_address is string
|
||||
- openbao_listen_address is match('^[0-9A-Fa-f.:]+\\Z')
|
||||
- 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_listen_address must be an IPv4 or IPv6 address (0.0.0.0 for every address); 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)
|
||||
|
||||
- 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.
|
||||
when: openbao_tls_disable | bool
|
||||
@@ -0,0 +1,34 @@
|
||||
{{ 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() -}}
|
||||
}
|
||||
{% 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,53 @@
|
||||
{{ 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
|
||||
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user