Compare commits
8
Commits
d1c7412f07
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6c71c3a3a | ||
|
|
6108d6dbf5 | ||
|
|
7586d8af31 | ||
|
|
063688746e | ||
|
|
86af2c6fcb | ||
|
|
2091607f0d | ||
|
|
d815334b04 | ||
|
|
4ae597cfc4 |
No files matched your search
+104
-9
@@ -26,6 +26,12 @@ const worker2Ip = config.requireSecret("worker2Ip");
|
|||||||
const worker3Ip = config.requireSecret("worker3Ip");
|
const worker3Ip = config.requireSecret("worker3Ip");
|
||||||
|
|
||||||
const ansibleIp = config.requireSecret("ansibleIp");
|
const ansibleIp = config.requireSecret("ansibleIp");
|
||||||
|
const runnerIp = config.requireSecret("runnerIp");
|
||||||
|
// Generated on the Ansible node and used only for the runner VM, so access to
|
||||||
|
// the runner (and the CI credentials on it) can be revoked on its own.
|
||||||
|
const runnerAnsibleSshPublicKey = config.requireSecret(
|
||||||
|
"runnerAnsibleSshPublicKey",
|
||||||
|
);
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// VM templates — one per node, cloned from the downloaded cloud image.
|
// VM templates — one per node, cloned from the downloaded cloud image.
|
||||||
@@ -332,21 +338,21 @@ k3sVms.forEach((vmResource, i) => {
|
|||||||
// boot; otherwise its first DHCP lease could come from the dynamic pool.
|
// boot; otherwise its first DHCP lease could come from the dynamic pool.
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
const ansibleHost = hostFor("pve-b550");
|
const proxmoHost = hostFor("pve-b550");
|
||||||
const ansibleMac = "02:A5:1B:00:01:54";
|
const ansibleMac = "02:A5:1B:00:01:54";
|
||||||
|
|
||||||
const ansibleTemplate = new proxmox.download.File(
|
const ubuntuTemplate = new proxmox.download.File(
|
||||||
"ubuntu-resolute-lxc-pve-b550",
|
"ubuntu-resolute-lxc-pve-b550",
|
||||||
{
|
{
|
||||||
nodeName: ansibleHost.nodeName,
|
nodeName: proxmoHost.nodeName,
|
||||||
datastoreId: ansibleHost.isoStore,
|
datastoreId: proxmoHost.isoStore,
|
||||||
contentType: "vztmpl",
|
contentType: "vztmpl",
|
||||||
fileName: "ubuntu-26.04-standard_26.04-1_amd64.tar.zst",
|
fileName: "ubuntu-26.04-standard_26.04-1_amd64.tar.zst",
|
||||||
url: "https://download.proxmox.com/images/system/ubuntu-26.04-standard_26.04-1_amd64.tar.zst",
|
url: "https://download.proxmox.com/images/system/ubuntu-26.04-standard_26.04-1_amd64.tar.zst",
|
||||||
overwrite: false,
|
overwrite: false,
|
||||||
overwriteUnmanaged: true,
|
overwriteUnmanaged: true,
|
||||||
},
|
},
|
||||||
{ provider: ansibleHost.provider },
|
{ provider: proxmoHost.provider },
|
||||||
);
|
);
|
||||||
|
|
||||||
const ansibleDhcp = new pfsense.Dhcpv4Staticmapping(
|
const ansibleDhcp = new pfsense.Dhcpv4Staticmapping(
|
||||||
@@ -363,18 +369,18 @@ const ansibleDhcp = new pfsense.Dhcpv4Staticmapping(
|
|||||||
new proxmox.ContainerLegacy( // NOSONAR typescript:S1848
|
new proxmox.ContainerLegacy( // NOSONAR typescript:S1848
|
||||||
"ansible",
|
"ansible",
|
||||||
{
|
{
|
||||||
nodeName: ansibleHost.nodeName,
|
nodeName: proxmoHost.nodeName,
|
||||||
description: "Ansible control node — managed by Pulumi",
|
description: "Ansible control node — managed by Pulumi",
|
||||||
tags: ["ansible"],
|
tags: ["ansible"],
|
||||||
unprivileged: true,
|
unprivileged: true,
|
||||||
features: { nesting: true },
|
features: { nesting: true },
|
||||||
operatingSystem: {
|
operatingSystem: {
|
||||||
templateFileId: ansibleTemplate.id,
|
templateFileId: ubuntuTemplate.id,
|
||||||
type: "ubuntu",
|
type: "ubuntu",
|
||||||
},
|
},
|
||||||
cpu: { cores: 1 },
|
cpu: { cores: 1 },
|
||||||
memory: { dedicated: 1024, swap: 0 },
|
memory: { dedicated: 1024, swap: 0 },
|
||||||
disk: { datastoreId: ansibleHost.dataStore, size: 8 },
|
disk: { datastoreId: proxmoHost.dataStore, size: 8 },
|
||||||
networkInterfaces: [
|
networkInterfaces: [
|
||||||
{ name: "eth0", bridge: "vmbr0", macAddress: ansibleMac },
|
{ name: "eth0", bridge: "vmbr0", macAddress: ansibleMac },
|
||||||
],
|
],
|
||||||
@@ -394,13 +400,102 @@ new proxmox.ContainerLegacy( // NOSONAR typescript:S1848
|
|||||||
protection: true,
|
protection: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provider: ansibleHost.provider,
|
provider: proxmoHost.provider,
|
||||||
dependsOn: ansibleDhcp,
|
dependsOn: ansibleDhcp,
|
||||||
retainOnDelete: true,
|
retainOnDelete: true,
|
||||||
protect: true,
|
protect: true,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Gitea Runner — VM with a pfSense DHCP reservation.
|
||||||
|
// A VM rather than an LXC: jobs run in Docker, and Docker in an LXC needs
|
||||||
|
// nesting + keyctl, which widens the shared-kernel attack surface towards the
|
||||||
|
// Proxmox host. The runner holds the most powerful credentials (Proxmox,
|
||||||
|
// pfSense, Pulumi), so it gets its own kernel. Fixed MAC for the same reason
|
||||||
|
// as the Ansible node: the reservation exists before the first boot.
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const runnerMac = "02:A5:1B:00:01:55";
|
||||||
|
|
||||||
|
const runnerDhcp = new pfsense.Dhcpv4Staticmapping(
|
||||||
|
"runner-dhcp",
|
||||||
|
{
|
||||||
|
interface: "lan",
|
||||||
|
macAddress: runnerMac,
|
||||||
|
ipAddress: runnerIp,
|
||||||
|
hostname: "runner",
|
||||||
|
},
|
||||||
|
{ provider: pfSenseProvider, protect: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
new proxmox.VmLegacy( // NOSONAR typescript:S1848
|
||||||
|
"runner",
|
||||||
|
{
|
||||||
|
nodeName: proxmoHost.nodeName,
|
||||||
|
name: "runner",
|
||||||
|
description: "Gitea Runner — managed by Pulumi",
|
||||||
|
tags: ["runner"],
|
||||||
|
clone: {
|
||||||
|
vmId: proxmoHost.pveTemplate.vmId,
|
||||||
|
full: true,
|
||||||
|
datastoreId: proxmoHost.dataStore,
|
||||||
|
},
|
||||||
|
cpu: {
|
||||||
|
cores: 2,
|
||||||
|
sockets: 1,
|
||||||
|
type: "host",
|
||||||
|
numa: true,
|
||||||
|
},
|
||||||
|
memory: {
|
||||||
|
dedicated: 4096,
|
||||||
|
floating: 0,
|
||||||
|
},
|
||||||
|
disks: [
|
||||||
|
{
|
||||||
|
interface: "scsi0",
|
||||||
|
datastoreId: proxmoHost.dataStore,
|
||||||
|
size: 20,
|
||||||
|
ssd: true,
|
||||||
|
discard: "on",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
initialization: {
|
||||||
|
datastoreId: proxmoHost.dataStore,
|
||||||
|
ipConfigs: [{ ipv4: { address: "dhcp" } }],
|
||||||
|
// Key-only login: no password, unlike the k3s nodes.
|
||||||
|
userAccount: {
|
||||||
|
username: "ubuntu",
|
||||||
|
keys: [
|
||||||
|
pve1SshPublicKey.apply((k) => k.trim()),
|
||||||
|
pve2SshPublicKey.apply((k) => k.trim()),
|
||||||
|
pve3SshPublicKey.apply((k) => k.trim()),
|
||||||
|
runnerAnsibleSshPublicKey.apply((k) => k.trim()),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
networkDevices: [
|
||||||
|
{ bridge: "vmbr0", model: "virtio", macAddress: runnerMac },
|
||||||
|
],
|
||||||
|
scsiHardware: "virtio-scsi-pci",
|
||||||
|
serialDevices: [{}],
|
||||||
|
vga: { type: "serial0" },
|
||||||
|
agent: { enabled: true, timeout: "30s" },
|
||||||
|
cdrom: { fileId: "none" },
|
||||||
|
started: true,
|
||||||
|
onBoot: true,
|
||||||
|
protection: true,
|
||||||
|
rebootAfterUpdate: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provider: proxmoHost.provider,
|
||||||
|
dependsOn: runnerDhcp,
|
||||||
|
retainOnDelete: true,
|
||||||
|
protect: true,
|
||||||
|
ignoreChanges: ["clone", "disks[0].speed"],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
export const vmIds = {
|
export const vmIds = {
|
||||||
master1: k3sVms[0].vmId,
|
master1: k3sVms[0].vmId,
|
||||||
master2: k3sVms[1].vmId,
|
master2: k3sVms[1].vmId,
|
||||||
|
|||||||
@@ -74,11 +74,10 @@ function k3sInstallScript(
|
|||||||
return pulumi.interpolate`set -euo pipefail; IFS= read -r K3S_TOKEN || true; export K3S_TOKEN; curl -sfL ${k3sInstallerUrl} | sudo --preserve-env=K3S_TOKEN INSTALL_K3S_VERSION='${k3sVersion}' ${installEnv} sh -s - ${installArgs}`;
|
return pulumi.interpolate`set -euo pipefail; IFS= read -r K3S_TOKEN || true; export K3S_TOKEN; curl -sfL ${k3sInstallerUrl} | sudo --preserve-env=K3S_TOKEN INSTALL_K3S_VERSION='${k3sVersion}' ${installEnv} sh -s - ${installArgs}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Control-plane VIP — floating IP for API server access, ARP-announced by
|
// Kubernetes API address (port 6443), used by kubectl, Pulumi and joining nodes.
|
||||||
// kube-vip on whichever master is alive. Added as a TLS SAN on master-1's
|
// pfSense holds this IP, and HAProxy forwards connections to the masters, so
|
||||||
// cert below, then used (instead of master1Ip) for every other node's join
|
// the API doesn't depend on a single master.
|
||||||
// URL and for the exported kubeconfig, so the cluster stays reachable
|
// This isn't kubeVipAddress in 03-k8s-infra, which is Traefik's IP for web apps.
|
||||||
// through the loss of any single master.
|
|
||||||
const controlPlaneVipAddress = config.requireSecret("controlPlaneVipAddress");
|
const controlPlaneVipAddress = config.requireSecret("controlPlaneVipAddress");
|
||||||
|
|
||||||
// VM IDs and CI runner SSH key — read from proxmox-infra stack outputs
|
// VM IDs and CI runner SSH key — read from proxmox-infra stack outputs
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ const truenasNfsPath = config.requireSecret("truenasNfsPath");
|
|||||||
const cloudflareToken = config.requireSecret("cloudflareApiToken");
|
const cloudflareToken = config.requireSecret("cloudflareApiToken");
|
||||||
const letsencryptEmail = config.requireSecret("letsencryptEmail");
|
const letsencryptEmail = config.requireSecret("letsencryptEmail");
|
||||||
|
|
||||||
|
// Traefik's IP for web apps (ports 80 and 443). kube-vip announces it on the
|
||||||
|
// LAN, and the app domains in pfSense's DNS Resolver must point to it.
|
||||||
|
// This isn't the Kubernetes API address. That's controlPlaneVipAddress in
|
||||||
|
// 02-k8s-bootstrap, which is provided by pfSense and HAProxy.
|
||||||
const kubeVipAddress = config.requireSecret("kubeVipAddress");
|
const kubeVipAddress = config.requireSecret("kubeVipAddress");
|
||||||
const kubeVipInterface = config.require("kubeVipInterface");
|
const kubeVipInterface = config.require("kubeVipInterface");
|
||||||
|
|
||||||
@@ -547,6 +551,7 @@ const kubeVipCloudProvider = new k8s.apps.v1.Deployment(
|
|||||||
opts({ dependsOn: [cloudProviderClusterRoleBinding, kubeVipPool] }),
|
opts({ dependsOn: [cloudProviderClusterRoleBinding, kubeVipPool] }),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Assigns kubeVipAddress to the Traefik Service that k3s creates.
|
||||||
new k8s.core.v1.ServicePatch(
|
new k8s.core.v1.ServicePatch(
|
||||||
"traefik-vip",
|
"traefik-vip",
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ pulumi up --yes
|
|||||||
|
|
||||||
Stack-specific notes:
|
Stack-specific notes:
|
||||||
|
|
||||||
1. **proxmox-infra** — set Proxmox API tokens, pfSense credentials, VM credentials/SSH public key, and a static IP per node.
|
1. **proxmox-infra** — set Proxmox API tokens, pfSense credentials, VM credentials/SSH public key, and a static IP per node. The CI runner VM needs `runnerIp` and `runnerAnsibleSshPublicKey`, see [the runbook](docs/runbooks/ci-runner-vm.md).
|
||||||
2. **k8s-bootstrap** — set `k3sToken` (e.g. `openssl rand -hex 32`) and `controlPlaneVipAddress` (secret; a free IP outside the DHCP pool, fronted by pfSense + HAProxy, see [the runbook](docs/runbooks/pfsense-control-plane-vip.md)). Node IPs, Proxmox credentials and the SSH key come automatically from `proxmox-infra`.
|
2. **k8s-bootstrap** — set `k3sToken` (e.g. `openssl rand -hex 32`) and `controlPlaneVipAddress` (secret; a free IP outside the DHCP pool, fronted by pfSense + HAProxy, see [the runbook](docs/runbooks/pfsense-control-plane-vip.md)). Node IPs, Proxmox credentials and the SSH key come automatically from `proxmox-infra`.
|
||||||
3. **k8s-infra** — before deploying, create an NFS dataset/share on TrueNAS (POSIX ACLs, `root`/`root` maproot, restricted to your k3s nodes). Set `truenasHost`, `truenasNfsPath`, `cloudflareApiToken`, `letsencryptEmail`, `kubeVipAddress` (all secrets) and `kubeVipInterface`.
|
3. **k8s-infra** — before deploying, create an NFS dataset/share on TrueNAS (POSIX ACLs, `root`/`root` maproot, restricted to your k3s nodes). Set `truenasHost`, `truenasNfsPath`, `cloudflareApiToken`, `letsencryptEmail`, `kubeVipAddress` (all secrets) and `kubeVipInterface`.
|
||||||
4. **k8s-apps** — set `domain`, the base domain used for ingress hostnames.
|
4. **k8s-apps** — set `domain`, the base domain used for ingress hostnames.
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# 0002: CI runner on a dedicated VM with Docker job containers
|
||||||
|
|
||||||
|
Status: accepted (December 2026)
|
||||||
|
|
||||||
|
## Context
|
||||||
|
|
||||||
|
The Gitea runner ran as a container on the shared Docker host, next to Gitea and Postgres, with the Docker socket mounted. A job that reached the socket had root on that host. Jobs in this repo also hold the most powerful credentials in the homelab: the Proxmox API tokens, pfSense access and the Pulumi passphrase.
|
||||||
|
|
||||||
|
## Decision
|
||||||
|
|
||||||
|
The runner runs on its own VM (`runner`, defined in `01-proxmox-infra`), outside the k3s cluster:
|
||||||
|
|
||||||
|
- act_runner runs as a systemd service, installed and configured by Ansible.
|
||||||
|
- Each job runs in a fresh Docker container that is removed afterwards. Job containers don't get the Docker socket (`container.docker_host: "-"`), and `capacity: 1`.
|
||||||
|
- The registration token is entered by hand at registration time and isn't stored anywhere.
|
||||||
|
- SSH is key-only. Ansible uses a key that exists only for this VM.
|
||||||
|
|
||||||
|
## Alternatives considered
|
||||||
|
|
||||||
|
- **Unprivileged LXC with Docker:** Docker in an LXC needs `nesting` and `keyctl`, which widens the shared-kernel attack surface towards the Proxmox host. Proxmox itself recommends running Docker in a VM. For the host holding the strongest credentials, a separate kernel is worth the extra RAM.
|
||||||
|
- **Host mode (no Docker):** jobs would leave files and tools behind for the next job and could read the runner's own credential (`.runner`). The security gain is small, because deploy secrets are in the job environment in either mode.
|
||||||
|
- **Runner pods in k3s:** `01` and `02` create and repair the cluster, so the runner can't depend on it. Gitea also has no mature per-job pod autoscaler.
|
||||||
|
|
||||||
|
## Consequences
|
||||||
|
|
||||||
|
- When everything is down, recovery doesn't go through CI. You run `pulumi up` from the workstation instead.
|
||||||
|
- Deploy secrets are still readable by any job. The real protection is scoping the credentials and filtering the runner's outbound traffic, both tracked separately.
|
||||||
|
- Access to the runner VM is as sensitive as the CI credentials themselves. That includes the Ansible node, through its dedicated key.
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
# CI runner VM: first-time setup
|
||||||
|
|
||||||
|
The `runner` VM is defined in `01-proxmox-infra`. For the design, see [decision 0002](../decisions/0002-ci-runner-on-a-vm.md). Do this once, before the first deploy that creates the VM.
|
||||||
|
|
||||||
|
1. On the Ansible node, create a key that is used only for the runner VM:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ssh-keygen -t ed25519 -f ~/.ssh/runner_vm -C ansible-runner-vm
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Set the config from the repo root, then commit and push it in the private config repo:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd 01-proxmox-infra
|
||||||
|
pulumi config set --secret runnerIp <free IP outside the DHCP pool>
|
||||||
|
pulumi config set --secret runnerAnsibleSshPublicKey "$(cat runner_vm.pub)" # copy of ~/.ssh/runner_vm.pub from the Ansible node
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Deploy `01-proxmox-infra`. Pulumi creates the pfSense DHCP reservation and the VM.
|
||||||
|
|
||||||
|
4. Check that the Ansible node can log in: `ssh -i ~/.ssh/runner_vm ubuntu@<runnerIp>`.
|
||||||
|
|
||||||
|
5. Install and register act_runner with the runner playbook in the Ansible repo. The playbook asks for a registration token: create one in Gitea, then reset it right after registering.
|
||||||
|
|
||||||
|
## Revoke access
|
||||||
|
|
||||||
|
To lock the Ansible node out of the runner VM, remove its key from `~ubuntu/.ssh/authorized_keys` on the VM. Changing the config alone isn't enough, because cloud-init only applies keys on the first boot.
|
||||||
Reference in new issue
Block a user