golink is a tsnet service, and Tailscale's data plane is very good at monitoring for changes to network state and reacting to them. As such, it doesn't need to wait for network-online.target, it can start up concurrently with everything else and shorten the long pole of bootup.
Additionally, network-online.target is an antipattern in systemd that almost never means what people want it to mean. "Online" has no precise definition, and (I posit) almost never matches the ideal version of "online" that people have in their mind. It specifically does _not_ mean that the network functions, or that any particular flavor of connectivity exists. A machine behind a captive portal is "online" for the purposes of bootup, and so is a machine that got a DHCP lease but is having all its packets blackholed. Systemd has a whole page of documentation on "what does online even mean", because this is such a recurring point of confusion: https://systemd.io/NETWORK_ONLINE/
It is almost always wrong to depend on network-online.target, and I wish it was named slow-down-boot-for-no-reason.target, which is how most downstream programs use it.
</rant>, the point is, golink is a well-behaved service that reacts to connectivity changes on the fly (it has to, that's what tailscale does), and so can be started concurrently with networking and other services.
If you visit a non-existent go link, we render the home page and pre-
populate the "short" input with the name of the link, and autofocus the
"long" input so that you can simply paste a long URL and submit.
It is common (at least at Tailscale) to create go links that correspond
to the name of a device on the tailnet. For example, go/who points to
http://who/. With this change, when you visit a non-existent go link,
we check to see if a peer exists on the tailnet with that name, and if
so we suggest that as the long URL.
Signed-off-by: Will Norris <will@tailscale.com>
we've had support for enabling the web UI in tsnet apps from the
beginning, but I don't think we've ever actually used it anywhere.
some of the settings exposed through the web ui don't make a ton of
sense for tsnet, and might not even work. But we're working toward
being able to enable the web ui on clients by default (with all of the
existing restrictions and ACL enforcement in place), and golink seemed
like a good playground to try it in a tsnet app.
Signed-off-by: Will Norris <will@tailscale.com>
We have fixed the issue in the corp repo that required us to use
pseudo-versions for the tailscale.com module here. So we can now switch
to the latest stable version.
Signed-off-by: Will Norris <will@tailscale.com>
golink: listen on HTTPS and redirect HTTP traffic
Updates tailscale/golink#9Fixestailscale/golink#29
On tailnets with HTTPS enabled golink will serve the primary endpoints via
HTTPS. With HTTPS enabled golink will respond to HTTP traffic with a
separate redirectHandler which redirects requests to their HTTPS equivalent.
Update documented examples of `curl` to include the `-L` flog to follow these
redirects if present.
Add a HTTPS section to the README documenting all of the above.
Signed-off-by: Patrick O'Doherty <patrick@tailscale.com>
I didn't think the order mattered (as long as none of the response body
had been written), but I guess I was wrong. Currently, it's returning
the 302 status, but no Location header. And tests, at least some of
which should be passing through this full code path, are passing. I'll
look into adding better testing later, but for now this fixes the
immediate issue.
Updates #91
Signed-off-by: Will Norris <will@tailscale.com>
Both http.ServeMux as well as the http.Redirect method pass the request
URL through `cleanPath` which, among other things, collapses double
slashes `//` to a single slash `/`. Most of the time this is fine, since
most servers treat those as identical anyway. But some destination
servers need the original path unmodified. Since we're just redirecting,
we don't need to be concerned with the additional benefits of
`cleanPath` such as eliminating `../` path components, since that is the
responsibility of the destination server to clean if needed.
This change adds a separate root http.Handler for golink requests. It
still uses http.ServeMux for internal endpoints, but serves golinks
directly without passing the request through ServeMux. Additionally,
this sets the redirect status and Location header directly rather than
calling http.Redirect, since that also modifies the URL it is given.
Fixes#89
Signed-off-by: Will Norris <will@tailscale.com>
The "tailscale.com/golink" peercap includes a single "admin" bool field.
When set, this grants the user the ability to edit all links stored in
the system.
Update currentUser to return a simple user struct instead of just a bare
username. Rename checkLinkOwnership to canEditLink and change to a bool
return value.
Signed-off-by: Will Norris <will@tailscale.com>
The detail page of a link only displays the form if the link is editable
for the logged in user.
Therefore, it's not necessary to disable the input fields within the
form if the link isn't editable.
Signed-off-by: Marco Hofstetter <marco.hofstetter@bluewin.ch>
Even in dev mode, the user `tagged-devices` should not be
reported as existing user.
This allows editing & deleting links owned by `taggged-devices`
in dev mode.
Signed-off-by: Marco Hofstetter <marco.hofstetter@bluewin.ch>
It should be possible to delete links owned by non-existing users
(tagged-devices or deleted) in the same ways as it's possible
to edit these links.
Signed-off-by: Marco Hofstetter <marco.hofstetter@bluewin.ch>
When resolving a go link, combine the query string parameters from the
request and long URL.
Updates #77
Signed-off-by: Will Norris <will@tailscale.com>
return a *url.URL value from expandLink rather than a string, and both
accept and return a *url.URL value from resolveLink rather than a
string. These are both unexported funcs, so this has no changes to the
current behavior. It does prevent a few unnecessary conversions back and
forth between url.URL and string values, and will make it simpler to
retain request query strings.
Updates #77
Signed-off-by: Will Norris <will@tailscale.com>
Previously, we were parsing from r.RequestURI, which includes both the
path and query string. This causes problem for requests like go/who?q
which try to lookup a link named "who?q" rather than "who" (see #77).
For now, this just ignores the request query string. Eventually we
should probably retain the query string, but this begins by parsing out
the short name properly.
Updates #77
Signed-off-by: Will Norris <will@tailscale.com>
bump version again, back to the latest commit on main, rather than the
latest released version. Otherwise, this causes issues in tailscale's
corp repo (sadly).
Signed-off-by: Will Norris <will@tailscale.com>
If the current user can't be determined (either because of a legitimate
error within the localapi client, or the user is coming through a subnet
router and doesn't have a Tailscale IP address), and the
-allow-unknown-users flag is set, then go ahead and save new links
without an owner.
By saving links without an owner, these unknown users can continue to
modify the link, and actual Tailscale users can take ownership. Once the
link is owned, it can no longer be modified by anyone other than the
owner.
Links that use the current user by having `{{ .User }}` in their long
URL cannot be resolved by unknown users and will return an error.
Fixes#60
Signed-off-by: Will Norris <will@tailscale.com>
To delete a link, go to its page in `.detail` and click on the "Delete"
button. Stats for the deleted link are removed as well.
Co-authored-by: Will Norris <will@tailscale.com>
Signed-off-by: Gabriel Wong <gabriel@bifrost.ai>
Signed-off-by: Will Norris <will@tailscale.com>
Also check error returned from tmpl.Execute. Refactor currentUser to
make the logic a little simpler, and make it a package var for easier
testing.
Signed-off-by: Will Norris <will@tailscale.com>
It's not uncommon to have multiple links pointing to the same
destination, for example to handle different spellings of a word or
because different people created them at different times.
A common best practice is to select one as the "primary" link and point
the others to that link as "aliases". This change updates resolveLink
to follow those aliases so that the final destination is returned when
using `golink -resolve-from-backup`.
Signed-off-by: Will Norris <will@tailscale.com>
Add "User" to the expansion environment for links. The intent here it
support personalized go links such as:
go/mycal => https://calendar.google.com/calendar/embed?src={{.User}}
That's not a terribly interesting example, but there are others I intend
to use internally.
Signed-off-by: Will Norris <will@tailscale.com>
PR #12 changes directory used by Docker image. This commit updates the fly.io
instructions to use the same directory.
Signed-off-by: Gabriel Wong <gabriel@bifrost.ai>