Moving my homelab's secrets out of GitLab using OpenBao and KMS on GCP
In One-click homelab every piece of the homelab became a tag away from being rebuilt. The pipelines that do the rebuilding need secrets. They all lived where GitLab tells you to put them: masked, protected CI/CD variables.
That's fine, right up until you ask who can decrypt them.
Fair warning: this post was written wearing the hat below.

The problem
GitLab encrypts CI variables at rest, but the key lives on GitLab's own application servers. That protects against a stolen database disk, not against a breach of GitLab itself: the attacker gets the ciphertext and the key together.
So the threat model is deliberately narrow: a platform-wide breach of GitLab, or of the cloud the secrets end up in. Nobody is targeting my homelab specifically (I hope!), so the heavyweight answers (keys split between several people, encrypted VMs, dedicated hardware) would guard against an adversary I don't have (again, I hope). And if one shows up, the design is built from the same pieces enterprises use (KMS, IAP, workload identity), so breaking in would cost far more than my homelab's secrets are worth.
The design
The vault is OpenBao on a single free-tier e2-micro in its own GCP project.
- No public IP, no internet access. The VM reaches Google APIs through Private Google Access and nothing else. The OpenBao package is served from a bucket in the same project.
- One way in: IAP. Both I and CI reach port 8200 through Google's Identity-Aware Proxy tunnel. There's no SSH bastion, no VPN, no open port.
- Unlocks itself with KMS. OpenBao starts locked after every restart and asks Google KMS to unlock it, so a reboot or a brand-new VM needs nothing from me. That's how OS updates work: every apply replaces the VM with the latest Debian image and reattaches the data disk.
- A verified boot. The VM runs Debian's official cloud image as a Shielded VM: it only boots a signed bootloader and kernel, and Google flags it if the boot ever looks different from the first good one. That catches a tampered OS, but not someone reading memory from Google's side of the host. That would take a Confidential VM (see below).
- Only Google-signed identities can log in. OpenBao's JWT auth method trusts Google's signing keys and nothing else. I log in with my own identity token; each pipeline logs in as its own service account.
- Everything is OpenTofu, applied from my laptop, never from CI. The thing that guards CI's secrets shouldn't be deployable by CI.
Secrets are laid out per component, named after the tag prefixes the IaC repo already uses (exit-node/1.0.12, sre-agent/2.3.0): iac/<component>/*, plus a small iac/shared/ for the rare secret two components need. A single JSON file lists the components, and both sides of the system are generated from it.
Cost
About $0.15 a month, almost all of it KMS:
| Monthly | |
|---|---|
e2-micro VM in us-central1 | $0 (Free Tier) |
Boot and data disk, 10 GB pd-standard each | $0 (in the 30 GB free) |
| Public IP | none: access is IAP only |
| Two KMS keys (unseal, OpenTofu state) | ~$0.12 |
| KMS calls, snapshot bucket, logs, IAP | a few cents at most |
The same setup on a Spot VM in Paris with a public IP would be around $9.
How a pipeline gets its secrets
Step by step:
- GitLab mints a JWT for the job. The Workload Identity Federation provider only accepts it if it comes from the IaC project, from a protected tag, on one of my own runners. The tag prefix becomes an attribute, and only jobs whose tag starts with
exit-node/may impersonateci-exit-node. - The job opens the IAP tunnel as that service account, which is allowed to tunnel to port 8200 and nothing else.
- It asks Google for an ID token for
ci-<component>, with audienceopenbao. - OpenBao checks the token against Google's keys, matches the email to the role, and hands back a token valid for 10 minutes, whose policy reads
iac/<component>/*and nothing more. - The values become
TF_VAR_*variables for the plan or apply, the token is revoked, the tunnel is killed, and the temp directory is deleted. That happens on every exit path, including failures.
Wiring it into the IaC repo
The IaC repo gets one include, .gitlab/ci/openbao.yml, with a hidden .openbao job. It asks GitLab for the JWT and sources a small shell script before the job runs.
.openbao:
id_tokens:
OPENBAO_GITLAB_JWT:
aud: https://iam.googleapis.com/projects/<project-number>/locations/global/workloadIdentityPools/gitlab/providers/gitlab-com
before_script:
- . "$CI_PROJECT_DIR/.gitlab/ci/openbao.sh" && openbao_load
A component opts in by adding it next to the OpenTofu templates it already uses, and by saying which secrets go into which variables:
opentofu-plan-production-sre-agent:
extends: [.opentofu:plan, .openbao]
variables:
OPENBAO_COMPONENT: "sre-agent"
OPENBAO_ENV: |
TF_VAR_sre_agent_telegram_bot_token=sre-agent/telegram#bot_token
TF_VAR_sre_agent_gatus_token=shared/gatus/sre-agent#token
Each line is TF_VAR_name=path#field, read from iac/<path>. The OpenTofu code doesn't change at all: it still gets the same TF_VAR_* variables, they just come from somewhere else.
The script's entry point reads like the steps above:
openbao_load() {
# GitLab's CI_DEBUG_TRACE would print every value
case $- in *x*) openbao_xtrace=1 && set +x ;; *) openbao_xtrace= ;; esac
[ -n "${OPENBAO_COMPONENT:-}" ] || openbao_fail "OPENBAO_COMPONENT is not set"
openbao_tmp=$(mktemp -d)
trap openbao_disconnect EXIT
openbao_install # pinned gcloud, checked by hash
openbao_connect # IAP tunnel, Google ID token, OpenBao login
openbao_export # one TF_VAR_* per OPENBAO_ENV line
openbao_disconnect # revoke the token, kill the tunnel, delete the temp dir
trap - EXIT
echo "openbao: loaded $(printf '%s\n' "$OPENBAO_ENV" | grep -c =) variables for $OPENBAO_COMPONENT"
[ -z "$openbao_xtrace" ] || set -x
unset openbao_xtrace
}
There's no custom image: each job downloads a pinned gcloud, checks its hash, and only uses it for the tunnel.
Three ways back
A vault you can lose is worse than no vault, so there are three independent ways back:
- Raft snapshots every 6 hours to a bucket with a locked retention policy: not even I can delete them early. Failed runs send an email, and a restore test proves the snapshots actually restore.
- A recovery key, for the day Google login breaks.
- An
age-encrypted export of every secret, restorable without GCP. Either of two passphrase-locked keys, kept in different places, opens it.
Both export keys are post-quantum, which age supports since version 1.3 (age-keygen -pq). After the joint statement from ONCD, NSA and CISA on new attacks against today's cryptography, that felt like the sensible default.
Possible improvements
One upgrade is planned, and one I left out on purpose because it guards against a stronger attacker than the one I'm planning for:
- An HSM-backed unseal key (planned), about $1 a month. Today the KMS key is software-protected. At the HSM level it would live in certified hardware that never lets it out. It's one setting in OpenTofu, but the protection level of an existing key can't change, so it means a new key and a seal migration.
- A Confidential VM (not planned, maybe when I have a decent salary), about $74 a month. The VM's memory would be encrypted even from Google's hosts. The free
e2-microdoesn't support it, hence the price. On its own it buys little: with KMS auto-unseal, anyone who controls the project can still ask KMS for the key. The real gain needs the key released only to a verified VM image, which is a much bigger redesign.
Closing
Security isn't about finding the one provider you can trust. It's about layers, so that a single mistake or a single leak isn't enough: defense in depth, homelab edition.
Total cost: one coffee a year. Total drama: hopefully zero.
This article is licensed under the CC BY-SA 4.0 license.