Skip to content

Azure Provider will now query for groups#1514

Closed
tschechniker wants to merge 4 commits intooauth2-proxy:masterfrom
tschechniker:master
Closed

Azure Provider will now query for groups#1514
tschechniker wants to merge 4 commits intooauth2-proxy:masterfrom
tschechniker:master

Conversation

@tschechniker
Copy link

Description

The Azure Provider did not query for groups. I added the azure graph api call to resolve the groups of the logged in user

Motivation and Context

How Has This Been Tested?

Tested with Azure environment.

Checklist:

  • [ X ] 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.

@tschechniker tschechniker requested a review from a team as a code owner January 12, 2022 08:40
Copy link
Member

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

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

Would be keen to see if anyone who knows Azure a bit better has any input on this, eg @pierluigilenoci perhaps

Comment on lines +56 to +62
// Default Groipe URL for Azure.
// Pre-parsed URL of https://graph.microsoft.com/v1.0/me.
azureDefaultGroupURL = &url.URL{
Scheme: "https",
Host: "graph.microsoft.com",
Path: "/v1.0/me/transitiveMemberOf/microsoft.graph.group",
}
Copy link
Member

Choose a reason for hiding this comment

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

Is any configuration of the Azure application required to enable this to work or should it work with default configurations (is this likely to be a breaking change for anyone)

Copy link
Collaborator

Choose a reason for hiding this comment

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

This Path is also odd. You should probably just be calling /me here.
I'm pretty sure you'll need at least one of the permissions here: https://docs.microsoft.com/en-us/graph/permissions-reference#application-permissions-19

ProfileURL *url.URL
ProtectedResource *url.URL
ValidateURL *url.URL
GroupURL *url.URL
Copy link
Member

Choose a reason for hiding this comment

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

This isn't a common pattern for other providers, most of the time the groups should be included within the profile or ID tokens returned, do we really want to add this for all providers?

@pierluigilenoci
Copy link
Member

@JoelSpeed unfortunately Azure Provider has a lot of problems but I am on the side of those who suffer from it.
Who has the information to solve, in this case, I think is @weinong.

Ref: #1231, #1505 and #1144

@braunsonm
Copy link
Collaborator

I use Azure frequently. I can provide some thoughts on this.

var groups []string
for url != "" {
logger.Printf("Calling Group API: %s", url)
json, err := requests.New(url).
Copy link
Collaborator

Choose a reason for hiding this comment

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

What scopes did you test this with? Calling the graph API requires a graph scoped access token unless I'm wrong.
This would mean you used the scope https://graph.microsoft.com/.default which would generate a token with the graph audience which isn't necessarily correct for upstream applications.

for _, doc := range json.Get("value").MustArray() {
for k, v := range doc.(map[string]interface{}) {
if k == "displayName" {
groups = append(groups, v.(string))
Copy link
Contributor

Choose a reason for hiding this comment

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

This will panic if v is nil with

http: panic serving [::1]:58156: interface conversion: interface {} is nil, not string

azureDefaultGroupURL = &url.URL{
Scheme: "https",
Host: "graph.microsoft.com",
Path: "/v1.0/me/transitiveMemberOf/microsoft.graph.group",
Copy link
Contributor

Choose a reason for hiding this comment

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

This path requires high privileges like Directory.Read.All otherwise it won't work(e.g. will retrieve nil as value for displayName key).

One approach that might not need extended permissions could be to use /v1.0/me/getMemberGroups instead, but in this case there are no trivial ways to find if a group is part of another group. Authentication might fail in this case when it shouldn't(e.g. a user will be denied even if he is part of a group that is part of the group configured in the oauth2-proxy allowed-group list).

Copy link
Contributor

Choose a reason for hiding this comment

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

Even /v1.0/me/getMemberGroups requires Directory.Read.All permissions based on my testing 😞

Copy link
Contributor

@adriananeci adriananeci Feb 19, 2022

Choose a reason for hiding this comment

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

Why not using id instead of displayName(in getGroupsFromJSON method) when checking if a user is part of group or not? In this way we don't need elevated permissions anymore.

Or put the groups field selection(id or displayName) behind a config flag and let users choose which one fits best for their needs.

@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 Apr 21, 2022
@pierluigilenoci
Copy link
Member

This is still an issue

@JoelSpeed JoelSpeed removed the Stale label Apr 27, 2022
@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 Jun 27, 2022
@pierluigilenoci
Copy link
Member

This is still an issue

@pierluigilenoci
Copy link
Member

@tschechniker could you take a look?

@JoelSpeed JoelSpeed removed the Stale label Jun 27, 2022
@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 Aug 27, 2022
@pierluigilenoci
Copy link
Member

@tschechniker could you please fix the PR?

@JoelSpeed JoelSpeed removed the Stale label Aug 29, 2022
@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 Oct 29, 2022
@github-actions github-actions bot closed this Nov 5, 2022
@mvalenzisi
Copy link

This is still an issue.

@pierluigilenoci
Copy link
Member

@adriananeci your PR solve also this?

@pierluigilenoci
Copy link
Member

@JoelSpeed could you please reopen this?

@pierluigilenoci
Copy link
Member

@tschechniker could you try if the latest version of the proxy works for your problem?

@braunsonm
Copy link
Collaborator

This should be resolved in the latest update, please advise otherwise in the related issue if that's not the case

@vittoriocanilli
Copy link

Hello,
we are using an AKS cluster with managed AAD, so we have to use the resource attribute set to 6dae42f8-4368-4678-94ff-3960e28e3630 as described here.

The resource attribute can not be used with Azure OAuth v2.0, so we have to use Azure OAuth v1.0, otherwise the groups won't be used properly per the permissions, even if they are retrieved correctly.

Anyway if we use Azure OAuth v1.0 with OAuth2 Proxy in a version greater or equal to the 7.2.1, the groups are not retrieved at all. So we are still using OAuth2 Proxy 7.2.0 at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants