Skip to content

Commit afa9502

Browse files
authored
Use pagination when retrieving groups for an okta application (#162)
* When retrieving groups for an okta application, use pagination to retrieve all groups instead of stopping on the first page * Update documentation around groupLimit now that the behavior is different * Add missing groupLimit description
1 parent b5affa4 commit afa9502

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,8 @@ The following table describes the set of configuration options for the Okta prov
416416
| `appId` | Application ID of App Groups are assigned to | `''` | Yes |
417417
| `extractLoginUsername` | Bool to determine if you should extract username from okta login | `false` | No |
418418
| `profileKey` | Attribute field on Okta User Profile you would like to use as identity | `'login'` | No |
419-
| `groupLimit` | Integer to set the maximum number of groups to sync | `1000` | No |
419+
| `groupLimit` | Integer to set the maximum number of groups to retrieve from OKTA per request. | `1000` | No |
420+
420421

421422
The following is an example of a minimal configuration that can be applied to integrate with an Okta provider:
422423

api/v1alpha1/groupsync_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ type OktaProvider struct {
403403
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Profile Key",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:text"}
404404
// +kubebuilder:validation:Optional
405405
ProfileKey string `json:"profileKey"`
406-
// GroupLimit is the maximum number of groups that can be synced. Default is "1000"
406+
// GroupLimit is the maximum number of groups that are requested from OKTA per request. Multiple requests will be made using pagination if you have more groups than this limit. Default is "1000"
407407
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Group Limit",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:number"}
408408
// +kubebuilder:validation:Optional
409409
GroupLimit int `json:"groupLimit"`

config/crd/bases/redhatcop.redhat.io_groupsyncs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ spec:
709709
description: ExtractLoginUsername is true if Okta username's are defaulted to emails and you would like the username only
710710
type: boolean
711711
groupLimit:
712-
description: GroupLimit is the maximum number of groups that can be synced. Default is "1000"
712+
description: GroupLimit is the maximum number of groups that are requested from OKTA per request. Multiple requests will be made using pagination if you have more groups than this limit. Default is "1000"
713713
type: integer
714714
groups:
715715
description: Groups represents a filtered list of groups to synchronize

config/manifests/bases/group-sync-operator.clusterserviceversion.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ spec:
590590
path: providers[0].okta.extractLoginUsername
591591
x-descriptors:
592592
- urn:alm:descriptor:com.tectonic.ui:text
593-
- description: GroupLimit is the maximum number of groups that can be synced.
593+
- description: GroupLimit is the maximum number of groups that are requested from OKTA per request. Multiple requests will be made using pagination if you have more groups than this limit.
594594
Default is "1000"
595595
displayName: Group Limit
596596
path: providers[0].okta.groupLimit
@@ -1003,6 +1003,7 @@ spec:
10031003
| `appId` | Application ID of App Groups are assigned to | | Yes |
10041004
| `extractLoginUsername` | Bool to determine if you should extract username from okta login | | No |
10051005
| `profileKey` | Attribute field on Okta User Profile you would like to use as identity | `login` | No |
1006+
| `groupLimit` | Integer to set the maximum number of groups to retrieve from OKTA per request. | `1000` | No |
10061007
10071008
10081009
The following is an example of a minimal configuration that can be applied to integrate with an Okta provider:

pkg/syncer/okta.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import (
44
"context"
55
"errors"
66
"fmt"
7-
"github.com/okta/okta-sdk-golang/v2/okta/query"
87
"net/url"
98
"strings"
109
"sync"
1110

11+
"github.com/okta/okta-sdk-golang/v2/okta/query"
12+
1213
"github.com/okta/okta-sdk-golang/v2/okta"
1314
userv1 "github.com/openshift/api/user/v1"
1415
"github.com/redhat-cop/group-sync-operator/api/v1alpha1"
@@ -177,13 +178,25 @@ func (o OktaSyncer) getGroups() ([]*okta.Group, error) {
177178
groups []*okta.Group
178179
)
179180

180-
appGroups, _, err := o.goOkta.Application.ListApplicationGroupAssignments(context.TODO(), o.Provider.AppId, query.NewQueryParams(query.WithLimit(int64(o.Provider.GroupLimit))))
181+
appGroups, resp, err := o.goOkta.Application.ListApplicationGroupAssignments(context.TODO(), o.Provider.AppId, query.NewQueryParams(query.WithLimit(int64(o.Provider.GroupLimit))))
181182

182183
if err != nil {
183184
oktaLogger.Error(err, "getting groups for specified application")
184185
return nil, err
185186
}
186187

188+
for resp.HasNextPage() {
189+
var nextAppGroups []*okta.ApplicationGroupAssignment
190+
resp, err = resp.Next(context.TODO(), &nextAppGroups)
191+
192+
if err != nil {
193+
oktaLogger.Error(err, "getting groups for specified application")
194+
return nil, err
195+
}
196+
197+
appGroups = append(appGroups, nextAppGroups...)
198+
}
199+
187200
groups, err = o.fetchGroupsAsync(appGroups)
188201
return groups, err
189202
}

0 commit comments

Comments
 (0)