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 +IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqpePKTVYh0XfTxa9/UQmVRut +oSUCYJdsBD7V1FfkiLDdUef9shoISyQ/JUR8KDLiyrCeImq71sIa2V8+CuZ5lgUx +7+tKzq+1nRQpXDpj1mSbqTVjjOD/BCBCN4XVfNNKdCmc4bi/pPOPD52ZtkZvlk98 +/j/SkWkqMoKMi82fq0s5NDEf4AogwhxhCDDM9bnK/3tNCSAtnHzYEj3hYHEX7s9m +MKvjZ30CofqJvzD0pcx3HzJXqDNj4EKmdn7fTS7IGzVEHtcydI7F8G71+BY+recs +y84KxSzOK8YBjcOdJh01QemMRigefmrcMNamHXnxh1MnuLQL87QAgabbcBacCwID +AQABo4GZMIGWMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgWgMBMGA1UdJQQM +MAoGCCsGAQUFBwMBMCEGA1UdEQQaMBiCFnBvcnRhaW5lci5hcHAuaW50ZXJuYWww +HQYDVR0OBBYEFF2IEkWyZktX5uJAHtdfzPCV161dMB8GA1UdIwQYMBaAFMr8tqeF +YL21we0UJHQv8wK6JEOCMA0GCSqGSIb3DQEBCwUAA4ICAQA69Tlj+bHUBQAhHfBW +0ApKj7cnWIzhSd6cbLpE9UDSLL/Lj5PZh5CXlnocyXhE3BZGqJkehTUOvYHtIory +HkjmDq822ob9tm844J5GYNxxxBPvgZgLr6eiW4R/0fdwZmshXejaEq3uG94Z0eWO +MASRWRZDH4CsckY5f2VEzOnCI8hFZWtd/IUnYVU0IsWHmdzajJgR9SBpapEEQoAv +LwQ7/Yac0m2sp59lde0nX9uHhqb8gFBYwtHY1A9niPA8pR+pRwjhtWuAOPSKKWwJ +D6+ILOu+p5tZLQo3H2Sl0OFSpOs4p794vcpxk32jsWmGs3vR0efdxjPGBvYp9joT +9CrzuWnjyKor/lG3I3SCPKX/nFFpTrzw7URzEUIvERiZa7WgCjehPKmChhcdvd7f +RzEKwWbtrdDKsZSxOcfZ5vPfo/ejNkINovmXCPhL/10dyEbtjBwAImQBUg6DD8yC +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 a98b00c..a61d74a 100644 Binary files a/secrets/portainer-agent-bigbox1.age and b/secrets/portainer-agent-bigbox1.age differ diff --git a/secrets/portainer-agent-minipc1.age b/secrets/portainer-agent-minipc1.age new file mode 100644 index 0000000..8029864 Binary files /dev/null and b/secrets/portainer-agent-minipc1.age differ diff --git a/secrets/portainer-tls-key.age b/secrets/portainer-tls-key.age new file mode 100644 index 0000000..6966ad4 Binary files /dev/null and b/secrets/portainer-tls-key.age differ