git.iko.soy/typeable/oauth2-proxy
on master help sign in
Skip 404 errors when looking up Google groups

When checking user membership against Google groups the groups are checked one at a time and in the order that they were supplied. If one of the groups does not exist then the checking is halted with the following error. google.go:201: googleapi: Error 404: Resource Not Found: groupKey, notFound None of the groups following the missing group are checked either. This means that something as trivial as a typo in the first group will make it impossible for anybody to login. This change catches the 404, logs a message, and then carries on as usual. In this way a typo will cause a particular group to stop working but will not affect any other groups.

commit652f43ed38d62d48911197a80eb4b01ca95f611c authorEskil Andreen <eskil.andreen@gmail.com> dateTue 28 Mar 2017, 15:58 (10 years ago) parent712739f
1 file changed+7−2
providers/google.go+7−2
providers/google.go+7−2
@@ -17,6 +17,7 @@ import (
1717 "golang.org/x/oauth2"
1818 "golang.org/x/oauth2/google"
1919 "google.golang.org/api/admin/directory/v1"
20+ "google.golang.org/api/googleapi"
2021)
2122
2223type GoogleProvider struct {
@@ -197,8 +198,12 @@ func userInGroup(service *admin.Service, groups []string, email string) bool {
197198 for _, group := range groups {
198199 members, err := fetchGroupMembers(service, group)
199200 if err != nil {
200− log.Printf("error fetching group members: %v", err)
201− return false
201+ if err, ok := err.(*googleapi.Error); ok && err.Code == 404 {
202+ log.Printf("error fetching members for group %s: group does not exist", group)
203+ } else {
204+ log.Printf("error fetching group members: %v", err)
205+ return false
206+ }
202207 }
203208
204209 for _, member := range members {