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

New option -suppressTailnetDialer, to help access off-tailnet addresses #11

Merged
merged 1 commit into from
Aug 2, 2023
Merged
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
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type TailnetSrv struct {
SuppressWhois bool
PrometheusAddr string
UpstreamHeaders headers
SuppressTailnetDialer bool
}

type validTailnetSrv struct {
Expand Down Expand Up @@ -107,6 +108,7 @@ func tailnetSrvFromArgs(args []string) (*validTailnetSrv, *ffcli.Command, error)
fs.BoolVar(&s.SuppressWhois, "suppressWhois", false, "Do not set X-Tailscale-User-* headers in upstream requests")
fs.StringVar(&s.PrometheusAddr, "prometheusAddr", ":9099", "Serve prometheus metrics from this address. Empty string to disable.")
fs.Var(&s.UpstreamHeaders, "upstreamHeader", "Additional headers (separated by ': ') on requests to upstream.")
fs.BoolVar(&s.SuppressTailnetDialer, "suppressTailnetDialer", false, "Whether to use the stdlib net.Dialer instead of a tailnet-enabled one")

root := &ffcli.Command{
ShortUsage: "tsnsrv -name <serviceName> [flags] <toURL>",
Expand Down Expand Up @@ -199,9 +201,14 @@ func (s *validTailnetSrv) run(ctx context.Context) error {
}

dial := srv.Dial
if s.SuppressTailnetDialer {
d := net.Dialer{}
dial = d.DialContext
}
if s.UpstreamTCPAddr != "" {
dialOrig := dial
dial = func(ctx context.Context, network, address string) (net.Conn, error) {
return srv.Dial(ctx, "tcp", s.UpstreamTCPAddr)
return dialOrig(ctx, "tcp", s.UpstreamTCPAddr)
}
} else if s.UpstreamUnixAddr != "" {
dial = func(ctx context.Context, network, address string) (net.Conn, error) {
Expand Down
7 changes: 7 additions & 0 deletions nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@
default = {};
};

suppressTailnetDialer = mkOption {
description = "Disable using the tsnet-provided dialer, which can sometimes cause issues hitting addresses outside the tailnet";
type = types.bool;
default = false;
};

toURL = mkOption {
description = "URL to forward HTTP requests to";
type = types.str;
Expand Down Expand Up @@ -144,6 +150,7 @@
-authkeyPath=${lib.escapeShellArg value.authKeyPath} \
-insecureHTTPS=${lib.boolToString value.insecureHTTPS} \
-suppressWhois=${lib.boolToString value.suppressWhois} \
-suppressTailnetDialer=${lib.boolToString value.suppressTailnetDialer} \
${
if value.whoisTimeout != null
then "-whoisTimeout=${lib.escapeShellArg value.whoisTimeout}"
Expand Down