Repository navigation
tsidp-server: add -login-server for custom control servers - #202
Open
RyoKusnadi wants to merge 1 commit into
Open
RyoKusnadi wants to merge 1 commit into
RyoKusnadi wants to merge 1 commit into
Conversation
Add a -login-server flag, with TS_LOGIN_SERVER as its environment variable, that sets tsnet.Server.ControlURL. This lets tsidp join a tailnet run by a control server other than Tailscale's, such as Headscale, the same way `tailscale up --login-server` does. The value must be an absolute http:// or https:// URL with a host. URLs with credentials, a query or a fragment are rejected, and error messages never repeat the input so a mistyped URL can't leak a secret into the logs. The scheme is lowercased and trailing slashes are removed. When the flag is empty, tsnet keeps its default behavior, including honoring TS_CONTROL_URL. With -use-local-tailscaled the flag has no effect and a warning is logged, as for -authkey-file. Fixes tailscale#104 Signed-off-by: Ryo Kusnadi <ryokusnadi@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #104
What
Adds a
-login-serverflag (envTS_LOGIN_SERVER) that setstsnet.Server.ControlURL, so tsidp can join a tailnet run by a control server other than Tailscale's, such as Headscale. It works liketailscale up --login-server.tsidp -login-server https://headscale.example.com # or TS_LOGIN_SERVER=https://headscale.example.com tsidpBehavior
Empty (default):
ControlURLis left unset, so tsnet behaves exactly as before, including honoring its ownTS_CONTROL_URLenv var. When-login-serveris set, it takes precedence overTS_CONTROL_URL.Precedence: the env var supplies the flag's default and an explicit flag wins, the same pattern as
-advertise-tagsand-authkey-file.Validation (
parseLoginServer): the value must be an absolutehttp://orhttps://URL with a host. It rejects:https://user:pass@host, or any@), so they can't end up in logs?x=1,#f), which would break the URLs tsnet builds on top of ithttps://,https://:443) or an opaque form (https:host)On a bad value tsidp exits with code 1 and a fixed error message. Error messages never include any part of the input, so a mistyped URL that contains a token or password isn't written to the logs.
Normalizing: the scheme is lowercased and trailing slashes are removed (
HTTPS://hs.example.com//→https://hs.example.com). The host keeps its case.With
-use-local-tailscaled: the flag has no effect (the local tailscaled must be set up withtailscale up --login-serverinstead), so tsidp logs a warning, as it already does for-authkey-file.README: added the flag to the CLI flags table, the env var list and the Docker env table.
Tests
TestParseLoginServeris table-driven with 32 cases:ftp://, no host, port without host, opaque URL, unparsable URL, userinfo, username only, query, empty query, fragment, empty fragment, plus malformed credential URLs (https:user:secret@host,user:secret@host,https://host:secret, …).I also ran the built binary by hand: invalid values via both the flag and the env var exit 1 with the fixed messages; a valid value logs
using custom control server url=...and proceeds to login; the flag overrides the env var; and-use-local-tailscaledlogs the warning.Not covered
As noted in the issue thread, tsidp serves HTTPS through
ts.ListenTLS, which needs the control server to issue certificates. This PR only adds the control-server setting; it doesn't change how certificates are obtained, so tsidp may still be unable to serve HTTPS on control servers without certificate support. I didn't test against a live Headscale server.The README notes that
TS_env names may move toTSIDP_later. I usedTS_LOGIN_SERVERto match the existing network settings (TS_HOSTNAME,TS_AUTHKEY_FILE, …) and the CLI's--login-server. Happy to rename it.