-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ROX-11640: RHSSO dynamic clients rotation API (#1236)
Co-authored-by: dhaus67 <[email protected]>
- Loading branch information
1 parent
3e65804
commit 8220021
Showing
10 changed files
with
337 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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,38 @@ | ||
package rhsso | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/pkg/errors" | ||
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/api/dbapi" | ||
"github.com/stackrox/acs-fleet-manager/pkg/client/iam" | ||
"github.com/stackrox/acs-fleet-manager/pkg/client/redhatsso/api" | ||
"github.com/stackrox/rox/pkg/stringutils" | ||
) | ||
|
||
const ( | ||
oidcProviderCallbackPath = "/sso/providers/oidc/callback" | ||
dynamicClientsNameMaxLength = 50 | ||
) | ||
|
||
func AugmentWithDynamicAuthConfig(ctx context.Context, r *dbapi.CentralRequest, realmConfig *iam.IAMRealmConfig, apiClient *api.AcsTenantsApiService) error { | ||
// There is a limit on name length of the dynamic client. To avoid unnecessary errors, | ||
// we truncate name here. | ||
name := stringutils.Truncate(fmt.Sprintf("acscs-%s", r.Name), dynamicClientsNameMaxLength) | ||
orgID := r.OrganisationID | ||
redirectURIs := []string{fmt.Sprintf("https://%s%s", r.GetUIHost(), oidcProviderCallbackPath)} | ||
|
||
dynamicClientData, _, err := apiClient.CreateAcsClient(ctx, api.AcsClientRequestData{ | ||
Name: name, | ||
OrgId: orgID, | ||
RedirectUris: redirectURIs, | ||
}) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to create RHSSO dynamic client for %s", r.ID) | ||
} | ||
|
||
r.AuthConfig.ClientID = dynamicClientData.ClientId | ||
r.AuthConfig.ClientSecret = dynamicClientData.Secret // pragma: allowlist secret | ||
r.AuthConfig.Issuer = realmConfig.ValidIssuerURI | ||
return nil | ||
} |
This file contains 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 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
Oops, something went wrong.