mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-09 17:43:40 +00:00
cmd/tsidp: fix tsnet listener
Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
parent
93664ac8dc
commit
3fa5c76cba
@ -56,6 +56,8 @@ func main() {
|
|||||||
lc *tailscale.LocalClient
|
lc *tailscale.LocalClient
|
||||||
st *ipnstate.Status
|
st *ipnstate.Status
|
||||||
err error
|
err error
|
||||||
|
|
||||||
|
lns []net.Listener
|
||||||
)
|
)
|
||||||
if *flagUseLocalTailscaled {
|
if *flagUseLocalTailscaled {
|
||||||
lc = &tailscale.LocalClient{}
|
lc = &tailscale.LocalClient{}
|
||||||
@ -63,6 +65,23 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("getting status: %v", err)
|
log.Fatalf("getting status: %v", err)
|
||||||
}
|
}
|
||||||
|
portStr := fmt.Sprint(*flagPort)
|
||||||
|
anySuccess := false
|
||||||
|
for _, ip := range st.TailscaleIPs {
|
||||||
|
ln, err := net.Listen("tcp", net.JoinHostPort(ip.String(), portStr))
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("failed to listen on %v: %v", ip, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
anySuccess = true
|
||||||
|
ln = tls.NewListener(ln, &tls.Config{
|
||||||
|
GetCertificate: lc.GetCertificate,
|
||||||
|
})
|
||||||
|
lns = append(lns, ln)
|
||||||
|
}
|
||||||
|
if !anySuccess {
|
||||||
|
log.Fatalf("failed to listen on any of %v", st.TailscaleIPs)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ts := &tsnet.Server{
|
ts := &tsnet.Server{
|
||||||
Hostname: "idp",
|
Hostname: "idp",
|
||||||
@ -78,34 +97,38 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("getting local client: %v", err)
|
log.Fatalf("getting local client: %v", err)
|
||||||
}
|
}
|
||||||
|
ln, err := ts.ListenTLS("tcp", fmt.Sprintf(":%d", *flagPort))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
lns = append(lns, ln)
|
||||||
}
|
}
|
||||||
|
|
||||||
srv := &idpServer{
|
srv := &idpServer{
|
||||||
lc: lc,
|
lc: lc,
|
||||||
serverURL: fmt.Sprintf("https://%s:%d", strings.TrimSuffix(st.Self.DNSName, "."), *flagPort),
|
|
||||||
}
|
}
|
||||||
|
if *flagPort != 443 {
|
||||||
|
srv.serverURL = fmt.Sprintf("https://%s:%d", strings.TrimSuffix(st.Self.DNSName, "."), *flagPort)
|
||||||
|
} else {
|
||||||
|
srv.serverURL = fmt.Sprintf("https://%s", strings.TrimSuffix(st.Self.DNSName, "."))
|
||||||
|
}
|
||||||
|
|
||||||
log.Printf("Running tsidp at %s ...", srv.serverURL)
|
log.Printf("Running tsidp at %s ...", srv.serverURL)
|
||||||
|
|
||||||
if *flagLocalPort != -1 {
|
if *flagLocalPort != -1 {
|
||||||
|
log.Printf("Also running tsidp at %s ...", srv.loopbackURL)
|
||||||
srv.loopbackURL = fmt.Sprintf("http://localhost:%d", *flagLocalPort)
|
srv.loopbackURL = fmt.Sprintf("http://localhost:%d", *flagLocalPort)
|
||||||
go func() {
|
ln, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", *flagLocalPort))
|
||||||
ln, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", *flagLocalPort))
|
if err != nil {
|
||||||
if err != nil {
|
log.Fatal(err)
|
||||||
log.Fatal(err)
|
}
|
||||||
}
|
lns = append(lns, ln)
|
||||||
log.Printf("Also running tsidp at %s ...", srv.loopbackURL)
|
|
||||||
http.Serve(ln, srv)
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ln, err := net.Listen("tcp", fmt.Sprintf("%s:%d", st.TailscaleIPs[0], *flagPort))
|
for _, ln := range lns {
|
||||||
if err != nil {
|
go http.Serve(ln, srv)
|
||||||
log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
ln = tls.NewListener(ln, &tls.Config{
|
select {}
|
||||||
GetCertificate: lc.GetCertificate,
|
|
||||||
})
|
|
||||||
log.Fatal(http.Serve(ln, srv))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type idpServer struct {
|
type idpServer struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user