feat(api): add normalisation at machine register step

This commit is contained in:
Adrien Raffin-Caboisse 2022-03-07 22:46:29 +01:00
parent 1114449601
commit 6cc8bbc24f
No known key found for this signature in database
GPG Key ID: 7FB60532DEBEAD6A

14
api.go
View File

@ -134,6 +134,18 @@ func (h *Headscale) RegistrationHandler(ctx *gin.Context) {
return
}
hname, err := NormalizeName(
req.Hostinfo.Hostname,
h.cfg.OIDC.StripEmaildomain,
)
if err != nil {
log.Error().
Caller().
Str("func", "RegistrationHandler").
Str("hostinfo.name", req.Hostinfo.Hostname).
Err(err)
return
}
// The machine did not have a key to authenticate, which means
// that we rely on a method that calls back some how (OpenID or CLI)
@ -141,7 +153,7 @@ func (h *Headscale) RegistrationHandler(ctx *gin.Context) {
// happens
newMachine := Machine{
MachineKey: machineKeyStr,
Name: req.Hostinfo.Hostname,
Name: hname,
NodeKey: NodePublicKeyStripPrefix(req.NodeKey),
LastSeen: &now,
Expiry: &time.Time{},