Proposal for documentation for Keycloak to Keycloak Federation (WebSSO)
The followig section is a reasonably detailed hands on description of how
to configure a federation between two separate SCS compliant domains by means
of Keycloak Identity Brokering. If we decide to use Keycloak as a component
to allow self service by tenants, then this documentation may be a useful addition
to some tenant facing documentation (or for the SCS operators too).
OTOH one could probably also script pretty much everything of this to allow tenants to use a CLI tool to automate the setup. For that purpose the documentation may be useful to guide the implementation of such a scripted solution.
Detailed tutorial on how to configure Federation (OpenID Connect) between two Keycloak instances in two separate SCS domains
Assume you have two CSPs using SCS. The first one wants to grant access to users of the other.
So let's call the first domain "resource domain" and the second one "accounts domain".
Both domains need to agree upon a name for the "OIDC RP" (which Keycloak calls Clients).
The Keycloak in the "resource domain" will be the OIDC RP and the Keycloak in the "accounts domain" will be the OIDC OP.
Assuming the "resource domain" is called foo and the "accounts domain" is called bar, the name for the "OIDC RP" could be oidc-rp-foo.
-
In the accounts domain (
bar) open Keycloak realmosism, click onClientsin the sidebar and click onCreate client. Leave the client type asOpenID Connectand enter theClient ID, e.g.oidc-rp-foo. Turn onClient authenticationfor it and clickSave.On the
Client detailspage open the tabCredentialsand copy theClient secret. Communicate this to the operato of the "resource domain"foovia a secure channel. -
In the resource domain (
foo) open Keycloak realmosism, click onIdentity providersand create a new provider definition of typeOpenID Connect v1.0. AsAliaschoose a name, e.g.oidc-op-bar. Don't copy theRedirect URIgiven at the top yet, because is will change depending on the chosenAlias. Instead, scroll down to the mandatory fieldDiscovery endpointand paste the OpenID Connect metadata URL of the KEycloak realmosismin the "accounts domain" (bar). The operator of the "accounts domain" (bar) may easily copy that URL from theRealm Settinsin the sidebar of his Keycloak instance, where theEndpointsare listed on the bottom of that form. The URL may have the formathttps://bar.com/auth/realms/osism/.well-known/openid-configuration. Once you leave that input field, Keycloak will attempt to fetch the metadata and extract the required details about protocol enspoints from the retrieved document. If this shows an error, it will give you an HTTP status code. If this shows an error code of 500, then this may be caused by a failure in certificate verification. In that case you may want to check the output ofdocker logs keycloakfor java stack traces. If you find any, the top of those stack traces may indicate what kind of problem occurred to the java code. From here we will assume that the emtadata URL could be fecthed without any issues.Now, go to the bottom of that form and insert tjhe
Client ID(oidc-rp-foo) and theClient secretthat was provided by the operator of the "accounts domain" (bar). Finally click onAdd. From theProvider Detailspage on the top for theSettingstab copy the value of theRedirect URIand communicate it back to the operator of the "accounts domain" (bar). -
In the accounts domain (
bar) open Keycloak realmosism, click onClientsin the sidebar and click on the name of the OIDC RP clinent that you created for domainfoo(e.g.oidc-rp-foo). On theClient detailspage on the tabSettingsfill in the fieldValid redirect URIswith the value obtained from the resource domain (foo), which should look similar tohttps://foo.com/auth/realms/osism/broker/oidc-op-bar/endpoint. Additionally theValid post logout redirect URIsneed to be set to something likehttps://foo.com/auth/realms/osism/*. -
To test federated login in the "resource domain" (
foo) open the URL of the Keycloak admin console for the realmosism:https://foo.com/auth/admin/osism/console(orhttps://foo.com/auth/realms/osism/protocol/openid-connect/auth?client_id=security-admin-console). Ignore the top section of the login form titledSign in to your accountand choose one of the OIDC OP federation choises below the lineOr sign in with. In this example it would beoidc-op-bar. This should redirect your browser to the authentication endpoint of the "accounts domain" (https://bar.com/auth/realms/osism/protocol/openid-connect/auth?scope=openid&...) where you should be able to log in with credentials that are valid in the "accounts domain" (bar). After successull authentication your broser should be redirected to admin console of the "resource domain", which may offer you a "first login flow" form where you can choose a username, email, firstname and lastname. The details depend on theMappersthat have been configured for the Identity Provideroidc-op-bar. After that you will be presented with a Keycloak themed page with the error messageRequest failed with status code 403, which is normal because the test account is not authorized to access any elements of the Keycloak admin console.