Skip to content

Commit 31556e1

Browse files
authored
Merge pull request #48 from juanfont/better-profile-info
Improving namespace/user support
2 parents cf9d920 + 0159649 commit 31556e1

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

api.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (h *Headscale) RegistrationHandler(c *gin.Context) {
7676
}
7777

7878
var m Machine
79-
if result := h.db.First(&m, "machine_key = ?", mKey.HexString()); errors.Is(result.Error, gorm.ErrRecordNotFound) {
79+
if result := h.db.Preload("Namespace").First(&m, "machine_key = ?", mKey.HexString()); errors.Is(result.Error, gorm.ErrRecordNotFound) {
8080
log.Println("New Machine!")
8181
m = Machine{
8282
Expiry: &req.Expiry,
@@ -200,7 +200,7 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) {
200200
}
201201

202202
var m Machine
203-
if result := h.db.First(&m, "machine_key = ?", mKey.HexString()); errors.Is(result.Error, gorm.ErrRecordNotFound) {
203+
if result := h.db.Preload("Namespace").First(&m, "machine_key = ?", mKey.HexString()); errors.Is(result.Error, gorm.ErrRecordNotFound) {
204204
log.Printf("Ignoring request, cannot find machine with key %s", mKey.HexString())
205205
c.String(http.StatusUnauthorized, "")
206206
return
@@ -357,16 +357,23 @@ func (h *Headscale) getMapResponse(mKey wgkey.Key, req tailcfg.MapRequest, m Mac
357357
log.Printf("Cannot fetch peers: %s", err)
358358
return nil, err
359359
}
360+
361+
profile := tailcfg.UserProfile{
362+
ID: tailcfg.UserID(m.NamespaceID),
363+
LoginName: m.Namespace.Name,
364+
DisplayName: m.Namespace.Name,
365+
}
366+
360367
resp := tailcfg.MapResponse{
361368
KeepAlive: false,
362369
Node: node,
363370
Peers: *peers,
364371
DNS: []netaddr.IP{},
365372
SearchPaths: []string{},
366-
Domain: "[email protected]",
373+
Domain: "headscale.net",
367374
PacketFilter: *h.aclRules,
368375
DERPMap: h.cfg.DerpMap,
369-
UserProfiles: []tailcfg.UserProfile{},
376+
UserProfiles: []tailcfg.UserProfile{profile},
370377
}
371378

372379
var respBody []byte

app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func (h *Headscale) Serve() error {
175175
}()
176176
err = s.ListenAndServeTLS("", "")
177177
} else {
178-
return errors.New("Unknown value for TLSLetsEncryptChallengeType")
178+
return errors.New("unknown value for TLSLetsEncryptChallengeType")
179179
}
180180
} else if h.cfg.TLSCertPath == "" {
181181
if !strings.HasPrefix(h.cfg.ServerURL, "http://") {

machine.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ func (m Machine) toNode() (*tailcfg.Node, error) {
154154
}
155155

156156
func (h *Headscale) getPeers(m Machine) (*[]*tailcfg.Node, error) {
157-
158157
machines := []Machine{}
159158
if err := h.db.Where("namespace_id = ? AND machine_key <> ? AND registered",
160159
m.NamespaceID, m.MachineKey).Find(&machines).Error; err != nil {

namespaces.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ func (h *Headscale) SetMachineNamespace(m *Machine, namespaceName string) error
106106
func (n *Namespace) toUser() *tailcfg.User {
107107
u := tailcfg.User{
108108
ID: tailcfg.UserID(n.ID),
109-
LoginName: "",
109+
LoginName: n.Name,
110110
DisplayName: n.Name,
111111
ProfilePicURL: "",
112-
Domain: "",
112+
Domain: "headscale.net",
113113
Logins: []tailcfg.LoginID{},
114114
Created: time.Time{},
115115
}

0 commit comments

Comments
 (0)