Skip to content

Commit e0d291a

Browse files
Maisem Alimaisem
Maisem Ali
authored andcommitted
ipn/store: add support for stores to hook into a custom dialer
For stores like k8s secrets we need to dial out to the k8s API as though Tailscale wasn't running. The issue currently only manifests when you try to use an exit node while running inside a k8s cluster and are trying to use Kubernetes secrets as the backing store. This doesn't address cmd/containerboot, which I'll do in a follow up. Updates tailscale#7695 Signed-off-by: Maisem Ali <[email protected]>
1 parent 2b00d69 commit e0d291a

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

ipn/ipnlocal/local.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ func NewLocalBackend(logf logger.Logf, logID logid.PublicID, store ipn.StateStor
276276
if err != nil {
277277
return nil, err
278278
}
279+
if sds, ok := store.(ipn.StateStoreDialerSetter); ok {
280+
sds.SetDialer(dialer.SystemDial)
281+
}
279282

280283
hi := hostinfo.New()
281284
logf.JSON(1, "Hostinfo", hi)

ipn/store.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
package ipn
55

66
import (
7+
"context"
78
"errors"
89
"fmt"
10+
"net"
911
"strconv"
1012
)
1113

@@ -72,6 +74,12 @@ type StateStore interface {
7274
WriteState(id StateKey, bs []byte) error
7375
}
7476

77+
// StateStoreDialerSetter is an optional interface that StateStores
78+
// can implement to allow the caller to set a custom dialer.
79+
type StateStoreDialerSetter interface {
80+
SetDialer(d func(ctx context.Context, network, address string) (net.Conn, error))
81+
}
82+
7583
// ReadStoreInt reads an integer from a StateStore.
7684
func ReadStoreInt(store StateStore, id StateKey) (int64, error) {
7785
v, err := store.ReadState(id)

ipn/store/kubestore/store_kube.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package kubestore
77

88
import (
99
"context"
10+
"net"
1011
"strings"
1112
"time"
1213

@@ -33,6 +34,10 @@ func New(_ logger.Logf, secretName string) (*Store, error) {
3334
}, nil
3435
}
3536

37+
func (s *Store) SetDialer(d func(ctx context.Context, network, address string) (net.Conn, error)) {
38+
s.client.SetDialer(d)
39+
}
40+
3641
func (s *Store) String() string { return "kube.Store" }
3742

3843
// ReadState implements the StateStore interface.

kube/client.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"fmt"
1616
"io"
1717
"log"
18+
"net"
1819
"net/http"
1920
"net/url"
2021
"os"
@@ -90,6 +91,12 @@ func (c *Client) SetURL(url string) {
9091
c.url = url
9192
}
9293

94+
// SetDialer sets the dialer to use when establishing a connection
95+
// to the Kubernetes API server.
96+
func (c *Client) SetDialer(dialer func(ctx context.Context, network, addr string) (net.Conn, error)) {
97+
c.client.Transport.(*http.Transport).DialContext = dialer
98+
}
99+
93100
func (c *Client) expireToken() {
94101
c.mu.Lock()
95102
defer c.mu.Unlock()

0 commit comments

Comments
 (0)