Skip to content

Commit eecf645

Browse files
Merge pull request #2695 from dexidp/fix-google-admin-regression
Make admin email optional when no service account path is configured
2 parents e4bceef + 9bcce63 commit eecf645

2 files changed

Lines changed: 18 additions & 27 deletions

File tree

connector/google/google.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,10 @@ func (c *Config) Open(id string, logger log.Logger) (conn connector.Connector, e
7171
scopes = append(scopes, "profile", "email")
7272
}
7373

74-
var srv *admin.Service
75-
if len(c.Groups) > 0 {
76-
srv, err = createDirectoryService(c.ServiceAccountFilePath, c.AdminEmail, logger)
77-
if err != nil {
78-
cancel()
79-
return nil, fmt.Errorf("could not create directory service: %v", err)
80-
}
74+
srv, err := createDirectoryService(c.ServiceAccountFilePath, c.AdminEmail, logger)
75+
if err != nil {
76+
cancel()
77+
return nil, fmt.Errorf("could not create directory service: %v", err)
8178
}
8279

8380
clientID := c.ClientID
@@ -286,7 +283,9 @@ func (c *googleConnector) getGroups(email string, fetchTransitiveGroupMembership
286283
// the google admin api. If no serviceAccountFilePath is defined, the application default credential
287284
// is used.
288285
func createDirectoryService(serviceAccountFilePath, email string, logger log.Logger) (*admin.Service, error) {
289-
if email == "" {
286+
// We know impersonation is required when using a service account credential
287+
// TODO: or is it?
288+
if email == "" && serviceAccountFilePath != "" {
290289
return nil, fmt.Errorf("directory service requires adminEmail")
291290
}
292291

@@ -311,7 +310,12 @@ func createDirectoryService(serviceAccountFilePath, email string, logger log.Log
311310
if err != nil {
312311
return nil, fmt.Errorf("unable to parse credentials to config: %v", err)
313312
}
314-
config.Subject = email
313+
314+
// Only attempt impersonation when there is a user configured
315+
if email != "" {
316+
config.Subject = email
317+
}
318+
315319
return admin.NewService(ctx, option.WithHTTPClient(config.Client(ctx)))
316320
}
317321

connector/google/google_test.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,13 @@ func TestOpen(t *testing.T) {
7272
assert.Nil(t, err)
7373

7474
for name, reference := range map[string]testCase{
75-
"not_requesting_groups": {
76-
config: &Config{
77-
ClientID: "testClient",
78-
ClientSecret: "testSecret",
79-
RedirectURI: ts.URL + "/callback",
80-
Scopes: []string{"openid"},
81-
},
82-
expectedErr: "",
83-
},
8475
"missing_admin_email": {
8576
config: &Config{
86-
ClientID: "testClient",
87-
ClientSecret: "testSecret",
88-
RedirectURI: ts.URL + "/callback",
89-
Scopes: []string{"openid", "groups"},
90-
Groups: []string{"someGroup"},
77+
ClientID: "testClient",
78+
ClientSecret: "testSecret",
79+
RedirectURI: ts.URL + "/callback",
80+
Scopes: []string{"openid", "groups"},
81+
ServiceAccountFilePath: serviceAccountFilePath,
9182
},
9283
expectedErr: "requires adminEmail",
9384
},
@@ -99,7 +90,6 @@ func TestOpen(t *testing.T) {
9990
Scopes: []string{"openid", "groups"},
10091
AdminEmail: "foo@bar.com",
10192
ServiceAccountFilePath: "not_found.json",
102-
Groups: []string{"someGroup"},
10393
},
10494
expectedErr: "error reading credentials",
10595
},
@@ -111,7 +101,6 @@ func TestOpen(t *testing.T) {
111101
Scopes: []string{"openid", "groups"},
112102
AdminEmail: "foo@bar.com",
113103
ServiceAccountFilePath: serviceAccountFilePath,
114-
Groups: []string{"someGroup"},
115104
},
116105
expectedErr: "",
117106
},
@@ -122,7 +111,6 @@ func TestOpen(t *testing.T) {
122111
RedirectURI: ts.URL + "/callback",
123112
Scopes: []string{"openid", "groups"},
124113
AdminEmail: "foo@bar.com",
125-
Groups: []string{"someGroup"},
126114
},
127115
adc: serviceAccountFilePath,
128116
expectedErr: "",
@@ -135,7 +123,6 @@ func TestOpen(t *testing.T) {
135123
Scopes: []string{"openid", "groups"},
136124
AdminEmail: "foo@bar.com",
137125
ServiceAccountFilePath: serviceAccountFilePath,
138-
Groups: []string{"someGroup"},
139126
},
140127
adc: "/dev/null",
141128
expectedErr: "",

0 commit comments

Comments
 (0)