feat: allow running over plain http #37
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/plain-http"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Traefik Control can now be served over plain HTTP, for example over a VPN at
http://control.vpn.example:4000or behind a reverse proxy without TLS. Until now it could not:force_sslwas set at compile time inconfig/prod.exs(every plain-HTTP request was redirected tohttps://PHX_HOSTand HSTS was sent), andconfig/runtime.exshardcodedurl: [host: host, port: 443, scheme: "https"]. Deployments that leave the new variables unset behave as before.Changes
config/runtime.exs: newPHX_SCHEME(httpsdefault, orhttp) andPHX_URL_PORT(default443for https,80for http, integer 1-65535). Any other value raises at boot, like the other env checks. The endpoint getsurl: [host: PHX_HOST, port: PHX_URL_PORT, scheme: PHX_SCHEME], and:force_sslis set toscheme == "https"(production only).config/prod.exs: removed the compile-timeforce_ssl.TraefikControlWeb.Plugs.ForceSSL(endpoint, right afterHealthPlug): appliesPlug.SSLwith the same options as before (rewrite_on: [:x_forwarded_proto], exclude/healthz/readyzandlocalhost/127.0.0.1, default HSTS, redirect to the configured host via{Endpoint, :host, []}as Phoenix did). The options are computed once at compile time and only the boolean switch is read per request. Dev and test never set the switch, so they never redirect.Hostheader (invites, confirmations, the OIDC callback, node snippets, the OpenAPI server URL and the WebAuthn origin all go throughEndpoint.url()/url(~p...)).WebAuthn.available?/1(https, or a loopback name over http). When it is false, the security keys section of the two-factor settings page says that keys need https or localhost and does not show "Add a key". Authenticator apps and recovery codes still work.PHX_SCHEMEandPHX_URL_PORTrows next toPHX_HOST, a "Running over plain HTTP" paragraph (VPN or your own proxy, the WebAuthn limit,TRAEFIK_CONTROL_TRUST_PROXYonly behind a proxy you control, node snippets showinghttp://), and the WebAuthn paragraph. Comments that describedforce_sslas compile-time were updated (HealthPlugmoduledoc,runtime.exs).test/traefik_control_web/plugs/force_ssl_test.exscovers https mode (301/307 tohttps://<configured host>even for a foreign Host header; HSTS on https and onX-Forwarded-Proto: https;/healthz,/readyz,localhostand127.0.0.1left alone), http mode (no redirect, no HSTS) and the unset switch (dev/test).web_authn_test.exscoversavailable?/1. Existingruntime.exsoptions have no tests, so the new parsing has none either; it was checked against the release image instead (see below).Verification
All commands ran in the repo's tooling image (
podman build -f Containerfile.dev -t traefik-control-dev ., run with--userns=keep-id -v "$PWD":/work):TRAEFIK_CONTROL_DB=sqlite3:mix format --check-formattedpassed;mix compile --warnings-as-errorspassed;mix credo --strict: 2324 mods/funs, no issues;mix dialyzer: Total errors: 0, passed successfully.TRAEFIK_CONTROL_DB=sqlite3 MIX_ENV=test mix test: 1522 passed.TRAEFIK_CONTROL_DB=postgres PGHOST=127.0.0.1 MIX_ENV=test mix test(withpostgres:latestin a keep-id pod): 1522 passed.Smoke test of the release image (
podman build --build-arg DB=sqlite3 .) with a throwaway/datavolume,PHX_HOST=localhost.test: