Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b37e3451b | ||
|
|
3c07c5d3b3 | ||
|
|
73a03134d3 | ||
|
|
2327e42cdd | ||
|
|
031ab44f71 | ||
|
|
f6c71c3a3a | ||
|
|
6108d6dbf5 | ||
|
|
7586d8af31 | ||
|
|
063688746e | ||
|
|
2091607f0d | ||
|
|
d815334b04 | ||
|
|
4ae597cfc4 |
No files matched your search
+144
-71
@@ -26,36 +26,21 @@ 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");
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
const pve1SshPublicKey = config.requireSecret("pve1SshPublicKey");
|
||||||
// VM templates — one per node, cloned from the downloaded cloud image.
|
const pve2SshPublicKey = config.requireSecret("pve2SshPublicKey");
|
||||||
// Templates are not started and have no cloud-init config; that is applied
|
const pve3SshPublicKey = config.requireSecret("pve3SshPublicKey");
|
||||||
// per-clone so each node gets its own hostname (derived from VM name).
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
const templateSettings = {
|
const pvePublicKeys: pulumi.Output<string>[] = [
|
||||||
template: true,
|
pve1SshPublicKey.apply((k) => k.trim()),
|
||||||
protection: true,
|
pve2SshPublicKey.apply((k) => k.trim()),
|
||||||
started: false,
|
pve3SshPublicKey.apply((k) => k.trim()),
|
||||||
operatingSystem: { type: "l26" },
|
];
|
||||||
stopOnDestroy: true,
|
|
||||||
scsiHardware: "virtio-scsi-pci",
|
const runnerAnsibleSshPublicKey = config.requireSecret(
|
||||||
cdrom: { fileId: "none" },
|
"runnerAnsibleSshPublicKey",
|
||||||
cpu: {
|
);
|
||||||
cores: 2,
|
|
||||||
sockets: 1,
|
|
||||||
type: "host",
|
|
||||||
numa: true,
|
|
||||||
},
|
|
||||||
memory: {
|
|
||||||
dedicated: 2048,
|
|
||||||
floating: 0,
|
|
||||||
},
|
|
||||||
networkDevices: [{ bridge: "vmbr0", model: "virtio" }],
|
|
||||||
serialDevices: [{}],
|
|
||||||
vga: { type: "serial0" },
|
|
||||||
agent: { enabled: true, timeout: "30s" },
|
|
||||||
};
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Providers — one per standalone Proxmox machine
|
// Providers — one per standalone Proxmox machine
|
||||||
@@ -127,7 +112,27 @@ const pveNodes = pveNodeSeeds
|
|||||||
pveTemplate: new proxmox.VmLegacy(
|
pveTemplate: new proxmox.VmLegacy(
|
||||||
`k3s-template-${n.hostLabel}`,
|
`k3s-template-${n.hostLabel}`,
|
||||||
{
|
{
|
||||||
...templateSettings,
|
template: true,
|
||||||
|
protection: true,
|
||||||
|
started: false,
|
||||||
|
operatingSystem: { type: "l26" },
|
||||||
|
stopOnDestroy: true,
|
||||||
|
scsiHardware: "virtio-scsi-pci",
|
||||||
|
cdrom: { fileId: "none" },
|
||||||
|
cpu: {
|
||||||
|
cores: 2,
|
||||||
|
sockets: 1,
|
||||||
|
type: "host",
|
||||||
|
numa: true,
|
||||||
|
},
|
||||||
|
memory: {
|
||||||
|
dedicated: 2048,
|
||||||
|
floating: 0,
|
||||||
|
},
|
||||||
|
networkDevices: [{ bridge: "vmbr0", model: "virtio" }],
|
||||||
|
serialDevices: [{}],
|
||||||
|
vga: { type: "serial0" },
|
||||||
|
agent: { enabled: true, timeout: "30s" },
|
||||||
nodeName: n.nodeName,
|
nodeName: n.nodeName,
|
||||||
name: "k3s-ubuntu-noble-template",
|
name: "k3s-ubuntu-noble-template",
|
||||||
disks: [
|
disks: [
|
||||||
@@ -170,10 +175,6 @@ const ciRunnerKey = new tls.PrivateKey("ci-runner-key", {
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
const k3sVmPassword = config.requireSecret("k3sVmPassword");
|
const k3sVmPassword = config.requireSecret("k3sVmPassword");
|
||||||
const pve1SshPublicKey = config.requireSecret("pve1SshPublicKey");
|
|
||||||
const pve2SshPublicKey = config.requireSecret("pve2SshPublicKey");
|
|
||||||
const pve3SshPublicKey = config.requireSecret("pve3SshPublicKey");
|
|
||||||
|
|
||||||
interface NodeConfig {
|
interface NodeConfig {
|
||||||
name: string;
|
name: string;
|
||||||
role: "master" | "worker";
|
role: "master" | "worker";
|
||||||
@@ -277,9 +278,7 @@ const k3sVms = nodeConfigs.map(
|
|||||||
username: "ubuntu",
|
username: "ubuntu",
|
||||||
password: k3sVmPassword,
|
password: k3sVmPassword,
|
||||||
keys: [
|
keys: [
|
||||||
pve1SshPublicKey.apply((k) => k.trim()),
|
...pvePublicKeys,
|
||||||
pve2SshPublicKey.apply((k) => k.trim()),
|
|
||||||
pve3SshPublicKey.apply((k) => k.trim()),
|
|
||||||
ciRunnerKey.publicKeyOpenssh.apply((k) => k.trim()),
|
ciRunnerKey.publicKeyOpenssh.apply((k) => k.trim()),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -309,21 +308,25 @@ const k3sVms = nodeConfigs.map(
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function staticDhcp(
|
||||||
|
iface: pfsense.Dhcpv4StaticmappingArgs["interface"],
|
||||||
|
hostname: string,
|
||||||
|
macAddress: pfsense.Dhcpv4StaticmappingArgs["macAddress"],
|
||||||
|
ipAddress: pfsense.Dhcpv4StaticmappingArgs["ipAddress"],
|
||||||
|
dependsOn?: pulumi.Resource,
|
||||||
|
): pfsense.Dhcpv4Staticmapping {
|
||||||
|
return new pfsense.Dhcpv4Staticmapping(
|
||||||
|
`${hostname}-dhcp`,
|
||||||
|
{ interface: iface, macAddress, ipAddress, hostname },
|
||||||
|
{ dependsOn, provider: pfSenseProvider, protect: true },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
k3sVms.forEach((vmResource, i) => {
|
k3sVms.forEach((vmResource, i) => {
|
||||||
const assignedMac = vmResource.networkDevices.apply(
|
const assignedMac = vmResource.networkDevices.apply(
|
||||||
(nic) => nic[0].macAddress,
|
(nic) => nic[0].macAddress,
|
||||||
);
|
);
|
||||||
|
staticDhcp("lan", nodeConfigs[i].name, assignedMac, nodeConfigs[i].ip, vmResource);
|
||||||
new pfsense.Dhcpv4Staticmapping(
|
|
||||||
`${nodeConfigs[i].name}-dhcp`,
|
|
||||||
{
|
|
||||||
interface: "lan",
|
|
||||||
macAddress: assignedMac,
|
|
||||||
ipAddress: nodeConfigs[i].ip,
|
|
||||||
hostname: nodeConfigs[i].name,
|
|
||||||
},
|
|
||||||
{ dependsOn: vmResource, provider: pfSenseProvider, protect: true },
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -332,49 +335,40 @@ 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 proxmoxHost = 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: proxmoxHost.nodeName,
|
||||||
datastoreId: ansibleHost.isoStore,
|
datastoreId: proxmoxHost.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: proxmoxHost.provider },
|
||||||
);
|
);
|
||||||
|
|
||||||
const ansibleDhcp = new pfsense.Dhcpv4Staticmapping(
|
const ansibleDhcp = staticDhcp("lan", "ansible", ansibleMac, ansibleIp);
|
||||||
"ansible-dhcp",
|
|
||||||
{
|
|
||||||
interface: "lan",
|
|
||||||
macAddress: ansibleMac,
|
|
||||||
ipAddress: ansibleIp,
|
|
||||||
hostname: "ansible",
|
|
||||||
},
|
|
||||||
{ provider: pfSenseProvider, protect: true },
|
|
||||||
);
|
|
||||||
|
|
||||||
new proxmox.ContainerLegacy( // NOSONAR typescript:S1848
|
new proxmox.ContainerLegacy( // NOSONAR typescript:S1848
|
||||||
"ansible",
|
"ansible",
|
||||||
{
|
{
|
||||||
nodeName: ansibleHost.nodeName,
|
nodeName: proxmoxHost.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: proxmoxHost.dataStore, size: 8 },
|
||||||
networkInterfaces: [
|
networkInterfaces: [
|
||||||
{ name: "eth0", bridge: "vmbr0", macAddress: ansibleMac },
|
{ name: "eth0", bridge: "vmbr0", macAddress: ansibleMac },
|
||||||
],
|
],
|
||||||
@@ -382,11 +376,7 @@ new proxmox.ContainerLegacy( // NOSONAR typescript:S1848
|
|||||||
hostname: "ansible",
|
hostname: "ansible",
|
||||||
ipConfigs: [{ ipv4: { address: "dhcp" } }],
|
ipConfigs: [{ ipv4: { address: "dhcp" } }],
|
||||||
userAccount: {
|
userAccount: {
|
||||||
keys: [
|
keys: [...pvePublicKeys],
|
||||||
pve1SshPublicKey.apply((k) => k.trim()),
|
|
||||||
pve2SshPublicKey.apply((k) => k.trim()),
|
|
||||||
pve3SshPublicKey.apply((k) => k.trim()),
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
started: true,
|
started: true,
|
||||||
@@ -394,13 +384,91 @@ new proxmox.ContainerLegacy( // NOSONAR typescript:S1848
|
|||||||
protection: true,
|
protection: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provider: ansibleHost.provider,
|
provider: proxmoxHost.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 = staticDhcp("lan", "runner", runnerMac, runnerIp);
|
||||||
|
|
||||||
|
new proxmox.VmLegacy( // NOSONAR typescript:S1848
|
||||||
|
"runner",
|
||||||
|
{
|
||||||
|
nodeName: proxmoxHost.nodeName,
|
||||||
|
name: "runner",
|
||||||
|
description: "Gitea Runner — managed by Pulumi",
|
||||||
|
tags: ["runner"],
|
||||||
|
clone: {
|
||||||
|
vmId: proxmoxHost.pveTemplate.vmId,
|
||||||
|
full: true,
|
||||||
|
datastoreId: proxmoxHost.dataStore,
|
||||||
|
},
|
||||||
|
cpu: {
|
||||||
|
cores: 2,
|
||||||
|
sockets: 1,
|
||||||
|
type: "host",
|
||||||
|
numa: true,
|
||||||
|
},
|
||||||
|
memory: {
|
||||||
|
dedicated: 4096,
|
||||||
|
floating: 0,
|
||||||
|
},
|
||||||
|
disks: [
|
||||||
|
{
|
||||||
|
interface: "scsi0",
|
||||||
|
datastoreId: proxmoxHost.dataStore,
|
||||||
|
size: 20,
|
||||||
|
ssd: true,
|
||||||
|
discard: "on",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
initialization: {
|
||||||
|
datastoreId: proxmoxHost.dataStore,
|
||||||
|
ipConfigs: [{ ipv4: { address: "dhcp" } }],
|
||||||
|
// Key-only login: no password, unlike the k3s nodes.
|
||||||
|
userAccount: {
|
||||||
|
username: "ubuntu",
|
||||||
|
keys: [
|
||||||
|
...pvePublicKeys,
|
||||||
|
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: proxmoxHost.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,
|
||||||
@@ -413,6 +481,11 @@ export const vmIds = {
|
|||||||
// CI runner SSH private key — consumed by k8s-bootstrap via StackReference.
|
// CI runner SSH private key — consumed by k8s-bootstrap via StackReference.
|
||||||
export const ciRunnerPrivateKey = pulumi.secret(ciRunnerKey.privateKeyOpenssh);
|
export const ciRunnerPrivateKey = pulumi.secret(ciRunnerKey.privateKeyOpenssh);
|
||||||
|
|
||||||
|
// Public half, so k8s-bootstrap can remove it from the nodes after bootstrap.
|
||||||
|
export const ciRunnerPublicKey = ciRunnerKey.publicKeyOpenssh.apply((k) =>
|
||||||
|
k.trim(),
|
||||||
|
);
|
||||||
|
|
||||||
export {
|
export {
|
||||||
pve1Endpoint,
|
pve1Endpoint,
|
||||||
pve1ApiToken,
|
pve1ApiToken,
|
||||||
|
|||||||
+176
-144
@@ -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
|
||||||
@@ -88,6 +87,9 @@ const vmIdsOutput = infraRef.requireOutput("vmIds") as pulumi.Output<
|
|||||||
const ciRunnerPrivateKey = infraRef.requireOutput(
|
const ciRunnerPrivateKey = infraRef.requireOutput(
|
||||||
"ciRunnerPrivateKey",
|
"ciRunnerPrivateKey",
|
||||||
) as pulumi.Output<string>;
|
) as pulumi.Output<string>;
|
||||||
|
const ciRunnerPublicKey = infraRef.requireOutput(
|
||||||
|
"ciRunnerPublicKey",
|
||||||
|
) as pulumi.Output<string>;
|
||||||
|
|
||||||
const master1VmId = vmIdsOutput.apply((ids) => String(ids.master1));
|
const master1VmId = vmIdsOutput.apply((ids) => String(ids.master1));
|
||||||
const master2VmId = vmIdsOutput.apply((ids) => String(ids.master2));
|
const master2VmId = vmIdsOutput.apply((ids) => String(ids.master2));
|
||||||
@@ -121,42 +123,56 @@ function startVmScript(
|
|||||||
' "$PVE_API_TOKEN"; }; is_running() { auth | curl -sf -K - --cacert "$ca" "$base/current" | grep -Eq '"status" *: *"running"'; }; is_running && exit 0; auth | curl -sf -K - --cacert "$ca" -X POST "$base/start" >/dev/null || exit 1; for i in $(seq 1 30); do is_running && exit 0; sleep 2; done; exit 1`;
|
' "$PVE_API_TOKEN"; }; is_running() { auth | curl -sf -K - --cacert "$ca" "$base/current" | grep -Eq '"status" *: *"running"'; }; is_running && exit 0; auth | curl -sf -K - --cacert "$ca" -X POST "$base/start" >/dev/null || exit 1; for i in $(seq 1 30); do is_running && exit 0; sleep 2; done; exit 1`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const startMaster1 = new command.local.Command("start-master-1", {
|
function startVm(
|
||||||
create: startVmScript(pve1Endpoint, "pve1", "pve", master1VmId),
|
name: string,
|
||||||
environment: { PVE_API_TOKEN: pve1ApiToken },
|
create: pulumi.Input<string>,
|
||||||
triggers: [master1VmId],
|
apiToken: pulumi.Input<string>,
|
||||||
interpreter: ["/bin/bash", "-c"],
|
vmId: pulumi.Input<string>,
|
||||||
});
|
): command.local.Command {
|
||||||
const startMaster2 = new command.local.Command("start-master-2", {
|
return new command.local.Command(name, {
|
||||||
create: startVmScript(pve3Endpoint, "pve3", "pve", master2VmId),
|
create,
|
||||||
environment: { PVE_API_TOKEN: pve3ApiToken },
|
environment: { PVE_API_TOKEN: apiToken },
|
||||||
triggers: [master2VmId],
|
triggers: [vmId],
|
||||||
interpreter: ["/bin/bash", "-c"],
|
|
||||||
});
|
|
||||||
const startWorker1 = new command.local.Command("start-worker-1", {
|
|
||||||
create: startVmScript(pve1Endpoint, "pve1", "pve", worker1VmId),
|
|
||||||
environment: { PVE_API_TOKEN: pve1ApiToken },
|
|
||||||
triggers: [worker1VmId],
|
|
||||||
interpreter: ["/bin/bash", "-c"],
|
|
||||||
});
|
|
||||||
const startMaster3 = new command.local.Command("start-master-3", {
|
|
||||||
create: startVmScript(pve2Endpoint, "pve2", "pve-bckp", master3VmId),
|
|
||||||
environment: { PVE_API_TOKEN: pve2ApiToken },
|
|
||||||
triggers: [master3VmId],
|
|
||||||
interpreter: ["/bin/bash", "-c"],
|
|
||||||
});
|
|
||||||
const startWorker2 = new command.local.Command("start-worker-2", {
|
|
||||||
create: startVmScript(pve2Endpoint, "pve2", "pve-bckp", worker2VmId),
|
|
||||||
environment: { PVE_API_TOKEN: pve2ApiToken },
|
|
||||||
triggers: [worker2VmId],
|
|
||||||
interpreter: ["/bin/bash", "-c"],
|
|
||||||
});
|
|
||||||
const startWorker3 = new command.local.Command("start-worker-3", {
|
|
||||||
create: startVmScript(pve3Endpoint, "pve3", "pve", worker3VmId),
|
|
||||||
environment: { PVE_API_TOKEN: pve3ApiToken },
|
|
||||||
triggers: [worker3VmId],
|
|
||||||
interpreter: ["/bin/bash", "-c"],
|
interpreter: ["/bin/bash", "-c"],
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const startMaster1 = startVm(
|
||||||
|
"start-master-1",
|
||||||
|
startVmScript(pve1Endpoint, "pve1", "pve", master1VmId),
|
||||||
|
pve1ApiToken,
|
||||||
|
master1VmId,
|
||||||
|
);
|
||||||
|
const startMaster2 = startVm(
|
||||||
|
"start-master-2",
|
||||||
|
startVmScript(pve3Endpoint, "pve3", "pve", master2VmId),
|
||||||
|
pve3ApiToken,
|
||||||
|
master2VmId,
|
||||||
|
);
|
||||||
|
const startWorker1 = startVm(
|
||||||
|
"start-worker-1",
|
||||||
|
startVmScript(pve1Endpoint, "pve1", "pve", worker1VmId),
|
||||||
|
pve1ApiToken,
|
||||||
|
worker1VmId,
|
||||||
|
);
|
||||||
|
const startMaster3 = startVm(
|
||||||
|
"start-master-3",
|
||||||
|
startVmScript(pve2Endpoint, "pve2", "pve-bckp", master3VmId),
|
||||||
|
pve2ApiToken,
|
||||||
|
master3VmId,
|
||||||
|
);
|
||||||
|
const startWorker2 = startVm(
|
||||||
|
"start-worker-2",
|
||||||
|
startVmScript(pve2Endpoint, "pve2", "pve-bckp", worker2VmId),
|
||||||
|
pve2ApiToken,
|
||||||
|
worker2VmId,
|
||||||
|
);
|
||||||
|
const startWorker3 = startVm(
|
||||||
|
"start-worker-3",
|
||||||
|
startVmScript(pve3Endpoint, "pve3", "pve", worker3VmId),
|
||||||
|
pve3ApiToken,
|
||||||
|
worker3VmId,
|
||||||
|
);
|
||||||
|
|
||||||
const allStarts = [
|
const allStarts = [
|
||||||
startMaster1,
|
startMaster1,
|
||||||
@@ -171,14 +187,29 @@ const allStarts = [
|
|||||||
// Step 2: Wait for SSH on master-1, install k3s
|
// Step 2: Wait for SSH on master-1, install k3s
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
const waitMaster1Ssh = new command.local.Command(
|
// Succeeds once port 22 answers, polling every 5 s for up to 5 min.
|
||||||
"wait-ssh-master-1",
|
function waitSsh(
|
||||||
|
name: string,
|
||||||
|
ip: pulumi.Input<string>,
|
||||||
|
vmId: pulumi.Input<string>,
|
||||||
|
dependsOn: pulumi.ResourceOptions["dependsOn"],
|
||||||
|
): command.local.Command {
|
||||||
|
return new command.local.Command(
|
||||||
|
name,
|
||||||
{
|
{
|
||||||
create: pulumi.interpolate`for i in $(seq 1 60); do (timeout 5 bash -c "echo > /dev/tcp/${master1Ip}/22") 2>/dev/null && exit 0; sleep 5; done; exit 1`,
|
create: pulumi.interpolate`for i in $(seq 1 60); do (timeout 5 bash -c "echo > /dev/tcp/${ip}/22") 2>/dev/null && exit 0; sleep 5; done; exit 1`,
|
||||||
triggers: [master1VmId],
|
triggers: [vmId],
|
||||||
interpreter: ["/bin/bash", "-c"],
|
interpreter: ["/bin/bash", "-c"],
|
||||||
},
|
},
|
||||||
{ dependsOn: allStarts },
|
{ dependsOn },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const waitMaster1Ssh = waitSsh(
|
||||||
|
"wait-ssh-master-1",
|
||||||
|
master1Ip,
|
||||||
|
master1VmId,
|
||||||
|
allStarts,
|
||||||
);
|
);
|
||||||
|
|
||||||
const installMaster1 = new command.remote.Command(
|
const installMaster1 = new command.remote.Command(
|
||||||
@@ -234,138 +265,105 @@ const waitControlPlaneVipReady = new command.remote.Command(
|
|||||||
// Step 4: Wait for SSH on remaining masters, join cluster via the VIP
|
// Step 4: Wait for SSH on remaining masters, join cluster via the VIP
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
const waitMaster2Ssh = new command.local.Command(
|
const waitMaster2Ssh = waitSsh("wait-ssh-master-2", master2Ip, master2VmId, [
|
||||||
"wait-ssh-master-2",
|
waitK3sMaster1Ready,
|
||||||
{
|
]);
|
||||||
create: pulumi.interpolate`for i in $(seq 1 60); do (timeout 5 bash -c "echo > /dev/tcp/${master2Ip}/22") 2>/dev/null && exit 0; sleep 5; done; exit 1`,
|
|
||||||
triggers: [master2VmId],
|
|
||||||
interpreter: ["/bin/bash", "-c"],
|
|
||||||
},
|
|
||||||
{ dependsOn: [waitK3sMaster1Ready] },
|
|
||||||
);
|
|
||||||
|
|
||||||
const waitMaster3Ssh = new command.local.Command(
|
const waitMaster3Ssh = waitSsh("wait-ssh-master-3", master3Ip, master3VmId, [
|
||||||
"wait-ssh-master-3",
|
waitK3sMaster1Ready,
|
||||||
{
|
]);
|
||||||
create: pulumi.interpolate`for i in $(seq 1 60); do (timeout 5 bash -c "echo > /dev/tcp/${master3Ip}/22") 2>/dev/null && exit 0; sleep 5; done; exit 1`,
|
|
||||||
triggers: [master3VmId],
|
|
||||||
interpreter: ["/bin/bash", "-c"],
|
|
||||||
},
|
|
||||||
{ dependsOn: [waitK3sMaster1Ready] },
|
|
||||||
);
|
|
||||||
|
|
||||||
const joinMaster2 = new command.remote.Command(
|
// Joins an extra control-plane node through the VIP. Every master must get the
|
||||||
"join-k3s-master-2",
|
// same server flags, so they live here, not at the call site.
|
||||||
|
function joinMaster(
|
||||||
|
nodeName: string,
|
||||||
|
ip: pulumi.Input<string>,
|
||||||
|
vmId: pulumi.Input<string>,
|
||||||
|
dependsOn: pulumi.ResourceOptions["dependsOn"],
|
||||||
|
): command.remote.Command {
|
||||||
|
return new command.remote.Command(
|
||||||
|
`join-${nodeName}`,
|
||||||
{
|
{
|
||||||
connection: conn(master2Ip),
|
connection: conn(ip),
|
||||||
create: k3sInstallScript(
|
create: k3sInstallScript(
|
||||||
"",
|
"",
|
||||||
pulumi.interpolate`server --server https://${controlPlaneVipAddress}:6443 --disable servicelb ${secretsEncryptionArgs} --node-name k3s-master-2`,
|
pulumi.interpolate`server --server https://${controlPlaneVipAddress}:6443 --disable servicelb ${secretsEncryptionArgs} --node-name ${nodeName}`,
|
||||||
),
|
),
|
||||||
stdin: k3sToken,
|
stdin: k3sToken,
|
||||||
triggers: [master2VmId],
|
triggers: [vmId],
|
||||||
},
|
},
|
||||||
{ dependsOn: [waitMaster2Ssh, waitControlPlaneVipReady] },
|
{ dependsOn },
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const joinMaster3 = new command.remote.Command(
|
const joinMaster2 = joinMaster("k3s-master-2", master2Ip, master2VmId, [
|
||||||
"join-k3s-master-3",
|
waitMaster2Ssh,
|
||||||
{
|
waitControlPlaneVipReady,
|
||||||
connection: conn(master3Ip),
|
]);
|
||||||
create: k3sInstallScript(
|
|
||||||
"",
|
const joinMaster3 = joinMaster("k3s-master-3", master3Ip, master3VmId, [
|
||||||
pulumi.interpolate`server --server https://${controlPlaneVipAddress}:6443 --disable servicelb ${secretsEncryptionArgs} --node-name k3s-master-3`,
|
waitMaster3Ssh,
|
||||||
),
|
waitControlPlaneVipReady,
|
||||||
stdin: k3sToken,
|
joinMaster2,
|
||||||
triggers: [master3VmId],
|
]);
|
||||||
},
|
|
||||||
{ dependsOn: [waitMaster3Ssh, waitControlPlaneVipReady, joinMaster2] },
|
|
||||||
);
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Step 5: Join worker nodes via the VIP
|
// Step 5: Join worker nodes via the VIP
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
const waitWorker1Ssh = new command.local.Command(
|
const waitWorker1Ssh = waitSsh("wait-ssh-worker-1", worker1Ip, worker1VmId, [
|
||||||
"wait-ssh-worker-1",
|
joinMaster3,
|
||||||
{
|
]);
|
||||||
create: pulumi.interpolate`for i in $(seq 1 60); do (timeout 5 bash -c "echo > /dev/tcp/${worker1Ip}/22") 2>/dev/null && exit 0; sleep 5; done; exit 1`,
|
|
||||||
triggers: [worker1VmId],
|
|
||||||
interpreter: ["/bin/bash", "-c"],
|
|
||||||
},
|
|
||||||
{ dependsOn: [joinMaster3] },
|
|
||||||
);
|
|
||||||
|
|
||||||
const waitWorker2Ssh = new command.local.Command(
|
const waitWorker2Ssh = waitSsh("wait-ssh-worker-2", worker2Ip, worker2VmId, [
|
||||||
"wait-ssh-worker-2",
|
joinMaster3,
|
||||||
{
|
]);
|
||||||
create: pulumi.interpolate`for i in $(seq 1 60); do (timeout 5 bash -c "echo > /dev/tcp/${worker2Ip}/22") 2>/dev/null && exit 0; sleep 5; done; exit 1`,
|
|
||||||
triggers: [worker2VmId],
|
|
||||||
interpreter: ["/bin/bash", "-c"],
|
|
||||||
},
|
|
||||||
{ dependsOn: [joinMaster3] },
|
|
||||||
);
|
|
||||||
|
|
||||||
const waitWorker3Ssh = new command.local.Command(
|
const waitWorker3Ssh = waitSsh("wait-ssh-worker-3", worker3Ip, worker3VmId, [
|
||||||
"wait-ssh-worker-3",
|
joinMaster3,
|
||||||
{
|
]);
|
||||||
create: pulumi.interpolate`for i in $(seq 1 60); do (timeout 5 bash -c "echo > /dev/tcp/${worker3Ip}/22") 2>/dev/null && exit 0; sleep 5; done; exit 1`,
|
|
||||||
triggers: [worker3VmId],
|
|
||||||
interpreter: ["/bin/bash", "-c"],
|
|
||||||
},
|
|
||||||
{ dependsOn: [joinMaster3] },
|
|
||||||
);
|
|
||||||
|
|
||||||
const joinWorker1 = new command.remote.Command(
|
function joinWorker(
|
||||||
"join-k3s-worker-1",
|
nodeName: string,
|
||||||
|
ip: pulumi.Input<string>,
|
||||||
|
vmId: pulumi.Input<string>,
|
||||||
|
dependsOn: pulumi.ResourceOptions["dependsOn"],
|
||||||
|
): command.remote.Command {
|
||||||
|
return new command.remote.Command(
|
||||||
|
`join-${nodeName}`,
|
||||||
{
|
{
|
||||||
connection: conn(worker1Ip),
|
connection: conn(ip),
|
||||||
create: k3sInstallScript(
|
create: k3sInstallScript(
|
||||||
pulumi.interpolate`K3S_URL=https://${controlPlaneVipAddress}:6443`,
|
pulumi.interpolate`K3S_URL=https://${controlPlaneVipAddress}:6443`,
|
||||||
"--node-name k3s-worker-1",
|
`--node-name ${nodeName}`,
|
||||||
),
|
),
|
||||||
stdin: k3sToken,
|
stdin: k3sToken,
|
||||||
triggers: [worker1VmId],
|
triggers: [vmId],
|
||||||
},
|
},
|
||||||
{ dependsOn: [waitWorker1Ssh] },
|
{ dependsOn },
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const joinWorker2 = new command.remote.Command(
|
const joinWorker1 = joinWorker("k3s-worker-1", worker1Ip, worker1VmId, [
|
||||||
"join-k3s-worker-2",
|
waitWorker1Ssh,
|
||||||
{
|
]);
|
||||||
connection: conn(worker2Ip),
|
|
||||||
create: k3sInstallScript(
|
|
||||||
pulumi.interpolate`K3S_URL=https://${controlPlaneVipAddress}:6443`,
|
|
||||||
"--node-name k3s-worker-2",
|
|
||||||
),
|
|
||||||
stdin: k3sToken,
|
|
||||||
triggers: [worker2VmId],
|
|
||||||
},
|
|
||||||
{ dependsOn: [waitWorker2Ssh] },
|
|
||||||
);
|
|
||||||
|
|
||||||
const joinWorker3 = new command.remote.Command(
|
const joinWorker2 = joinWorker("k3s-worker-2", worker2Ip, worker2VmId, [
|
||||||
"join-k3s-worker-3",
|
waitWorker2Ssh,
|
||||||
{
|
]);
|
||||||
connection: conn(worker3Ip),
|
|
||||||
create: k3sInstallScript(
|
const joinWorker3 = joinWorker("k3s-worker-3", worker3Ip, worker3VmId, [
|
||||||
pulumi.interpolate`K3S_URL=https://${controlPlaneVipAddress}:6443`,
|
waitWorker3Ssh,
|
||||||
"--node-name k3s-worker-3",
|
]);
|
||||||
),
|
|
||||||
stdin: k3sToken,
|
|
||||||
triggers: [worker3VmId],
|
|
||||||
},
|
|
||||||
{ dependsOn: [waitWorker3Ssh] },
|
|
||||||
);
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Step 6: Format and mount Longhorn disks
|
// Step 6: Format and mount Longhorn disks
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
const workers = [worker1Ip, worker2Ip, worker3Ip];
|
const workers = [worker1Ip, worker2Ip, worker3Ip];
|
||||||
const workerSshReader = [waitWorker1Ssh, waitWorker2Ssh, waitWorker3Ssh];
|
const workerSshReady = [waitWorker1Ssh, waitWorker2Ssh, waitWorker3Ssh];
|
||||||
|
|
||||||
workers.forEach((worker, i) => {
|
const longhornMounts = workers.map((worker, i) => {
|
||||||
return new command.remote.Command(
|
return new command.remote.Command(
|
||||||
`mount-longhorn-disk-${i}`,
|
`mount-longhorn-disk-${i}`,
|
||||||
{
|
{
|
||||||
@@ -383,7 +381,7 @@ workers.forEach((worker, i) => {
|
|||||||
mountpoint -q /mnt/longhorn-extra;
|
mountpoint -q /mnt/longhorn-extra;
|
||||||
df -h /mnt/longhorn-extra`,
|
df -h /mnt/longhorn-extra`,
|
||||||
},
|
},
|
||||||
{ dependsOn: workerSshReader[i] },
|
{ dependsOn: workerSshReady[i] },
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -447,7 +445,8 @@ const allVms = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
allVms.forEach(({ id, ip, name, readiness }) => {
|
const packageInstalls = allVms.map(
|
||||||
|
({ id, ip, name, readiness }) =>
|
||||||
new command.remote.Command(
|
new command.remote.Command(
|
||||||
`install-packages-${name}`,
|
`install-packages-${name}`,
|
||||||
{
|
{
|
||||||
@@ -457,6 +456,39 @@ allVms.forEach(({ id, ip, name, readiness }) => {
|
|||||||
triggers: [id],
|
triggers: [id],
|
||||||
},
|
},
|
||||||
{ dependsOn: readiness },
|
{ dependsOn: readiness },
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Step 9: Remove the CI runner's SSH key from every node
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// The key is only needed for the steps above, so it shouldn't stay valid on
|
||||||
|
// the nodes afterwards. A rebuilt VM gets it again from cloud-init, so a fresh
|
||||||
|
// bootstrap still works.
|
||||||
|
const sshSteps = [getKubeconfig, ...longhornMounts, ...packageInstalls];
|
||||||
|
|
||||||
|
const revokeCiKeyScript = `set -euo pipefail
|
||||||
|
IFS= read -r KEY || true
|
||||||
|
[ -n "$KEY" ]
|
||||||
|
f="$HOME/.ssh/authorized_keys"
|
||||||
|
grep -qxF -- "$KEY" "$f"
|
||||||
|
grep -vxF -- "$KEY" "$f" > "$f.new" || [ $? -eq 1 ]
|
||||||
|
[ -s "$f.new" ]
|
||||||
|
chmod 600 "$f.new"
|
||||||
|
mv "$f.new" "$f"
|
||||||
|
if grep -qxF -- "$KEY" "$f"; then exit 1; fi`;
|
||||||
|
|
||||||
|
allVms.forEach(({ id, ip, name }) => {
|
||||||
|
new command.remote.Command(
|
||||||
|
`revoke-ci-key-${name}`,
|
||||||
|
{
|
||||||
|
connection: conn(ip),
|
||||||
|
create: revokeCiKeyScript,
|
||||||
|
stdin: ciRunnerPublicKey,
|
||||||
|
triggers: [id],
|
||||||
|
},
|
||||||
|
{ dependsOn: sshSteps },
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -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