google: add support for groups access without service account #4138
+250
−76
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Add support for retrieving groups the user is a member of without needing to configure a Service Account with Domain-Wide Delegation.
The Google connector has support for retrieving groups the user is a member of using the Admin SDK API. This API requires using an authenticated client sourced from a service account granted domain-wide delegation. This account would be highly-privileged and give access to all Workspace users, which is less than ideal.
This change adds an alternative method to retrieve group membership using the Cloud Identity API. When using the
SearchDirectGroups
API endpoint, we can provide an access token that has been authorized with the appropriate Cloud Identity API scope and search for direct and transitive membership.In contrast to the existing method where the user is expected to specify the
groups
scope, this one relies on the user setting one of the required Cloud Identity scope explicitly:This is similar to how Grafana provides this feature. Alternatively, we could also decide to support this feature by providing an explicit way in the config to choose which method to use.
This PR supersedes: #1896 which is now 4+ years old.
NOTE: contrary to what was mentioned in the above PR, this feature does NOT require Google Workspace Enterprise Standard, Enterprise Plus, Enterprise for Education, and Cloud Identity Premium accounts.
TODO: update documentation (supersede: dexidp/website#74).
Fixes: #3517
Testing
I added a basic unit test that mirrors the coverage that the existing
TestGetGroups
provide.Additionally, I tested the new changes with a free version of Google Workspace + Google Cloud
I configured ArgoCD with the following:
To validate transitive group membership, I created the following group hierarchy:
admins@devodev.cloud
argocd-admins@devodev.cloud
alex@devodev.cloud
And after login, I see the following log (+ admin role assigned):
Special notes for your reviewer
Couple of changes on this PR that are not directly related to the new feature:
golang.org/x/exp
to get access to new functions (slices.ContainsFunc).