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

Fix idtyp issue with GetMemberGroupsUsingARCOboService #392

Merged
merged 5 commits into from
Jun 12, 2024
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
13 changes: 11 additions & 2 deletions auth/providers/azure/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,17 @@ func (u *UserInfo) getMemberGroupsUsingARCOboService(ctx context.Context, access
return nil, errors.Wrap(err, "Error while parsing accessToken for validation")
}

// the arc obo service does not support getting groups for applications
if claims[idtypClaim] != nil {
// the arc obo service does not support getting groups for applications(SPN)
isAADUser := false
if claims[idtypClaim] == nil {
isAADUser = true
} else {
idtyp, ok := claims[idtypClaim].(string)
if ok && strings.EqualFold(idtyp, "user") {
isAADUser = true
}
}
if !isAADUser {
return nil, errors.New("Overage claim (users with more than 200 group membership) for SPN is currently not supported. For troubleshooting, please refer to aka.ms/overageclaimtroubleshoot")
}

Expand Down
42 changes: 38 additions & 4 deletions auth/providers/azure/graph/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ import (
)

const (
accessTokenWithOverageClaim = `{ "aud": "client", "iss" : "%v", "exp" : "%v", "upn": "arc", "_claim_names": {"groups": "src1"}, "_claim_sources": {"src1": {"endpoint": "https://foobar" }} }`
accessTokenWithOverageClaimForApp = `{ "aud": "client", "iss" : "%v", "exp" : "%v", "idtyp" : "app", "upn": "arc", "_claim_names": {"groups": "src1"}, "_claim_sources": {"src1": {"endpoint": "https://foobar" }} }`
location = "eastus"
tenant_id = "tenantId"
accessTokenWithOverageClaim = `{ "aud": "client", "iss" : "%v", "exp" : "%v", "upn": "arc", "_claim_names": {"groups": "src1"}, "_claim_sources": {"src1": {"endpoint": "https://foobar" }} }`
accessTokenWithOverageClaimForApp = `{ "aud": "client", "iss" : "%v", "exp" : "%v", "idtyp" : "app", "upn": "arc", "_claim_names": {"groups": "src1"}, "_claim_sources": {"src1": {"endpoint": "https://foobar" }} }`
accessTokenWithOverageClaimForUser = `{ "aud": "client", "iss" : "%v", "exp" : "%v", "idtyp" : "user", "upn": "arc", "_claim_names": {"groups": "src1"}, "_claim_sources": {"src1": {"endpoint": "https://foobar" }} }`
location = "eastus"
tenant_id = "tenantId"
)

type swKey struct {
Expand Down Expand Up @@ -346,6 +347,39 @@ func TestGetMemberGroupsUsingARCOboService(t *testing.T) {
t.Errorf("Should have gotten a list of groups with 1 entry. Got: %d", len(groups))
}
})
t.Run("successful request for token with 'user' idtyp claim", func(t *testing.T) {
validBody := `{
"value": [
"f36ec2c5-fa5t-4f05-b87f-deadbeef"
]
}`

ts, u := getAPIServerAndUserInfo(http.StatusOK, validBody)
u.region = location
u.authMode = arcAuthMode
u.resourceID = ts.URL
u.tenantID = tenant_id
defer ts.Close()

getOBORegionalEndpoint = func(location string, resourceID string) (string, error) {
return ts.URL, nil
}

u.headers.Set("Authorization", "Bearer msitoken")

tokenstring, err := key.GenerateToken([]byte(fmt.Sprintf(accessTokenWithOverageClaimForUser, ts.URL, time.Now().Add(time.Minute*5).Unix())))
if err != nil {
t.Fatalf("Error when generating token. Error:%+v", err)
}

groups, err := u.getMemberGroupsUsingARCOboService(ctx, tokenstring)
if err != nil {
t.Errorf("Should not have gotten error: %s", err)
}
if len(groups) != 1 {
t.Errorf("Should have gotten a list of groups with 1 entry. Got: %d", len(groups))
}
})
t.Run("bad server response", func(t *testing.T) {
ts, u := getAPIServerAndUserInfo(http.StatusInternalServerError, "shutdown")
u.region = location
Expand Down
Loading