3.3. Migration of services using SAML for authentication#
This section gives a general idea about the migration of services that use SimpleSAMLphp for the authentication to Keycloak as a SAML client.
The general approach for the migration includes the following:
Install the latest version of the Keycloak app in the UCS domain.
Get an overview of all the services that use SimpleSAMLphp and their settings.
Check and create attribute mappers for LDAP. Selected LDAP attributes become available to Keycloak.
Create a SAML SP, the client, and necessary attribute mappers in Keycloak for every service that uses SimpleSAMLphp as SAML IDP.
Change the SAML settings in the services to use Keycloak as a SAML IDP and validate the setup.
The following sections explain each step of the migration in detail.
3.3.1. Create LDAP attribute mappers#
Some services require specific LDAP attributes, for example, the service requires the user’s email address, which the SAML IDP can pass to the service during authentication. Create appropriate LDAP attribute mappers based on your needs.
The user object in Keycloak doesn’t have every attribute available in the LDAP directory. You can find a list of attributes mapped to Keycloak in Import of user attributes from UCS to Keycloak of Univention Keycloak app documentation [1].
To check, if the attribute mapping is sufficient for your services, compare the list with the attributes that SimpleSAMLphp reads from the LDAP directory. To get a complete list of LDAP attributes available to SimpleSAMLphp, run the following command:
$ udm saml/idpconfig list | sed -n 's/LdapGetAttributes: //p'
If you find attributes, that don’t map to Keycloak, you can create an LDAP mapper object through the tool univention-keycloak or directly in the Keycloak Admin Console. To create a mapping on the command line, run the following command:
$ univention-keycloak user-attribute-ldap-mapper create $LDAP_ATTRIBUTE_NAME
3.3.2. Create a SAML client in Keycloak#
Each SAML SP, or client, that you have configured for SimpleSAMLphp, requires a corresponding SAML SP created in Keycloak with the appropriate settings. Depending on the specific settings of your SAML SP, there are several ways to create a SAML client:
To inspect the SimpleSAMLphp configuration on the command line, run:
$ udm saml/serviceprovider list
Through the UMC module SAML Identity Provider. For a description of each LDAP attribute in this object, see Adding a new external service provider in UCS 5.0 Manual [2].
Use one of the following approaches that best suits your needs:
If your application provides a metadata XML file for the SAML client settings, you can create a client in Keycloak with the command line tool univention-keycloak by using either the URL to that XML file or the file itself.
# with URL $ univention-keycloak saml/sp create --metadata-url="$URL" # with local XML file $ univention-keycloak saml/sp create \ --metadata-url="REPLACE WITH SAML CLIENT ISSUER NAME OR URL" \ --metadata-file "/path/to/xml"
You can transfer each of the SAML client settings from the
saml/serviceprovider
object to the Keycloak client. The tool univention-keycloak has flags and options for each of these settings.# UMC SAML Identity Provider module / UDM attribute name
Keycloak GUI
univention-keycloak saml/sp create
optionService provider activation status:
isActivated
Enabled
--not-enabled
Service provider identifier:
Identifier
Client ID
--client-id
Respond to this service provider URL after login:
AssertionConsumerService
Valid redirect URI. This value is also automatically parsed from a metadata XML file.
--valid-redirect-uris
Format of NameID attribute:
NameIDFormat
Name ID format
--name-id-format
Description of this service provider:
serviceproviderdescription
Description
--description
URL to the service provider’s privacy policy:
privacypolicyURL
Policy URI
--policy-url
Respond to this service provider URL after login:
AssertionConsumerService
Assertion Consumer Service POST Binding URL
--assertion-consumer-url-post
Single logout URL for this service provider:
singleLogoutService
Logout Service POST Binding URL
--single-logout-service-url-post
Allow transition of LDAP attributes to the service provider:
simplesamlAttributes
n/a
Not available in Keycloak, only implicitly configured if specific attributes are configured to be transitioned to the service provider.
Name of the attribute that is used as NameID:
simplesamlNameIDAttribute
n/a
Not available during the creation of the SAML SP client. Instead another mappings object has to be created for Keycloak, see Configure user attributes for SAML response.
List of LDAP attributes to transmit:
LDAPattributes
n/a
Not available during the creation of the SAML SP client. Instead another mappings object has to be created for Keycloak, see Configure user attributes for SAML response.
Value for attribute format field:
attributesNameFormat
n/a
Not available during the creation of the SAML SP client. Instead another mappings object has to be created for Keycloak, see Configure user attributes for SAML response.
You can also use the Keycloak Admin Console to create SAML clients manually or to adjust clients created with
univention-keycloak saml/sp create
. You may want to consult the Keycloak documentation at Managing OpenID Connect and SAML Clients [4] about how to create clients in Keycloak.Some SAML clients may use custom configurations (e.g. with the attribute
rawsimplesamlSPconfig
of thesaml/serviceprovider
object). If you have a service configured in that way, please check the/etc/simplesamlphp/metadata.d/*.php
files to get the appropriate settings for the client.
3.3.3. Configure user attributes for SAML response#
The following listing demonstrates how to create attribute mappings in
Keycloak for the simplesamlNameIDAttribute
and
LDAPattributes
settings of the saml/serviceprovider
object.
These mappings allow you to configure the unique identifier for the user and
additional user attributes for the SAML response.
- NameID attribute (
simplesamlNameIDAttribute
) To map the attribute to Keycloak that uniquely identifies a user, create a so-called
SAML client nameid mapper
and attach it to the SAML SP. The table Table 3.2 shows which SimpleSAMLphp settings correspond to which options of the commandunivention-keycloak saml-client-nameid-mapper create
.# UMC SAML Identity Provider module / UDM attribute name
Keycloak GUI
univention-keycloak saml-client-nameid-mapper create
optionName of the attribute used as NameID:
simplesamlNameIDAttribute
User attribute
--user-attribute
Format of NameID attribute:
NameIDFormat
Mapper NameID format
--mapper-nameid-format
For example, a command might look like one of the following:
$ univention-keycloak saml-client-nameid-mapper create CLIENTID MAPPERNAME \ --user-attribute uid \ --mapper-nameid-format urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified
- Additional user attributes (
LDAPattributes
) Some SAML SP require additional attributes. The name of the attribute on the user object requires a mapping to the name of the attribute in the SAML assertion. The table Table 3.3 shows which SimpleSAMLphp settings correspond to which
univention-keycloak saml-client-user-attribute-mapper create
options.# UMC SAML Identity Provider module / UDM attribute name
Keycloak GUI
univention-keycloak saml-client-nameid-mapper create
optionValue for attribute format field:
attributesNameFormat
Name ID
--attribute-nameformat
List of LDAP attributes to transmit:
LDAPattributes
User attribute, SAML attribute name
--user-attribute
--attribute-name
You need to create such a mapper for each attribute listed in the SAML SP configuration. In Keycloak, you find flags to specify the name of the attribute to send:
--user-attribute
:is the attribute name present on the Keycloak user object.
--attribute-name
:is the SAML attribute utilizing the
urn:oid
namespace.
For example, a command might look like one of the following:
$ univention-keycloak saml-client-user-attribute-mapper create CLIENTID MAPPERNAME \ --user-attribute uid \ --attribute-name urn:oid:0.9.2342.19200300.100.1.1
Note
To get a list of client IDs for all existing SAML SP clients Keycloak, run:
$ univention-keycloak saml/sp get
3.3.4. Configure SAML services to use Keycloak#
After creating SAML SP clients and mappers in Keycloak, the next step is to update the service settings to use Keycloak as IdP.
Change the SAML settings in the services to use Keycloak as SAML IDP and validate the setup. The service needs some information about Keycloak as the IdP. This includes the Identity Provider Metadata URL, and the public certificate.
The SAML Identity Provider Metadata endpoint for Keycloak is
https://$sso_url/realms/ucs/protocol/saml/descriptor
. You can obtainsso_url
from the output of the following command:$ sso_url="$(univention-keycloak get-keycloak-base-url)"
It’s necessary to update the IdP public certificate in your SAML settings. You can obtain the Keycloak server certificate in PEM format with the following command:
$ univention-keycloak saml/idp/cert get \ --as-pem \ --output "/tmp/keycloak.cert"
How and where you need to configure this information in the service itself is very specific to the service, and this document can’t describe it in general terms. Consult the documentation of the service itself. To get a better idea of using SAML with Keycloak, take a look at the Services using SAML in the next section.
3.3.5. UCR variable differences#
This section describes the differences between UCR variables when using SimpleSAMLphp (SAML) and Keycloak.
3.3.5.1. Added variables#
Keycloak introduces the following UCR variables:
3.3.5.2. Renamed variables#
Keycloak uses the following variables known to be used for SAML before:
SAML |
Keycloak |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3.3.5.3. No longer supported variables#
Keycloak doesn’t support the following UCR variables anymore:
saml/idp/ldap/debug
saml/idp/ldap/get_attribute
saml/idp/ldap/user
saml/idp/log/debug/enabled
saml/idp/session-duration
saml/idp/show-error-reporting
saml/idp/show-errors
saml/idp/technicalcontactemail
saml/idp/technicalcontactname
saml/idp/timezone
ucs/server/sso/certificate/download
ucs/server/sso/certificate/generation
Keycloak enables the following UCR variables with the LDAP federation:
saml/idp/ldap/enable_tls
saml/idp/negotiate
starting with Keycloak app version22.0.3-ucs1
.
Keycloak sets the following UCR variables with the LDAP federation:
saml/idp/ldap/user
saml/idp/ldap/search_attributes
3.3.5.4. Not used anymore#
Keycloak doesn’t use the following UCR variables anymore and automatically sets a respective configuration:
saml/apache2/ssl/certificatechain
saml/idp/certificate/certificate
saml/idp/certificate/privatekey
saml/idp/https
Keycloak redirects to HTTPS automatically.
For cookies, the following UCR variables existed:
saml/idp/session-cookie/secure
saml/idp/session-cookie/samesite
saml/idp/language-cookie/secure
saml/idp/language-cookie/samesite
To set the cookie policy for Keycloak use the UCR variable
keycloak/cookies/samesite
. For possible values, see
Univention Keycloak app documentation [1].
SAML doesn’t use the following UCR variables anymore:
stunnel/debuglevel
saml/idp/lookandfeel/theme
To set the theme in Keycloak, use the command ucr set
ucs/web/theme=dark|light for ucs/web/theme
.
Use univention-keycloak saml to handle the SAML integration done with the following UCR variables before:
saml/idp/enableSAML20-IdP
saml/idp/entityID
saml/idp/entityID/supplement
/.*