mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-24 17:48:57 +00:00
cmd/sniproxy: add port forwarding and prometheus metrics
1. Add TCP port forwarding. For example: ./sniproxy -forwards=tcp/22/github.com will forward SSH to github. % ssh -i ~/.ssh/id_ecdsa.pem -T git@github.com Hi GitHubUser! You've successfully authenticated, but GitHub does not provide shell access. % ssh -i ~/.ssh/id_ecdsa.pem -T git@100.65.x.y Hi GitHubUser! You've successfully authenticated, but GitHub does not provide shell access. 2. Additionally export clientmetrics as prometheus metrics for local scraping over the tailnet: http://sniproxy-hostname:8080/debug/varz Updates https://github.com/tailscale/tailscale/issues/1748 Signed-off-by: Denton Gentry <dgentry@tailscale.com>
This commit is contained in:
committed by
Denton Gentry
parent
98a5116434
commit
24d41e4ae7
37
cmd/sniproxy/sniproxy_test.go
Normal file
37
cmd/sniproxy/sniproxy_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
func TestPortForwardingArguments(t *testing.T) {
|
||||
tests := []struct {
|
||||
in string
|
||||
wanterr string
|
||||
want *portForward
|
||||
}{
|
||||
{"", "", nil},
|
||||
{"bad port specifier", "cannot parse", nil},
|
||||
{"tcp/xyz/example.com", "bad forwarding port", nil},
|
||||
{"tcp//example.com", "bad forwarding port", nil},
|
||||
{"tcp/2112/", "bad destination", nil},
|
||||
{"udp/53/example.com", "unsupported forwarding protocol", nil},
|
||||
{"tcp/22/github.com", "", &portForward{Proto: "tcp", Port: 22, Destination: "github.com"}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
got, goterr := parseForward(tt.in)
|
||||
if tt.wanterr != "" {
|
||||
if !strings.Contains(goterr.Error(), tt.wanterr) {
|
||||
t.Errorf("f(%q).err = %v; want %v", tt.in, goterr, tt.wanterr)
|
||||
}
|
||||
} else if diff := cmp.Diff(got, tt.want); diff != "" {
|
||||
t.Errorf("Parsed forward (-got, +want):\n%s", diff)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user