Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth: walk nested groups #149

Merged
merged 3 commits into from
Jan 30, 2019
Merged

auth: walk nested groups #149

merged 3 commits into from
Jan 30, 2019

Conversation

jphines
Copy link
Contributor

@jphines jphines commented Jan 24, 2019

Problem

We have nested google groups we need to unroll in-order to properly leverage them

Solution

Recursively resolve nested groups up to maxDepth (default is 4)

@jphines jphines force-pushed the recursively-walk-nested-groups branch from 02450d6 to a4ac0c4 Compare January 24, 2019 21:28
@@ -109,6 +109,17 @@ func (gs *GoogleAdminService) GetMembers(groupName string) ([]string, error) {

for _, member := range r.Members {
members = append(members, member.Email)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to append the member.Email if the member type is a group?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated this logic with a switch to not add if its a group

@jphines jphines force-pushed the recursively-walk-nested-groups branch 6 times, most recently from 73dd940 to 36a0158 Compare January 25, 2019 01:23
Copy link
Contributor

@mccutchen mccutchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple more small nits/questions, but this looks great otherwise @jphines!

if len(allGroups) == 0 {
return p.AdminService.GetGroups(email)
return []string{}, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems to invalidate the docstring for this function, which says

If allGroups is an empty list it returns all the groups that the user belongs to.

The implications of this change aren't obvious to me, so it's not clear if it's a necessary part of this feature, or something unrelated. Would you mind explaining?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We added this originally to ensure backward compatibility when the proxy didn't use to ask for explicit groups, but instead asked for membership of all groups -- will update the docstring.

// GetGroups gets the groups that a user with a given email address belongs to.
func (gs *GoogleAdminService) GetGroups(email string) ([]string, error) {
var groups []string
// HasMember checks if the user has membership in the given groups
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: HasMember strikes me as an odd name for a function that returns a subset of the given groups that the given email is in. Basically, I'd expect HasMember to return a bool. What about something like CheckMembership instead?

(Also, it might be good to expand the docstring here to more accurately describe what this function is doing w/r/t returning a subset of the given groups.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to reflect the underlying API endpoint we're leveraging on the google side (which is a bool endpoint, but is nice because it does nested group resolution).

I agree this seems to imply this would be a bool by name along -- not sure what would be better.

@jphines jphines force-pushed the recursively-walk-nested-groups branch from 68f0509 to 63ce4bd Compare January 25, 2019 16:37
@sporkmonger
Copy link
Contributor

I have the AD provider set up to do this too for the same reason.

@jphines jphines force-pushed the recursively-walk-nested-groups branch from 2e8cf5f to 7177147 Compare January 29, 2019 20:17
@jphines jphines force-pushed the recursively-walk-nested-groups branch from 7177147 to 77d7221 Compare January 29, 2019 20:19
Copy link
Contributor

@mccutchen mccutchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This turned out nice, LGTM @jphines!

@jphines
Copy link
Contributor Author

jphines commented Jan 30, 2019

Fixes #133

@jphines jphines merged commit 803d979 into master Jan 30, 2019
@jphines jphines deleted the recursively-walk-nested-groups branch January 30, 2019 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants