diff --git a/.claude/skills/merge/SKILL.md b/.claude/skills/merge/SKILL.md index 82a2550..f49a05a 100644 --- a/.claude/skills/merge/SKILL.md +++ b/.claude/skills/merge/SKILL.md @@ -91,6 +91,6 @@ Keep it short: - PR link and commits. - What the merge deploys, from the `on.push.paths` in `.gitea/workflows/`. `01`, `03`, `04` and `05` deploy on merge. A change under `.gitea/workflows/` can deploy `03`, `04` and `05`, and a change to `01`'s own workflow deploys `01`. - For `02` changes, say that they are not live until someone runs the manual workflow. -- Anything left uncommitted, and a reminder to update `_PULUMI_DEV_YAML` if local Pulumi config changed. +- Anything left uncommitted. Also run `git -C .pulumi-config status --short --branch`, and if it shows uncommitted or unpushed changes, remind the user to commit and push them there because CI uses that repo's `main`. Don't commit or push that repo as part of `/merge`. Do not delete the branch, dispatch a workflow, or change a live system. diff --git a/.gitea/workflows/01-deploy-proxmox-infra.yaml b/.gitea/workflows/01-deploy-proxmox-infra.yaml index bb8dda8..3c76f72 100644 --- a/.gitea/workflows/01-deploy-proxmox-infra.yaml +++ b/.gitea/workflows/01-deploy-proxmox-infra.yaml @@ -31,8 +31,14 @@ jobs: with: node-version: "24" - - name: Restore Stack Config - run: echo "${{ secrets.PROXMOX_INFRA_PULUMI_DEV_YAML }}" | base64 -d > 01-proxmox-infra/Pulumi.dev.yaml + - name: Checkout Stack Config + uses: actions/checkout@v4 + with: + repository: kasun/homelab-pulumi-config + ref: main + token: ${{ secrets.PULUMI_CONFIG_REPO_TOKEN }} + path: .pulumi-config + persist-credentials: false - name: Install Dependencies run: npm ci @@ -68,8 +74,14 @@ jobs: with: node-version: "24" - - name: Restore Stack Config - run: echo "${{ secrets.PROXMOX_INFRA_PULUMI_DEV_YAML }}" | base64 -d > 01-proxmox-infra/Pulumi.dev.yaml + - name: Checkout Stack Config + uses: actions/checkout@v4 + with: + repository: kasun/homelab-pulumi-config + ref: main + token: ${{ secrets.PULUMI_CONFIG_REPO_TOKEN }} + path: .pulumi-config + persist-credentials: false - name: Install Dependencies run: npm ci diff --git a/.gitea/workflows/02-deploy-k8s-bootstrap.yaml b/.gitea/workflows/02-deploy-k8s-bootstrap.yaml index 5c0545d..8a1ca84 100644 --- a/.gitea/workflows/02-deploy-k8s-bootstrap.yaml +++ b/.gitea/workflows/02-deploy-k8s-bootstrap.yaml @@ -23,8 +23,14 @@ jobs: with: node-version: "24" - - name: Restore Stack Config - run: echo "${{ secrets.K8S_BOOTSTRAP_PULUMI_DEV_YAML }}" | base64 -d > 02-k8s-bootstrap/Pulumi.dev.yaml + - name: Checkout Stack Config + uses: actions/checkout@v4 + with: + repository: kasun/homelab-pulumi-config + ref: main + token: ${{ secrets.PULUMI_CONFIG_REPO_TOKEN }} + path: .pulumi-config + persist-credentials: false - name: Install Dependencies run: npm install @@ -53,8 +59,14 @@ jobs: with: node-version: "24" - - name: Restore Stack Config - run: echo "${{ secrets.K8S_BOOTSTRAP_PULUMI_DEV_YAML }}" | base64 -d > 02-k8s-bootstrap/Pulumi.dev.yaml + - name: Checkout Stack Config + uses: actions/checkout@v4 + with: + repository: kasun/homelab-pulumi-config + ref: main + token: ${{ secrets.PULUMI_CONFIG_REPO_TOKEN }} + path: .pulumi-config + persist-credentials: false - name: Install Dependencies run: npm install diff --git a/.gitea/workflows/03-deploy-k8s-infra.yaml b/.gitea/workflows/03-deploy-k8s-infra.yaml index 2db0c44..0202317 100644 --- a/.gitea/workflows/03-deploy-k8s-infra.yaml +++ b/.gitea/workflows/03-deploy-k8s-infra.yaml @@ -29,8 +29,14 @@ jobs: with: node-version: "24" - - name: Restore Stack Config - run: echo "${{ secrets.K8S_INFRA_PULUMI_DEV_YAML }}" | base64 -d > 03-k8s-infra/Pulumi.dev.yaml + - name: Checkout Stack Config + uses: actions/checkout@v4 + with: + repository: kasun/homelab-pulumi-config + ref: main + token: ${{ secrets.PULUMI_CONFIG_REPO_TOKEN }} + path: .pulumi-config + persist-credentials: false - name: Install Helm uses: azure/setup-helm@v4 @@ -62,8 +68,14 @@ jobs: with: node-version: "24" - - name: Restore Stack Config - run: echo "${{ secrets.K8S_INFRA_PULUMI_DEV_YAML }}" | base64 -d > 03-k8s-infra/Pulumi.dev.yaml + - name: Checkout Stack Config + uses: actions/checkout@v4 + with: + repository: kasun/homelab-pulumi-config + ref: main + token: ${{ secrets.PULUMI_CONFIG_REPO_TOKEN }} + path: .pulumi-config + persist-credentials: false - name: Install Helm uses: azure/setup-helm@v4 diff --git a/.gitea/workflows/04-deploy-k8s-apps.yaml b/.gitea/workflows/04-deploy-k8s-apps.yaml index e375538..edd9762 100644 --- a/.gitea/workflows/04-deploy-k8s-apps.yaml +++ b/.gitea/workflows/04-deploy-k8s-apps.yaml @@ -29,8 +29,14 @@ jobs: with: node-version: "24" - - name: Restore Stack Config - run: echo "${{ secrets.K8S_APPS_PULUMI_DEV_YAML }}" | base64 -d > 04-k8s-apps/Pulumi.dev.yaml + - name: Checkout Stack Config + uses: actions/checkout@v4 + with: + repository: kasun/homelab-pulumi-config + ref: main + token: ${{ secrets.PULUMI_CONFIG_REPO_TOKEN }} + path: .pulumi-config + persist-credentials: false - name: Install Dependencies run: npm install @@ -59,8 +65,14 @@ jobs: with: node-version: "24" - - name: Restore Stack Config - run: echo "${{ secrets.K8S_APPS_PULUMI_DEV_YAML }}" | base64 -d > 04-k8s-apps/Pulumi.dev.yaml + - name: Checkout Stack Config + uses: actions/checkout@v4 + with: + repository: kasun/homelab-pulumi-config + ref: main + token: ${{ secrets.PULUMI_CONFIG_REPO_TOKEN }} + path: .pulumi-config + persist-credentials: false - name: Install Dependencies run: npm install diff --git a/01-proxmox-infra/Pulumi.yaml b/01-proxmox-infra/Pulumi.yaml index 44776b0..ae8f502 100644 --- a/01-proxmox-infra/Pulumi.yaml +++ b/01-proxmox-infra/Pulumi.yaml @@ -15,3 +15,4 @@ packages: parameters: - marshallford/pfsense - 0.22.0 +stackConfigDir: ../.pulumi-config/01-proxmox-infra diff --git a/02-k8s-bootstrap/Pulumi.yaml b/02-k8s-bootstrap/Pulumi.yaml index 4bd20f0..f4ca6fe 100644 --- a/02-k8s-bootstrap/Pulumi.yaml +++ b/02-k8s-bootstrap/Pulumi.yaml @@ -8,3 +8,4 @@ config: pulumi:tags: value: pulumi:template: typescript +stackConfigDir: ../.pulumi-config/02-k8s-bootstrap \ No newline at end of file diff --git a/03-k8s-infra/Pulumi.yaml b/03-k8s-infra/Pulumi.yaml index 62386e8..1e93e87 100644 --- a/03-k8s-infra/Pulumi.yaml +++ b/03-k8s-infra/Pulumi.yaml @@ -4,3 +4,4 @@ runtime: name: nodejs options: packagemanager: npm +stackConfigDir: ../.pulumi-config/03-k8s-infra \ No newline at end of file diff --git a/04-k8s-apps/Pulumi.yaml b/04-k8s-apps/Pulumi.yaml index 960ab01..058af5b 100644 --- a/04-k8s-apps/Pulumi.yaml +++ b/04-k8s-apps/Pulumi.yaml @@ -4,3 +4,4 @@ runtime: name: nodejs options: packagemanager: npm +stackConfigDir: ../.pulumi-config/04-k8s-apps diff --git a/CLAUDE.md b/CLAUDE.md index c339a91..2866535 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -24,7 +24,9 @@ proxmox-infra → k8s-bootstrap → k8s-infra ## Shared conventions - **Secrets**: read via `config.requireSecret()`, never via environment variables or hardcoded values. -- **`Pulumi.dev.yaml`**: gitignored (contains the encryption salt). Never delete it or secrets become unrecoverable. CI restores it from a base64 Gitea secret `_PULUMI_DEV_YAML`; after changing local config, remind me to update that secret. +- **`Pulumi.dev.yaml`**: in `.pulumi-config//` (set by `stackConfigDir`). `.pulumi-config/` is a separate private repo, gitignored here and not a submodule, so this repo's `git status` doesn't show its changes; use `git -C .pulumi-config status`. These files contain the encryption salt: never delete them or secrets become unrecoverable, and never commit them to this repo. Any `0N-*/Pulumi.dev.yaml` is an unused old copy; don't edit it. +- **Config changes**: CI checks out the config repo's `main`, so a local preview can use config that CI doesn't have yet. After config changes, remind me to commit and push them there, before opening or updating a PR that needs them. That push doesn't start a deploy. The commit rule below applies to that repo too. Setup steps are in `.pulumi-config/README.md`. +- **Private repos**: don't write a private repo's name, owner/name path or URL in READMEs or other docs. Say "the private config repo", or use a placeholder. Naming it in workflows is fine, and so is the local folder name `.pulumi-config/`. - **Environment**: `PULUMI_BACKEND_URL` (self-hosted Postgres backend) and `PULUMI_CONFIG_PASSPHRASE` must be set. - **CI**: PRs run `pulumi preview`. `01` and `03`–`05` deploy on push to `main`; `02` deploys only via manual dispatch. Automatic `01` deploys skip `pulumi refresh`, so run its workflow manually after changing VMs in the Proxmox GUI. diff --git a/README.md b/README.md index f616d18..ddcd565 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,8 @@ export PULUMI_BACKEND_URL=postgresql://:@/ export PULUMI_CONFIG_PASSPHRASE= ``` +Clone your private config repo into `.pulumi-config/` (see [Stack config](#stack-config)). For an existing setup, use the config from that repo and skip the `stack init` and `config set` commands below. + Then for each stack, in order: ```bash @@ -133,26 +135,28 @@ To rebuild the whole cluster from new VMs, follow [the rebuild runbook](docs/run | Secret | Used by | | --- | --- | | `PULUMI_BACKEND_URL`, `PULUMI_CONFIG_PASSPHRASE` | all workflows | -| `PROXMOX_INFRA_PULUMI_DEV_YAML` | 01-deploy-proxmox-infra | -| `K8S_BOOTSTRAP_PULUMI_DEV_YAML` | 02-deploy-k8s-bootstrap | -| `K8S_INFRA_PULUMI_DEV_YAML` | 03-deploy-k8s-infra | -| `K8S_APPS_PULUMI_DEV_YAML` | 04-deploy-k8s-apps | -| `MONITORING_PULUMI_DEV_YAML` | 05-deploy-monitoring | +| `PULUMI_CONFIG_REPO_TOKEN` (`ci-bot` token with read-only access to the config repo) | all workflows | -Each `_PULUMI_DEV_YAML` secret is a base64-encoded copy of that stack's gitignored `Pulumi.dev.yaml`. After changing local config, re-encode and update the secret: +### Stack config -```bash -base64 -w 0 0N-/Pulumi.dev.yaml -``` +Each stack's encrypted `Pulumi.dev.yaml` is in a private repo, cloned into the gitignored `.pulumi-config/` folder. CI checks out its `main` branch. After changing config, commit and push it there. That push doesn't start a deploy. See that repo's README for setup and usage. + +CI reads the config repo as a separate user, so its token can't access your other private repos: + +1. As a Gitea admin, create a regular (non-admin) user named `ci-bot`. +2. In the config repo's settings, add `ci-bot` as a collaborator with **Read** access. Don't add it to any other private repo. +3. Sign in as `ci-bot` and create an access token with only the `read:repository` permission. +4. In this repo's Actions secrets, add the token as `PULUMI_CONFIG_REPO_TOKEN`. ## Using this as a template 1. Fork or copy the repo 2. Update Proxmox node names/datastores and the `nodeConfigs` array in `01-proxmox-infra/index.ts` for your VM topology 3. Set your own config/secrets per stack with `pulumi config set [--secret]` — see each stack's `CLAUDE.md` for the full list of required keys -4. Point the CI/CD workflows at your own Gitea/GitOps instance and update the secrets above +4. Create your own private config repo and a `ci-bot` user that can read it (see [Stack config](#stack-config)), then set the repo as `repository` in each workflow's `Checkout Stack Config` steps +5. Point the CI/CD workflows at your own Gitea/GitOps instance and update the secrets above ## Roadmap -- Migrate secrets management to [OpenBao](https://openbao.org/) — replace `PULUMI_CONFIG_PASSPHRASE` and manual `Pulumi.dev.yaml` encoding with a self-hosted vault +- Migrate secrets management to [OpenBao](https://openbao.org/) — replace `PULUMI_CONFIG_PASSPHRASE` and the encrypted config repo with a self-hosted vault - Add a third bare-metal Proxmox node for true 3-node HA parity diff --git a/docs/runbooks/full-cluster-rebuild.md b/docs/runbooks/full-cluster-rebuild.md index 108394e..fade9e1 100644 --- a/docs/runbooks/full-cluster-rebuild.md +++ b/docs/runbooks/full-cluster-rebuild.md @@ -31,7 +31,7 @@ Use this to rebuild the k3s cluster from new VMs. **It destroys everything store 5. **If you reinstalled any Proxmox host:** - Replace its CA in `02-k8s-bootstrap/certs/` (`pve1` is B550, `pve2` is Optiplex, `pve3` is Esprimo). Get it with `cat /etc/pve/pve-root-ca.pem`, and never copy anything from `/etc/pve/priv/`. - Check that the host's certificate lists its current IP. `/etc/hosts` must have that IP before the certificate is generated. - - Recreate the API token, then update the token and endpoint in `01-proxmox-infra` config. After changing local config, update the matching `_PULUMI_DEV_YAML` secret in Gitea. + - Recreate the API token, then update the token and endpoint in `01-proxmox-infra` config. Commit and push the change in `.pulumi-config` (see [Stack config](../../README.md#stack-config)), because CI uses the pushed version. - The VM template on that host is gone too, so expect step 1 to recreate it. ## 1. Recreate the VMs (`01-proxmox-infra`)