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 onClients
in the sidebar and click onCreate client
. Leave the client type asOpenID Connect
and enter theClient ID
, e.g.oidc-rp-foo
. Turn onClient authentication
for it and clickSave
.On the
Client details
page open the tabCredentials
and copy theClient secret
. Communicate this to the operato of the "resource domain"foo
via a secure channel. -
In the resource domain (
foo
) open Keycloak realmosism
, click onIdentity providers
and create a new provider definition of typeOpenID Connect v1.0
. AsAlias
choose a name, e.g.oidc-op-bar
. Don't copy theRedirect URI
given at the top yet, because is will change depending on the chosenAlias
. Instead, scroll down to the mandatory fieldDiscovery endpoint
and paste the OpenID Connect metadata URL of the KEycloak realmosism
in the "accounts domain" (bar
). The operator of the "accounts domain" (bar
) may easily copy that URL from theRealm Settins
in the sidebar of his Keycloak instance, where theEndpoints
are 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 keycloak
for 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 secret
that was provided by the operator of the "accounts domain" (bar
). Finally click onAdd
. From theProvider Details
page on the top for theSettings
tab copy the value of theRedirect URI
and communicate it back to the operator of the "accounts domain" (bar
). -
In the accounts domain (
bar
) open Keycloak realmosism
, click onClients
in the sidebar and click on the name of the OIDC RP clinent that you created for domainfoo
(e.g.oidc-rp-foo
). On theClient details
page on the tabSettings
fill in the fieldValid redirect URIs
with 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 URIs
need 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 account
and 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 theMappers
that 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.