tree: 1e13b4b926ddd07d40b1f3de6274696238f4c6ee [path history] [tgz]
  1. keycloak-gerrit-client-export.json

Keycloak as Gerrit SAML provider

Keycloak is open source Identity and Access Management tool and supports the SAML authentication protocol.


This document provides a step-by-step tutorial how to set-up Keycloak as SAML provider for Gerrit Code Review for development and guidance only. For production HTTPS protocol and other more secure credentials and keys would need to be put in place.



  1. Install Keycloak official Docker image from this repository and start it:
  $ git clone
  $ cd keycloak/docker-compose-examples
  $ docker-compose -f keycloak-postgres.yml up
  1. Login to Keycloak using user=admin and password=Pa55w0rd credentials and import the Gerrit client keycloak json file.

  2. Create test user (e.g., fullname=“John Doe”, username “jdoe”, email: “”, password “secret”, Temporary=OFF)

  3. Add the following configuration settings to $GERRIT_SITE/etc/gerrit.config:

    type = HTTP
    logoutUrl = http://localhost:8080/auth/realms/master/protocol/openid-connect/logout
    httpHeader = X-SAML-UserName
    httpEmailHeader = X-SAML-EmailHeader
    httpExternalIdHeader = X-SAML-ExternalId

    listenUrl = http://*:8081/
    filterClass = com.googlesource.gerrit.plugins.saml.SamlWebFilter

    serviceProviderEntityId = SAML2Client
    keystorePath = etc/samlKeystore.jks
    keystorePassword = pac4j-demo-password
    privateKeyPassword = pac4j-demo-password
    metadataPath = http://localhost:8080/auth/realms/master/protocol/saml/descriptor
    userNameAttr = UserName
    displayNameAttr = DisplayName
    emailAddressAttr = EmailAddress
    computedDisplayName = true
    firstNameAttr = firstName
    lastNameAttr = lastName
  1. Generate keystore in $GERRIT_SITE/etc local keystore:
keytool -genkeypair -alias pac4j -keypass pac4j-demo-password \
  -keystore samlKeystore.jks \
  -storepass pac4j-demo-password -keyalg RSA -keysize 2048 -validity 365
  1. Install the saml.jar filter into the $GERRIT_SITE/lib directory

  2. Start gerrit using: $GERRIT_SITE/bin/ start

  3. Enter gerrit URL in browser: http://localhost:8081 and hit “Sign In” button

  4. Keycloak Login Dialog should appear

  5. Enter user: “jdoe” and password: “secret”

  6. You are redirected to gerrit and the first user/admin John Doe is created in gerrit with the right user name and email address.

  7. Congrats, you have Gerrit / Keycloak SAML integration up and running.