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

🚑️ OIDC: use Azure-AD unique identifier #2510

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions filters/auth/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ type claimSource struct {
type azureGraphGroups struct {
OdataNextLink string `json:"@odata.nextLink,omitempty"`
Value []struct {
DisplayName string `json:"displayName"`
ID string `json:"id"`
OnPremisesSamAccountName string `json:"onPremisesSamAccountName"`
ID string `json:"id"`
} `json:"value"`
}

Expand Down Expand Up @@ -1017,7 +1017,7 @@ func (f *tokenOidcFilter) handleDistributedClaimsAzure(url *url.URL, oauth2Token
}
url.Path = fmt.Sprintf("/v1.0/users/%s/transitiveMemberOf", userID)
q := url.Query()
q.Set("$select", "displayName,id")
q.Set("$select", "onPremisesSamAccountName,id")
url.RawQuery = q.Encode()
return f.resolveDistributedClaimAzure(url, oauth2Token)
}
Expand Down Expand Up @@ -1075,7 +1075,9 @@ func (f *tokenOidcFilter) resolveDistributedClaimAzure(url *url.URL, oauth2Token
return nil, fmt.Errorf("unabled to decode response: %w", err)
}
for _, v := range target.Value {
values = append(values, v.DisplayName)
if v.OnPremisesSamAccountName != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Switching to the guaranteed unique identifier onPremisesSamAccountName available in the Microsoft Graph API

Could it be empty?

Copy link
Member

Choose a reason for hiding this comment

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

And should we have a test to ensure behaviour when it is empty?

Copy link
Contributor Author

@universam1 universam1 Aug 14, 2023

Choose a reason for hiding this comment

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

Yes it can be empty and I have extended a test to reflect it.

Copy link
Member

Choose a reason for hiding this comment

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

onPremisesSamAccountName does not look like a standard attribute so we have to rely on you testing that this works correctly.

I guess id is also not stable/reliable to use for the purpose, is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The onPremisesSamAccountName is the equivalent of the samAccountName issued with the standard group claim.

But it might be that someone rather would like the GUID / ID to be issued, it is configurable in Azure app registration.

If you want @AlexanderYastrebov the field selector could be extended to be configurable. If so, which way, using a flag or another filter parameter?

Copy link
Member

@AlexanderYastrebov AlexanderYastrebov Aug 14, 2023

Choose a reason for hiding this comment

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

We do not use azure-based auth and have no experience with it. Lets have it like you proposed and see if we get any feedback on the change from other users.

values = append(values, v.OnPremisesSamAccountName)
}
}
// recursive pagination
if target.OdataNextLink != "" {
Expand All @@ -1089,6 +1091,7 @@ func (f *tokenOidcFilter) resolveDistributedClaimAzure(url *url.URL, oauth2Token
}
values = append(values, vs...)
}
log.Debugf("Distributed claim is :%v", values)
return
}

Expand Down
19 changes: 10 additions & 9 deletions filters/auth/oidc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,15 @@ func createOIDCServer(cb, client, clientsecret string, extraClaims jwt.MapClaims
}
case "/v1.0/users/me/transitiveMemberOf":
if r.Header.Get(authHeaderName) == authHeaderPrefix+validAccessToken &&
r.URL.Query().Get("$select") == "displayName,id" {
r.URL.Query().Get("$select") == "onPremisesSamAccountName,id" {
body, err := json.Marshal(azureGraphGroups{
OdataNextLink: fmt.Sprintf("http://%s/v1.0/users/paginatedresponse", r.Host),
Value: []struct {
DisplayName string `json:"displayName"`
ID string `json:"id"`
OnPremisesSamAccountName string `json:"onPremisesSamAccountName"`
ID string `json:"id"`
}{
{DisplayName: "CD-Administrators", ID: "1"},
{DisplayName: "Purchasing-Department", ID: "2"},
{OnPremisesSamAccountName: "CD-Administrators", ID: "1"},
{OnPremisesSamAccountName: "Purchasing-Department", ID: "2"},
}})
if err != nil {
log.Fatalf("Failed to marshal to json: %v", err)
Expand All @@ -338,11 +338,12 @@ func createOIDCServer(cb, client, clientsecret string, extraClaims jwt.MapClaims
body, err := json.Marshal(azureGraphGroups{
OdataNextLink: "",
Value: []struct {
DisplayName string `json:"displayName"`
ID string `json:"id"`
OnPremisesSamAccountName string `json:"onPremisesSamAccountName"`
ID string `json:"id"`
}{
{DisplayName: "AppX-Test-Users", ID: "3"},
{DisplayName: "white space", ID: "4"},
{OnPremisesSamAccountName: "AppX-Test-Users", ID: "3"},
{OnPremisesSamAccountName: "white space", ID: "4"},
{ID: "5"}, // null value
}})
if err != nil {
log.Fatalf("Failed to marshal to json: %v", err)
Expand Down