summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@tailscale.com>2022-06-27 21:23:48 -0700
committerBrad Fitzpatrick <brad@danga.com>2022-06-27 21:57:57 -0700
commit3ac8ab17917095ce13495c8093f310f2bbfe6d4a (patch)
tree370e6b60427addfb32847af581be48e75ce6a7d3
parentbef6e2831a9b03e77ce1276ce94f8295061becc4 (diff)
downloadtailscale-3ac8ab17917095ce13495c8093f310f2bbfe6d4a.tar.xz
tailscale-3ac8ab17917095ce13495c8093f310f2bbfe6d4a.zip
tsnet: add Server.AuthKey field
... so callers can provide the AuthKey via mechanisms other than environment variables which means multiple Servers can't be started concurrently in the same process without coordination. Change-Id: I7736ef4f59b7cc29637939e140e990613ce58e0d Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
-rw-r--r--tsnet/tsnet.go18
1 files changed, 16 insertions, 2 deletions
diff --git a/tsnet/tsnet.go b/tsnet/tsnet.go
index 5d2dc65b6..4990c208d 100644
--- a/tsnet/tsnet.go
+++ b/tsnet/tsnet.go
@@ -74,6 +74,13 @@ type Server struct {
// as an Ephemeral node (https://tailscale.com/kb/1111/ephemeral-nodes/).
Ephemeral bool
+ // AuthKey, if non-empty, is the auth key to create the node
+ // and will be preferred over the TS_AUTHKEY environment
+ // variable. If the node is already created (from state
+ // previously stored in in Store), then this field is not
+ // used.
+ AuthKey string
+
initOnce sync.Once
initErr error
lb *ipnlocal.LocalBackend
@@ -151,6 +158,13 @@ func (s *Server) doInit() {
}
}
+func (s *Server) getAuthKey() string {
+ if v := s.AuthKey; v != "" {
+ return v
+ }
+ return os.Getenv("TS_AUTHKEY")
+}
+
func (s *Server) start() error {
exe, err := os.Executable()
if err != nil {
@@ -292,7 +306,7 @@ func (s *Server) start() error {
prefs := ipn.NewPrefs()
prefs.Hostname = s.hostname
prefs.WantRunning = true
- authKey := os.Getenv("TS_AUTHKEY")
+ authKey := s.getAuthKey()
err = lb.Start(ipn.Options{
StateKey: ipn.GlobalDaemonStateKey,
UpdatePrefs: prefs,
@@ -306,7 +320,7 @@ func (s *Server) start() error {
logf("LocalBackend state is %v; running StartLoginInteractive...", st)
s.lb.StartLoginInteractive()
} else if authKey != "" {
- logf("TS_AUTHKEY is set; but state is %v. Ignoring authkey. Re-run with TSNET_FORCE_LOGIN=1 to force use of authkey.", st)
+ logf("Authkey is set; but state is %v. Ignoring authkey. Re-run with TSNET_FORCE_LOGIN=1 to force use of authkey.", st)
}
go s.printAuthURLLoop()