-
Notifications
You must be signed in to change notification settings - Fork 14
APIGOV-32943 — Okta IDP per-scope policy lifecycle, app name templates, and scope exclude list #1049
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
Merged
Merged
APIGOV-32943 — Okta IDP per-scope policy lifecycle, app name templates, and scope exclude list #1049
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
ca4b013
APIGOV-32943 - Extend clients Okta and remove deprecated features. Fi…
sbolosan ffc6843
APIGOV-32943 - remove policy token and priority configs according to …
sbolosan ec48100
APIGOV-32943 - update for owning team and group property
sbolosan 2c9245c
APIGOV-32943 - update for scopes
sbolosan 88e69c1
APIGOV-32943 - blacklist processing
sbolosan e1c9356
APIGOV-32943 - change to guid for query
sbolosan 0751ef1
APIGOV-32943 - get proper placement of team owner
sbolosan 6c350e1
APIGOV-32943 - update to delete policy only after list is cleared
sbolosan d133f0c
APIGOV-32943 - udpate blacklist to exclude
sbolosan bc063c3
idp changes
dgghinea 5cdd3a1
persist IDPClient on managedApp straight after RegisterClient()
dgghinea dafd65f
fix tests
dgghinea ec038cd
change unregister logic
dgghinea 0511b01
add return
dgghinea 4c9db8a
changes
dgghinea a7507e9
fix deprov
dgghinea 47189bc
APIGOV-32989 - update golang.org/x libraries (#1050)
dfeldickgit d6e0c6c
APIGOV-32994 - Fix to create Idp resource if not already existing (#1…
vivekschauhan 23fa54d
APIGOV-31191 validate cache (#1015)
alrosca 5d5047a
APIGOV-31452 - Send New Insights Event Formats (#1040)
sbolosan bb065ca
APIGOV-31452 - resolve concurrent metric collector lock contention un…
sbolosan 3d3c287
APIGOV-32943 - rollback on invalid scope not on AS
sbolosan f2c19d1
Merge branch 'main' into APIGOV-32943
sbolosan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| package handler | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| management "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/management/v1alpha1" | ||
| defs "github.com/Axway/agent-sdk/pkg/apic/definitions" | ||
| "github.com/Axway/agent-sdk/pkg/authz/oauth" | ||
| "github.com/Axway/agent-sdk/pkg/util" | ||
| "github.com/Axway/agent-sdk/pkg/util/log" | ||
| ) | ||
|
|
||
| const ( | ||
| oktaClientIDsAgentDetail = "oktaClientIDs" | ||
| tokenURLAgentDetail = "tokenURL" | ||
| ) | ||
|
|
||
| // persistIDPClientOnManagedApplication stores IDP client IDs on the ManagedApplication x-agent-details | ||
| // so they can be cleaned up if the app is deleted before credential-level cleanup runs. | ||
| func persistIDPClientOnManagedApplication(logger log.FieldLogger, client client, app *management.ManagedApplication, clientID, tokenURL string) error { | ||
| if app == nil || clientID == "" { | ||
| return nil | ||
| } | ||
|
|
||
| details := util.GetAgentDetails(app) | ||
| if details == nil { | ||
| details = make(map[string]interface{}) | ||
| } | ||
|
|
||
| existing := extractClientIDs(details[oktaClientIDsAgentDetail]) | ||
| for _, id := range existing { | ||
| if id == clientID { | ||
| return nil | ||
| } | ||
| } | ||
| existing = append(existing, clientID) | ||
|
|
||
| details[oktaClientIDsAgentDetail] = existing | ||
| if tokenURL != "" { | ||
| details[tokenURLAgentDetail] = tokenURL | ||
| } | ||
|
|
||
| if err := client.CreateSubResource(app.ResourceMeta, map[string]interface{}{defs.XAgentDetails: details}); err != nil { | ||
| return fmt.Errorf("could not persist IDP client reference on managed application %s: %w", app.Name, err) | ||
| } | ||
|
|
||
| if logger != nil { | ||
| logger.WithField("clientID", clientID).Trace("persisted IDP client reference on managed application") | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func removeClientIDFromManagedApp(logger log.FieldLogger, client client, app *management.ManagedApplication, clientID, tokenURL string) error { | ||
| if app == nil || clientID == "" { | ||
| return nil | ||
| } | ||
|
|
||
| details := util.GetAgentDetails(app) | ||
| if details == nil { | ||
| return nil | ||
| } | ||
|
|
||
| clientIDs := extractClientIDs(details[oktaClientIDsAgentDetail]) | ||
| if len(clientIDs) == 0 { | ||
| logger.Trace("empty clientIDs agent detail") | ||
| return nil | ||
| } | ||
|
|
||
| for i := len(clientIDs) - 1; i >= 0; i-- { | ||
| if clientIDs[i] != clientID { | ||
| continue | ||
| } | ||
| clientIDs = append(clientIDs[:i], clientIDs[i+1:]...) | ||
| details[oktaClientIDsAgentDetail] = clientIDs | ||
| if err := client.CreateSubResource(app.ResourceMeta, map[string]interface{}{defs.XAgentDetails: details}); err != nil { | ||
| return fmt.Errorf("could not persist IDP client reference on managed application %s: %w", app.Name, err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| logger.WithField("clientID", clientID).Trace("could not find the clientID to remove from managedApp x-agent-details") | ||
| return nil | ||
| } | ||
|
|
||
| // cleanupManagedApplicationIDPClients removes any tracked IDP clients for a ManagedApplication. | ||
| func cleanupManagedApplicationIDPClients(ctx context.Context, logger log.FieldLogger, registry oauth.IdPRegistry, app *management.ManagedApplication) error { | ||
| if registry == nil || app == nil { | ||
| return nil | ||
| } | ||
|
|
||
| details := util.GetAgentDetails(app) | ||
| if details == nil { | ||
| return nil | ||
| } | ||
|
|
||
| clientIDs := extractClientIDs(details[oktaClientIDsAgentDetail]) | ||
| if len(clientIDs) == 0 { | ||
| return nil | ||
| } | ||
|
|
||
| tokenURL := util.ToString(details[tokenURLAgentDetail]) | ||
| if tokenURL == "" { | ||
| logger.Warn("no tokenURL in managed application x-agent-details, skipping IDP app cleanup") | ||
| return nil | ||
| } | ||
|
|
||
| provider, err := registry.GetProviderByTokenEndpoint(ctx, tokenURL) | ||
| if err != nil || provider == nil { | ||
| logger.WithField("tokenURL", tokenURL).Warn("no IDP provider registered for tokenURL, skipping IDP app cleanup") | ||
| return nil | ||
| } | ||
|
|
||
| for _, clientID := range clientIDs { | ||
| if err := provider.UnregisterClient(clientID, "", "", nil, ""); err != nil { | ||
| return fmt.Errorf("cleanupManagedApplicationIDPClients: failed for client %s: %w", clientID, err) | ||
| } | ||
| logger.WithField("clientID", clientID).Info("IDP client unregistered") | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func extractClientIDs(raw interface{}) []string { | ||
| switch v := raw.(type) { | ||
| case []string: | ||
| return append([]string(nil), v...) | ||
| case []interface{}: | ||
| ids := make([]string, 0, len(v)) | ||
| for _, item := range v { | ||
| if s, ok := item.(string); ok && s != "" { | ||
| ids = append(ids, s) | ||
| } | ||
| } | ||
| return ids | ||
| case string: | ||
| if v == "" { | ||
| return nil | ||
| } | ||
| var ids []string | ||
| if err := json.Unmarshal([]byte(v), &ids); err == nil { | ||
| return ids | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.