From 86dee1edc55fb68220035bbfe673da1eb2d0e7e8 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Thu, 29 Oct 2026 00:07:17 +0100 Subject: [PATCH] feat(web-app-openbao): record every request through a declared stdout audit device OpenBao keeps no record of who read which secret without an audit device, and 2.7 refuses to enable one over the API, so the server config declares a file device writing to stdout, which cannot block and lands in the container log with secret values only as salted HMACs. Every deploy fails unless the device is active, a probe secret read through the AppRole session shows up in the log with path, operation, display_name and time, and the probe value does not appear in plaintext. openbao becomes a regular shared provider so consumers such as the landing page role can declare services.openbao. Requirement 047; taken over from the feature/openbao-audit worktree. Co-Authored-By: Claude Opus 5.5 (1M context) --- docs/requirements/047-openbao-audit-device.md | 19 +++++++++ roles/web-app-openbao/README.md | 1 + roles/web-app-openbao/meta/services.yml | 4 ++ roles/web-app-openbao/tasks/03_policies.yml | 39 +++++++++++++++++++ .../web-app-openbao/templates/openbao.hcl.j2 | 6 +++ .../templates/policies/ansible-admin.hcl.j2 | 4 ++ roles/web-app-openbao/vars/main.yml | 2 + .../test_credential_rotation.py | 1 + 8 files changed, 76 insertions(+) create mode 100644 docs/requirements/047-openbao-audit-device.md diff --git a/docs/requirements/047-openbao-audit-device.md b/docs/requirements/047-openbao-audit-device.md new file mode 100644 index 0000000000..edda635639 --- /dev/null +++ b/docs/requirements/047-openbao-audit-device.md @@ -0,0 +1,19 @@ +# 047 - OpenBao Audit Device + +## User Story + +As an operator of applications that keep customer credentials in [`web-app-openbao`](../../roles/web-app-openbao/), I want every request to OpenBao recorded with the accessing identity and a timestamp, so that each read of a stored secret can be traced to the person or machine that made it. + +## Background + +OpenBao writes nothing about who read which secret unless an audit device is enabled. OpenBao 2.7 refuses to create audit devices through the API (`cannot enable audit device via API; use declarative, config-based audit device management instead`), so the device is declared in the server configuration. Once any audit device is enabled, OpenBao refuses requests it cannot log. The device therefore writes to the server's stdout, which cannot block. That output reaches the same container log as the rest of the server output. By default OpenBao replaces secret values in audit entries with salted HMACs, so the audit trail does not contain credentials. + +## Acceptance Criteria + +- [ ] The server configuration declares `audit "file" "stdout"` with `file_path = "stdout"`. +- [ ] The `ansible-admin` policy grants `read` and `sudo` on `sys/audit` to list audit devices, and no other policy of the role gains access to `sys/audit`. +- [ ] Every deploy fails unless `bao audit list` reports `stdout/` of type `file`; the check never reports changed. +- [ ] The deploy reads a probe secret with its AppRole session and fails unless the container log then holds an audit response entry for that read, carrying the request path, the `read` operation, a `display_name` and a `time`. +- [ ] Audit entries carry no plaintext secret value: the probe secret's value does not appear in the container log. +- [ ] The role README documents the audit device, its stdout destination and the deploy probe. +- [ ] `make compose-deploy` of `web-app-openbao` is green on a fresh stack and on a re-run. diff --git a/roles/web-app-openbao/README.md b/roles/web-app-openbao/README.md index e0f61a186d..216f4c7176 100644 --- a/roles/web-app-openbao/README.md +++ b/roles/web-app-openbao/README.md @@ -63,6 +63,7 @@ Solid `1:1` edges are fixed relationships; dashed `0..1` edges are conditional ( - **Automatic unsealing:** A `static` seal reads a 32-byte key from the encrypted inventory, so the node unseals itself on every container restart. - **Machine identity:** AppRole is configured independently of human login, so services and automation use their own identities and short-lived tokens instead of a shared administrator token. - **Optional internal PKI:** A service flag mounts the `pki` engine with an internal root CA and an issuing role. +- **Audit trail:** A `file` audit device at `stdout/`, declared in the server config, writes every request, with the accessing identity and a timestamp, to the server's stdout and so to the container log. Secret values appear only as salted HMACs. Every deploy reads a probe secret and fails unless the log shows that read with its identity and time. - **Monitoring:** Prometheus scrapes `/v1/sys/metrics` on the role-local network. A sealed node is detected from `/v1/sys/health`, which answers 503 while sealed and 200 once unsealed. - **Automated provisioning:** Configured by Ansible without manual steps; no Keycloak client or OpenBao path has to be created by hand. diff --git a/roles/web-app-openbao/meta/services.yml b/roles/web-app-openbao/meta/services.yml index 8f8a9e2276..63811f83e2 100644 --- a/roles/web-app-openbao/meta/services.yml +++ b/roles/web-app-openbao/meta/services.yml @@ -37,6 +37,7 @@ prometheus: native_metrics: enabled: true port: 8200 +# nocheck: playwright-service-flag self-provider openbao: # nocheck: default-placement-manager raft keeps its BoltDB store mmap'd with fsync durability, so it cannot live on NFS; the node is pinned in swarm to stay with its volume placement: manager @@ -45,6 +46,9 @@ openbao: enabled: true swarm: enabled: true + bond: 1 + enabled: true # nocheck: dynamic-flag + shared: true cpus: 0.5 mem_reservation: 128m mem_limit: 512m diff --git a/roles/web-app-openbao/tasks/03_policies.yml b/roles/web-app-openbao/tasks/03_policies.yml index 84c28ad92a..a716d8ced8 100644 --- a/roles/web-app-openbao/tasks/03_policies.yml +++ b/roles/web-app-openbao/tasks/03_policies.yml @@ -27,3 +27,42 @@ [ "$before" = "$after" ] || echo OPENBAO_CHANGED' register: openbao_admin_policy_write changed_when: "'OPENBAO_CHANGED' in openbao_admin_policy_write.stdout" + +- name: "๐Ÿ“ Fail unless the declared stdout audit device is active" + ansible.builtin.shell: > # nocheck: container-exec-resolver runtime-resolved CID, delegated to the hosting node + container exec {{ OPENBAO_LOCAL_CID | quote }} + bao audit list -format=json + register: openbao_audit_devices + changed_when: false + failed_when: >- + openbao_audit_devices.rc != 0 + or (openbao_audit_devices.stdout | from_json).get(OPENBAO_AUDIT_PATH ~ '/', {}).get('type') != 'file' + +- name: "๐Ÿ”Ž Read the audit probe secret through the AppRole session" + ansible.builtin.shell: > # nocheck: container-exec-resolver runtime-resolved CID, delegated to the hosting node + container exec {{ OPENBAO_LOCAL_CID | quote }} + sh -c 'bao kv get -mount={{ OPENBAO_KV_MOUNT | quote }} -field=value {{ OPENBAO_AUDIT_PROBE | quote }} 2>/dev/null || + { bao kv put -mount={{ OPENBAO_KV_MOUNT | quote }} {{ OPENBAO_AUDIT_PROBE | quote }} value="probe-$(date +%s)-$$" >/dev/null && + bao kv get -mount={{ OPENBAO_KV_MOUNT | quote }} -field=value {{ OPENBAO_AUDIT_PROBE | quote }}; }' + register: openbao_audit_probe + changed_when: false + +- name: "๐Ÿงพ Fail unless the audit log recorded the probe read with identity and time" + ansible.builtin.shell: > # nocheck: container-exec-resolver runtime-resolved CID, delegated to the hosting node + container logs --since 10m {{ OPENBAO_LOCAL_CID | quote }} 2>&1 + | grep -F '"type":"response"' + | grep -F '"path":"{{ OPENBAO_KV_MOUNT }}/data/{{ OPENBAO_AUDIT_PROBE }}"' + | grep -F '"operation":"read"' + | grep -F '"display_name":' + | grep -cF '"time":' + register: openbao_audit_entries + changed_when: false + failed_when: openbao_audit_entries.stdout | trim | int < 1 + +- name: "๐Ÿ™ˆ Fail if the audit log holds the probe secret in plaintext" + ansible.builtin.shell: > # nocheck: container-exec-resolver runtime-resolved CID, delegated to the hosting node + container logs --since 10m {{ OPENBAO_LOCAL_CID | quote }} 2>&1 + | grep -cF {{ openbao_audit_probe.stdout | trim | quote }} + register: openbao_audit_leak + changed_when: false + failed_when: openbao_audit_leak.stdout | trim | int > 0 diff --git a/roles/web-app-openbao/templates/openbao.hcl.j2 b/roles/web-app-openbao/templates/openbao.hcl.j2 index 9fc02c3bbc..acba58a60f 100644 --- a/roles/web-app-openbao/templates/openbao.hcl.j2 +++ b/roles/web-app-openbao/templates/openbao.hcl.j2 @@ -27,6 +27,12 @@ seal "static" { {% endif %} } +audit "file" "{{ OPENBAO_AUDIT_PATH }}" { + options { + file_path = "stdout" + } +} + telemetry { prometheus_retention_time = "24h" disable_hostname = true diff --git a/roles/web-app-openbao/templates/policies/ansible-admin.hcl.j2 b/roles/web-app-openbao/templates/policies/ansible-admin.hcl.j2 index c96fe76e97..1497fe5ad7 100644 --- a/roles/web-app-openbao/templates/policies/ansible-admin.hcl.j2 +++ b/roles/web-app-openbao/templates/policies/ansible-admin.hcl.j2 @@ -18,6 +18,10 @@ path "sys/mounts/*" { capabilities = ["create", "read", "update", "delete", "sudo"] } +path "sys/audit" { + capabilities = ["read", "sudo"] +} + path "sys/plugins/reload/backend" { capabilities = ["update"] } diff --git a/roles/web-app-openbao/vars/main.yml b/roles/web-app-openbao/vars/main.yml index 3f9285a34a..08a3495498 100644 --- a/roles/web-app-openbao/vars/main.yml +++ b/roles/web-app-openbao/vars/main.yml @@ -48,6 +48,8 @@ OPENBAO_RECOVERY_KEY: >- OPENBAO_SECRET_ID_REGISTERED: "{{ openbao_secret_id_registered | default('', true) }}" OPENBAO_SECRET_ID_ROTATING: "{{ (OPENBAO_SECRET_ID_REGISTERED | length > 0) and (OPENBAO_SECRET_ID_REGISTERED != OPENBAO_APPROLE_SECRET_ID) }}" OPENBAO_KV_MOUNT: "infinito" +OPENBAO_AUDIT_PATH: "stdout" +OPENBAO_AUDIT_PROBE: "audit-probe" OPENBAO_ANSIBLE_APPROLE: "ansible" OPENBAO_PKI_MOUNT: "pki" OPENBAO_PKI_ISSUING_ROLE: "internal" diff --git a/tests/unit/python/roles/web-app-openbao/test_credential_rotation.py b/tests/unit/python/roles/web-app-openbao/test_credential_rotation.py index 582607a82d..c1b5880234 100644 --- a/tests/unit/python/roles/web-app-openbao/test_credential_rotation.py +++ b/tests/unit/python/roles/web-app-openbao/test_credential_rotation.py @@ -31,6 +31,7 @@ HCL_CONTEXT = { "OPENBAO_SEAL_KEY_ID": "0123456789abcdef", "OPENBAO_SEAL_KEY_PREVIOUS_ID": "fedcba9876543210", "OPENBAO_BASE_URL": "https://bao.example.com", + "OPENBAO_AUDIT_PATH": "stdout", } ENV_CONTEXT = {