From 3f087466f50c30d7c793f73577fdf4a4f53c013b Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Thu, 9 Apr 2020 17:16:36 +1000 Subject: [PATCH] controlclient: add auth key Signed-off-by: David Crawshaw --- control/controlclient/direct.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/control/controlclient/direct.go b/control/controlclient/direct.go index 56a8f30c0..03e51715e 100644 --- a/control/controlclient/direct.go +++ b/control/controlclient/direct.go @@ -83,6 +83,7 @@ type Direct struct { mu sync.Mutex // mutex guards the following fields serverKey wgcfg.Key persist Persist + authKey string tryingNewKey wgcfg.PrivateKey expiry *time.Time hostinfo *tailcfg.Hostinfo // always non-nil @@ -94,6 +95,7 @@ type Options struct { Persist Persist // initial persistent data HTTPC *http.Client // HTTP client used to talk to tailcontrol ServerURL string // URL of the tailcontrol server + AuthKey string // optional node auth key for auto registration TimeNow func() time.Time // time.Now implementation used by Client Hostinfo *tailcfg.Hostinfo // non-nil passes ownership, nil means to use default using os.Hostname, etc NewDecompressor func() (Decompressor, error) @@ -131,6 +133,7 @@ func NewDirect(opts Options) (*Direct, error) { newDecompressor: opts.NewDecompressor, keepAlive: opts.KeepAlive, persist: opts.Persist, + authKey: opts.AuthKey, } if opts.Hostinfo == nil { c.SetHostinfo(NewHostinfo()) @@ -313,6 +316,7 @@ func (c *Direct) doLogin(ctx context.Context, t *oauth2.Token, flags LoginFlags, request.Auth.Oauth2Token = t request.Auth.Provider = persist.Provider request.Auth.LoginName = persist.LoginName + request.Auth.AuthKey = c.authKey bodyData, err := encode(request, &serverKey, &persist.PrivateMachineKey) if err != nil { return regen, url, err