From a33f1284dcfe220141126929599e924d6d908c34 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Tue, 22 Sep 2026 15:17:35 -0400 Subject: [PATCH] portainer management --- configs/pki/lab-ca.srl | 2 +- configs/pki/portainer.app.internal.crt | 26 +++++ hosts/hl-bigbox1.nix | 23 +---- hosts/hl-minipc1.nix | 8 ++ hosts/hl-minipc2.nix | 28 ++--- modules/nixos/desktop/tiler/default.nix | 6 -- modules/nixos/server/ABOUTME.md | 2 + modules/nixos/server/default.nix | 1 + modules/nixos/server/portainer.nix | 130 ++++++++++++++++++++++++ secrets.nix | 2 + secrets/portainer-agent-bigbox1.age | Bin 519 -> 525 bytes secrets/portainer-agent-minipc1.age | Bin 0 -> 525 bytes secrets/portainer-tls-key.age | Bin 0 -> 2026 bytes 13 files changed, 182 insertions(+), 46 deletions(-) create mode 100644 configs/pki/portainer.app.internal.crt create mode 100644 modules/nixos/server/portainer.nix create mode 100644 secrets/portainer-agent-minipc1.age create mode 100644 secrets/portainer-tls-key.age diff --git a/configs/pki/lab-ca.srl b/configs/pki/lab-ca.srl index 4a995f3..e9c7270 100644 --- a/configs/pki/lab-ca.srl +++ b/configs/pki/lab-ca.srl @@ -1 +1 @@ -0D0C7C270FF7DD6600BBC42B9282088EC96C8C08 +0D0C7C270FF7DD6600BBC42B9282088EC96C8C09 diff --git a/configs/pki/portainer.app.internal.crt b/configs/pki/portainer.app.internal.crt new file mode 100644 index 0000000..3d3a0d6 --- /dev/null +++ b/configs/pki/portainer.app.internal.crt @@ -0,0 +1,26 @@ +-----BEGIN CERTIFICATE----- +MIIEXzCCAkegAwIBAgIUDQx8Jw/33WYAu8QrkoIIjslsjAkwDQYJKoZIhvcNAQEL +BQAwFjEUMBIGA1UEAwwLU2t5ZyBMYWIgQ0EwHhcNMjYwOTIyMTg1NzQyWhcNMjgx +MjI1MTg1NzQyWjAhMR8wHQYDVQQDDBZwb3J0YWluZXIuYXBwLmludGVybmFsMIIB +IjANBgkqhkiG9w0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QBUg6DD8yC +6cKb4A+zmNNcnAHSDeqfg3rWWUHd/K7nblg7mU/pg490GuhhTkRflbwSF3HlAxJq +k/00QH9H+CS/RT3aNnoG1H6f5H8+7FEqgTXmVuNHBuTVL1IRGRiyJooCIv4P2C8E +EoJTG+bUrUPbVlZI5MlCYnM2WU33Sz9NIg0XAWibXsIZzih7L6zP2R0X9f9yt8PL +HkNyNXVHJkFgB6ipfii2fll36g== +-----END CERTIFICATE----- diff --git a/hosts/hl-bigbox1.nix b/hosts/hl-bigbox1.nix index 744952e..0b421e6 100644 --- a/hosts/hl-bigbox1.nix +++ b/hosts/hl-bigbox1.nix @@ -35,27 +35,12 @@ networkDrives.enable = true; }; - # Portainer Agent + # Portainer Edge Agent age.secrets.portainer-agent-bigbox1.file = ../secrets/portainer-agent-bigbox1.age; - skyg.nixos.common.container-services.portainer-agent = { + skyg.nixos.server.portainer = { enable = true; - autoUpdate.enable = true; - services.agent = { - image = "portainer/agent:2.45.0"; - volumes = [ - "/var/run/docker.sock:/var/run/docker.sock" - "/var/lib/docker/volumes:/var/lib/docker/volumes" - "portainer_agent_data:/data" - ]; - environmentFiles = [ config.age.secrets.portainer-agent-bigbox1.path ]; - environment = { - EDGE_INSECURE_POLL = "1"; - EDGE = "1"; - }; - }; - volumes.portainer_agent_data = { - name = "portainer_data"; - }; + mode = "agent"; + agent.edgeKeySecretName = "portainer-agent-bigbox1"; }; # Jellyfin container service group diff --git a/hosts/hl-minipc1.nix b/hosts/hl-minipc1.nix index a168b8b..a427c28 100644 --- a/hosts/hl-minipc1.nix +++ b/hosts/hl-minipc1.nix @@ -455,6 +455,14 @@ in }; }; + # Portainer Edge Agent + age.secrets.portainer-agent-minipc1.file = ../secrets/portainer-agent-minipc1.age; + skyg.nixos.server.portainer = { + enable = true; + mode = "agent"; + agent.edgeKeySecretName = "portainer-agent-minipc1"; + }; + # Buzz management CLI. environment.systemPackages = [ buzz-manage ]; diff --git a/hosts/hl-minipc2.nix b/hosts/hl-minipc2.nix index 5fa3b46..47bb808 100644 --- a/hosts/hl-minipc2.nix +++ b/hosts/hl-minipc2.nix @@ -75,28 +75,16 @@ in networks.lan = config.skyg.nixos.common.containers.networks.ipvlanLab.compose; }; - # Portainer Service - skyg.nixos.common.container-services.portainer = { + # Portainer Server + age.secrets.portainer-tls-key.file = ../secrets/portainer-tls-key.age; + skyg.nixos.server.portainer = { enable = true; - autoUpdate.enable = true; - services.portainer = { - image = "portainer/portainer-ce:lts"; - volumes = [ - "/var/run/docker.sock:/var/run/docker.sock" - "portainer_data:/data" - ]; - ports = [ - "9443:9443" - "8000:8000" - ]; - # networks = staticIp "10.0.101.5"; + mode = "server"; + server.tls = { + enable = true; + cert = builtins.readFile ../configs/pki/portainer.app.internal.crt; + keySecretName = "portainer-tls-key"; }; - volumes = { - portainer_data = { - name = "portainer_data"; - }; - }; - # networks = macvlanNetwork; }; age.secrets.stack1.file = ../secrets/stack1.age; diff --git a/modules/nixos/desktop/tiler/default.nix b/modules/nixos/desktop/tiler/default.nix index ff34d0b..996d89e 100644 --- a/modules/nixos/desktop/tiler/default.nix +++ b/modules/nixos/desktop/tiler/default.nix @@ -48,12 +48,6 @@ in enableGnomeKeyring = true; fprintAuth = true; u2fAuth = true; - text = lib.mkDefault '' - auth include login - account include login - password include login - session include login - ''; }; security.pam.services.login.enableGnomeKeyring = true; security.polkit.enable = true; diff --git a/modules/nixos/server/ABOUTME.md b/modules/nixos/server/ABOUTME.md index 0a2f20e..5a8f288 100644 --- a/modules/nixos/server/ABOUTME.md +++ b/modules/nixos/server/ABOUTME.md @@ -17,6 +17,7 @@ server/ ├── dns/ # Local DNS resolver, certbot, local CA ├── k3s/ # Single-binary K3s cluster role ├── k8s/ # Full upstream Kubernetes (master/node) +├── portainer.nix # skyg.nixos.server.portainer — Portainer server or Edge agent └── services/ # Self-hosted apps (jellyfin, audiobookshelf, comfyui, ds4, colibri, ai…) ``` @@ -43,6 +44,7 @@ skyg.server.dns.* → dns/ skyg.nixos.server.k3s.* → k3s/ skyg.nixos.server.k8s.* → k8s/ skyg.nixos.server.services.* → services/ +skyg.nixos.server.portainer.* → portainer.nix ``` ## Conventions diff --git a/modules/nixos/server/default.nix b/modules/nixos/server/default.nix index c5569ba..b23d6a0 100644 --- a/modules/nixos/server/default.nix +++ b/modules/nixos/server/default.nix @@ -10,5 +10,6 @@ ./services ./timers.nix ./dns + ./portainer.nix ]; } diff --git a/modules/nixos/server/portainer.nix b/modules/nixos/server/portainer.nix new file mode 100644 index 0000000..940b707 --- /dev/null +++ b/modules/nixos/server/portainer.nix @@ -0,0 +1,130 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.skyg.nixos.server.portainer; +in +{ + options.skyg.nixos.server.portainer = { + enable = mkEnableOption "Portainer container management UI"; + + mode = mkOption { + type = types.enum [ "server" "agent" ]; + default = "agent"; + description = '' + Whether to run the Portainer server (management UI) or an Edge agent. + ''; + }; + + server = { + ip = mkOption { + type = types.str; + default = "10.0.101.241"; + description = "Static IP on the ipvlan lab network for the server container."; + }; + + dnsName = mkOption { + type = types.str; + default = "portainer"; + description = '' + Internal DNS name for the server. The app.internal suffix is added + automatically by the DNS module. + ''; + }; + + tls = { + enable = mkEnableOption "TLS with a lab CA certificate for the Portainer server"; + + cert = mkOption { + type = types.nullOr types.str; + default = null; + description = '' + Content of the TLS certificate in PEM format. Set to the output of + builtins.readFile on the lab CA leaf cert committed in configs/pki/. + Run `skyg ca issue --for ` first to create it. + Example: builtins.readFile ../../configs/pki/portainer.app.internal.crt + ''; + }; + + keySecretName = mkOption { + type = types.nullOr types.str; + default = null; + description = '' + Name of the age secret containing the TLS private key. + Created by `skyg ca issue --for `. + The corresponding age.secrets..file must be declared + in the host file. + Example: "portainer-tls-key" + ''; + }; + }; + }; + + agent = { + edgeKeySecretName = mkOption { + type = types.nullOr types.str; + default = null; + description = '' + Name of the age secret (without the secrets/ prefix or .age suffix) + containing the EDGE_KEY for this agent. The corresponding + age.secrets..file must be declared in the host file. + Example: "portainer-agent-minipc1" + ''; + }; + }; + }; + + config = mkIf cfg.enable { + skyg.nixos.common.container-services.portainer = + if cfg.mode == "server" + then { + enable = true; + autoUpdate.enable = true; + services.portainer = { + image = "portainer/portainer-ce:lts"; + volumes = + [ "/var/run/docker.sock:/var/run/docker.sock" "portainer_data:/data" ] + ++ lib.optional (cfg.server.tls.enable && cfg.server.tls.keySecretName != null) + "${config.age.secrets.${cfg.server.tls.keySecretName}.path}:/certs/key.pem:ro"; + networks.lan.ipv4_address = cfg.server.ip; + dns.names = [ cfg.server.dnsName ]; + } + // lib.optionalAttrs cfg.server.tls.enable { + files."/certs/cert.pem" = cfg.server.tls.cert; + environment = { + PORTAINER_HTTP_ENABLED = "true"; + PORTAINER_SSL = "true"; + PORTAINER_SSLCERT = "/certs/cert.pem"; + PORTAINER_SSLKEY = "/certs/key.pem"; + PORTAINER_TUNNEL_PORT = "8000"; + }; + }; + volumes.portainer_data = { + name = "portainer_data"; + }; + networks.lan = config.skyg.nixos.common.containers.networks.ipvlanLab.compose; + } + else { + enable = true; + autoUpdate.enable = true; + services.agent = { + image = "portainer/agent:2.45.0"; + volumes = [ + "/var/run/docker.sock:/var/run/docker.sock" + "/var/lib/docker/volumes:/var/lib/docker/volumes" + "portainer_agent_data:/data" + ]; + environmentFiles = lib.optional (cfg.agent.edgeKeySecretName != null) + config.age.secrets.${cfg.agent.edgeKeySecretName}.path; + environment = { + EDGE_INSECURE_POLL = "1"; + EDGE = "1"; + }; + }; + volumes.portainer_agent_data = { + name = "portainer_data"; + }; + }; + }; +} diff --git a/secrets.nix b/secrets.nix index 08486c1..7fc2f2e 100644 --- a/secrets.nix +++ b/secrets.nix @@ -37,6 +37,8 @@ in # portainer agent envs "secrets/portainer-agent-bigbox1.age".publicKeys = [ ari bigbox1 ]; + "secrets/portainer-agent-minipc1.age".publicKeys = [ ari minipc1 ]; "secrets/lab-ca-key.age".publicKeys = [ ari ]; "secrets/buzz-tls-key.age".publicKeys = [ ari minipc1 ]; + "secrets/portainer-tls-key.age".publicKeys = [ ari minipc2 ]; } diff --git a/secrets/portainer-agent-bigbox1.age b/secrets/portainer-agent-bigbox1.age index a98b00c5fc932cddd49ac340bd79d62d9723ca73..a61d74abcb512627faaa4abfc852a9ae16442c5b 100644 GIT binary patch delta 491 zcmVb67(wOhq_MVnk$TaBenuW>{!6Oj33*N_SH;dTB9Z zNGoSiGzvveIc01|P;p9aMr1Wmb4z41d08?rZAnf}ZZI-bRd`r=MrTH8X<>9{a|$g! zAaiqQEoEdfH8n9gAV+9$ZAU>MX*XA4bW}wzH%~ZjWHLodYkzrBMMyVdFn3o=LsD^b zL1HylQZ#orG-gp%3UN0~IAJtFc1KD$WHE0_Q)5X+Sb1SMM|e3>V`(*UPh)vOK~7_3 zGC@sq3N0-yAXa%-G*?tuWOPF_ICga~G(j>VOdr6m;2Opn!SPe?7q13;z+64EAlCjmSGFg!;7>ME;TM4n-^BJ3BzBnTiw!P$U7w=3DtO<`P$Q{ocMzAvsR6!dSo?q5P;U4dM9 hIolJamRcwJZAMwNDzw{SJ^*S6by;PoysaVR{&Kuq#}xno delta 485 zcmVIY&%6F=kC-IV*NzV^33fVo_mIVNP#(GB7iEYc_3WVlq)VYYHts zAaiqQEoEdfH8n9gAV+9$ZAU>MO*T??Pe(;dQZ+_$ZEjR$ZhvG`V`yr6RBw26PIz^9 zQZP9yP(gK2H*IG$3Nc1jQ!r&TLN`ujOjlZUWkOL?K~ZZ(N@I0#Qc+?>OHNO1YAZ@= zQA>JJ3N0-yAZkN3aYR^DWI}RCT1P`vQ8`3zIAK~ea5zv-dO~$mOLIvvFj-S^V{B?P z3Tdn_bR+1grGG0mG$D8^8V79r%;O8h;JdGs%YtCK4_wu+9`%@IRS1fdGXQEh$ywQ*Ej-! zs!kan{Ye50gw$FhZIoa-rW?H#l#E+nhfb}t#`J#j{9YO1_NGge0W^E;xe4A2uWV(0Ow68G=RO-SA diff --git a/secrets/portainer-agent-minipc1.age b/secrets/portainer-agent-minipc1.age new file mode 100644 index 0000000000000000000000000000000000000000..8029864dd7662c67e150bac3df06ec995cc55522 GIT binary patch literal 525 zcmYdHPt{G$OD?J`D9Oyv)5|YP*Do{V(zR14F3!+RO))YxHMCT4_6#z}byO&?i1KvG z^9*&*4$lfI2rTgojZE|nC=b-mE~)Z&NeK%v%t>+64)ic|3gxQEu}CU2D#FDNq#_sWf^bT76rPtGl=GC;S@r_{?Y&{3h#Fw)%5Kd92xCqFnZ zr_$5Ku_!&jGSkz?z_BVIT;H%T-?6yBJt^BaJe{jDEYjCcKgY~8JUhZ7pxh{^sGz*k z)juOCDZ4b=DL*a3q^i)^%+JrgIGsyZS69I!z$M7PEUUuUA|pFH)h#zO+_b_p)XdX6 zE!WvHHzLU2IN7T-tfJJU$bd_9(WK?Gx4qx>&4|x}XXi=g<~Q$D_5M8j;U(-`;I^u5 zr@8R8eI=jX#Kpf)du)`Wm3#Zk8vk;G)>RkW101XDF2DNtF-SxBdvaP_w<(BTjwYx1y2@_n3Vzi{@3{>)OXVd9tzK zC+!Ees@C7^t}m`Sa?tyb*rZ*Iu0m&BBQ9s#U+lPL+)`F9)O6*d4%?r~Dv`C{de~|% L+Y27Q=sg<%8vfHM literal 0 HcmV?d00001 diff --git a/secrets/portainer-tls-key.age b/secrets/portainer-tls-key.age new file mode 100644 index 0000000000000000000000000000000000000000..6966ad403ec8157f1e3e025ff242ee575bbb52a9 GIT binary patch literal 2026 zcmVBXH-dRS1<}#W@~I}LsoBE zM{#9WMsZkgGjMA&RX9*jGHXF}LwGqwH*rK^S9)1XZf^=LJ|J^*Xf0)AGBq_ZIUsds zD|1bEAWTLzYeP{mRCiV}L}4>?d1NwqSy(f2O+{8yR$*&IY-uk?dTl{CVpDlz3T10F zbXIdhRB~Z5O-W}?HAYfpSyeMIWo9`|H)UsfYBXmnS2r?LZ%j^e3N0-yAZ>6oVns7n zNJB_)SZq^FQc7-GF->lDZFFX6FiA~ROF?;SYBzXyXG3mD3L1fZi>A=wVq_~55=_Mv z!^N$H%UMP+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