Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Tailscale hostname through environment variable. #18

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ It's really multiple plugins in one, providing:
- the ability for a Caddy server to directly join your Tailscale network
without needing a separate Tailscale client.
- a Caddy authentication provider, so that you can pass a user's Tailscale
identity to an applicatiton.
identity to an application.
- a Caddy subcommand to quickly setup a reverse-proxy using either or both of
the network listener or authentication provider.

Expand All @@ -27,7 +27,7 @@ xcaddy build v2.7.3 --with github.com/tailscale/caddy-tailscale

New in Caddy 2.6, modules are able to provide custom network listeners. This
allows your Caddy server to directly join your Tailscale network without needing
a separate Tailcale client running on the machine exposing a network device.
a separate Tailscale client running on the machine exposing a network device.
Each site can be configured in Caddy to join your network as a separate node, or
you can have multiple sites listening on different ports of a single node.

Expand Down Expand Up @@ -115,7 +115,7 @@ is not advised to use the same instance of Caddy for your external-facing apps
as you use for your internal-facing apps. This deficiency will be resolved as
soon as possible.

### Authenticating to the Tailcale network
### Authenticating to the Tailscale network

New nodes can be added to your Tailscale network by providing an [Auth
key](https://tailscale.com/kb/1085/auth-keys/) or by following a special URL.
Expand All @@ -130,6 +130,10 @@ somewhat noisy so are turned off by default. Set `TS_VERBOSE=1` to see the URL
logged. After the node had been added to your network, you can restart Caddy
without the debug flag.

### Choosing the Tailscale hostname

The default Tailscale hostname is set to `caddy-tsnet-client`. You may use your own Tailscale hostname by setting the `TS_HOSTNAME` environment variable.

## Caddy authentication provider

Setup the Tailscale authentication provider with `tailscale_auth` directive.
Expand Down
8 changes: 7 additions & 1 deletion transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tscaddy
import (
"fmt"
"net/http"
"os"

"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
Expand All @@ -21,7 +22,12 @@ func (t *TailscaleCaddyTransport) UnmarshalCaddyfile(d *caddyfile.Dispenser) err
func (t *TailscaleCaddyTransport) Provision(context caddy.Context) error {
t.logger = context.Logger()

s, err := getServer("", "caddy-tsnet-client:80")
host := os.Getenv("TS_HOSTNAME")
if host == "" {
host = "caddy-tsnet-client"
}

s, err := getServer("", host+":80")
if err != nil {
return err
}
Expand Down