@@ -43,10 +43,7 @@ func (h *Headscale) handleRegister(
43
43
}
44
44
45
45
if regReq .Followup != "" {
46
- // TODO(kradalby): Does this need to return an error of some sort?
47
- // Maybe if the registration fails down the line it can be sent
48
- // on the channel and returned here?
49
- h .waitForFollowup (ctx , regReq )
46
+ return h .waitForFollowup (ctx , regReq )
50
47
}
51
48
52
49
if regReq .Auth != nil && regReq .Auth .AuthKey != "" {
@@ -111,42 +108,51 @@ func (h *Headscale) handleExistingNode(
111
108
h .nodeNotifier .NotifyWithIgnore (ctx , types .UpdateExpire (node .ID , requestExpiry ), node .ID )
112
109
}
113
110
111
+ return nodeToRegisterResponse (node ), nil
112
+ }
113
+
114
+ func nodeToRegisterResponse (node * types.Node ) * tailcfg.RegisterResponse {
114
115
return & tailcfg.RegisterResponse {
115
116
// TODO(kradalby): Only send for user-owned nodes
116
117
// and not tagged nodes when tags is working.
117
118
User : * node .User .TailscaleUser (),
118
119
Login : * node .User .TailscaleLogin (),
119
- NodeKeyExpired : expired ,
120
+ NodeKeyExpired : node . IsExpired () ,
120
121
121
122
// Headscale does not implement the concept of machine authorization
122
123
// so we always return true here.
123
124
// Revisit this if #2176 gets implemented.
124
125
MachineAuthorized : true ,
125
- }, nil
126
+ }
126
127
}
127
128
128
129
func (h * Headscale ) waitForFollowup (
129
130
ctx context.Context ,
130
131
regReq tailcfg.RegisterRequest ,
131
- ) {
132
+ ) ( * tailcfg. RegisterResponse , error ) {
132
133
fu , err := url .Parse (regReq .Followup )
133
134
if err != nil {
134
- return
135
+ return nil , NewHTTPError ( http . StatusUnauthorized , "invalid followup URL" , err )
135
136
}
136
137
137
138
followupReg , err := types .RegistrationIDFromString (strings .ReplaceAll (fu .Path , "/register/" , "" ))
138
139
if err != nil {
139
- return
140
+ return nil , NewHTTPError ( http . StatusUnauthorized , "invalid registration ID" , err )
140
141
}
141
142
142
143
if reg , ok := h .registrationCache .Get (followupReg ); ok {
143
144
select {
144
145
case <- ctx .Done ():
145
- return
146
- case <- reg .Registered :
147
- return
146
+ return nil , NewHTTPError (http .StatusUnauthorized , "registration timed out" , err )
147
+ case node := <- reg .Registered :
148
+ if node == nil {
149
+ return nil , NewHTTPError (http .StatusUnauthorized , "node not found" , nil )
150
+ }
151
+ return nodeToRegisterResponse (node ), nil
148
152
}
149
153
}
154
+
155
+ return nil , NewHTTPError (http .StatusNotFound , "followup registration not found" , nil )
150
156
}
151
157
152
158
// canUsePreAuthKey checks if a pre auth key can be used.
@@ -271,7 +277,7 @@ func (h *Headscale) handleRegisterInteractive(
271
277
Hostinfo : regReq .Hostinfo ,
272
278
LastSeen : ptr .To (time .Now ()),
273
279
},
274
- Registered : make (chan struct {} ),
280
+ Registered : make (chan * types. Node ),
275
281
}
276
282
277
283
if ! regReq .Expiry .IsZero () {
0 commit comments