From 6cc8bbc24fb0666b68d3ea9ba44dab83ec0d69a8 Mon Sep 17 00:00:00 2001 From: Adrien Raffin-Caboisse Date: Mon, 7 Mar 2022 22:46:29 +0100 Subject: [PATCH] feat(api): add normalisation at machine register step --- api.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/api.go b/api.go index 3b3b6757..b4ad92f3 100644 --- a/api.go +++ b/api.go @@ -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{},