From 020b277a04a7fbeefcebb9c6b68ca6141aec5634 Mon Sep 17 00:00:00 2001 From: kasun Date: Sat, 21 Nov 2026 02:26:44 +0100 Subject: [PATCH] feature(k8s-infra): expose the Longhorn UI behind Traefik basic auth The Longhorn UI has no login of its own and can delete volumes, so it is only reachable through a Traefik basicAuth middleware. Credentials come from the new longhornUiUser/longhornUiPassword config secrets; the hostname uses the new domain config. --- 03-k8s-infra/index.ts | 68 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/03-k8s-infra/index.ts b/03-k8s-infra/index.ts index 98a5cb9..9be80b1 100644 --- a/03-k8s-infra/index.ts +++ b/03-k8s-infra/index.ts @@ -19,6 +19,10 @@ const letsencryptEmail = config.requireSecret("letsencryptEmail"); const kubeVipAddress = config.requireSecret("kubeVipAddress"); const kubeVipInterface = config.require("kubeVipInterface"); +const domain = config.requireSecret("domain"); +const longhornUiUser = config.requireSecret("longhornUiUser"); +const longhornUiPassword = config.requireSecret("longhornUiPassword"); + const k8sProvider = new k8s.Provider("k3s", { kubeconfig }); const opts = (extras?: pulumi.ResourceOptions): pulumi.ResourceOptions => ({ provider: k8sProvider, @@ -174,6 +178,70 @@ const longhorn = new k8s.helm.v3.Release( ), ); +// ── Longhorn UI ─────────────────────────────────────────────────────────── +// Docs: https://longhorn.io/docs/1.12.0/deploy/accessing-the-ui/longhorn-ingress-traefik/ +// https://doc.traefik.io/traefik/reference/routing-configuration/http/middlewares/basicauth/ + +const longhornUiAuthSecret = new k8s.core.v1.Secret( + "longhorn-ui-basic-auth", + { + metadata: { name: "longhorn-ui-basic-auth", namespace: "longhorn-system" }, + type: "kubernetes.io/basic-auth", + stringData: { username: longhornUiUser, password: longhornUiPassword }, + }, + opts({ dependsOn: [longhorn] }), +); + +// Fixed name: the Ingress references it as -@kubernetescrd. +const longhornUiAuth = new k8s.apiextensions.CustomResource( + "longhorn-ui-auth", + { + apiVersion: "traefik.io/v1alpha1", + kind: "Middleware", + metadata: { name: "longhorn-ui-auth", namespace: "longhorn-system" }, + spec: { basicAuth: { secret: longhornUiAuthSecret.metadata.name } }, + }, + opts(), +); + +const longhornUiHost = pulumi.interpolate`longhorn.${domain}`; + +new k8s.networking.v1.Ingress( + "longhorn-ui", + { + metadata: { + name: "longhorn-ui", + namespace: "longhorn-system", + annotations: { + "cert-manager.io/cluster-issuer": "letsencrypt-prod", + "traefik.ingress.kubernetes.io/router.middlewares": + "longhorn-system-longhorn-ui-auth@kubernetescrd", + }, + }, + spec: { + ingressClassName: "traefik", + tls: [{ hosts: [longhornUiHost], secretName: "longhorn-ui-tls" }], + rules: [ + { + host: longhornUiHost, + http: { + paths: [ + { + path: "/", + pathType: "Prefix", + backend: { + service: { name: "longhorn-frontend", port: { number: 80 } }, + }, + }, + ], + }, + }, + ], + }, + }, + opts({ dependsOn: [longhorn, longhornUiAuth] }), +); + // ── kube-vip ──────────── const kubeVipNamespace = "kube-system"; -- 2.54.1