Fix cli registration of expired machines

Signed-off-by: Laurent Marchaud <laurent@marchaud.com>
This commit is contained in:
Laurent Marchaud
2022-08-19 12:38:39 +02:00
parent 19455399f4
commit c6ea9b4b80
2 changed files with 19 additions and 2 deletions

View File

@@ -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
)
@@ -789,6 +790,11 @@ 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
@@ -796,6 +802,10 @@ func (h *Headscale) RegisterMachineFromAuthCallback(
registrationMachine,
)
if err == nil {
h.registrationCache.Delete(machineKeyStr)
}
return machine, err
} else {
return nil, ErrCouldNotConvertMachineInterface