Skip to content

Commit

Permalink
Fix cli registration of expired machines
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent Marchaud <[email protected]>
  • Loading branch information
Aluxima committed Aug 19, 2022
1 parent 1945539 commit c6ea9b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,13 @@ func (h *Headscale) RegistrationHandler(
// The machine has expired
h.handleMachineExpired(writer, req, machineKey, registerRequest, *machine)

machine.Expiry = &time.Time{}
h.registrationCache.Set(
machineKeyStr,
*machine,
registerCacheExpiration,
)

return
}
}
Expand Down
14 changes: 12 additions & 2 deletions machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ const (
ErrMachineNotFoundRegistrationCache = Error(
"machine not found in registration cache",
)
ErrCouldNotConvertMachineInterface = Error("failed to convert machine interface")
ErrHostnameTooLong = Error("Hostname too long")
errCouldNotConvertMachineInterface = Error("failed to convert machine interface")
errHostnameTooLong = Error("Hostname too long")
errDifferentRegisteredNamespace = Error("machine was previously registered with a different namespace")
MachineGivenNameHashLength = 8
MachineGivenNameTrimSize = 2
)
Expand Down Expand Up @@ -789,13 +790,22 @@ func (h *Headscale) RegisterMachineFromAuthCallback(
)
}

// Registration of expired machine with different namespace
if registrationMachine.ID != 0 && registrationMachine.NamespaceID != namespace.ID {
return nil, errDifferentRegisteredNamespace
}

registrationMachine.NamespaceID = namespace.ID
registrationMachine.RegisterMethod = registrationMethod

machine, err := h.RegisterMachine(
registrationMachine,
)

if err == nil {
h.registrationCache.Delete(machineKeyStr)
}

return machine, err
} else {
return nil, ErrCouldNotConvertMachineInterface
Expand Down

0 comments on commit c6ea9b4

Please sign in to comment.