mirror of
https://github.com/tailscale/tailscale.git
synced 2025-07-29 07:13:44 +00:00
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:
parent
ab159f748b
commit
0f12ead567
@ -18,10 +18,18 @@ async function main() {
|
|||||||
go.run(wasmInstance.instance).then(() =>
|
go.run(wasmInstance.instance).then(() =>
|
||||||
app.handleGoPanic("Unexpected shutdown")
|
app.handleGoPanic("Unexpected shutdown")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const params = new URLSearchParams(window.location.search)
|
||||||
|
const authKey = params.get("authkey") ?? undefined
|
||||||
|
|
||||||
const ipn = newIPN({
|
const ipn = newIPN({
|
||||||
// Persist IPN state in sessionStorage in development, so that we don't need
|
// Persist IPN state in sessionStorage in development, so that we don't need
|
||||||
// to re-authorize every time we reload the page.
|
// to re-authorize every time we reload the page.
|
||||||
stateStorage: DEBUG ? sessionStateStorage : undefined,
|
stateStorage: DEBUG ? sessionStateStorage : undefined,
|
||||||
|
// authKey allows for an auth key to be
|
||||||
|
// specified as a url param which automatically
|
||||||
|
// authorizes the client for use.
|
||||||
|
authKey: DEBUG ? authKey : undefined,
|
||||||
})
|
})
|
||||||
app.runWithIPN(ipn)
|
app.runWithIPN(ipn)
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,7 @@ declare global {
|
|||||||
|
|
||||||
type IPNConfig = {
|
type IPNConfig = {
|
||||||
stateStorage?: IPNStateStorage
|
stateStorage?: IPNStateStorage
|
||||||
|
authKey?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
type IPNCallbacks = {
|
type IPNCallbacks = {
|
||||||
|
@ -69,6 +69,12 @@ func newIPN(jsConfig js.Value) map[string]any {
|
|||||||
store = &jsStateStore{jsStateStorage}
|
store = &jsStateStore{jsStateStorage}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jsAuthKey := jsConfig.Get("authKey")
|
||||||
|
var authKey string
|
||||||
|
if jsAuthKey.Type() == js.TypeString {
|
||||||
|
authKey = jsAuthKey.String()
|
||||||
|
}
|
||||||
|
|
||||||
lpc := getOrCreateLogPolicyConfig(store)
|
lpc := getOrCreateLogPolicyConfig(store)
|
||||||
c := logtail.Config{
|
c := logtail.Config{
|
||||||
Collection: lpc.Collection,
|
Collection: lpc.Collection,
|
||||||
@ -135,7 +141,7 @@ func newIPN(jsConfig js.Value) map[string]any {
|
|||||||
})`)
|
})`)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
jsIPN.run(args[0])
|
jsIPN.run(args[0], authKey)
|
||||||
return nil
|
return nil
|
||||||
}),
|
}),
|
||||||
"login": js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
"login": js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||||
@ -182,7 +188,7 @@ type jsIPN struct {
|
|||||||
lb *ipnlocal.LocalBackend
|
lb *ipnlocal.LocalBackend
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *jsIPN) run(jsCallbacks js.Value) {
|
func (i *jsIPN) run(jsCallbacks js.Value, authKey string) {
|
||||||
notifyState := func(state ipn.State) {
|
notifyState := func(state ipn.State) {
|
||||||
jsCallbacks.Call("notifyState", int(state))
|
jsCallbacks.Call("notifyState", int(state))
|
||||||
}
|
}
|
||||||
@ -253,6 +259,7 @@ func (i *jsIPN) run(jsCallbacks js.Value) {
|
|||||||
WantRunning: true,
|
WantRunning: true,
|
||||||
Hostname: generateHostname(),
|
Hostname: generateHostname(),
|
||||||
},
|
},
|
||||||
|
AuthKey: authKey,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Start error: %v", err)
|
log.Printf("Start error: %v", err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user