mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-26 17:03:06 +00:00
Merge pull request #495 from appbricks/appbricks/main-bug-fix
Regression bug fix when re-authenticating machine with auth-key
This commit is contained in:
commit
0abfbdc18a
1 changed files with 49 additions and 28 deletions
25
api.go
25
api.go
|
@ -568,8 +568,13 @@ func (h *Headscale) handleAuthKey(
|
||||||
Str("func", "handleAuthKey").
|
Str("func", "handleAuthKey").
|
||||||
Str("machine", registerRequest.Hostinfo.Hostname).
|
Str("machine", registerRequest.Hostinfo.Hostname).
|
||||||
Msg("Failed authentication via AuthKey")
|
Msg("Failed authentication via AuthKey")
|
||||||
|
|
||||||
|
if pak != nil {
|
||||||
machineRegistrations.WithLabelValues("new", RegisterMethodAuthKey, "error", pak.Namespace.Name).
|
machineRegistrations.WithLabelValues("new", RegisterMethodAuthKey, "error", pak.Namespace.Name).
|
||||||
Inc()
|
Inc()
|
||||||
|
} else {
|
||||||
|
machineRegistrations.WithLabelValues("new", RegisterMethodAuthKey, "error").Inc()
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -580,8 +585,23 @@ func (h *Headscale) handleAuthKey(
|
||||||
Msg("Authentication key was valid, proceeding to acquire IP addresses")
|
Msg("Authentication key was valid, proceeding to acquire IP addresses")
|
||||||
|
|
||||||
nodeKey := NodePublicKeyStripPrefix(registerRequest.NodeKey)
|
nodeKey := NodePublicKeyStripPrefix(registerRequest.NodeKey)
|
||||||
now := time.Now().UTC()
|
|
||||||
|
|
||||||
|
// retrieve machine information if it exist
|
||||||
|
// The error is not important, because if it does not
|
||||||
|
// exist, then this is a new machine and we will move
|
||||||
|
// on to registration.
|
||||||
|
machine, _ := h.GetMachineByMachineKey(machineKey)
|
||||||
|
if machine != nil {
|
||||||
|
log.Trace().
|
||||||
|
Caller().
|
||||||
|
Str("machine", machine.Name).
|
||||||
|
Msg("machine already registered, refreshing with new auth key")
|
||||||
|
|
||||||
|
machine.NodeKey = nodeKey
|
||||||
|
machine.AuthKeyID = uint(pak.ID)
|
||||||
|
h.RefreshMachine(machine, registerRequest.Expiry)
|
||||||
|
} else {
|
||||||
|
now := time.Now().UTC()
|
||||||
machineToRegister := Machine{
|
machineToRegister := Machine{
|
||||||
Name: registerRequest.Hostinfo.Hostname,
|
Name: registerRequest.Hostinfo.Hostname,
|
||||||
NamespaceID: pak.Namespace.ID,
|
NamespaceID: pak.Namespace.ID,
|
||||||
|
@ -593,7 +613,7 @@ func (h *Headscale) handleAuthKey(
|
||||||
AuthKeyID: uint(pak.ID),
|
AuthKeyID: uint(pak.ID),
|
||||||
}
|
}
|
||||||
|
|
||||||
machine, err := h.RegisterMachine(
|
machine, err = h.RegisterMachine(
|
||||||
machineToRegister,
|
machineToRegister,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -610,6 +630,7 @@ func (h *Headscale) handleAuthKey(
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
h.UsePreAuthKey(pak)
|
h.UsePreAuthKey(pak)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue