Skip to content

Conversation

tuunit
Copy link
Member

@tuunit tuunit commented Dec 14, 2022

Motivation and Context

GitHub's hierarchy is structured by organization and teams. As of now, in version 7.4.0 this hierarchy can only be used for restricting access but the details about a users membership are not passed through to the underlying applications behind the oauth2-proxy. Therefore this PRs aim is to extend the GitHub provider with the functionality to expose the users membership. As the session storage already provides the functionality to store "groups" and forward them as headers, this is a valid feature / extension and in line with other providers.

Description of the implementation details

I refactored the GitHub provider quite extensively. To ensure backwards compatibility all the restrictions and checks are done as before. The only logical change is that instead of just fetching the org and team information when an organisation or team restriction is set, the membership information is always fetched from GitHub and added to the sessions group storage.

How Has This Been Tested?

All existing GitHub tests have been corrected to accommodate the new code structure. Manual testing has been done and I already use this version of the implementation in a production environment.

Checklist:

  • My change requires a change to the documentation or CHANGELOG.
  • I have updated the documentation/CHANGELOG accordingly.
  • I have created a feature (non-master) branch for my PR.

@tuunit tuunit requested a review from a team as a code owner December 14, 2022 13:02
@tuunit tuunit changed the title Feature/GitHub orgs and teams as groups Feature - Add GitHub Orgs/Teams as Groups to the OAuth Session Storage Dec 14, 2022
@tuunit tuunit changed the title Feature - Add GitHub Orgs/Teams as Groups to the OAuth Session Storage WIP: Feature - Add GitHub Orgs/Teams as Groups to the OAuth Session Storage Dec 17, 2022
@tuunit tuunit force-pushed the feature/github-orgs-and-teams-as-groups branch 2 times, most recently from 08273ac to 125ead6 Compare December 23, 2022 09:26
@tuunit tuunit changed the title WIP: Feature - Add GitHub Orgs/Teams as Groups to the OAuth Session Storage Add GitHub groups (orgs/teams) support Dec 29, 2022
@tuunit
Copy link
Member Author

tuunit commented Dec 29, 2022

@JoelSpeed ready for first review.
I might write some additional tests for better coverage.

@tuunit
Copy link
Member Author

tuunit commented Dec 29, 2022

@JoelSpeed I was thinking about replacing the restriction on orgs and teams by a single flag containing either orgs or org:teams
Like for example:

--github-groups="Org1,Org2,Org3:Team1,Org3:Team2"

Furthermore, the original and current implementation only allows to restrict on a single org with multiple teams but not multiple orgs. What do you think about this proposal? (Could be part of a second PR)

@@ -31,7 +32,8 @@ var _ Provider = (*GitHubProvider)(nil)

const (
githubProviderName = "GitHub"
githubDefaultScope = "user:email"
githubDefaultScope = "user:email read:org"
orgTeamSeparator = ":"
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm still considering "/" as the orgTeamSeparator

Copy link
Member Author

@tuunit tuunit Jan 3, 2023

Choose a reason for hiding this comment

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

@JoelSpeed ":" vs. "/" ? do you have a clear preference?

Or should it be configurable 🤔

// <https://api.github.com/user/teams?page=3&per_page=10>; rel="prev", <https://api.github.com/user/teams?page=1&per_page=10>; rel="first"

link := result.Headers().Get("Link")
rep1 := regexp.MustCompile(`(?s).*\<https://api.github.com/user/teams\?page=(.)&per_page=[0-9]+\>; rel="last".*`)
Copy link
Member Author

@tuunit tuunit Dec 30, 2022

Choose a reason for hiding this comment

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

I haven't had the chance to check this. But I don't think this will work on an enterprise server instance with a custom domain as the api url would be different. As this isn't part of the new implementation and has been in the code base for a while. I would leave it as is for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll create a PR, already fixed it locally to work with Github Enterprise Server.

@tuunit
Copy link
Member Author

tuunit commented Feb 2, 2023

@JoelSpeed any thoughts on this PR? Or should I ask someone else from the maintainer list regarding the review?

@tuunit tuunit force-pushed the feature/github-orgs-and-teams-as-groups branch from 59b1ed6 to 6489cc6 Compare February 27, 2023 07:16
@tuunit
Copy link
Member Author

tuunit commented Feb 27, 2023

@JoelSpeed any thoughts on this PR? Or should I ask someone else from the maintainer list regarding the review?

Any updates regarding the review? 😄

@hoax
Copy link
Contributor

hoax commented Mar 13, 2023

I would really like to see this merged soon! Would simply our setup at work a lot.

@hoax
Copy link
Contributor

hoax commented Mar 13, 2023

I did a quick test with GitHub Enterprise Server 3.5.2 using /auth endpoint and it works very well. Thank you @tuunit!

@tuunit
Copy link
Member Author

tuunit commented Apr 3, 2023

@JoelSpeed @steakunderscore @desaintmartin @NickMeves can I help you to review this and some of the other open pull requests? As there are currently 44 open PRs and 98 issues.

// <https://api.github.com/user/teams?page=3&per_page=10>; rel="prev", <https://api.github.com/user/teams?page=1&per_page=10>; rel="first"

link := result.Headers().Get("Link")
rep1 := regexp.MustCompile(`(?s).*\<https://api.github.com/user/teams\?page=(.)&per_page=[0-9]+\>; rel="last".*`)

Check failure

Code scanning / CodeQL

Incomplete regular expression for hostnames

This regular expression has an unescaped dot before 'github.com', so it might match more hosts than expected when [the regular expression is used](1).
@github-actions
Copy link
Contributor

This pull request has been inactive for 60 days. If the pull request is still relevant please comment to re-activate the pull request. If no action is taken within 7 days, the pull request will be marked closed.

@github-actions github-actions bot added the Stale label Jul 18, 2023
@github-actions github-actions bot closed this Jul 26, 2023
@tuunit
Copy link
Member Author

tuunit commented Aug 24, 2023

@JoelSpeed please reopen :)

@JoelSpeed
Copy link
Member

The branch has since been force pushed so I can't reopen it, will need a fresh PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants