Feature: Render stack secrets from OpenBao and adopt Gitea #21

Merged
claude-bot Bot merged 4 commits from feature/render-stack-env-from-openbao into main 2026-12-04 04:21:47 +01:00

What changes

  • The docker_stack role renders a stack's .env from OpenBao when stacks/<stack>/env.j2 exists. It reads docker/<stack> from the KV engine with an AppRole login, writes .env with mode 600, and uses no_log and diff: false so values never reach the job log. Stacks without an env.j2 behave as before.
  • community.hashi_vault 7.1.0 is added to the collection requirements.
  • inventory/group_vars/all.yml reads the OpenBao address and AppRole credentials from files on the ansible LXC, so no hostname or credential is committed.
  • The README gets a Secrets section on setting up and using OpenBao.
  • Gitea is adopted: its compose file is in the repo without the Watchtower label, stacks/gitea/env.j2 lists its variables, and playbooks/gitea.yml deploys it.

Why

Secrets have to stay out of this repo, which is meant to become public. Gitea gets its own playbook because it runs the deploy pipeline: no workflow calls playbooks/gitea.yml, so it is only run by hand from the ansible LXC.

Deploy effect

Merging triggers Deploy Stacks, which runs docker_stacks.yml (it-tools only). it-tools has no env.j2, so it does not contact OpenBao. Gitea is not deployed by the merge.

## What changes - The `docker_stack` role renders a stack's `.env` from OpenBao when `stacks/<stack>/env.j2` exists. It reads `docker/<stack>` from the KV engine with an AppRole login, writes `.env` with mode `600`, and uses `no_log` and `diff: false` so values never reach the job log. Stacks without an `env.j2` behave as before. - `community.hashi_vault` 7.1.0 is added to the collection requirements. - `inventory/group_vars/all.yml` reads the OpenBao address and AppRole credentials from files on the ansible LXC, so no hostname or credential is committed. - The README gets a Secrets section on setting up and using OpenBao. - Gitea is adopted: its compose file is in the repo without the Watchtower label, `stacks/gitea/env.j2` lists its variables, and `playbooks/gitea.yml` deploys it. ## Why Secrets have to stay out of this repo, which is meant to become public. Gitea gets its own playbook because it runs the deploy pipeline: no workflow calls `playbooks/gitea.yml`, so it is only run by hand from the ansible LXC. ## Deploy effect Merging triggers Deploy Stacks, which runs `docker_stacks.yml` (it-tools only). it-tools has no `env.j2`, so it does not contact OpenBao. Gitea is not deployed by the merge.
claude-bot Bot added 3 commits 2026-12-04 04:09:49 +01:00
Stacks with an env.j2 get their .env from OpenBao, so secrets stay out of the
repo. The address and AppRole credentials are read from files on the ansible
LXC, which keeps hostnames out of the public repo.
feature(stacks): adopt gitea with secrets from OpenBao
Checks / Secret Scan (pull_request) Successful in 8s
Checks / Lint (pull_request) Successful in 1m15s
6e2dd06b9e
Gitea runs the deploy pipeline, so it gets its own playbook that is run by
hand and never from a workflow.

Review

Effort: medium

  • stacks/gitea/env.j2:7: values are written to .env unquoted and unescaped, and the README tells you to strip quotes on import. A secret containing $, #, quotes or a newline is changed by Compose: $word is interpolated and #... is dropped as a comment. That would give Gitea the wrong DB password. (important)
  • README.md:41: the secret files are readable only by the runner user, but playbooks/gitea.yml is run by hand. The README doesn't say to run it as the runner user, so a manual run fails with permission denied on the lookup. (nit)
  • stacks/gitea/docker-compose.yml:7: USER_GID=${NON_ROOT_USER_UID} uses the UID variable for the GID. It was copied from the live file as-is. (pre-existing)
  • roles/docker_stack/tasks/main.yml:41: no_log also hides which key is missing when the template fails to render. (nit)
  • roles/docker_stack/tasks/main.yml:34: deleting a stack's env.j2 leaves its old .env on the host. (nit)
  • README.md:63: the jq import keeps \r from CRLF files and inline comments, and skips export lines. (nit)
<!-- claude-review: fail 6e2dd06b9e4716013590a18c7210236f862d0c81 --> ## Review Effort: medium - `stacks/gitea/env.j2:7`: values are written to `.env` unquoted and unescaped, and the README tells you to strip quotes on import. A secret containing `$`, ` #`, quotes or a newline is changed by Compose: `$word` is interpolated and ` #...` is dropped as a comment. That would give Gitea the wrong DB password. (important) - `README.md:41`: the secret files are readable only by the runner user, but `playbooks/gitea.yml` is run by hand. The README doesn't say to run it as the runner user, so a manual run fails with permission denied on the lookup. (nit) - `stacks/gitea/docker-compose.yml:7`: `USER_GID=${NON_ROOT_USER_UID}` uses the UID variable for the GID. It was copied from the live file as-is. (pre-existing) - `roles/docker_stack/tasks/main.yml:41`: `no_log` also hides which key is missing when the template fails to render. (nit) - `roles/docker_stack/tasks/main.yml:34`: deleting a stack's `env.j2` leaves its old `.env` on the host. (nit) - `README.md:63`: the jq import keeps `\r` from CRLF files and inline comments, and skips `export` lines. (nit)
kasun added 1 commit 2026-12-04 04:20:26 +01:00
docs: keep imported secret values as they are
Checks / Secret Scan (pull_request) Successful in 6s
Checks / Lint (pull_request) Successful in 46s
69a1c0a9fb

Review

Effort: medium

The earlier quoting finding is resolved: values are rendered unquoted on purpose, matching the live .env format byte for byte, and the README now says to import values as they are and to avoid $, #, quotes and spaces in new values.

  • stacks/gitea/docker-compose.yml:7: USER_GID=${NON_ROOT_USER_UID} uses the UID variable for the GID. It was copied from the live file as-is. (pre-existing)
  • roles/docker_stack/tasks/main.yml:34: a newline in a secret value would add an extra line to .env. No check refuses it. (nit)
  • roles/docker_stack/tasks/main.yml:32: no_log also hides the cause when the OpenBao login, the read or the rendering fails. (nit)
  • roles/docker_stack/tasks/main.yml:39: deleting a stack's env.j2 leaves its old .env on the host. (nit)
  • roles/docker_stack/tasks/main.yml:23: set_fact keeps the secrets as a host fact for the rest of the play. Task-level vars on the template task would scope them to that one task. (nit)
  • stacks/gitea/env.j2:1: the header comment hardcodes secret/docker/gitea, though the mount and path are variables. (nit)
<!-- claude-review: pass 69a1c0a9fb8bb62e0304d7d64fcb7fae83036c2e --> ## Review Effort: medium The earlier quoting finding is resolved: values are rendered unquoted on purpose, matching the live `.env` format byte for byte, and the README now says to import values as they are and to avoid `$`, `#`, quotes and spaces in new values. - `stacks/gitea/docker-compose.yml:7`: `USER_GID=${NON_ROOT_USER_UID}` uses the UID variable for the GID. It was copied from the live file as-is. (pre-existing) - `roles/docker_stack/tasks/main.yml:34`: a newline in a secret value would add an extra line to `.env`. No check refuses it. (nit) - `roles/docker_stack/tasks/main.yml:32`: `no_log` also hides the cause when the OpenBao login, the read or the rendering fails. (nit) - `roles/docker_stack/tasks/main.yml:39`: deleting a stack's `env.j2` leaves its old `.env` on the host. (nit) - `roles/docker_stack/tasks/main.yml:23`: `set_fact` keeps the secrets as a host fact for the rest of the play. Task-level `vars` on the template task would scope them to that one task. (nit) - `stacks/gitea/env.j2:1`: the header comment hardcodes `secret/docker/gitea`, though the mount and path are variables. (nit)
claude-bot Bot merged commit 72485d6037 into main 2026-12-04 04:21:47 +01:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: kasun/homelab-ansible#21