tsconnect: pass in authkey in dev mode (#5320)

This change allows for an auth key to be specified as a url query param
for use in development mode. If an auth key is specified and valid, it
will authorize the client for use immediately.

Updates #5144

Signed-off-by: Charlotte Brandhorst-Satzkorn <charlotte@tailscale.com>
This commit is contained in:
Charlotte Brandhorst-Satzkorn
2022-08-09 13:07:01 -07:00
committed by GitHub
parent ab159f748b
commit 0f12ead567
3 changed files with 18 additions and 2 deletions

View File

@@ -69,6 +69,12 @@ func newIPN(jsConfig js.Value) map[string]any {
store = &jsStateStore{jsStateStorage}
}
jsAuthKey := jsConfig.Get("authKey")
var authKey string
if jsAuthKey.Type() == js.TypeString {
authKey = jsAuthKey.String()
}
lpc := getOrCreateLogPolicyConfig(store)
c := logtail.Config{
Collection: lpc.Collection,
@@ -135,7 +141,7 @@ func newIPN(jsConfig js.Value) map[string]any {
})`)
return nil
}
jsIPN.run(args[0])
jsIPN.run(args[0], authKey)
return nil
}),
"login": js.FuncOf(func(this js.Value, args []js.Value) interface{} {
@@ -182,7 +188,7 @@ type jsIPN struct {
lb *ipnlocal.LocalBackend
}
func (i *jsIPN) run(jsCallbacks js.Value) {
func (i *jsIPN) run(jsCallbacks js.Value, authKey string) {
notifyState := func(state ipn.State) {
jsCallbacks.Call("notifyState", int(state))
}
@@ -253,6 +259,7 @@ func (i *jsIPN) run(jsCallbacks js.Value) {
WantRunning: true,
Hostname: generateHostname(),
},
AuthKey: authKey,
})
if err != nil {
log.Printf("Start error: %v", err)