diff --git a/docs/decisions/2026-11-21-traefik-tls-http01.md b/docs/decisions/2026-11-21-traefik-tls-http01.md index 4f7dec4..9542c3c 100644 --- a/docs/decisions/2026-11-21-traefik-tls-http01.md +++ b/docs/decisions/2026-11-21-traefik-tls-http01.md @@ -32,10 +32,10 @@ WAN TCP 443 -> 192.168.1.114:443 Configure a Traefik `websecure` entrypoint on port `443` and use Traefik's Let's Encrypt ACME resolver with the HTTP-01 challenge on the `web` entrypoint -(port `80`). Ordinary HTTP requests on `web` are permanently redirected to -`websecure`; Traefik's internal ACME challenge handling remains available for -HTTP-01 validation. Public Kubernetes Ingress resources will opt into TLS using -the same resolver. +(port `80`). Ordinary HTTP routes use a separate permanent `redirectScheme` +middleware on `web`; TLS routes are pinned to `websecure`. This keeps the +internal ACME challenge router separate from backend routes. Public Kubernetes +Ingress resources will opt into TLS using the same resolver. The router must not terminate TLS, use a KeenDNS HTTPS proxy, rewrite SNI, or replace the HTTP `Host` header on the forwarded path. diff --git a/k3s_rencher/apps/hermes/ui.yaml b/k3s_rencher/apps/hermes/ui.yaml index 278fdaf..fe0c865 100644 --- a/k3s_rencher/apps/hermes/ui.yaml +++ b/k3s_rencher/apps/hermes/ui.yaml @@ -5,6 +5,7 @@ metadata: labels: app.kubernetes.io/name: hermes annotations: + traefik.ingress.kubernetes.io/router.entrypoints: websecure traefik.ingress.kubernetes.io/router.tls: "true" traefik.ingress.kubernetes.io/router.tls.certresolver: letsencrypt spec: diff --git a/k3s_rencher/infrastructure/ingress/README.md b/k3s_rencher/infrastructure/ingress/README.md index f9f089a..9d6d7ad 100644 --- a/k3s_rencher/infrastructure/ingress/README.md +++ b/k3s_rencher/infrastructure/ingress/README.md @@ -41,12 +41,17 @@ version. Inspect the live `HelmChart/traefik` values before applying a chart override; do not assume that a values schema from another K3s release is compatible. -For each public Ingress, enable TLS with the same resolver. The resulting -Ingress shape is: +For each public Ingress, pin the TLS route to `websecure`. The separate +`http-redirect.yaml` resource attaches a `redirectScheme` middleware to +`web`-only routes. Keeping the HTTP redirect separate prevents the internal +ACME challenge router from being sent to a backend. + +The resulting TLS Ingress shape is: ```yaml metadata: annotations: + traefik.ingress.kubernetes.io/router.entrypoints: websecure traefik.ingress.kubernetes.io/router.tls: "true" traefik.ingress.kubernetes.io/router.tls.certresolver: letsencrypt spec: @@ -66,9 +71,9 @@ private key, an API token, or an unencrypted Kubernetes Secret. The repository configuration is in `traefik-https-config.yaml`. It extends the installed K3s `HelmChart/traefik` with: -- `web` exposed on TCP `80`; -- `websecure` exposed on TCP `443`; -- permanent HTTP-to-HTTPS redirection from `web` to `websecure`; +- `web` exposed on TCP `80` for the HTTP redirect and ACME HTTP-01; +- `websecure` exposed on TCP `443` for TLS termination; +- a permanent HTTP-to-HTTPS `redirectScheme` middleware on web-only routes; - the `letsencrypt` ACME resolver using HTTP-01 through `web` (Traefik's ACME challenge handling remains available on the `web` entrypoint); - persistent `/data/acme.json` storage through a `1Gi` PVC. diff --git a/k3s_rencher/infrastructure/ingress/http-redirect.yaml b/k3s_rencher/infrastructure/ingress/http-redirect.yaml new file mode 100644 index 0000000..e5cd516 --- /dev/null +++ b/k3s_rencher/infrastructure/ingress/http-redirect.yaml @@ -0,0 +1,63 @@ +apiVersion: traefik.io/v1alpha1 +kind: Middleware +metadata: + name: http-to-https + namespace: hermes +spec: + redirectScheme: + scheme: https + permanent: true +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: http-redirect + namespace: hermes + labels: + app.kubernetes.io/name: http-redirect + annotations: + traefik.ingress.kubernetes.io/router.entrypoints: web + traefik.ingress.kubernetes.io/router.middlewares: hermes-http-to-https@kubernetescrd +spec: + ingressClassName: traefik + rules: + - host: hermes.rudolf.keenetic.link + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: hermes + port: + name: dashboard + - host: brencher.rudolf.keenetic.link + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: brencher-swarm + port: + name: http + - host: immich.rudolf.keenetic.link + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: immich-swarm + port: + name: http + - host: gitea.rudolf.keenetic.link + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: gitea-swarm + port: + name: http diff --git a/k3s_rencher/infrastructure/ingress/kustomization.yaml b/k3s_rencher/infrastructure/ingress/kustomization.yaml index 9628179..2626367 100644 --- a/k3s_rencher/infrastructure/ingress/kustomization.yaml +++ b/k3s_rencher/infrastructure/ingress/kustomization.yaml @@ -3,4 +3,5 @@ kind: Kustomization resources: - swarm-backends.yaml - traefik-https-config.yaml + - http-redirect.yaml - public-ingress.yaml diff --git a/k3s_rencher/infrastructure/ingress/public-ingress.yaml b/k3s_rencher/infrastructure/ingress/public-ingress.yaml index a9ef04e..d966b71 100644 --- a/k3s_rencher/infrastructure/ingress/public-ingress.yaml +++ b/k3s_rencher/infrastructure/ingress/public-ingress.yaml @@ -6,6 +6,7 @@ metadata: labels: app.kubernetes.io/name: public-ingress annotations: + traefik.ingress.kubernetes.io/router.entrypoints: websecure traefik.ingress.kubernetes.io/router.tls: "true" traefik.ingress.kubernetes.io/router.tls.certresolver: letsencrypt spec: diff --git a/k3s_rencher/infrastructure/ingress/traefik-https-config.yaml b/k3s_rencher/infrastructure/ingress/traefik-https-config.yaml index d46b0c9..3fb3124 100644 --- a/k3s_rencher/infrastructure/ingress/traefik-https-config.yaml +++ b/k3s_rencher/infrastructure/ingress/traefik-https-config.yaml @@ -25,9 +25,6 @@ spec: additionalArguments: - "--entrypoints.web.address=:8000/tcp" - "--entrypoints.websecure.address=:8443/tcp" - - "--entrypoints.web.http.redirections.entrypoint.to=websecure" - - "--entrypoints.web.http.redirections.entrypoint.scheme=https" - - "--entrypoints.web.http.redirections.entrypoint.permanent=true" - "--certificatesresolvers.letsencrypt.acme.email=rudolfss13@gmail.com" - "--certificatesresolvers.letsencrypt.acme.storage=/data/acme.json" - "--certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=web"