@@ -134,34 +134,28 @@ func (a *AuthProviderOIDC) RegisterHandler(
134
134
req * http.Request ,
135
135
) {
136
136
vars := mux .Vars (req )
137
- registrationIdStr , ok := vars ["registration_id" ]
137
+ registrationIdStr , _ := vars ["registration_id" ]
138
138
139
139
// We need to make sure we dont open for XSS style injections, if the parameter that
140
140
// is passed as a key is not parsable/validated as a NodePublic key, then fail to render
141
141
// the template and log an error.
142
142
registrationId , err := types .RegistrationIDFromString (registrationIdStr )
143
143
if err != nil {
144
- http . Error (writer , "invalid registration ID" , http .StatusBadRequest )
144
+ httpError (writer , err , "invalid registration ID" , http .StatusBadRequest )
145
145
return
146
146
}
147
147
148
- log .Debug ().
149
- Caller ().
150
- Str ("registration_id" , registrationId .String ()).
151
- Bool ("ok" , ok ).
152
- Msg ("Received oidc register call" )
153
-
154
148
// Set the state and nonce cookies to protect against CSRF attacks
155
149
state , err := setCSRFCookie (writer , req , "state" )
156
150
if err != nil {
157
- http . Error (writer , "Internal server error" , http .StatusInternalServerError )
151
+ httpError (writer , err , "Internal server error" , http .StatusInternalServerError )
158
152
return
159
153
}
160
154
161
155
// Set the state and nonce cookies to protect against CSRF attacks
162
156
nonce , err := setCSRFCookie (writer , req , "nonce" )
163
157
if err != nil {
164
- http . Error (writer , "Internal server error" , http .StatusInternalServerError )
158
+ httpError (writer , err , "Internal server error" , http .StatusInternalServerError )
165
159
return
166
160
}
167
161
@@ -225,64 +219,64 @@ func (a *AuthProviderOIDC) OIDCCallbackHandler(
225
219
) {
226
220
code , state , err := extractCodeAndStateParamFromRequest (req )
227
221
if err != nil {
228
- http . Error (writer , err .Error (), http .StatusBadRequest )
222
+ httpError (writer , err , err .Error (), http .StatusBadRequest )
229
223
return
230
224
}
231
225
232
- log .Debug ().Interface ("cookies" , req .Cookies ()).Msg ("Received oidc callback" )
233
226
cookieState , err := req .Cookie ("state" )
234
227
if err != nil {
235
- http . Error (writer , "state not found" , http .StatusBadRequest )
228
+ httpError (writer , err , "state not found" , http .StatusBadRequest )
236
229
return
237
230
}
238
231
239
232
if state != cookieState .Value {
240
- http . Error (writer , "state did not match" , http .StatusBadRequest )
233
+ httpError (writer , err , "state did not match" , http .StatusBadRequest )
241
234
return
242
235
}
243
236
244
237
idToken , err := a .extractIDToken (req .Context (), code , state )
245
238
if err != nil {
246
- http . Error (writer , err .Error (), http .StatusBadRequest )
239
+ httpError (writer , err , err .Error (), http .StatusBadRequest )
247
240
return
248
241
}
249
242
250
243
nonce , err := req .Cookie ("nonce" )
251
244
if err != nil {
252
- http . Error (writer , "nonce not found" , http .StatusBadRequest )
245
+ httpError (writer , err , "nonce not found" , http .StatusBadRequest )
253
246
return
254
247
}
255
248
if idToken .Nonce != nonce .Value {
256
- http . Error (writer , "nonce did not match" , http .StatusBadRequest )
249
+ httpError (writer , err , "nonce did not match" , http .StatusBadRequest )
257
250
return
258
251
}
259
252
260
253
nodeExpiry := a .determineNodeExpiry (idToken .Expiry )
261
254
262
255
var claims types.OIDCClaims
263
256
if err := idToken .Claims (& claims ); err != nil {
264
- http .Error (writer , fmt .Errorf ("failed to decode ID token claims: %w" , err ).Error (), http .StatusInternalServerError )
257
+ err = fmt .Errorf ("decoding ID token claims: %w" , err )
258
+ httpError (writer , err , err .Error (), http .StatusInternalServerError )
265
259
return
266
260
}
267
261
268
262
if err := validateOIDCAllowedDomains (a .cfg .AllowedDomains , & claims ); err != nil {
269
- http . Error (writer , err .Error (), http .StatusUnauthorized )
263
+ httpError (writer , err , err .Error (), http .StatusUnauthorized )
270
264
return
271
265
}
272
266
273
267
if err := validateOIDCAllowedGroups (a .cfg .AllowedGroups , & claims ); err != nil {
274
- http . Error (writer , err .Error (), http .StatusUnauthorized )
268
+ httpError (writer , err , err .Error (), http .StatusUnauthorized )
275
269
return
276
270
}
277
271
278
272
if err := validateOIDCAllowedUsers (a .cfg .AllowedUsers , & claims ); err != nil {
279
- http . Error (writer , err .Error (), http .StatusUnauthorized )
273
+ httpError (writer , err , err .Error (), http .StatusUnauthorized )
280
274
return
281
275
}
282
276
283
277
user , err := a .createOrUpdateUserFromClaim (& claims )
284
278
if err != nil {
285
- http . Error (writer , err .Error (), http .StatusInternalServerError )
279
+ httpError (writer , err , err .Error (), http .StatusInternalServerError )
286
280
return
287
281
}
288
282
@@ -297,7 +291,7 @@ func (a *AuthProviderOIDC) OIDCCallbackHandler(
297
291
verb := "Reauthenticated"
298
292
newNode , err := a .handleRegistrationID (user , * registrationId , nodeExpiry )
299
293
if err != nil {
300
- http . Error (writer , err .Error (), http .StatusInternalServerError )
294
+ httpError (writer , err , err .Error (), http .StatusInternalServerError )
301
295
return
302
296
}
303
297
@@ -308,7 +302,7 @@ func (a *AuthProviderOIDC) OIDCCallbackHandler(
308
302
// TODO(kradalby): replace with go-elem
309
303
content , err := renderOIDCCallbackTemplate (user , verb )
310
304
if err != nil {
311
- http . Error (writer , err .Error (), http .StatusInternalServerError )
305
+ httpError (writer , err , err .Error (), http .StatusInternalServerError )
312
306
return
313
307
}
314
308
@@ -323,7 +317,7 @@ func (a *AuthProviderOIDC) OIDCCallbackHandler(
323
317
324
318
// Neither node nor machine key was found in the state cache meaning
325
319
// that we could not reauth nor register the node.
326
- http . Error (writer , "login session expired, try again" , http .StatusInternalServerError )
320
+ httpError (writer , nil , "login session expired, try again" , http .StatusInternalServerError )
327
321
return
328
322
}
329
323
@@ -423,7 +417,6 @@ func validateOIDCAllowedUsers(
423
417
) error {
424
418
if len (allowedUsers ) > 0 &&
425
419
! slices .Contains (allowedUsers , claims .Email ) {
426
- log .Trace ().Msg ("authenticated principal does not match any allowed user" )
427
420
return errOIDCAllowedUsers
428
421
}
429
422
0 commit comments