Skip to content

feat: redirect the bare tailnet name to the HTTPS origin for discovery - #3

Merged
Quick104 merged 2 commits into
mainfrom
feat/overlay-discovery-redirect
Oct 3, 2026
Merged

Quick104 merged 2 commits into
mainfrom
feat/overlay-discovery-redirect

Conversation

@Quick104

@Quick104 Quick104 commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A phone or TV on the tailnet cannot find Silo without being told its full name, silo.<tailnet>.ts.net. Tailscale's DNS search domain lets a device resolve the bare name silo, but the node's HTTPS certificate covers only the full name, so https://silo/ fails and apps cannot use the short name. This makes the API node answer plain HTTP on the bare name with a redirect to its HTTPS origin, so Silo apps can find the server by probing http://silo/ and a person can type just the machine name.

Related: Silo-Server/silo-server#1846 (discovery contract in docs/architecture/server-discovery.md), Silo-Server/silo-apple#591 (the app side).

Approach

  • With the new Discovery setting on (the default), the API host also listens on tailnet port 80 and answers GET and HEAD with 307 to the API listener's HTTPS origin, keeping the path and query. Other methods get 405. It never proxies, so no request reaches Silo without TLS. Proxy nodes do not listen: nobody types their names. Discovery off keeps port 80 closed.
  • The target is the node's own parsed origin with only the request's path and query copied in, never a string built from the request line, so an absolute-form request cannot move it to another host. 307 rather than a permanent redirect, because the node can be renamed.
  • The listener opens after the Silo listeners and closes and reopens with them (disconnect, backend loss, rename). It does not gate connected: a failed listen or server exit is logged once and retried every 30 seconds while the node stays connected. It is skipped when a Silo listener already uses port 80.

Validation

  • make check passes: unit tests with -race, the patched-Tailscale ACME test, go vet, and gofmt. New tests cover the redirect target, HEAD and hostile request lines, the listener's close and reopen across backend loss and rename, retry after a failed listen, Discovery off, and the setting's parsing.
  • Installed on a shared dev server: http://<node>/api/v2/system/identity returned 307 to the HTTPS origin and the server's identity; POST returned 405. With the hostname prefix set to silo, an Apple TV on the tailnet running the feat(onboarding): list Silo servers found on the network and tailnet Silo-Server/silo-apple#591 build listed the server automatically.
  • Not run: NetBird or other providers, a tailnet whose policy blocks port 80.

Risks

  • One more tailnet listener (port 80) on the API node, on by default after upgrade. Tailnet policies that restrict ports need to allow it for discovery; everything else works without it, and the Discovery setting turns it off.

AI Disclosure

  • Harness: Claude Code in T3 Code
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: an independent Claude Code review agent (claude-opus-5-5) read the server, plugin and Apple diffs. For this repo it checked redirect safety, listener lifecycle and failure isolation and found no problems. A maintainer's review on the PR then found that an absolute-form request line could move the redirect's host, that the listener could stall the loop in Up, that failures were silent and never retried, that there was no off switch, and gaps in the docs and tests; all are fixed in the follow-up commit.

The API node now also listens on tailnet port 80 and answers GET and HEAD
with a 307 to its HTTPS API origin, keeping the path. Tailscale's search
domain resolves the bare machine name (`silo`), but the certificate covers
only the full name, so apps can now find the server by probing
`http://silo/` and people can type just the machine name. The redirect
never proxies, refuses other methods, and a node that cannot open port 80
still serves every listener.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Quick104

Quick104 commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator Author

@macroscope-app review

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline findings from a code review. The most serious is the redirect host issue on proxy.go:193. Its practical risk is low, but it breaks the guarantee that the redirect can't send a client to another host. I found everything by reading the code; I didn't run the tests.

Comment thread internal/tailscale/proxy.go Resolved
Comment thread internal/tailscale/network.go Resolved
Comment thread internal/tailscale/network.go Resolved
Comment thread internal/tailscale/network.go Resolved
Comment thread docs/DEVELOPMENT.md Resolved
Comment thread internal/tailscale/network_test.go Resolved
Comment thread internal/tailscale/network_test.go Resolved
Comment thread internal/tailscale/network_test.go Resolved
Comment thread README.md Resolved
Review follow-ups:
- Build the Location from the parsed origin with only the request's path
  and query copied in. An absolute-form request line such as
  "GET http:@evil.example" turned the origin into userinfo and redirected
  to another host.
- Open the port-80 listener without calling Up again, so an optional
  listener cannot stall the connection loop if the backend leaves Running.
- Log a failed discovery listener once and retry it every 30 seconds while
  connected, including when its server exits.
- Add a Discovery setting (on by default) and say in the manifest that the
  API host answers plain HTTP on port 80 with a redirect.
- Tests cover the :80 attempt, close on backend loss, reopen with the new
  origin after a rename, retry after a failure, discovery off, HEAD, and
  hostile request lines; the test client has a timeout and its own
  transport.
- Docs: the discovery listener does not gate "connected", the redirect
  keeps the query, and a stale `silo` machine makes a new node `silo-1`.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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