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

View file

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