Skip to content

Commit

Permalink
Integrate expiration fixes (#754) in TS2021 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfont committed Aug 20, 2022
2 parents f0a8a28 + 061e2fe commit e20e818
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 0.17.0 (2022-XX-XX)

- Add ability to connect to PostgreSQL over TLS/SSL [#745](https://github.com/juanfont/headscale/pull/745)
- Fix CLI registration of expired machines [#754](https://github.com/juanfont/headscale/pull/754)

## 0.16.3 (2022-08-17)

Expand Down
10 changes: 10 additions & 0 deletions machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
)
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 @@ -805,13 +806,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(nodeKeyStr)
}

return machine, err
} else {
return nil, ErrCouldNotConvertMachineInterface
Expand Down
7 changes: 7 additions & 0 deletions protocol_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ func (h *Headscale) handleRegisterCommon(
// The machine has expired
h.handleMachineExpiredCommon(writer, req, registerRequest, *machine, machineKey)

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

return
}
}
Expand Down

0 comments on commit e20e818

Please sign in to comment.