Skip to content

Commit 5303cf5

Browse files
committed
Support no_tailscale build tag, added local manual Makefile test for tailscale host
1 parent 48f943f commit 5303cf5

File tree

7 files changed

+48
-5
lines changed

7 files changed

+48
-5
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11

22
test:
33
go test -race ./...
4+
go test -race -tags no_tailscale ./...
45
go run -race . version
56

67
test-local:
78
go run -race . -h2 -config-dir sampleConfig/ -redirect-port :8081 -https-port :8443 -http-port :8001
89

910

1011
docker-test:
11-
GOOS=linux go build
12+
GOOS=linux go build -tags no_tailscale
1213
docker build . --tag fortio/proxy:test
1314
docker run -v `pwd`/sampleConfig:/etc/fortio-proxy-config fortio/proxy:test
1415

@@ -32,6 +33,11 @@ dev-h2c:
3233
-debug-host "debug.fortio.org" \
3334
-routes.json '[{"host":"*", "destination":"http://localhost:8080/"}]'
3435

36+
TAILSCALE_SERVERNAME=$(shell tailscale status --json | jq -r '.Self.DNSName | sub("\\.$$"; "")')
37+
dev-tailscale:
38+
@echo "Visit https://$(TAILSCALE_SERVERNAME)/"
39+
go run -race . -loglevel debug -hostid local -certs-domains $(TAILSCALE_SERVERNAME) -debug-host $(TAILSCALE_SERVERNAME)
40+
3541
dev:
3642
# Run: curl -H "Host: debug.fortio.org" http://localhost:8001/debug
3743
# and curl -H "Host: debug.fortio.org" http://localhost:8000/foo (no redirect with that host header)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ go install fortio.org/proxy@latest
2222
sudo setcap CAP_NET_BIND_SERVICE=+eip $(which proxy)
2323
```
2424

25+
If you don't need or want the tailscale support, add `-tags no_tailscale` for a much smaller binary.
26+
2527
You can also download one of the many binary [releases](https://github.com/fortio/proxy/releases)
2628

2729
We publish a multi architecture docker image (linux/amd64, linux/arm64) `docker run fortio/proxy`

config/no_tailscale.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//go:build no_tailscale
2+
// +build no_tailscale
3+
4+
package config
5+
6+
func IsTailscale(_ string) bool {
7+
return false
8+
}
9+
10+
func Tailscale() CertGetter {
11+
return nil
12+
}

config/tailscale.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
//go:build !no_tailscale
2+
// +build !no_tailscale
3+
14
package config
25

3-
import "strings"
6+
// build constraints
7+
8+
import (
9+
"strings"
10+
11+
"tailscale.com/client/tailscale"
12+
)
413

514
// Suffix for server names which will use the tailscale client instead of the autocert client.
615
// Not expected to be changed but just in case.
@@ -11,3 +20,9 @@ var TailscaleSuffix = ".ts.net"
1120
func IsTailscale(serverName string) bool {
1221
return strings.HasSuffix(serverName, TailscaleSuffix)
1322
}
23+
24+
var tcert = &tailscale.LocalClient{}
25+
26+
func Tailscale() CertGetter {
27+
return tcert
28+
}

config/tailscale_common.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package config
2+
3+
import "crypto/tls"
4+
5+
type CertGetter interface {
6+
GetCertificate(hello *tls.ClientHelloInfo) (*tls.Certificate, error)
7+
}

config/tailscale_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build !no_tailscale
2+
// +build !no_tailscale
3+
14
package config_test
25

36
import (

proxy_main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"fortio.org/proxy/rp"
2525
"fortio.org/scli"
2626
"golang.org/x/crypto/acme/autocert"
27-
"tailscale.com/client/tailscale"
2827
)
2928

3029
var (
@@ -36,7 +35,6 @@ var (
3635
redirect = flag.String("redirect-port", ":80", "`port` to listen on for redirection")
3736
httpPort = flag.String("http-port", "disabled", "`port` to listen on for non tls traffic (or 'disabled')")
3837
acert *autocert.Manager
39-
tcert = &tailscale.LocalClient{}
4038
)
4139

4240
func hostPolicy(_ context.Context, host string) error {
@@ -57,7 +55,7 @@ func debugGetCert(hello *tls.ClientHelloInfo) (*tls.Certificate, error) {
5755
if err := hostPolicy(context.Background(), hello.ServerName); err != nil {
5856
return nil, err
5957
}
60-
return tcert.GetCertificate(hello)
58+
return config.Tailscale().GetCertificate(hello)
6159
}
6260
return acert.GetCertificate(hello)
6361
}

0 commit comments

Comments
 (0)