Generate unique givennames for hosts joining (and debug added)

This commit is contained in:
Kristoffer Dalby 2022-05-16 20:32:37 +02:00
parent 03cccd60a6
commit 5fa3016703
2 changed files with 8 additions and 6 deletions

8
api.go
View file

@ -134,11 +134,7 @@ func (h *Headscale) RegistrationHandler(ctx *gin.Context) {
return
}
// TODO(kradalby): We need these fields to be unique, we need to add a hash or something at the end.
normalizedHostname, err := NormalizeToFQDNRules(
req.Hostinfo.Hostname,
h.cfg.OIDC.StripEmaildomain,
)
givenName, err := h.GenerateGivenName(req.Hostinfo.Hostname)
if err != nil {
log.Error().
Caller().
@ -156,7 +152,7 @@ func (h *Headscale) RegistrationHandler(ctx *gin.Context) {
newMachine := Machine{
MachineKey: machineKeyStr,
Hostname: req.Hostinfo.Hostname,
GivenName: normalizedHostname,
GivenName: givenName,
NodeKey: NodePublicKeyStripPrefix(req.NodeKey),
LastSeen: &now,
Expiry: &time.Time{},

View file

@ -394,9 +394,15 @@ func (api headscaleV1APIServer) DebugCreateMachine(
Hostname: "DebugTestMachine",
}
givenName, err := api.h.GenerateGivenName(request.GetName())
if err != nil {
return nil, err
}
newMachine := Machine{
MachineKey: request.GetKey(),
Hostname: request.GetName(),
GivenName: givenName,
Namespace: *namespace,
Expiry: &time.Time{},