Este contenido no está disponible en el idioma seleccionado.
Chapter 3. Authenticating with Red Hat Build of Keycloak (RHBK)
To authenticate users with Red Hat Build of Keycloak (RHBK):
3.1. Enabling authentication with Red Hat Build of Keycloak (RHBK) Copiar enlaceEnlace copiado en el portapapeles!
To authenticate users with Red Hat Build of Keycloak (RHBK), enable the OpenID Connect (OIDC) authentication provider in Red Hat Developer Hub.
Prerequisites
- You added a custom Developer Hub application configuration, and have sufficient permissions to modify it.
- You have sufficient permissions in RHSSO to create and manage a realm.
Procedure
To allow Developer Hub to authenticate with RHBK, complete the steps in RHBK, to create a realm and a user and secure the first application:
Use an existing realm, or create a realm, with a distinctive Name such as <my_realm>. Save the value for the next step:
- RHBK realm base URL, such as: <your_rhbk_URL>/realms/<your_realm>.
To register your Developer Hub in RHBK, in the created realm, secure the first application, with:
- Client ID: A distinctive client ID, such as <RHDH>.
-
Valid redirect URIs: Set to the OIDC handler URL:
https://<RHDH_URL>/api/auth/oidc/handler/frame. - Navigate to the Credentials tab and copy the Client secret.
Save the values for the next step:
- Client ID
- Client Secret
- To prepare for the verification steps, in the same realm, get the credential information for an existing user or create a user. Save the user credential information for the verification steps.
To add your RHSSO credentials to your Developer Hub, add the following key/value pairs to your Developer Hub secrets:
AUTH_OIDC_CLIENT_ID- Enter the saved Client ID.
AUTH_OIDC_CLIENT_SECRET- Enter the saved Client Secret.
AUTH_OIDC_METADATA_URL- Enter the saved RHBK realm base URL.
To set up the RHBK authentication provider in your Developer Hub custom configuration, edit your custom Developer Hub ConfigMap such as
app-config-rhdh, and add the following lines to theapp-config.yamlcontent:Configure mandatory fields:
app-config.yamlfragment with mandatory fields to enable authentication with RHBKCopy to Clipboard Copied! Toggle word wrap Toggle overflow environment: production-
Mark the environment as
productionto hide the Guest login in the Developer Hub home page. metadataUrl,clientId,clientSecret- To configure the OIDC provider with your secrets.
sigInPage: oidc- To enable the OIDC provider as default sign-in provider.
prompt: auto- To allow the identity provider to automatically determine whether to prompt for credentials or bypass the login redirect if an active RHSSO session exists.
If prompt: auto is not set, the identity provider defaults to prompt: none, which assumes that you are already logged in and rejects sign-in requests without an active session.
callbackUrlRHBK callback URL.
app-config.yamlfragment with optionalcallbackURLfieldauth: providers: oidc: production: callbackUrl: ${AUTH_OIDC_CALLBACK_URL}auth: providers: oidc: production: callbackUrl: ${AUTH_OIDC_CALLBACK_URL}Copy to Clipboard Copied! Toggle word wrap Toggle overflow tokenEndpointAuthMethodToken endpoint authentication method.
app-config.yamlfragment with optionaltokenEndpointAuthMethodfieldauth: providers: oidc: production: tokenEndpointAuthMethod: ${AUTH_OIDC_TOKEN_ENDPOINT_METHOD}auth: providers: oidc: production: tokenEndpointAuthMethod: ${AUTH_OIDC_TOKEN_ENDPOINT_METHOD}Copy to Clipboard Copied! Toggle word wrap Toggle overflow tokenSignedResponseAlgToken signed response algorithm.
app-config.yamlfragment with optionaltokenSignedResponseAlgfieldauth: providers: oidc: production: tokenSignedResponseAlg: ${AUTH_OIDC_SIGNED_RESPONSE_ALG}auth: providers: oidc: production: tokenSignedResponseAlg: ${AUTH_OIDC_SIGNED_RESPONSE_ALG}Copy to Clipboard Copied! Toggle word wrap Toggle overflow scopeRHBK scope.
app-config.yamlfragment with optionalscopefieldauth: providers: oidc: production: scope: ${AUTH_OIDC_SCOPE}auth: providers: oidc: production: scope: ${AUTH_OIDC_SCOPE}Copy to Clipboard Copied! Toggle word wrap Toggle overflow signInresolversAfter successful authentication, the user signing in must be resolved to an existing user in the Developer Hub catalog. To best match users securely for your use case, consider configuring a specific resolver. Enter the resolver list to override the default resolver:
oidcSubClaimMatchingKeycloakUserId.The authentication provider tries each sign-in resolver in order until it succeeds, and fails if none succeed.
WarningIn production mode, only configure one resolver to ensure users are securely matched.
resolver:::: Enter the sign-in resolver name. Available values: *oidcSubClaimMatchingKeycloakUserId*emailLocalPartMatchingUserEntityName*emailMatchingUserEntityProfileEmail*preferredUsernameMatchingUserEntityName+ .
app-config.yamlfragment with optionalresolverslistCopy to Clipboard Copied! Toggle word wrap Toggle overflow dangerouslyAllowSignInWithoutUserInCatalog: trueConfigure the sign-in resolver to bypass the user provisioning requirement in the Developer Hub software catalog.
WarningUse this option to explore Developer Hub features, but do not use it in production.
app-config-rhdh.yamlfragment with optional field to allow signing in users absent from the software catalogCopy to Clipboard Copied! Toggle word wrap Toggle overflow
sessionDurationLifespan of the user session. Enter a duration in
mslibrary format (such as '24h', '2 days'), ISO duration, or "human duration" as used in code.app-config-rhdh.yamlfragment with optionalsessionDurationfieldauth: providers: github: production: sessionDuration: { hours: 24 }auth: providers: github: production: sessionDuration: { hours: 24 }Copy to Clipboard Copied! Toggle word wrap Toggle overflow authbackstageTokenExpiration- To modify the Developer Hub token expiration from its default value of one hour, note that this refers to the validity of short-term cryptographic tokens, not the session duration. The expiration value must be set between 10 minutes and 24 hours.
app-config.yamlfragment with optionalauth.backstageTokenExpirationfieldauth: backstageTokenExpiration: { minutes: <user_defined_value> }auth: backstageTokenExpiration: { minutes: <user_defined_value> }Copy to Clipboard Copied! Toggle word wrap Toggle overflow Security considerationIf multiple valid refresh tokens are issued due to frequent refresh token requests, older tokens will remain valid until they expire. To enhance security and prevent potential misuse of older tokens, enable a refresh token rotation strategy in your RHBK realm.
- From the Configure section of the navigation menu, click Realm Settings.
- From the Realm Settings page, click the Tokens tab.
- From the Refresh tokens section of the Tokens tab, toggle the Revoke Refresh Token to the Enabled position.
Verification
- Go to the Developer Hub login page.
- Your Developer Hub sign-in page displays Sign in using OIDC and the Guest user sign-in is disabled.
- Log in with OIDC by using the saved Username and Password values.
3.2. Provisioning users from Red Hat Build of Keycloak (RHBK) to the software catalog Copiar enlaceEnlace copiado en el portapapeles!
Prerequisites
Procedure
To enable RHBK member discovery, edit your custom Developer Hub ConfigMap, such as
app-config-rhdh, and add the following lines to theapp-config.yamlcontent:app-config.yamlfragment with mandatorykeycloakOrgfieldsCopy to Clipboard Copied! Toggle word wrap Toggle overflow baseUrl- Your RHBK server URL, defined when enabling authentication with RHBK.
clientId- Your Developer Hub application client ID in RHBK, defined when enabling authentication with RHBK.
clientSecret- Your Developer Hub application client secret in RHBK, defined when enabling authentication with RHBK.
Optional: Consider adding the following optional fields:
realmRealm to synchronize. Default value:
master.app-config.yamlfragment with optionalrealmfieldcatalog: providers: keycloakOrg: default: realm: mastercatalog: providers: keycloakOrg: default: realm: masterCopy to Clipboard Copied! Toggle word wrap Toggle overflow loginRealmRealm used to authenticate. Default value:
master.app-config.yamlfragment with optionalloginRealmfieldcatalog: providers: keycloakOrg: default: loginRealm: mastercatalog: providers: keycloakOrg: default: loginRealm: masterCopy to Clipboard Copied! Toggle word wrap Toggle overflow userQuerySizeUser number to query simultaneously. Default value:
100.app-config.yamlfragment with optionaluserQuerySizefieldcatalog: providers: keycloakOrg: default: userQuerySize: 100catalog: providers: keycloakOrg: default: userQuerySize: 100Copy to Clipboard Copied! Toggle word wrap Toggle overflow groupQuerySizeGroup number to query simultaneously. Default value:
100.app-config.yamlfragment with optionalgroupQuerySizefieldcatalog: providers: keycloakOrg: default: groupQuerySize: 100catalog: providers: keycloakOrg: default: groupQuerySize: 100Copy to Clipboard Copied! Toggle word wrap Toggle overflow schedule.frequencyTo specify custom schedule frequency. Supports cron, ISO duration, and "human duration" as used in code.
app-config.yamlfragment with optionalschedule.frequencyfieldCopy to Clipboard Copied! Toggle word wrap Toggle overflow schedule.timeoutTo specify custom timeout. Supports ISO duration and "human duration" as used in code.
app-config.yamlfragment with optionalschedule.timeoutfieldCopy to Clipboard Copied! Toggle word wrap Toggle overflow schedule.initialDelayTo specify custom initial delay. Supports ISO duration and "human duration" as used in code.
app-config.yamlfragment with optionalschedule.initialDelayfieldCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Check the console logs to verify that the synchronization is completed.
Successful synchronization example:
{"class":"KeycloakOrgEntityProvider","level":"info","message":"Read 3 Keycloak users and 2 Keycloak groups in 1.5 seconds. Committing...","plugin":"catalog","service":"backstage","taskId":"KeycloakOrgEntityProvider:default:refresh","taskInstanceId":"bf0467ff-8ac4-4702-911c-380270e44dea","timestamp":"2024-09-25 13:58:04"} {"class":"KeycloakOrgEntityProvider","level":"info","message":"Committed 3 Keycloak users and 2 Keycloak groups in 0.0 seconds.","plugin":"catalog","service":"backstage","taskId":"KeycloakOrgEntityProvider:default:refresh","taskInstanceId":"bf0467ff-8ac4-4702-911c-380270e44dea","timestamp":"2024-09-25 13:58:04"}{"class":"KeycloakOrgEntityProvider","level":"info","message":"Read 3 Keycloak users and 2 Keycloak groups in 1.5 seconds. Committing...","plugin":"catalog","service":"backstage","taskId":"KeycloakOrgEntityProvider:default:refresh","taskInstanceId":"bf0467ff-8ac4-4702-911c-380270e44dea","timestamp":"2024-09-25 13:58:04"} {"class":"KeycloakOrgEntityProvider","level":"info","message":"Committed 3 Keycloak users and 2 Keycloak groups in 0.0 seconds.","plugin":"catalog","service":"backstage","taskId":"KeycloakOrgEntityProvider:default:refresh","taskInstanceId":"bf0467ff-8ac4-4702-911c-380270e44dea","timestamp":"2024-09-25 13:58:04"}Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Log in with an RHBK account.
3.3. Creating a custom transformer to provision users from Red Hat Build of Keycloak (RHBK) to the software catalog Copiar enlaceEnlace copiado en el portapapeles!
To customize how RHBK users and groups are mapped to Red Hat Developer Hub entities, you can create a backend module that uses the keycloakTransformerExtensionPoint to provide custom user and group transformers for the Keycloak backend.
Prerequisites
Procedure
-
Create a new backend module with the
yarn newcommand. Add your custom user and group transformers to the
keycloakTransformerExtensionPoint.The following is an example of how the backend module can be defined:
plugins/<module-name>/src/module.tsCopy to Clipboard Copied! Toggle word wrap Toggle overflow ImportantThe module’s
pluginIdmust be set tocatalogto match thepluginIdof thekeycloak-backend; otherwise, the module fails to initialize.Install this new backend module into your Developer Hub backend.
backend.add(import(backstage-plugin-catalog-backend-module-keycloak-transformer))
backend.add(import(backstage-plugin-catalog-backend-module-keycloak-transformer))Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Developer Hub imports the users and groups each time when started. Check the console logs to verify that the synchronization is completed.
Successful synchronization example:
{"class":"KeycloakOrgEntityProvider","level":"info","message":"Read 3 Keycloak users and 2 Keycloak groups in 1.5 seconds. Committing...","plugin":"catalog","service":"backstage","taskId":"KeycloakOrgEntityProvider:default:refresh","taskInstanceId":"bf0467ff-8ac4-4702-911c-380270e44dea","timestamp":"2024-09-25 13:58:04"} {"class":"KeycloakOrgEntityProvider","level":"info","message":"Committed 3 Keycloak users and 2 Keycloak groups in 0.0 seconds.","plugin":"catalog","service":"backstage","taskId":"KeycloakOrgEntityProvider:default:refresh","taskInstanceId":"bf0467ff-8ac4-4702-911c-380270e44dea","timestamp":"2024-09-25 13:58:04"}{"class":"KeycloakOrgEntityProvider","level":"info","message":"Read 3 Keycloak users and 2 Keycloak groups in 1.5 seconds. Committing...","plugin":"catalog","service":"backstage","taskId":"KeycloakOrgEntityProvider:default:refresh","taskInstanceId":"bf0467ff-8ac4-4702-911c-380270e44dea","timestamp":"2024-09-25 13:58:04"} {"class":"KeycloakOrgEntityProvider","level":"info","message":"Committed 3 Keycloak users and 2 Keycloak groups in 0.0 seconds.","plugin":"catalog","service":"backstage","taskId":"KeycloakOrgEntityProvider:default:refresh","taskInstanceId":"bf0467ff-8ac4-4702-911c-380270e44dea","timestamp":"2024-09-25 13:58:04"}Copy to Clipboard Copied! Toggle word wrap Toggle overflow - After the first import is complete, navigate to the Catalog page and select User to view the list of users.
- When you select a user, you see the information imported from RHBK.
- You can select a group, view the list, and access or review the information imported from RHBK.
- You can log in with an RHBK account.