2016-05-18 01:57:04 +00:00
[[_kerberos]]
=== Kerberos
2017-08-28 12:50:14 +00:00
{project_name} supports login with a Kerberos ticket through the SPNEGO protocol.
2016-05-18 01:57:04 +00:00
SPNEGO (Simple and Protected GSSAPI Negotiation Mechanism) is used to authenticate transparently through the web browser after the user
has been authenticated when logging-in his session.
2017-08-28 12:50:14 +00:00
For non-web cases or when ticket is not available during login, {project_name} also supports login with Kerberos username/password.
2016-05-18 01:57:04 +00:00
2016-12-02 15:59:53 +00:00
A typical use case for web authentication is the following:
2016-05-18 01:57:04 +00:00
2016-12-02 15:59:53 +00:00
. User logs into his desktop (Such as a Windows machine in Active Directory domain or Linux machine with Kerberos integration enabled).
2017-08-28 12:50:14 +00:00
. User then uses his browser (IE/Firefox/Chrome) to access a web application secured by {project_name}.
. Application redirects to {project_name} login.
. {project_name} renders HTML login screen together with status 401 and HTTP header `WWW-Authenticate: Negotiate`
. In case that the browser has Kerberos ticket from desktop login, it transfers the desktop sign on information to the {project_name}
2016-05-18 01:57:04 +00:00
in header `Authorization: Negotiate 'spnego-token'` . Otherwise it just displays the login screen.
2017-08-28 12:50:14 +00:00
. {project_name} validates token from the browser and authenticates the user.
2016-05-18 01:57:04 +00:00
It provisions user data from LDAP (in case of LDAPFederationProvider with Kerberos authentication support) or let user
to update his profile and prefill data (in case of KerberosFederationProvider).
2017-08-28 12:50:14 +00:00
. {project_name} returns back to the application.
Communication between {project_name} and application happens through OpenID Connect or SAML messages.
The fact that {project_name} was authenticated through Kerberos is hidden from the application.
So {project_name} acts as broker to Kerberos/SPNEGO login.
2016-05-18 01:57:04 +00:00
2016-12-02 15:59:53 +00:00
For setup there are 3 main parts:
2016-05-18 01:57:04 +00:00
2016-12-02 15:59:53 +00:00
. Setup and configuration of Kerberos server (KDC)
2017-08-28 12:50:14 +00:00
. Setup and configuration of {project_name} server
2016-12-02 15:59:53 +00:00
. Setup and configuration of client machines
2016-05-18 01:57:04 +00:00
==== Setup of Kerberos server
This is platform dependent.
Exact steps depend on your OS and the Kerberos vendor you're going to use.
2016-12-02 15:59:53 +00:00
Consult Windows Active Directory, MIT Kerberos and your OS documentation for how exactly to setup and configure Kerberos server.
2016-05-18 01:57:04 +00:00
2016-12-02 15:59:53 +00:00
At least you will need to:
2016-05-18 01:57:04 +00:00
* Add some user principals to your Kerberos database.
2016-12-02 15:59:53 +00:00
You can also integrate your Kerberos with LDAP, which means that user accounts will be provisioned from LDAP server.
2016-05-18 01:57:04 +00:00
* Add service principal for "HTTP" service.
2017-08-28 12:50:14 +00:00
For example if your {project_name} server will be running on `www.mydomain.org` you may need to add principal `HTTP/www.mydomain.org@MYDOMAIN.ORG`
2016-05-18 01:57:04 +00:00
assuming that MYDOMAIN.ORG will be your Kerberos realm.
+
2016-06-02 18:59:58 +00:00
For example on MIT Kerberos you can run a "kadmin" session.
2016-12-02 15:59:53 +00:00
If you are on the same machine where is MIT Kerberos, you can simply use the command:
2016-05-18 01:57:04 +00:00
[source]
----
sudo kadmin.local
2016-12-02 15:59:53 +00:00
----
Then add HTTP principal and export his key to a keytab file with the commands like:
2016-05-18 01:57:04 +00:00
[source]
----
addprinc -randkey HTTP/www.mydomain.org@MYDOMAIN.ORG
ktadd -k /tmp/http.keytab HTTP/www.mydomain.org@MYDOMAIN.ORG
2016-12-02 15:59:53 +00:00
----
2016-05-18 01:57:04 +00:00
2017-08-28 12:50:14 +00:00
The Keytab file `/tmp/http.keytab` will need to be accessible on the host where {project_name} server will be running.
2016-12-02 15:59:53 +00:00
2017-08-28 12:50:14 +00:00
==== Setup and configuration of {project_name} server
2016-05-18 01:57:04 +00:00
You need to install a kerberos client on your machine. This is also platform dependent.
2016-06-02 18:59:58 +00:00
If you are on Fedora, Ubuntu or RHEL, you can install the package `freeipa-client`, which contains a Kerberos client and several other utilities.
Configure the kerberos client (on linux it's in file `/etc/krb5.conf` ). You need to put your Kerberos realm and at least configure the HTTP domains your server will be running on.
2016-12-02 15:59:53 +00:00
For the example realm MYDOMAIN.ORG you may configure the `domain_realm` section like this:
2016-05-18 01:57:04 +00:00
[source]
----
[domain_realm]
.mydomain.org = MYDOMAIN.ORG
mydomain.org = MYDOMAIN.ORG
2016-12-02 15:59:53 +00:00
----
2017-08-28 12:50:14 +00:00
Next you need to export the keytab file with the HTTP principal and make sure the file is accessible to the process under which {project_name} server is running.
2016-05-18 01:57:04 +00:00
For production, it's ideal if it's readable just by this process and not by someone else.
2017-08-28 12:50:14 +00:00
For the MIT Kerberos example above, we already exported keytab to `/tmp/http.keytab` . If your KDC and {project_name} are running on same host,
2016-05-31 15:17:46 +00:00
you have that file already available.
2016-05-18 01:57:04 +00:00
2016-05-31 15:17:46 +00:00
===== Enable SPNEGO Processing
2016-05-18 01:57:04 +00:00
2017-08-28 12:50:14 +00:00
{project_name} does not have the SPNEGO protocol support turned on by default. So, you have to go to the <<_authentication-flows, browser flow>>
2016-05-31 15:17:46 +00:00
and enable `Kerberos`.
2016-05-18 01:57:04 +00:00
2016-06-02 18:59:58 +00:00
.Browser Flow
2017-08-28 12:50:14 +00:00
image:{project_images}/browser-flow.png[]
2016-05-18 01:57:04 +00:00
2016-06-01 13:18:03 +00:00
Switch the `Kerberos` requirement from _disabled_ to either _alternative_ or _required_. _Alternative_ basically means that Kerberos is optional. If
2017-08-28 12:50:14 +00:00
the user's browser hasn't been configured to work with SPNEGO/Kerberos, then {project_name} will fall back to the regular login screens. If you set the requirement
2016-05-31 15:17:46 +00:00
to _required_ then all users must have Kerberos enabled for their browser.
2016-05-18 01:57:04 +00:00
2016-05-31 15:17:46 +00:00
===== Configure Kerberos User Storage Federation Provider
2016-05-18 01:57:04 +00:00
2017-08-28 12:50:14 +00:00
Now that the SPNEGO protocol is turned on at the authentication server, you'll need to configure how {project_name} interprets the Kerberos ticket.
This is done through <<_user-storage-federation,User Storage Federation>>. We have 2 different federation providers with Kerberos authentication support.
2016-05-18 01:57:04 +00:00
2017-08-28 12:50:14 +00:00
If you want to authenticate with Kerberos backed by an LDAP server, you have to first configure the <<_ldap, LDAP Federation Provider>>.
2016-05-31 15:17:46 +00:00
If you look at the configuration page for your LDAP provider you'll see a `Kerberos Integration` section.
.LDAP Kerberos Integration
2017-08-28 12:50:14 +00:00
image:{project_images}/ldap-kerberos.png[]
2016-05-31 15:17:46 +00:00
2017-08-28 12:50:14 +00:00
Turning on the switch `Allow Kerberos authentication` will make {project_name} use the Kerberos principal to lookup information about the user so that it can
be imported into the {project_name} environment.
2016-05-31 15:17:46 +00:00
If your Kerberos solution is not backed by an LDAP server, you have to use the `Kerberos` User Storage Federation Provider. Go to the `User Federation`
2016-12-02 15:59:53 +00:00
left menu item and select `Kerberos` from the `Add provider` select box.
2016-05-31 15:17:46 +00:00
.Kerberos User Storage Provider
2017-08-28 12:50:14 +00:00
image:{project_images}/kerberos-provider.png[]
2016-05-31 15:17:46 +00:00
2017-08-28 12:50:14 +00:00
This provider parses the Kerberos ticket for simple principal information and does a small import into the local {project_name} database.
2016-06-02 18:59:58 +00:00
User profile information like first name, last name, and email are not provisioned.
2016-05-18 01:57:04 +00:00
==== Setup and configuration of client machines
Clients need to install kerberos client and setup krb5.conf as described above.
Additionally they need to enable SPNEGO login support in their browser.
See link:http://www.microhowto.info/howto/configure_firefox_to_authenticate_using_spnego_and_kerberos.html[configuring Firefox for Kerberos] if you are using that browser.
2016-06-02 18:59:58 +00:00
URI `.mydomain.org` must be allowed in the `network.negotiate-auth.trusted-uris` config option.
2016-05-18 01:57:04 +00:00
2016-12-02 15:59:53 +00:00
In a Windows domain, clients usually don't need to configure anything special as IE is already able to participate in SPNEGO authentication for the Windows domain.
2016-05-18 01:57:04 +00:00
2017-08-28 12:50:14 +00:00
ifeval::[{project_community}==true]
2016-05-18 01:57:04 +00:00
==== Example setups
2016-12-02 15:59:53 +00:00
For easier testing with Kerberos, we provided some example setups to test.
2016-05-18 01:57:04 +00:00
2017-08-28 12:50:14 +00:00
===== {project_name} and FreeIPA docker image
2016-05-18 01:57:04 +00:00
Once you install https://www.docker.com/[docker], you can run docker image with http://www.freeipa.org/[FreeIPA] server installed.
2017-08-28 12:50:14 +00:00
FreeIPA provides integrated security solution with MIT Kerberos and 389 LDAP server among other things . The image provides also {project_name}
2016-05-18 01:57:04 +00:00
server configured with LDAP Federation provider and enabled SPNEGO/Kerberos authentication against the FreeIPA server.
2016-12-02 15:59:53 +00:00
See details https://github.com/mposolda/keycloak-freeipa-docker/blob/master/README.md[here] .
2016-05-18 01:57:04 +00:00
===== ApacheDS testing Kerberos server
2016-06-02 18:59:58 +00:00
For quick testing and unit tests, we use a very simple http://directory.apache.org/apacheds/[ApacheDS] Kerberos server.
2017-08-28 12:50:14 +00:00
You need to build {project_name} from sources and then run the Kerberos server with maven-exec-plugin from our testsuite.
2016-05-18 01:57:04 +00:00
See details https://github.com/keycloak/keycloak/blob/master/misc/Testsuite.md#kerberos-server[here] .
2017-08-28 12:50:14 +00:00
endif::[]
2016-05-18 01:57:04 +00:00
2016-06-02 18:59:58 +00:00
==== Credential Delegation
2016-05-18 01:57:04 +00:00
2016-05-18 02:04:13 +00:00
Kerberos 5 supports the concept of credential delegation. In this scenario, your applications may want access to the Kerberos ticket so that
2017-08-28 12:50:14 +00:00
they can re-use it to interact with other services secured by Kerberos. Since the SPNEGO protocol is processed in the {project_name} server,
2016-05-18 01:57:04 +00:00
you have to propagate the GSS credential to your application
2017-08-28 12:50:14 +00:00
within the OpenID Connect token claim or a SAML assertion attribute that is transmitted to your application from the {project_name} server.
2016-05-18 02:04:13 +00:00
To have this claim inserted into the token or assertion, each application will need to enable the built-in protocol mapper called `gss delegation credential`.
This is enabled in the `Mappers` tab of the application's
2017-08-28 12:50:14 +00:00
client page. See <<_protocol-mappers, Protocol Mappers>> chapter for more details.
2016-05-18 01:57:04 +00:00
2017-08-28 12:50:14 +00:00
Applications will need to deserialize the claim it receives from {project_name} before it can use it to make GSS calls against other services.
2016-06-02 18:59:58 +00:00
Once you deserialize the credential from the access token to the GSSCredential object, the GSSContext will need to be created with this credential
2016-05-18 01:57:04 +00:00
passed to the method `GSSManager.createContext` for example like this:
[source]
----
2016-06-06 09:51:14 +00:00
// Obtain accessToken in your application.
KeycloakPrincipal keycloakPrincipal = (KeycloakPrincipal) servletReq.getUserPrincipal();
AccessToken accessToken = keycloakPrincipal.getKeycloakSecurityContext().getToken();
// Retrieve kerberos credential from accessToken and deserialize it
String serializedGssCredential = (String) accessToken.getOtherClaims().
get(org.keycloak.common.constants.KerberosConstants.GSS_DELEGATION_CREDENTIAL);
GSSCredential deserializedGssCredential = org.keycloak.common.util.KerberosSerializationUtils.
deserializeCredential(serializedGssCredential);
// Create GSSContext to call other kerberos-secured services
2016-05-18 01:57:04 +00:00
GSSContext context = gssManager.createContext(serviceName, krb5Oid,
2016-06-06 09:51:14 +00:00
deserializedGssCredential, GSSContext.DEFAULT_LIFETIME);
----
2017-08-28 12:50:14 +00:00
ifeval::[{project_community}==true]
2016-06-06 09:51:14 +00:00
We have an example, that shows this in detail.
2017-08-28 12:50:14 +00:00
It's in `examples/kerberos` in the {project_name} example distribution or demo distribution download.
2016-06-06 09:51:14 +00:00
You can also check the example sources directly https://github.com/keycloak/keycloak/blob/master/examples/kerberos[here] .
2017-08-28 12:50:14 +00:00
endif::[]
2016-06-06 09:51:14 +00:00
2016-05-18 01:57:04 +00:00
Note that you also need to configure `forwardable` kerberos tickets in `krb5.conf` file and add support for delegated credentials to your browser.
2016-05-18 02:04:13 +00:00
WARNING: Credential delegation has some security implications so only use it if you really need it.
It's highly recommended to use it together with HTTPS.
See for example http://www.microhowto.info/howto/configure_firefox_to_authenticate_using_spnego_and_kerberos.html#idp27072[this article] for more details.
2016-05-18 01:57:04 +00:00
==== Troubleshooting
2016-05-18 02:04:13 +00:00
If you have issues, we recommend that you enable additional logging to debug the problem:
2016-05-18 01:57:04 +00:00
2016-12-02 15:59:53 +00:00
* Enable `Debug` flag in admin console for Kerberos or LDAP federation providers
* Enable TRACE logging for category `org.keycloak` in logging section of `standalone/configuration/standalone.xml` to receive more info `standalone/log/server.log`
* Add system properties `-Dsun.security.krb5.debug=true` and `-Dsun.security.spnego.debug=true`