Skip to content

Commit

Permalink
add config option for control URL
Browse files Browse the repository at this point in the history
Closes #22

Co-authored-by: ChibangLW <ich@leonlenzen.de>
Signed-off-by: Will Norris <will@tailscale.com>
  • Loading branch information
willnorris and ChibangLW committed May 8, 2024
1 parent 27fad94 commit 8b9aa03
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ type TSApp struct {
// Ephemeral specifies whether Tailscale nodes should be registered as ephemeral.
Ephemeral bool `json:"ephemeral,omitempty" caddy:"namespace=tailscale.ephemeral"`

// ControlURL specifies the default control URL to use for nodes.
ControlURL string `json:"control_url,omitempty" caddy:"namespace=tailscale.control_url"`

// Nodes is a map of per-node configuration which overrides global options.
Nodes map[string]TSNode `json:"nodes,omitempty" caddy:"namespace=tailscale"`

Expand All @@ -41,6 +44,9 @@ type TSNode struct {
// Ephemeral specifies whether the node should be registered as ephemeral.
Ephemeral bool `json:"ephemeral,omitempty" caddy:"namespace=tailscale.ephemeral"`

// ControlURL specifies the control URL to use for the node.
ControlURL string `json:"control_url,omitempty" caddy:"namespace=tailscale.control_url"`

name string
}

Expand Down Expand Up @@ -119,6 +125,11 @@ func parseTSNode(d *caddyfile.Dispenser) (TSNode, error) {
return node, segment.ArgErr()
}
node.AuthKey = segment.Val()
case "control_url":
if !segment.NextArg() {
return node, segment.ArgErr()
}
node.ControlURL = segment.Val()
case "ephemeral":
node.Ephemeral = true
default:
Expand Down
16 changes: 16 additions & 0 deletions module.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func getNode(ctx caddy.Context, name string) (*tailscaleNode, error) {
if s.AuthKey, err = getAuthKey(name, app); err != nil {
app.logger.Warn("error parsing auth key", zap.Error(err))
}
if s.ControlURL, err = getControlURL(name, app); err != nil {
app.logger.Warn("error parsing control URL", zap.Error(err))
}

if name != "" {
// Set config directory for tsnet. By default, tsnet will use the name of the
Expand Down Expand Up @@ -179,6 +182,19 @@ func getEphemeral(name string, app *TSApp) bool {
return app.Ephemeral
}

func getControlURL(name string, app *TSApp) (string, error) {
if app == nil {
return "", nil
}
if node, ok := app.Nodes[name]; ok {
if node.ControlURL != "" {
return repl.ReplaceOrErr(node.ControlURL, true, true)
}
}

return repl.ReplaceOrErr(app.ControlURL, true, true)
}

// tailscaleNode is a wrapper around a tsnet.Server that provides a fully self-contained Tailscale node.
// This node can listen on the tailscale network interface, or be used to connect to other nodes in the tailnet.
type tailscaleNode struct {
Expand Down

0 comments on commit 8b9aa03

Please sign in to comment.