Skip to content

Add opt-in HTTP to HTTPS redirect for services - #129

Merged
marvinvr merged 3 commits into
mainfrom
http-redirect
Nov 25, 2026
Merged

marvinvr merged 3 commits into
mainfrom
http-redirect

Conversation

@marvinvr

@marvinvr marvinvr commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Redirects http:// to HTTPS for https services by default: DockTail adds a port 80 handler with Tailscale's serve Redirect field, pointing to the full MagicDNS name (avoids the ${HOST} short-name cert mismatch, tailscale#21683). Opt out per service with docktail.service.http-redirect=false (or docktail.service.N.http-redirect=false).

  • Port 80 handler is written through tailscaled's LocalAPI serve-config with ETag retry (not set-config, tailscale#18381)
  • Needs tailscaled >= 1.92 on the host; older daemons log a warning and keep plain HTTPS
  • With Tailscale API credentials, DockTail adds tcp:80 to new and existing Service definitions itself (never removes ports)
  • Without credentials, DockTail logs one warning per service and HTTPS keeps working; adding tcp:80 in the admin console is optional, only if you want the redirect
  • Docs + tests

Related: #37

docktail.service.http-redirect=true (also per index) makes port 80 of an
https service answer with a 308 redirect to its HTTPS endpoint, so
http:// URLs and bare MagicDNS names no longer hang.

The reconciler derives the port-80 endpoint from the label, so conflict
detection, Service definition port sync and stale-endpoint removal work
unchanged. The tailscale CLI has no redirect flag yet, so that one
listener is written through tailscaled's LocalAPI serve-config endpoint
with an If-Match ETag, keeping every other field of the config as is.
The target names the full MagicDNS FQDN instead of ${HOST}, which would
keep a short name the certificate does not cover (tailscale#21683).

Redirects need tailscaled 1.92+; older daemons and tailnets without
MagicDNS get a warning and keep serving HTTPS without the redirect.
Lint: check the LocalAPI response Body.Close errors, use a tagged switch
on the status code, and build the fake LocalAPI's ETag with strconv
instead of an int-to-rune conversion.

Keep a manual admin-panel comment when no description label is set. The
image-derived description (#127) overwrote any comment once the label was
absent, which broke the e2e check that a console comment survives a tag
reconcile. It is now a fallback: it is used on creation, fills an empty
comment, and refreshes a comment that names another version of the same
image, but never replaces a hand-written one. A description label stays
authoritative and an empty one still turns the fallback off.

Derive a single port-80 redirect per container and service name, so one
container redirecting on several HTTPS ports of a service does not
conflict with itself.

Claude-Session: https://claude.ai/code/session_01JyHejLZBcAeHAAVJY6aqBo
Every service-protocol https endpoint (not itself on port 80) now gets the
port-80 redirect without a label; docktail.service.http-redirect=false (or
the indexed variant) opts out. An explicit true is still validated.

The redirect never causes a conflict: a service name whose port 80 is
declared by any container, or which is ignored, keeps that endpoint and the
redirect is skipped with one info log. Several HTTPS ports or containers on
one name share a single redirect aimed at 443, else the lowest port.

With API credentials DockTail appends tcp:80 to an existing Service
definition that does not allow it (ports are never removed). Without
credentials, and on tailscaled older than 1.92 or without MagicDNS, it logs
one warning per process instead of one per reconcile; HTTPS is unaffected.

The e2e suite covers a real http:// request answered with 308 and the path
and query kept, the opt-out, a port 80 taken by another container, tcp:80
being added to a definition that lacks it, and cleanup when the redirect is
turned off and the container removed. Port assertions ignore redirect-only
ports so existing HTTPS fixtures keep their checks.

Claude-Session: https://claude.ai/code/session_01JyHejLZBcAeHAAVJY6aqBo
@marvinvr
marvinvr merged commit 163f2b1 into main Nov 25, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant