├── sampleConfig ├── debug-host ├── email ├── default-route ├── certs-domains └── routes.json ├── .gitignore ├── config ├── no_tailscale.go ├── certprovider.go ├── tailscale_test.go ├── tailscale.go ├── route.go └── route_test.go ├── Dockerfile ├── SECURITY.md ├── .github ├── dependabot.yml └── workflows │ └── include.yml ├── Makefile ├── go.mod ├── README.md ├── proxy_main.go ├── rp └── reverse_proxy.go ├── go.sum └── LICENSE /sampleConfig/debug-host: -------------------------------------------------------------------------------- 1 | debug.fortio.org -------------------------------------------------------------------------------- /sampleConfig/email: -------------------------------------------------------------------------------- 1 | fortio@fortio.org 2 | -------------------------------------------------------------------------------- /sampleConfig/default-route: -------------------------------------------------------------------------------- 1 | 127.0.0.1:8080 2 | -------------------------------------------------------------------------------- /sampleConfig/certs-domains: -------------------------------------------------------------------------------- 1 | demo.fortio.org,grpc.fortio.org 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .goreleaser.yaml 3 | .golangci.yml 4 | proxy 5 | .vscode 6 | dist/ 7 | -------------------------------------------------------------------------------- /sampleConfig/routes.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "host": "grpc.fortio.org", 4 | "destination": "http://127.0.0.1:8079" 5 | }, 6 | { 7 | "prefix": "/fgrpc.PingServer", 8 | "destination": "http://127.0.0.1:8079" 9 | }, 10 | { 11 | "prefix": "/grpc.health.v1.Health/Check", 12 | "destination": "http://127.0.0.1:8079" 13 | } 14 | ] 15 | -------------------------------------------------------------------------------- /config/no_tailscale.go: -------------------------------------------------------------------------------- 1 | //go:build no_tailscale 2 | // +build no_tailscale 3 | 4 | package config 5 | 6 | const HasTailscale = false 7 | 8 | func IsTailscale(_ string) bool { 9 | return false 10 | } 11 | 12 | func Tailscale() CertificateProvider { 13 | return nil 14 | } 15 | 16 | func TailscaleServerName() string { 17 | panic("Binary built without tailscale support, rebuild without -tags no_tailscale") 18 | } 19 | -------------------------------------------------------------------------------- /config/certprovider.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import "crypto/tls" 4 | 5 | // CertificateProvider interface is used to hide the tailscale dependency when not using it, 6 | // could also be use as a generic mapping between server name and cert provider 7 | // (while right now it's either autocert or tailscale). 8 | type CertificateProvider interface { 9 | GetCertificate(hello *tls.ClientHelloInfo) (*tls.Certificate, error) 10 | } 11 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM scratch 2 | COPY proxy /usr/bin/proxy 3 | ENTRYPOINT ["/usr/bin/proxy"] 4 | EXPOSE 443 5 | EXPOSE 80 6 | # configmap (dynamic flags) 7 | VOLUME /etc/fortio-proxy-config 8 | # certs 9 | VOLUME /etc/fortio-proxy-certs 10 | # logs etc 11 | WORKDIR /var/log/fortio 12 | # start the proxy with default; the routes and cert by default 13 | CMD ["-config-dir", "/etc/fortio-proxy-config", "-certs-directory", "/etc/fortio-proxy-certs"] 14 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | Use this section to tell people about which versions of your project are 6 | currently being supported with security updates. 7 | 8 | | Version | Supported | 9 | | ------- | ------------------ | 10 | | 1.x | :white_check_mark: | 11 | 12 | (Latest in release tag) 13 | 14 | ## Reporting a Vulnerability 15 | 16 | Send email to 17 | 18 | l d e m a i l l y @ g m a i l .com 19 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "gomod" 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "daily" 12 | - package-ecosystem: "github-actions" 13 | directory: "/" 14 | schedule: 15 | # Check for updates to GitHub Actions every week 16 | interval: "weekly" 17 | -------------------------------------------------------------------------------- /config/tailscale_test.go: -------------------------------------------------------------------------------- 1 | //go:build !no_tailscale 2 | // +build !no_tailscale 3 | 4 | package config_test 5 | 6 | import ( 7 | "testing" 8 | 9 | "fortio.org/proxy/config" 10 | ) 11 | 12 | func TestMatch(t *testing.T) { 13 | tests := []struct { 14 | serverName string 15 | match bool 16 | }{ 17 | {"foo.bar.ts.net", true}, // 0 18 | {"www.google.com", false}, // 1 19 | } 20 | for i, tst := range tests { 21 | res := config.IsTailscale(tst.serverName) 22 | if res != tst.match { 23 | t.Errorf("Mismatch %d expected %v for %s", i, tst.match, tst.serverName) 24 | } 25 | } 26 | } 27 | 28 | func TestClientNotNil(t *testing.T) { 29 | tailscale := config.Tailscale() 30 | if tailscale == nil { 31 | t.Errorf("Expected non-nil tailscale") 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /.github/workflows/include.yml: -------------------------------------------------------------------------------- 1 | name: "Shared server binery fortio workflows" 2 | on: 3 | push: 4 | branches: [ main ] 5 | tags: 6 | # so a vX.Y.Z-test1 doesn't trigger build 7 | - 'v[0-9]+.[0-9]+.[0-9]+' 8 | - 'v[0-9]+.[0-9]+.[0-9]+-pre*' 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | call-gochecks: 14 | uses: fortio/workflows/.github/workflows/gochecks.yml@main 15 | call-codecov: 16 | uses: fortio/workflows/.github/workflows/codecov.yml@main 17 | secrets: 18 | CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} 19 | call-codeql: 20 | uses: fortio/workflows/.github/workflows/codeql-analysis.yml@main 21 | call-releaser: 22 | if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') 23 | uses: fortio/workflows/.github/workflows/releaser.yml@main 24 | with: 25 | description: "TLS ingress reverse proxy and multiplexer with autocert and simple routing rules" 26 | secrets: 27 | GH_PAT: ${{ secrets.GH_PAT }} 28 | DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} 29 | DOCKER_USER: ${{ secrets.DOCKER_USER }} 30 | -------------------------------------------------------------------------------- /config/tailscale.go: -------------------------------------------------------------------------------- 1 | //go:build !no_tailscale 2 | // +build !no_tailscale 3 | 4 | package config 5 | 6 | // build constraints 7 | 8 | import ( 9 | "context" 10 | "strings" 11 | 12 | "fortio.org/log" 13 | "tailscale.com/client/local" 14 | ) 15 | 16 | const HasTailscale = true 17 | 18 | // TailscaleSuffix is the suffix for server names which will use the tailscale client instead of the autocert client. 19 | // Not expected to be changed but just in case. 20 | var TailscaleSuffix = ".ts.net" 21 | 22 | // IsTailscale returns true if the server name ends with the TailscaleSuffix. 23 | // Note the check is expecting lowercase serverName which is what hello.ServerName already is. 24 | func IsTailscale(serverName string) bool { 25 | return strings.HasSuffix(serverName, TailscaleSuffix) 26 | } 27 | 28 | var tcli = &local.Client{} 29 | 30 | func Tailscale() CertificateProvider { 31 | return tcli 32 | } 33 | 34 | func TailscaleServerName() string { 35 | status, err := tcli.StatusWithoutPeers(context.Background()) 36 | if err != nil { 37 | log.Critf("Error getting tailscale status: %v", err) 38 | return "" 39 | } 40 | // Remove the trailing dot as it's not there in ServerName. 41 | return strings.TrimSuffix(status.Self.DNSName, ".") 42 | } 43 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | test: 3 | go test -race ./... 4 | go test -race -tags no_tailscale ./... 5 | go run -race . version 6 | 7 | test-local: 8 | go run -race . -h2 -config-dir sampleConfig/ -redirect-port :8081 -https-port :8443 -http-port :8001 9 | 10 | 11 | docker-test: 12 | GOOS=linux go build -tags no_tailscale 13 | docker build . --tag fortio/proxy:test 14 | docker run -v `pwd`/sampleConfig:/etc/fortio-proxy-config fortio/proxy:test 15 | 16 | dev-prefix: 17 | go run -race . -h2 -http-port 8001 -https-port disabled -redirect-port disabled\ 18 | -loglevel debug \ 19 | -routes.json '[{"prefix":"/fgrpc", "destination":"http://localhost:8079/"}, {"host":"*", "destination":"http://localhost:8080/"}]' 20 | 21 | dev-prefix-only: 22 | go run -race . -http-port 8001 -https-port disabled -redirect-port disabled\ 23 | -loglevel debug \ 24 | -routes.json '[{"prefix":"/debug", "destination":"http://localhost:8080/"}]' 25 | 26 | dev-grpc: 27 | go run -race . -h2 -http-port 8001 -https-port disabled -redirect-port disabled\ 28 | -loglevel debug \ 29 | -routes.json '[{"host":"*", "destination":"http://localhost:8079/"}]' 30 | 31 | dev-h2c: 32 | go run -race . -h2 -http-port 8001 -https-port disabled -redirect-port disabled\ 33 | -debug-host "debug.fortio.org" \ 34 | -default-route http://localhost:8080/ 35 | 36 | # Not needed anymore outside of debughost, -tailscale does this for us 37 | TAILSCALE_SERVERNAME=$(shell tailscale status --json | jq -r '.Self.DNSName | sub("\\.$$"; "")') 38 | dev-tailscale: 39 | @echo "Visit https://$(TAILSCALE_SERVERNAME)/" 40 | go run -race . -loglevel debug -hostid local -tailscale -debug-host $(TAILSCALE_SERVERNAME) 41 | 42 | dev: 43 | # Run: curl -H "Host: debug.fortio.org" http://localhost:8001/debug 44 | # and curl -H "Host: debug.fortio.org" http://localhost:8000/foo (no redirect with that host header) 45 | go run -race . -http-port 8001 -https-port disabled -redirect-port 8000 -hostid "$(shell hostname)-test" \ 46 | -debug-host "debug.fortio.org" -routes.json '[{"host":"*", "destination":"http://localhost:8080/"}]' 47 | 48 | lint: .golangci.yml 49 | golangci-lint run 50 | 51 | .golangci.yml: Makefile 52 | curl -fsS -o .golangci.yml https://raw.githubusercontent.com/fortio/workflows/main/golangci.yml 53 | 54 | .PHONY: lint 55 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module fortio.org/proxy 2 | 3 | // should be 1.24.0 but tailscale is not playing along 4 | go 1.24.7 5 | 6 | require ( 7 | fortio.org/cli v1.12.3 8 | fortio.org/dflag v1.9.3 9 | fortio.org/fortio v1.73.0 10 | fortio.org/log v1.18.3 11 | fortio.org/scli v1.19.0 12 | golang.org/x/crypto v0.43.0 13 | golang.org/x/net v0.46.0 14 | tailscale.com v1.86.5 15 | ) 16 | 17 | // Note most of these are coming in because of tailscale, if you want a smaller 18 | // binary build with -tags no_tailscale 19 | require ( 20 | filippo.io/edwards25519 v1.1.0 // indirect 21 | fortio.org/duration v1.0.4 // indirect 22 | fortio.org/safecast v1.2.0 // indirect 23 | fortio.org/sets v1.3.0 // indirect 24 | fortio.org/struct2env v0.4.2 // indirect 25 | fortio.org/version v1.0.4 // indirect 26 | github.com/akutz/memconn v0.1.0 // indirect 27 | github.com/alexbrainman/sspi v0.0.0-20231016080023-1a75b4708caa // indirect 28 | github.com/coder/websocket v1.8.12 // indirect 29 | github.com/dblohm7/wingoes v0.0.0-20240119213807-a09d6be7affa // indirect 30 | github.com/fsnotify/fsnotify v1.8.0 // indirect 31 | github.com/fxamacker/cbor/v2 v2.7.0 // indirect 32 | github.com/go-json-experiment/json v0.0.0-20250223041408-d3c622f1b874 // indirect 33 | github.com/google/go-cmp v0.7.0 // indirect 34 | github.com/google/uuid v1.6.0 // indirect 35 | github.com/hdevalence/ed25519consensus v0.2.0 // indirect 36 | github.com/jsimonetti/rtnetlink v1.4.0 // indirect 37 | github.com/kortschak/goroutine v1.1.3 // indirect 38 | github.com/mdlayher/netlink v1.7.3-0.20250113171957-fbb4dce95f42 // indirect 39 | github.com/mdlayher/socket v0.5.0 // indirect 40 | github.com/mitchellh/go-ps v1.0.0 // indirect 41 | github.com/tailscale/go-winio v0.0.0-20231025203758-c4f33415bf55 // indirect 42 | github.com/x448/float16 v0.8.4 // indirect 43 | go4.org/mem v0.0.0-20240501181205-ae6ca9944745 // indirect 44 | go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect 45 | golang.org/x/crypto/x509roots/fallback v0.0.0-20250406160420-959f8f3db0fb // indirect 46 | golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac // indirect 47 | golang.org/x/sync v0.17.0 // indirect 48 | golang.org/x/sys v0.38.0 // indirect 49 | golang.org/x/text v0.30.0 // indirect 50 | golang.zx2c4.com/wireguard/windows v0.5.3 // indirect 51 | ) 52 | -------------------------------------------------------------------------------- /config/route.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "net/url" 7 | "strings" 8 | 9 | "fortio.org/log" 10 | ) 11 | 12 | type JSONURL struct { 13 | Str string 14 | URL url.URL 15 | } 16 | 17 | // Route configuration. Does Host/Prefix match to destination, see Match* functions. 18 | // (only host,port,scheme part of Destination URL are used). 19 | // User lowercase for the config. Incoming Host/Authority header will be lowercased. 20 | // Paths (prefix) are case sensitive. 21 | type Route struct { 22 | // Host or * or empty to match any host (* without a Prefix must be the last rule) 23 | Host string 24 | // Prefix or empty for any 25 | Prefix string 26 | // Destination url string. 27 | Destination JSONURL 28 | } 29 | 30 | func FromString(urlStr string) (JSONURL, error) { 31 | var u JSONURL 32 | // special shortcut so "localhost:3000" -> "http://localhost:3000" 33 | if !strings.HasPrefix(urlStr, "http") { 34 | urlStr = "http://" + urlStr 35 | } 36 | u.Str = "Proxy to " + urlStr 37 | url, err := url.Parse(urlStr) 38 | if err == nil { 39 | u.URL = *url 40 | } 41 | return u, err 42 | } 43 | 44 | // UnmarshalJSON is needed to get a URL from json 45 | // until golang does it on its own. 46 | func (j *JSONURL) UnmarshalJSON(b []byte) error { 47 | l := len(b) 48 | if l == 0 { 49 | return nil 50 | } 51 | l-- 52 | if l == 0 || b[0] != '"' || b[l] != '"' { 53 | return fmt.Errorf("invalid url string %q", b) 54 | } 55 | j.Str = "Proxy to " + string(b[1:l]) 56 | return j.URL.UnmarshalBinary(b[1:l]) 57 | } 58 | 59 | // Match checks if there is a match. 60 | // Path prefix has to match (or be empty) 61 | // Host has to match or route spec be "*" (last entry). 62 | 63 | func (r *Route) MatchServerReq(req *http.Request) bool { 64 | // Server requests have host:port in req.Host (and nothing host/port related in req.URL) 65 | return r.MatchHostAndPath(req.Host, req.URL.Path) 66 | } 67 | 68 | func (r *Route) MatchHostAndPath(hostPort, path string) bool { 69 | host := hostPort 70 | idx := strings.LastIndex(hostPort, ":") 71 | if idx != -1 && hostPort[len(hostPort)-1] != ']' { // could be [:some:ip:v6:addr] without :port 72 | host = hostPort[:idx] 73 | } 74 | host = strings.ToLower(host) 75 | log.LogVf("path is %q. req host is %q -> %q", path, hostPort, host) 76 | if r.Prefix != "" && !strings.HasPrefix(path, r.Prefix) { 77 | return false 78 | } 79 | if r.Host == "" || r.Host == "*" { 80 | return true 81 | } 82 | return r.Host == host 83 | } 84 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Go Reference](https://pkg.go.dev/badge/fortio.org/proxy.svg)](https://pkg.go.dev/fortio.org/proxy) 2 | [![Go Report Card](https://goreportcard.com/badge/fortio.org/proxy)](https://goreportcard.com/report/fortio.org/proxy) 3 | [![GitHub Release](https://img.shields.io/github/release/fortio/proxy.svg?style=flat)](https://github.com/fortio/proxy/releases/) 4 | [![govulncheck](https://img.shields.io/badge/govulncheck-No%20vulnerabilities-success)](https://github.com/fortio/proxy/actions/workflows/gochecks.yml) 5 | [![golangci-lint](https://img.shields.io/badge/golangci%20lint-No%20issue-success)](https://github.com/fortio/proxy/actions/workflows/gochecks.yml) 6 | 7 | 8 | # Fortio proxy 9 | 10 | Fortio simple TLS/ingress autocert proxy 11 | 12 | Front end for running fortio report for instance standalone with TLS / Autocert and routing rules to multiplex multiple service behind a common TLS ingress (works with and allows multiplexing of grpc and h2c servers too) 13 | 14 | Any -certs-domains ending with `.ts.net` will be handled by the Tailscale cert client (see https://tailscale.com/kb/1153/enabling-https). Or you can now specify `-tailscale` and it will get the local server name and domain automatically using the tailscale go client api. 15 | 16 | # Install 17 | 18 | using golang 1.20+ (improved ReverseProxy api and security from 1.18) 19 | 20 | ```shell 21 | go install fortio.org/proxy@latest 22 | sudo setcap CAP_NET_BIND_SERVICE=+eip $(which proxy) 23 | ``` 24 | 25 | If you don't need or want the tailscale support, add `-tags no_tailscale` for a much smaller binary. 26 | 27 | You can also download one of the many binary [releases](https://github.com/fortio/proxy/releases) 28 | 29 | We publish a multi architecture docker image (linux/amd64, linux/arm64) `docker run fortio/proxy` 30 | 31 | # Usage 32 | 33 | See example of setup in https://github.com/fortio/demo-deployment 34 | 35 | You can define routing rules using host or prefix matching, for instance: 36 | 37 | ```json 38 | [ 39 | { 40 | "host": "grpc.fortio.org", 41 | "destination": "http://127.0.0.1:8079" 42 | }, 43 | { 44 | "prefix": "/fgrpc.PingServer", 45 | "destination": "http://127.0.0.1:8079" 46 | }, 47 | { 48 | "prefix": "/grpc.health.v1.Health/Check", 49 | "destination": "http://127.0.0.1:8079" 50 | }, 51 | { 52 | "host": "*", 53 | "destination": "http://127.0.0.1:8080" 54 | } 55 | ] 56 | ``` 57 | 58 | And which domains/common names you will accept and request certificates for (coma separated list in `-certs-domains` flag or dynamic config directory) 59 | 60 | Optionally you can also configure `debug-host` for a Host (header, Authority in h2) that will serve a secured variant of fortio's debug handler for these requests: you can see it on [https://debug.fortio.org/a/random/test](https://debug.fortio.org/a/random/test) 61 | 62 | There is a simpler config for single/default route: 63 | If you want to setup TLS and forward everything to local (h2c) http server running on port 3000 64 | ``` 65 | go run fortio.org/proxy@latest -certs-domains ...your..server..full..name -h2 -default-route localhost:3000 66 | ``` 67 | (`http://` prefix can be omitted in the default route only) 68 | 69 | You can get full help/flags using 70 | ```sh 71 | proxy help 72 | ``` 73 | 74 | Use `-timeout 0` or a high value like `1h` if you're going to use it to download/upload large models or otherwise slow transactions. The default is 1 minute maximum. 75 | -------------------------------------------------------------------------------- /config/route_test.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "encoding/json" 5 | "net/http" 6 | "testing" 7 | 8 | "fortio.org/log" 9 | ) 10 | 11 | func TestMatch(t *testing.T) { 12 | // Do 2 tests at once, deserialize json and use "Destination" as a match against the rule itself: 13 | tests := []struct { 14 | jsonRoute string 15 | match bool 16 | }{ 17 | {`{"host": "www.google.com", "destination": "http://www.google.com/"}`, true}, // 0 18 | {`{"host": "*", "prefix": "/foo", "destination": "http://www.google.com/"}`, false}, // 1 19 | {`{"host": "*", "prefix": "/foo", "destination": "http://www.google.com/foo/bar"}`, true}, // 2 20 | {`{"host": "www.google.com", "prefix": "/test1", "destination": "hTTp://www.google.com/test1?foo=bar"}`, true}, // 3 21 | {`{"host": "www.google.com", "prefix": "/x/y", "destination": "http://www.google.com:80/x/y"}`, true}, // 4 22 | {`{"host": "www.google.com", "prefix": "/x/y", "destination": "http://www.google.com/x"}`, false}, // 5 23 | {`{"host": "www.google.com", "prefix": "/", "destination": "https://www.google.com/"}`, true}, // 6 24 | {`{"host": "www.google.com", "prefix": "/ab", "destination": "https://www.google.com:443/abc"}`, true}, // 7 25 | {`{"host": "www.google.com", "destination": "https://www.google.com/"}`, true}, // 8 26 | {`{"host": "www.google.com", "destination": "https://www.google.com:443/"}`, true}, // 9 27 | {`{"host": "www.google.com", "destination": "http://www.google.com:443/"}`, true}, // 10 28 | {`{"host": "www.google.com", "destination": "https://google.com/"}`, false}, // 11 29 | {`{"host": "[::1:2:3]", "destination": "http://[::1:2:4]/"}`, false}, // 12 30 | {`{"host": "[::1:2:3]", "destination": "https://[::1:2:3]:443/"}`, true}, // 13 31 | {`{"host": "[::1:2:3]", "destination": "http://[::1:2:3]:443/"}`, true}, // 14 32 | {`{"host": "[::1:2:3]", "destination": "https://[::1:2:3]:443/"}`, true}, // 15 33 | {`{"host": "[::1:2:3]", "destination": "https://[::1:2:3]:673/"}`, true}, // 16 34 | {`{"host": "[::1:2:3]", "prefix": "/x", "destination": "https://[::1:2:3]:673/y"}`, false}, // 17 35 | {`{"host": "[::1:2:3]", "prefix": "/x", "destination": "https://[::1:2:3]:673/x"}`, true}, // 18 36 | {`{"host": "www.google.com", "destination": "http://www.GOOGLE.com:443/"}`, true}, // 19 37 | } 38 | for i, tst := range tests { 39 | route := Route{} 40 | err := json.Unmarshal([]byte(tst.jsonRoute), &route) 41 | if err != nil { 42 | t.Errorf("unmarshal error: %v", err) 43 | } 44 | if route.Destination.URL.String() == "" || route.Host == "" { 45 | t.Errorf("Unexpected empty deserialization: %s -> %+v", tst.jsonRoute, route) 46 | } 47 | urlStr := route.Destination.URL.String() 48 | req, err := http.NewRequest(http.MethodGet, urlStr, nil) 49 | if err != nil { 50 | t.Errorf("Unable to deserialize %q %+v: %v", urlStr, req, err) 51 | } 52 | req.Host = req.URL.Host 53 | res := route.MatchServerReq(req) 54 | log.Infof("%d expecting %v got %v for H %s P %s D %s vs Req scheme %s host %s port %s", 55 | i, tst.match, res, route.Host, route.Prefix, 56 | route.Destination.URL.String(), req.URL.Scheme, req.URL.Host, req.URL.Port()) 57 | if res != tst.match { 58 | t.Errorf("Mismatch %d expected %v for H %s P %s D %s vs Req scheme %s host %s port %s", i, tst.match, route.Host, route.Prefix, 59 | route.Destination.URL.String(), req.URL.Scheme, req.URL.Host, req.URL.Port()) 60 | } 61 | } 62 | } 63 | 64 | func TestFromStr(t *testing.T) { 65 | tests := []struct { 66 | urlStr string 67 | err bool 68 | expected string // use "" for same as input 69 | }{ 70 | {"foo bar", true, ""}, 71 | {"http://www.google.com/", false, ""}, 72 | {"http:/localhost:8080/", false, ""}, 73 | {"localhost:8080", false, "http://localhost:8080"}, 74 | } 75 | for i, tst := range tests { 76 | u, err := FromString(tst.urlStr) 77 | if tst.err { //nolint:nestif // it's not that complicated (and it's a test) 78 | if err == nil { 79 | t.Errorf("Expected error parsing %q: %+v", tst.urlStr, u) 80 | } 81 | } else { 82 | if err != nil { 83 | t.Errorf("Unexpected error parsing %q: %v", tst.urlStr, err) 84 | } 85 | expected := tst.expected 86 | if expected == "" { 87 | expected = tst.urlStr 88 | } 89 | if u.URL.String() != expected { 90 | t.Errorf("Mismatch %d expected %v got %v", i, expected, u.URL.String()) 91 | } 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /proxy_main.go: -------------------------------------------------------------------------------- 1 | // Fortio TLS Reverse Proxy. 2 | // 3 | // (c) 2022 Laurent Demailly 4 | // See LICENSE 5 | 6 | package main 7 | 8 | import ( 9 | "context" 10 | "crypto/tls" 11 | "flag" 12 | "fmt" 13 | "net" 14 | "net/http" 15 | "os" 16 | "strings" 17 | "time" 18 | 19 | "fortio.org/cli" 20 | "fortio.org/dflag" 21 | "fortio.org/fortio/fhttp" 22 | "fortio.org/log" 23 | "fortio.org/proxy/config" 24 | "fortio.org/proxy/rp" 25 | "fortio.org/scli" 26 | "golang.org/x/crypto/acme/autocert" 27 | ) 28 | 29 | const ( 30 | disabled = "disabled" 31 | ) 32 | 33 | var ( 34 | email = dflag.DynString(flag.CommandLine, "email", "", "`Email` to attach to cert requests.") 35 | certsFor = dflag.DynStringSet(flag.CommandLine, "certs-domains", []string{}, 36 | "Coma separated list of `domains` to get certs for") 37 | certsDirectory = flag.String("certs-directory", ".", "Directory `path` where to store the certs") 38 | port = flag.String("https-port", ":443", "`port` to listen on for main reverse proxy and tls traffic") 39 | redirect = flag.String("redirect-port", ":80", "`port` to listen on for redirection") 40 | httpPort = flag.String("http-port", disabled, "`port` to listen on for non tls traffic (or 'disabled')") 41 | autoTailscale = flag.Bool("tailscale", false, "Automatically add tailscale hostname to the certificate list") 42 | timeout = flag.Duration("timeout", 1*time.Minute, 43 | "Maximum duration for each request read/writes proxying (eg 1h or use 0 for no timeout)") 44 | acert *autocert.Manager 45 | tailscale string 46 | ) 47 | 48 | func hostPolicy(_ context.Context, host string) error { 49 | log.LogVf("cert host policy called for %q", host) 50 | if tailscale != "" && host == tailscale { 51 | return nil 52 | } 53 | allowed := certsFor.Get() 54 | if _, found := allowed[host]; found { 55 | return nil 56 | } 57 | return fmt.Errorf("acme/autocert: %q not in allowed list", host) 58 | } 59 | 60 | func debugGetCert(hello *tls.ClientHelloInfo) (*tls.Certificate, error) { 61 | // Note: hello.ServerName is already lowercase. 62 | isTailscale := config.IsTailscale(hello.ServerName) 63 | log.LogVf("GetCert from %s for %q (tailscale %t)", 64 | hello.Conn.RemoteAddr().String(), hello.ServerName, isTailscale) 65 | if isTailscale { 66 | if err := hostPolicy(context.Background(), hello.ServerName); err != nil { 67 | return nil, err 68 | } 69 | return config.Tailscale().GetCertificate(hello) 70 | } 71 | return acert.GetCertificate(hello) 72 | } 73 | 74 | func main() { 75 | cli.ProgramName = "Fortio proxy" 76 | scli.ServerMain() 77 | // Only turns on debug host if configured at launch, 78 | // can be turned off or changed later through dynamic flags but not turned on if starting off 79 | debugHost := rp.DebugHost.Get() 80 | if *redirect != disabled { 81 | var a net.Addr 82 | if debugHost != "" { 83 | // Special case for debug host, redirect to https but also serve debug on that host 84 | a = fhttp.HTTPServerWithHandler("https redirector + debug", *redirect, rp.DebugOnHostHandler(fhttp.RedirectToHTTPSHandler)) 85 | } else { 86 | // Standard redirector without special debug host case 87 | a = fhttp.RedirectToHTTPS(*redirect) 88 | } 89 | if a == nil { 90 | os.Exit(1) // Error already logged 91 | } 92 | } 93 | if *autoTailscale { 94 | tailscale = config.TailscaleServerName() 95 | if tailscale == "" { 96 | os.Exit(1) // Error already logged 97 | } 98 | log.S(log.Info, "Will accept TLS requests and obtain certificate for tailscale", log.Any("server-name", tailscale)) 99 | } 100 | // Main reverse proxy handler (with debug if configured) 101 | var hdlr http.Handler 102 | hdlr = rp.ReverseProxy() 103 | if debugHost != "" { 104 | log.Warnf("Running Debug echo handler for any request matching Host %q", debugHost) 105 | hdlr = rp.DebugOnHostHandler(hdlr.ServeHTTP) // that's the reverse proxy + debug handler 106 | } 107 | 108 | s := &http.Server{ 109 | ReadTimeout: *timeout, 110 | WriteTimeout: *timeout, 111 | IdleTimeout: 15 * time.Second, 112 | ReadHeaderTimeout: 3 * time.Second, // reasonably small as the header are sent quickly for valid clients. 113 | // The reverse proxy (+debug if configured) 114 | Handler: hdlr, 115 | ErrorLog: log.NewStdLogger("rp", log.Error), 116 | } 117 | 118 | log.Printf("Fortio Proxy %s started - hostid %q - tailscale %t", cli.LongVersion, rp.HostID.Get(), config.HasTailscale) 119 | 120 | if *httpPort != disabled { 121 | fhttp.HTTPServerWithHandler("http-reverse-proxy", *httpPort, hdlr) 122 | } 123 | 124 | if *port == disabled { 125 | log.Infof("No TLS server port.") 126 | } else { 127 | go startTLSProxy(s) 128 | } 129 | scli.UntilInterrupted() 130 | } 131 | 132 | func startTLSProxy(s *http.Server) { 133 | s.Addr = *port 134 | emailStr := strings.TrimSpace(email.Get()) 135 | acert = &autocert.Manager{ 136 | Prompt: autocert.AcceptTOS, 137 | HostPolicy: hostPolicy, 138 | Cache: autocert.DirCache(*certsDirectory), 139 | Email: emailStr, 140 | } 141 | tlsCfg := acert.TLSConfig() 142 | tlsCfg.GetCertificate = debugGetCert 143 | tlsCfg.MinVersion = tls.VersionTLS12 144 | s.TLSConfig = tlsCfg 145 | currentMap := certsFor.Get() 146 | currentDomains := make([]string, len(currentMap)) 147 | i := 0 148 | for k := range currentMap { 149 | currentDomains[i] = k 150 | i++ 151 | } 152 | log.Infof("Starting TLS on %s for %v (%s) - certs directory %s", *port, currentDomains, acert.Email, *certsDirectory) 153 | err := s.ListenAndServeTLS("", "") 154 | if err != nil { 155 | log.Fatalf("ListendAndServeTLS(): %v", err) 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /rp/reverse_proxy.go: -------------------------------------------------------------------------------- 1 | package rp 2 | 3 | import ( 4 | "bytes" 5 | "context" 6 | "crypto/tls" 7 | "flag" 8 | "fmt" 9 | "io" 10 | "net" 11 | "net/http" 12 | "net/http/httputil" 13 | "sort" 14 | "strings" 15 | "time" 16 | 17 | "fortio.org/dflag" 18 | "fortio.org/fortio/fhttp" 19 | "fortio.org/fortio/version" 20 | "fortio.org/log" 21 | "fortio.org/proxy/config" 22 | "golang.org/x/net/http2" 23 | ) 24 | 25 | var ( 26 | configs = dflag.DynJSON(flag.CommandLine, "routes.json", &[]config.Route{}, "json list of `routes`") 27 | h2Target = flag.Bool("h2", false, "Whether destinations support h2c prior knowledge") 28 | HostID = dflag.DynString(flag.CommandLine, "hostid", "", "host id to show in debug-host output") 29 | startTime = time.Now() 30 | // DebugHost is theoptional fortio debug virtual host. 31 | DebugHost = dflag.DynString(flag.CommandLine, "debug-host", "", 32 | "`hostname` to serve echo debug info on if non-empty (ex: debug.fortio.org)") 33 | defaultRoute = dflag.DynString(flag.CommandLine, "default-route", "", 34 | "Default `url` to use if no match/no other routes.json is set") 35 | ) 36 | 37 | // GetRoutes gets the current routes from the dynamic flag routes.json as object (deserialized). 38 | func GetRoutes() []config.Route { 39 | routes := *configs.Get().(*[]config.Route) 40 | dr := defaultRoute.Get() 41 | if dr != "" { 42 | dest, err := config.FromString(dr) 43 | if err != nil { 44 | log.Errf("Error parsing default route %q: %v", dr, err) 45 | } 46 | routes = append(routes, config.Route{Host: "*", Destination: dest}) 47 | } 48 | return routes 49 | } 50 | 51 | const noRouteMarker = "no-route" 52 | 53 | // Rewrite is how incoming request are processed for the ReverseProxy 54 | // to pick the route/destination. 55 | func Rewrite(pr *httputil.ProxyRequest) { 56 | routes := GetRoutes() 57 | log.LogVf("RP rewrite %+v", pr) 58 | req := pr.In 59 | for _, route := range routes { 60 | log.LogVf("Evaluating req %q vs route %q and path %q vs prefix %q for dest %s", 61 | req.Host, route.Host, req.URL.Path, route.Prefix, route.Destination.URL.String()) 62 | if route.MatchServerReq(req) { 63 | pr.SetXForwarded() 64 | pr.SetURL(&route.Destination.URL) 65 | log.LogRequest(req, route.Destination.Str) 66 | return 67 | } 68 | } 69 | // No route matched, log and return 404. 70 | log.Errf("No route matched for %q %q", req.Host, req.URL.Path) 71 | pr.Out.URL.Scheme = noRouteMarker 72 | } 73 | 74 | // ErrorHandler is the error handler for the ReverseProxy. We use 75 | // a Scheme marker to know that the error is just there was no route 76 | // and treat that as 404 and everything else remains a 502. 77 | func ErrorHandler(w http.ResponseWriter, r *http.Request, err error) { 78 | if r.URL.Scheme == noRouteMarker { 79 | http.Error(w, "No route matched", http.StatusNotFound) 80 | } else { 81 | log.Errf("Proxy error: %v", err) 82 | w.WriteHeader(http.StatusBadGateway) 83 | } 84 | } 85 | 86 | // PrintRoutes prints the current value of the routes config (dflag). 87 | func PrintRoutes() { 88 | if !log.Log(log.Info) { 89 | return 90 | } 91 | log.Printf("Initial Routes (routes.json and default-route dynamic flags):") 92 | for _, r := range GetRoutes() { 93 | log.Printf("host %q\t prefix %q\t -> %s", r.Host, r.Prefix, r.Destination.URL.String()) 94 | } 95 | } 96 | 97 | // ReverseProxy returns a new reverse proxy which will route based on the config/dflags. 98 | func ReverseProxy() *httputil.ReverseProxy { 99 | PrintRoutes() 100 | 101 | revp := httputil.ReverseProxy{ 102 | Rewrite: Rewrite, 103 | ErrorHandler: ErrorHandler, 104 | } 105 | 106 | // TODO: make h2c vs regular client more dynamic based on route config instead of all or nothing 107 | // (or maybe some day it will just ge the default behavior of the base http client) 108 | if *h2Target { 109 | revp.Transport = &http2.Transport{ 110 | AllowHTTP: true, 111 | DialTLSContext: func(ctx context.Context, network, addr string, _ *tls.Config) (net.Conn, error) { 112 | dialer := &net.Dialer{} 113 | return dialer.DialContext(ctx, network, addr) 114 | }, 115 | } 116 | } 117 | return &revp 118 | } 119 | 120 | // GzipDebugHandler is a handler wrapping SafeDebugHandler with optional gzip compression. 121 | var GzipDebugHandler = fhttp.Gzip(http.HandlerFunc(SafeDebugHandler)) 122 | 123 | // SafeDebugHandler is similar to Fortio's DebugHandler, 124 | // it returns debug/useful info to http client. 125 | // but doesn't have some of the extra sensitive info like env dump 126 | // and host name or echo delay or header setting options. 127 | func SafeDebugHandler(w http.ResponseWriter, r *http.Request) { 128 | log.LogRequest(r, "Debug") 129 | w.Header().Set("Content-Type", "text/plain; charset=UTF-8") 130 | var buf bytes.Buffer 131 | buf.WriteString("Φορτίο version ") 132 | buf.WriteString(version.Long()) 133 | buf.WriteString("\nDebug server") 134 | id := HostID.Get() 135 | if id != "" { 136 | buf.WriteString(" on ") 137 | buf.WriteString(id) 138 | } 139 | buf.WriteString(" up for ") 140 | buf.WriteString(fmt.Sprint(fhttp.RoundDuration(time.Since(startTime)))) 141 | buf.WriteString("\nRequest from ") 142 | buf.WriteString(r.RemoteAddr) 143 | buf.WriteString(log.TLSInfo(r)) 144 | buf.WriteString("\n\n") 145 | buf.WriteString(r.Method) 146 | buf.WriteByte(' ') 147 | buf.WriteString(r.URL.String()) 148 | buf.WriteByte(' ') 149 | buf.WriteString(r.Proto) 150 | buf.WriteString("\n\nheaders:\n\n") 151 | // Host is removed from headers map and put here (!) 152 | buf.WriteString("Host: ") 153 | buf.WriteString(r.Host) 154 | 155 | keys := make([]string, 0, len(r.Header)) 156 | for k := range r.Header { 157 | keys = append(keys, k) 158 | } 159 | sort.Strings(keys) 160 | for _, name := range keys { 161 | buf.WriteByte('\n') 162 | buf.WriteString(name) 163 | buf.WriteString(": ") 164 | first := true 165 | headers := r.Header[name] 166 | for _, h := range headers { 167 | if !first { 168 | buf.WriteByte(',') 169 | } 170 | buf.WriteString(h) 171 | first = false 172 | } 173 | } 174 | data, err := io.ReadAll(r.Body) 175 | if err != nil { 176 | log.Errf("Error reading %v", err) 177 | http.Error(w, err.Error(), http.StatusInternalServerError) 178 | return 179 | } 180 | buf.WriteString("\n\nbody:\n\n") 181 | buf.WriteString(fhttp.DebugSummary(data, 512)) 182 | buf.WriteByte('\n') 183 | if _, err = w.Write(buf.Bytes()); err != nil { 184 | log.Errf("Error writing response %v to %v", err, r.RemoteAddr) 185 | } 186 | } 187 | 188 | func DebugOnHostHandler(normalHandler http.HandlerFunc) http.HandlerFunc { 189 | return func(w http.ResponseWriter, r *http.Request) { 190 | debugHost := DebugHost.Get() 191 | if debugHost != "" && strings.ToLower(r.Host) == debugHost && r.URL.Path != "/favicon.ico" { 192 | GzipDebugHandler.ServeHTTP(w, r) 193 | } else { 194 | normalHandler(w, r) 195 | } 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= 2 | filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= 3 | fortio.org/assert v1.2.1 h1:48I39urpeDj65RP1KguF7akCjILNeu6vICiYMEysR7Q= 4 | fortio.org/assert v1.2.1/go.mod h1:039mG+/iYDPO8Ibx8TrNuJCm2T2SuhwRI3uL9nHTTls= 5 | fortio.org/cli v1.12.3 h1:PoqlAgkClqEv9Ztj4HK/J55UodnTc3Z+Ignm0ggyei4= 6 | fortio.org/cli v1.12.3/go.mod h1:miR0uK+QAJLctpMGeeYvuS/8SldOVJ5jyDl8d+bes8Q= 7 | fortio.org/dflag v1.9.3 h1:1E/flKspJ18H/RC6uqxUf8F1t0htpBS9XF5otT4iRwQ= 8 | fortio.org/dflag v1.9.3/go.mod h1:+FrKhZpKDqRbcfFcS9P0sY2WN/kc231dXuwpzfsLjzc= 9 | fortio.org/duration v1.0.4 h1:TB07ng4UsMZPDRujJRkTJIcNqMTLM283zob10nb9K24= 10 | fortio.org/duration v1.0.4/go.mod h1:RuBVqdcCKRwMmI8WIdVq8kd7ngQPCIe6G7AU0NC0XDw= 11 | fortio.org/fortio v1.73.0 h1:ZQU9uuzn7bF5Fvk3G/qyTQoRUUYdMLOWPsUr0RRhQ3k= 12 | fortio.org/fortio v1.73.0/go.mod h1:GM5lxkq25ukAxcgwTPjzT8L9QBddzBvvCW0NvI9Xlj8= 13 | fortio.org/log v1.18.3 h1:2kwEUise3faY4OouueQ/1tC+75Y2YGJjJaX2/ECmu4I= 14 | fortio.org/log v1.18.3/go.mod h1:vqpyEZd/TP4xO5eAHQaa4buDZDCn1AxCAV+wl3eaTec= 15 | fortio.org/safecast v1.2.0 h1:ckQJNenMJHycqPsi/QrzA4EUX5WQkyd+hGO4mxt/a8w= 16 | fortio.org/safecast v1.2.0/go.mod h1:xZmcPk3vi4kuUFf+tq4SvnlVdwViqf6ZSZl91Jr9Jdg= 17 | fortio.org/scli v1.19.0 h1:3nr1BzCmKds6Ms7O33sjM0r/y9N4ZCEeFZ6kCzI/ii0= 18 | fortio.org/scli v1.19.0/go.mod h1:cgaXS0ccxZl6i9pRn6rZQTtoRVeopu17XyvDdEeZpNE= 19 | fortio.org/sets v1.3.0 h1:UiEtck/ndNM3Tg53mJu3I7Zz1ED8+YSQLtPKSjd8LTE= 20 | fortio.org/sets v1.3.0/go.mod h1:y8fFzm4bPTk3Qfr/tF3Xz7oWwgzpy++QdkwURKhNbP4= 21 | fortio.org/struct2env v0.4.2 h1:Xh7HlS9vf2ZdRvRfmoGIasNDO8t6z36M713utVODRCo= 22 | fortio.org/struct2env v0.4.2/go.mod h1:lENUe70UwA1zDUCX+8AsO663QCFqYaprk5lnPhjD410= 23 | fortio.org/version v1.0.4 h1:FWUMpJ+hVTNc4RhvvOJzb0xesrlRmG/a+D6bjbQ4+5U= 24 | fortio.org/version v1.0.4/go.mod h1:2JQp9Ax+tm6QKiGuzR5nJY63kFeANcgrZ0osoQFDVm0= 25 | github.com/akutz/memconn v0.1.0 h1:NawI0TORU4hcOMsMr11g7vwlCdkYeLKXBcxWu2W/P8A= 26 | github.com/akutz/memconn v0.1.0/go.mod h1:Jo8rI7m0NieZyLI5e2CDlRdRqRRB4S7Xp77ukDjH+Fw= 27 | github.com/alexbrainman/sspi v0.0.0-20231016080023-1a75b4708caa h1:LHTHcTQiSGT7VVbI0o4wBRNQIgn917usHWOd6VAffYI= 28 | github.com/alexbrainman/sspi v0.0.0-20231016080023-1a75b4708caa/go.mod h1:cEWa1LVoE5KvSD9ONXsZrj0z6KqySlCCNKHlLzbqAt4= 29 | github.com/cilium/ebpf v0.15.0 h1:7NxJhNiBT3NG8pZJ3c+yfrVdHY8ScgKD27sScgjLMMk= 30 | github.com/cilium/ebpf v0.15.0/go.mod h1:DHp1WyrLeiBh19Cf/tfiSMhqheEiK8fXFZ4No0P1Hso= 31 | github.com/coder/websocket v1.8.12 h1:5bUXkEPPIbewrnkU8LTCLVaxi4N4J8ahufH2vlo4NAo= 32 | github.com/coder/websocket v1.8.12/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs= 33 | github.com/coreos/go-iptables v0.7.1-0.20240112124308-65c67c9f46e6 h1:8h5+bWd7R6AYUslN6c6iuZWTKsKxUFDlpnmilO6R2n0= 34 | github.com/coreos/go-iptables v0.7.1-0.20240112124308-65c67c9f46e6/go.mod h1:Qe8Bv2Xik5FyTXwgIbLAnv2sWSBmvWdFETJConOQ//Q= 35 | github.com/creachadair/taskgroup v0.13.2 h1:3KyqakBuFsm3KkXi/9XIb0QcA8tEzLHLgaoidf0MdVc= 36 | github.com/creachadair/taskgroup v0.13.2/go.mod h1:i3V1Zx7H8RjwljUEeUWYT30Lmb9poewSb2XI1yTwD0g= 37 | github.com/dblohm7/wingoes v0.0.0-20240119213807-a09d6be7affa h1:h8TfIT1xc8FWbwwpmHn1J5i43Y0uZP97GqasGCzSRJk= 38 | github.com/dblohm7/wingoes v0.0.0-20240119213807-a09d6be7affa/go.mod h1:Nx87SkVqTKd8UtT+xu7sM/l+LgXs6c0aHrlKusR+2EQ= 39 | github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= 40 | github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= 41 | github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M= 42 | github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= 43 | github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E= 44 | github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ= 45 | github.com/gaissmai/bart v0.18.0 h1:jQLBT/RduJu0pv/tLwXE+xKPgtWJejbxuXAR+wLJafo= 46 | github.com/gaissmai/bart v0.18.0/go.mod h1:JJzMAhNF5Rjo4SF4jWBrANuJfqY+FvsFhW7t1UZJ+XY= 47 | github.com/go-json-experiment/json v0.0.0-20250223041408-d3c622f1b874 h1:F8d1AJ6M9UQCavhwmO6ZsrYLfG8zVFWfEfMS2MXPkSY= 48 | github.com/go-json-experiment/json v0.0.0-20250223041408-d3c622f1b874/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M= 49 | github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= 50 | github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= 51 | github.com/godbus/dbus/v5 v5.1.1-0.20230522191255-76236955d466 h1:sQspH8M4niEijh3PFscJRLDnkL547IeP7kpPe3uUhEg= 52 | github.com/godbus/dbus/v5 v5.1.1-0.20230522191255-76236955d466/go.mod h1:ZiQxhyQ+bbbfxUKVvjfO498oPYvtYhZzycal3G/NHmU= 53 | github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= 54 | github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 55 | github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU= 56 | github.com/google/btree v1.1.2/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4= 57 | github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= 58 | github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= 59 | github.com/google/nftables v0.2.1-0.20240414091927-5e242ec57806 h1:wG8RYIyctLhdFk6Vl1yPGtSRtwGpVkWyZww1OCil2MI= 60 | github.com/google/nftables v0.2.1-0.20240414091927-5e242ec57806/go.mod h1:Beg6V6zZ3oEn0JuiUQ4wqwuyqqzasOltcoXPtgLbFp4= 61 | github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= 62 | github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 63 | github.com/hdevalence/ed25519consensus v0.2.0 h1:37ICyZqdyj0lAZ8P4D1d1id3HqbbG1N3iBb1Tb4rdcU= 64 | github.com/hdevalence/ed25519consensus v0.2.0/go.mod h1:w3BHWjwJbFU29IRHL1Iqkw3sus+7FctEyM4RqDxYNzo= 65 | github.com/illarion/gonotify/v3 v3.0.2 h1:O7S6vcopHexutmpObkeWsnzMJt/r1hONIEogeVNmJMk= 66 | github.com/illarion/gonotify/v3 v3.0.2/go.mod h1:HWGPdPe817GfvY3w7cx6zkbzNZfi3QjcBm/wgVvEL1U= 67 | github.com/jsimonetti/rtnetlink v1.4.0 h1:Z1BF0fRgcETPEa0Kt0MRk3yV5+kF1FWTni6KUFKrq2I= 68 | github.com/jsimonetti/rtnetlink v1.4.0/go.mod h1:5W1jDvWdnthFJ7fxYX1GMK07BUpI4oskfOqvPteYS6E= 69 | github.com/kortschak/goroutine v1.1.3 h1:kELvAfi7jpVD7a+MPWjmIxuQVJVYo/RELaOeGJZBb88= 70 | github.com/kortschak/goroutine v1.1.3/go.mod h1:zKpXs1FWN/6mXasDQzfl7g0LrGFIOiA6cLs9eXKyaMY= 71 | github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= 72 | github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= 73 | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 74 | github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 75 | github.com/mdlayher/genetlink v1.3.2 h1:KdrNKe+CTu+IbZnm/GVUMXSqBBLqcGpRDa0xkQy56gw= 76 | github.com/mdlayher/genetlink v1.3.2/go.mod h1:tcC3pkCrPUGIKKsCsp0B3AdaaKuHtaxoJRz3cc+528o= 77 | github.com/mdlayher/netlink v1.7.3-0.20250113171957-fbb4dce95f42 h1:A1Cq6Ysb0GM0tpKMbdCXCIfBclan4oHk1Jb+Hrejirg= 78 | github.com/mdlayher/netlink v1.7.3-0.20250113171957-fbb4dce95f42/go.mod h1:BB4YCPDOzfy7FniQ/lxuYQ3dgmM2cZumHbK8RpTjN2o= 79 | github.com/mdlayher/socket v0.5.0 h1:ilICZmJcQz70vrWVes1MFera4jGiWNocSkykwwoy3XI= 80 | github.com/mdlayher/socket v0.5.0/go.mod h1:WkcBFfvyG8QENs5+hfQPl1X6Jpd2yeLIYgrGFmJiJxI= 81 | github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc= 82 | github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg= 83 | github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= 84 | github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= 85 | github.com/tailscale/go-winio v0.0.0-20231025203758-c4f33415bf55 h1:Gzfnfk2TWrk8Jj4P4c1a3CtQyMaTVCznlkLZI++hok4= 86 | github.com/tailscale/go-winio v0.0.0-20231025203758-c4f33415bf55/go.mod h1:4k4QO+dQ3R5FofL+SanAUZe+/QfeK0+OIuwDIRu2vSg= 87 | github.com/tailscale/netlink v1.1.1-0.20240822203006-4d49adab4de7 h1:uFsXVBE9Qr4ZoF094vE6iYTLDl0qCiKzYXlL6UeWObU= 88 | github.com/tailscale/netlink v1.1.1-0.20240822203006-4d49adab4de7/go.mod h1:NzVQi3Mleb+qzq8VmcWpSkcSYxXIg0DkI6XDzpVkhJ0= 89 | github.com/tailscale/wireguard-go v0.0.0-20250716170648-1d0488a3d7da h1:jVRUZPRs9sqyKlYHHzHjAqKN+6e/Vog6NpHYeNPJqOw= 90 | github.com/tailscale/wireguard-go v0.0.0-20250716170648-1d0488a3d7da/go.mod h1:BOm5fXUBFM+m9woLNBoxI9TaBXXhGNP50LX/TGIvGb4= 91 | github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8= 92 | github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM= 93 | github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= 94 | github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= 95 | go4.org/mem v0.0.0-20240501181205-ae6ca9944745 h1:Tl++JLUCe4sxGu8cTpDzRLd3tN7US4hOxG5YpKCzkek= 96 | go4.org/mem v0.0.0-20240501181205-ae6ca9944745/go.mod h1:reUoABIJ9ikfM5sgtSF3Wushcza7+WeD01VB9Lirh3g= 97 | go4.org/netipx v0.0.0-20231129151722-fdeea329fbba h1:0b9z3AuHCjxk0x/opv64kcgZLBseWJUpBw5I82+2U4M= 98 | go4.org/netipx v0.0.0-20231129151722-fdeea329fbba/go.mod h1:PLyyIXexvUFg3Owu6p/WfdlivPbZJsZdgWZlrGope/Y= 99 | golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04= 100 | golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0= 101 | golang.org/x/crypto/x509roots/fallback v0.0.0-20250406160420-959f8f3db0fb h1:Iu0p/klM0SM7atONioa/bPhLS7cjhnip99x1OIGibwg= 102 | golang.org/x/crypto/x509roots/fallback v0.0.0-20250406160420-959f8f3db0fb/go.mod h1:lxN5T34bK4Z/i6cMaU7frUU57VkDXFD4Kamfl/cp9oU= 103 | golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac h1:l5+whBCLH3iH2ZNHYLbAe58bo7yrN4mVcnkHDYz5vvs= 104 | golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac/go.mod h1:hH+7mtFmImwwcMvScyxUhjuVHR3HGaDPMn9rMSUUbxo= 105 | golang.org/x/mod v0.28.0 h1:gQBtGhjxykdjY9YhZpSlZIsbnaE2+PgjfLWUQTnoZ1U= 106 | golang.org/x/mod v0.28.0/go.mod h1:yfB/L0NOf/kmEbXjzCPOx1iK1fRutOydrCMsqRhEBxI= 107 | golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4= 108 | golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210= 109 | golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= 110 | golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= 111 | golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc= 112 | golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= 113 | golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k= 114 | golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM= 115 | golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0= 116 | golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg= 117 | golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 h1:B82qJJgjvYKsXS9jeunTOisW56dUokqW/FOteYJJ/yg= 118 | golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2/go.mod h1:deeaetjYA+DHMHg+sMSMI58GrEteJUUzzw7en6TJQcI= 119 | golang.zx2c4.com/wireguard/windows v0.5.3 h1:On6j2Rpn3OEMXqBq00QEDC7bWSZrPIHKIus8eIuExIE= 120 | golang.zx2c4.com/wireguard/windows v0.5.3/go.mod h1:9TEe8TJmtwyQebdFwAkEWOPr3prrtqm+REGFifP60hI= 121 | gvisor.dev/gvisor v0.0.0-20250205023644-9414b50a5633 h1:2gap+Kh/3F47cO6hAu3idFvsJ0ue6TRcEi2IUkv/F8k= 122 | gvisor.dev/gvisor v0.0.0-20250205023644-9414b50a5633/go.mod h1:5DMfjtclAbTIjbXqO1qCe2K5GKKxWz2JHvCChuTcJEM= 123 | tailscale.com v1.86.5 h1:yBtWFjuLYDmxVnfnvPbZNZcKADCYgNfMd0rUAOA9XCs= 124 | tailscale.com v1.86.5/go.mod h1:Lm8dnzU2i/Emw15r6sl3FRNp/liSQ/nYw6ZSQvIdZ1M= 125 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------