OpenBao Ansible Role https://openbao.org/
  • Shell 76.6%
  • Dockerfile 23.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jonas Koenig 107c4f0020
All checks were successful
Lint + Build + Tag / lint (push) Successful in 25s
Lint + Build + Tag / tag (push) Successful in 8s
Lint + Build + Tag / build (push) Successful in 2m26s
fix: start Alloy only after the config oneshot
2026-11-26 15:28:28 +00:00
.forgejo/workflows ci: try the registry push even without a configured token 2026-11-26 13:53:31 +00:00
defaults feat: ship OpenBao logs and metrics with in-image Alloy 2026-11-26 15:27:17 +00:00
examples feat: ship OpenBao logs and metrics with in-image Alloy 2026-11-26 15:27:17 +00:00
image/rootfs fix: start Alloy only after the config oneshot 2026-11-26 15:28:28 +00:00
meta feat: add OpenBao image and Ansible role 2026-11-26 13:36:40 +00:00
tasks feat: ship OpenBao logs and metrics with in-image Alloy 2026-11-26 15:27:17 +00:00
tests feat: ship OpenBao logs and metrics with in-image Alloy 2026-11-26 15:27:17 +00:00
.ansible-lint feat: add OpenBao image and Ansible role 2026-11-26 13:36:40 +00:00
.gitignore feat: add OpenBao image and Ansible role 2026-11-26 13:36:40 +00:00
CHANGELOG.md feat: ship OpenBao logs and metrics with in-image Alloy 2026-11-26 15:27:17 +00:00
Containerfile feat: ship OpenBao logs and metrics with in-image Alloy 2026-11-26 15:27:17 +00:00
LICENSE feat: add OpenBao image and Ansible role 2026-11-26 13:36:40 +00:00
README.md feat: ship OpenBao logs and metrics with in-image Alloy 2026-11-26 15:27:17 +00:00

openbao

OpenBao as a Proxmox VE 9.1+ OCI application container, with the Ansible role in the same repository. The role extends oci_lxc: tasks/facts.yml maps the openbao_* variables onto the oci_lxc_* contract and includes the role, so a play needs only roles: [openbao].

Containerfile                     the image (s6-overlay, bao, acme.sh)
image/rootfs/                     PID 1 services, init script, health script
defaults/main.yml                 role variables
tasks/facts.yml                   openbao_* -> oci_lxc_*, include_role
tasks/seal.yml                    init once, unseal every start
tasks/pki.yml                     root CA and issuance role
tasks/autounseal.yml              node unit that unseals after a reboot
examples/playbook.yml             complete deploy play
tests/smoke.sh                    local image smoke test

Why an own image

The upstream openbao/openbao image cannot be used as a PVE application container as-is: it runs bao server -dev by default, uses dumb-init without service supervision, keeps its configuration in /openbao/config and ships no ACME client. PVE needs a single PID 1 that reaps and forwards SIGTERM, an environment-only config and a health script. This repository reuses the official release binary and adds exactly those parts.

Storage: raft, no database

OpenBao stores everything in its integrated raft log under /openbao/data (a bind mount, so an image update does not touch it). The role does not use the available PostgreSQL cluster: Raft needs no external service, and a single node does not gain anything from a database. The image therefore contains no database, and no connection string or schema migration is part of the deploy. PostgreSQL storage remains possible if the deployment ever needs multiple writers; it would only be a storage "postgresql" block in image/rootfs/etc/s6-overlay/scripts/openbao-init.sh plus environment variables.

Image

Environment only; every value is rendered at container start into /run/openbao/config.hcl, which is disposable.

Variable Default Meaning
OPENBAO_DOMAIN — Required. Listener name, api_addr, certificate name.
OPENBAO_NODE_ID openbao Raft node id. Keep stable after initialization.
OPENBAO_ACME_ENABLED true Issue the listener certificate with ACME DNS-01.
OPENBAO_ACME_EMAIL — ACME account email; required with ACME.
OPENBAO_ACME_CA Let's Encrypt prod ACME directory URL; use staging while testing.
HETZNER_TOKEN — Hetzner Cloud API token, DNS edit; required with ACME.
OPENBAO_LOG_LEVEL info trace, debug, info, warn, error.
OPENBAO_UI true Serve the web UI.
LOKI_URL — Loki push URL; empty leaves log shipping off.
LOKI_USERNAME — Basic auth for Loki (used only when set).
LOKI_PASSWORD — Basic auth for Loki.
PROMETHEUS_REMOTE_WRITE_URL — Prometheus remote-write URL; empty leaves metric shipping off.
PROMETHEUS_USERNAME — Basic auth for remote write.
PROMETHEUS_PASSWORD — Basic auth for remote write.

The listener always uses TLS: https://<domain>:8200. There is no port publishing in LXC; clients use the container's own address.

Hetzner DNS challenge

The old dns.hetzner.com DNS console API and its token are not used. The image runs acme.sh with its dns_hetznercloud provider, which calls https://api.hetzner.cloud/v1 (zones and RRsets) with HETZNER_TOKEN. Create the token in the Hetzner Console under the project's API tokens; the old DNS console token will fail with HTTP 401/403 in the container log.

Renewal runs twice a day. When the certificate changed, the renewal service sends SIGHUP to OpenBao, which reloads the listener certificate in place. A restart would leave the node sealed, so it is not used.

Deploy

- hosts: pve
  become: true
  vars:
    openbao_vmid: 252
    openbao_hostname: openbao01
    openbao_domain: bao.int.example.com
    openbao_ip: 10.20.0.24/16
    openbao_gateway: 10.20.0.1
    openbao_vlan: 20
    openbao_data_root: /brighttree/data/openbao
    openbao_acme_email: it@example.com
    openbao_hetzner_token: !vault |
      ...
  roles:
    - openbao

The role pulls the image, creates the container, waits for the API, runs bao operator init once (-key-shares=1 -key-threshold=1) and unseals it. The health script accepts a sealed or uninitialized server, because the container must exist before initialization can run.

Seal material

bao operator init returns the unseal key and root token. The role stores them in /var/lib/openbao/<vmid>.json on the Proxmox node, mode 0600, and reads them on every later run. This means:

  • root on the node can read the key and the raft data, so the seal does not protect against host compromise (same trust level as the data itself);
  • keep the file in the node backup, or move the material into Ansible Vault and set openbao_unseal_key / openbao_root_token instead;
  • lose the key and the data is unrecoverable.

openbao_auto_unseal: true (default) installs openbao-unseal-<vmid>.service on the node: after a reboot, it waits for the container and unseals it. Without it a rebooted node runs a sealed OpenBao until the role runs again.

Secrets

OpenBao initializes without a KV mount (unlike Vault), so the role enables kv-v2 at secret/ (openbao_kv_mount). Application secrets:

bao kv put secret/app/db password=...
bao kv get -field=password secret/app/db

Log and metric shipping

Alloy is in the image (same binary and version as the proxy image) and runs as its own s6 service. It tails OpenBao's rotating log file /openbao/data/logs/openbao.log and scrapes the loopback-only metrics listener http://127.0.0.1:8202/v1/sys/metrics. Both are loki.source.file → loki.write and prometheus.scrape → prometheus.remote_write; the config is rendered at container start, never edited inside the image.

Role variable Image variable Value for the TNI Monitoring Stack
openbao_loki_url LOKI_URL https://monitoring.tni.dev/loki/loki/api/v1/push
openbao_loki_username LOKI_USERNAME alloy
openbao_loki_password LOKI_PASSWORD the ingest password (tni_monitoring_ingest_password)
openbao_prometheus_url PROMETHEUS_REMOTE_WRITE_URL https://monitoring.tni.dev/prometheus/api/v1/write
openbao_prometheus_username PROMETHEUS_USERNAME alloy
openbao_prometheus_password PROMETHEUS_PASSWORD the same ingest password

Empty URLs leave Alloy idle. The log label set is job="openbao", instance="<openbao_domain>" and filename; metrics carry the same job and instance. Log rotation is 100 MiB or 24 h, keeping three files, all inside the persistent data directory. Alloy's tail positions live in /openbao/data/alloy, so a container update does not resend the whole file.

Alloy is not a health gate: a broken agent prints a warning from openbao-health but never blocks a container update or makes the secrets manager unavailable.

Certificate authority

The role enables the pki secrets engine, generates an EC P-256 root CA (openbao_pki_root_ttl, default 10 years), publishes the CA/CRL URLs and creates the issuance role internal. The root certificate is exported to /var/lib/openbao/<vmid>-ca.pem on the node (openbao_pki_ca_path).

# Issue a certificate (run inside the container, e.g. with pct exec).
BAO_TOKEN=... bao write pki/issue/internal \
    common_name=app.int.example.com ttl=720h

# Read a service's CA certificate.
bao read -field=certificate pki/cert/ca

openbao_pki_allowed_domains: [] permits any DNS name and IP SAN in an issued certificate; set the list to restrict it. Restriction changes are applied only with openbao_pki_reconfigure: true for one run, so a live role is not rewritten by an unrelated deploy.

The PKI engine is a CA, not an ACME server for clients: OpenBao's ACME endpoint only supports HTTP-01/TLS-ALPN-01, not the DNS-01 challenge. The listener certificate therefore comes from acme.sh, and internal certificates come from pki/issue/<role>.

Operations

pct exec 252 -- /usr/local/bin/openbao-health
pct exec 252 -- bao status
cat /var/lib/openbao/252.json            # unseal key + root token, root only
cat /var/lib/openbao/252-ca.pem          # root CA
pct console 252                          # PID 1 output (s6, bao)

Update: bump the image tag in openbao_image (or leave :latest) and re-run the play. oci_lxc recreates the container, keeps the bind mount, the role unseals again. Uninstall: openbao_uninstall: true (data stays unless openbao_purge_data: true).

CI

.forgejo/workflows/ci.yml lints, builds the image with buildah and (on main and tags) pushes it. Pushing needs a repository secret REGISTRY_TOKEN: a Forgejo personal access token with write:package. REGISTRY_USER is optional; the registry ignores the username for token logins. Without the secret the build still succeeds: the push is attempted once with any pre-existing credentials and otherwise reported as skipped, so the package list stays empty.

A push to main also creates the next semver tag, so a role pin in an inventory can reference 0.1.x.

Tests

tests/smoke.sh        # builds and runs the image locally, checks health + sealed status
tests/role.sh         # init, unseal, KV, PKI, shipping and reload against a local container
ansible-lint .        # role lint
ansible-playbook --syntax-check examples/playbook.yml

A full functional test needs a real PVE node; the container cannot start inside a CI job container.