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

feat: add team membership check to GitHub authentication method #2891

Merged
merged 3 commits into from
Mar 23, 2024

Conversation

thepabloaguilar
Copy link
Contributor

As we've discussed in the related issue I'm opening this PR to introduce a new filter for GitHub OAuth method allowing people to define allowed_teams plus to allowed_organizations!

Closes #2849

@thepabloaguilar thepabloaguilar requested a review from a team as a code owner March 23, 2024 03:48
@thepabloaguilar
Copy link
Contributor Author

I've tested it locally and it worked!

Copy link
Contributor

@GeorgeMac GeorgeMac left a comment

Choose a reason for hiding this comment

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

Change looks awesome. Thanks for taking the time to contribute it and the attention to tests is great. Nice improvements in the server tests there 💅.

I put one clarifying question for my own sake and one take it or leave it style suggestion. But it primarily looks great to me and im happy to merge as-is if you want to vito the style suggestion and we're happy with assuming folks have less than 100 memberships.

Comment on lines 175 to 185
teamOk := true
if userTeamsByOrg != nil {
allowedTeams := s.config.Methods.Github.Method.AllowedTeams[org]
userTeams := userTeamsByOrg[org]

teamOk = slices.ContainsFunc(allowedTeams, func(team string) bool {
return userTeams[team]
})
}

return teamOk
Copy link
Contributor

Choose a reason for hiding this comment

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

Take it or leave it: You could save a little on the right hand side justification here by returning early.

Suggested change
teamOk := true
if userTeamsByOrg != nil {
allowedTeams := s.config.Methods.Github.Method.AllowedTeams[org]
userTeams := userTeamsByOrg[org]
teamOk = slices.ContainsFunc(allowedTeams, func(team string) bool {
return userTeams[team]
})
}
return teamOk
if userTeamsByOrg == nil {
return true
}
allowedTeams := s.config.Methods.Github.Method.AllowedTeams[org]
userTeams := userTeamsByOrg[org]
return slices.ContainsFunc(allowedTeams, func(team string) bool {
return userTeams[team]
})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! I'll change it and rebase with main!

@@ -28,6 +28,7 @@ const (
githubAPI = "https://api.github.com"
githubUser endpoint = "/user"
githubUserOrganizations endpoint = "/user/orgs"
githubUserTeams endpoint = "/user/teams?per_page=100"
Copy link
Contributor

Choose a reason for hiding this comment

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

I take it we're just going to assume likelihood is 99.9% of folks have less that 100 team memberships and cross that bridge when we come to it for the outliers?

Seems reasonable to me, just clarifying.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly, I can't image someone having more than 100 team memberships (even they may exists 😆)!

Also, this is the same number used by Grafana as @markphelps pointed out: SocialGithub.fetchTeamMemberships

Copy link
Contributor

Choose a reason for hiding this comment

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

That's awesome. Makes total sense.

@thepabloaguilar
Copy link
Contributor Author

Thanks a lot for you feedback @GeorgeMac, I really appreciate it!

Copy link
Contributor

@GeorgeMac GeorgeMac left a comment

Choose a reason for hiding this comment

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

Looks great to me 🙌

We discussed on Friday, do a release this coming monday. Perfect timing!

Copy link
Collaborator

@markphelps markphelps left a comment

Choose a reason for hiding this comment

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

thank you @thepabloaguilar !! amazing work and thanks for all the tests too!

@markphelps markphelps added the automerge Used by Kodiak bot to automerge PRs label Mar 23, 2024
@markphelps
Copy link
Collaborator

@all-contributors please add @thepabloaguilar for code

Copy link
Contributor

@markphelps

I've put up a pull request to add @thepabloaguilar! 🎉

@kodiakhq kodiakhq bot merged commit 40007b9 into flipt-io:main Mar 23, 2024
24 of 25 checks passed
@markphelps markphelps added the needs docs Requires documentation updates label Mar 23, 2024
@markphelps markphelps removed the needs docs Requires documentation updates label May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Used by Kodiak bot to automerge PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add team membership check to GitHub authentication method
3 participants