Skip to main content
AI
  • Get started with AI

    • Red Hat AI

      Accelerate the development and deployment of enterprise AI solutions.

    • AI learning hub

      Explore learning materials and tools, organized by task.

    • AI interactive demos

      Click through scenarios with Red Hat AI, including training LLMs and more.

    • AI/ML learning paths

      Expand your Red Hat OpenShift AI knowledge using these learning resources.

    • AI quickstarts

      Focused AI use cases designed for fast deployment on Red Hat AI platforms.

    • No-cost AI training

      Foundational Red Hat AI training.

  • Featured resources

    • Red Hat OpenShift AI
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

Red Hat AI Factory with NVIDIA

Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.

Learn
  • Self-guided

    • Documentation

      Find answers, get step-by-step guidance, and learn how to use Red Hat products.

    • Learning paths

      Explore curated walkthroughs for common development tasks.

    • Guided learning

      Receive custom learning paths powered by our AI assistant.

    • See all learning
  • Hands-on

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

    • Interactive labs

      Learn by doing in these hands-on, browser-based experiences.

    • Interactive demos

      Click through product features in these guided tours.

  • Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics
  • Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
Build
  • Get started

    • Red Hat build of Podman Desktop

      A downloadable, local development hub to experiment with our products and builds.

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

  • Download products

    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products
  • Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset
  • References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
Community
  • Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions
  • Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github
  • Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

Join the Red Hat Developer program

Download Red Hat products and project builds, access support documentation, learning content, and more.

ConsoleDocsSupport Search
New For you

Recommended

We'll recommend resources you may like as you browse. Try these suggestions for now.

  • Product downloads
  • Cheat sheets
  • Red Hat Developer learning portal
  • Developer blog
  • E-books
  • Developer Sandbox
Log in

Get more with a Red Hat Developer account

  • Product downloads
  • Console access
  • Event registration
  • Training & trials
Explore more account benefitsLog in or register

A subscription may be required for some services.

Contact us

Protect apps with Red Hat build of Keycloak and Active Directory Federation Services

June 17, 2024
Torbjorn Dahlen
Related topics:
IntegrationSecurity
Related products:
Red Hat OpenShift

    In Active Directory Federation Services (AD FS) terminology, Red Hat build of Keycloak will be set up as a Resource Federation Server and AD FS as an Account Federation Server. This means that users will reside in Active Directory (AD) on Windows Server, while the protected web app will reside within the realm protected by Red Hat build of Keycloak on Red Hat OpenShift. With this, we want AD FS to authenticate users to give them access to web apps on OpenShift. Hence, when a user with an account in AD tries to access a web app on OpenShift, the user will be redirected to Red Hat build of Keycloak where they can choose to authenticate with AD FS. The user doesn't need to have an account in Red Hat build of Keycloak or in OpenShift for this to work.

    In Red Hat build of Keycloak terminology, we will configure a SAML 2.0 Identity Broker where AD FS will be configured as a SAML 2.0 Identity Provider (IdP). Furthermore, in AD FS Red Hat build of Keycloak will be configured as a Relying Party.

    Prerequisites

    In order to run the example in this article, you need to have the following set up beforehand.

    • A Windows Server with the following roles:

      • Active Directory Domain Services

      • Active Directory Federation Services

      • Certificate Authority

      • Public DNS record with internet access

      • In this article, I'm using Windows Server 2022 Datacenter Azure Edition.

    • An OpenShift cluster with the Red Hat build of Keycloak Operator installed. In this article I'm using Red Hat build of Keycloak 24 on OpenShift 4.15.

    Set up TLS certificates 

    Since Red Hat build of Keycloak and AD FS will need to reach each other securely over TLS, I'm setting up mutual TLS trust between Red Hat build of Keycloak and my Windows Server. Also, since I'm using self-signed certificates in this article, I will import the certificate for AD FS into the truststore of Red Hat build of Keycloak and also import the certificate for Red Hat build of Keycloak as a trusted certificate in Windows Server using the MMC Certificate snap-in. This is for demo purposes only and not intended for production use.

    First, I create a TLS certificate for AD FS using my Windows Server Certificate Authority and the MMC Certificate snap-in. In this example I'm setting the following properties (Figure 1).

    Screen shot showing the MMC Certificate snap-in
    Figure 1: Creating a TLS certificate for AD FS using my Windows Server Certificate Authority and the MMC Certificate snap-in.

    In Figure 1, I'm using the host name adfs-farm, configured in my local DNS as Common Name, and also adding Subject Alternative Names:

    • adfs-farm.adfs-demo.local (local AD FS DNS name)

    • certauth.adfs-farm.adfs-demo.local (AD FS user certificate hostname)

    • enterpriseregistration.adfs-demo.local (UPN suffix registration name)

    • adfs-demo.northeurope.cloudapp.azure.com (public AD FS DNS entry)

    The first SAN is the local hostname and domain of my Windows Server while the last one is the public DNS entry allowing clients to reach my AD FS instance over the internet.

    Then, I'm using the MMC Certificate snap-in to export the TLS certificate I've previously issued for AD FS using the Certificate Authority on Windows Server. I will also export the private key. The format used is PKCS#12 and the filename used in this example is adfs-cert.pfx.

    On my local workstation, the certificate is then converted to PEM as follows:

    % openssl pkcs12 -in adfs-cert.pfx -out adfs-cert.pem -clcerts -nokeys
    % openssl pkcs12 -in adfs-cert.pfx -out adfs-key.pem -nocerts -nodes 

    After that, I will create a TLS secret in OpenShift in my Red Hat build of Keycloak namespace:

    % oc new-project rhbk
    % oc create secret tls adfs-tls-secret --cert adfs-cert.pem --key adfs-key.pem

     Next, I will create a TLS secret for Red Hat build of Keycloak:

    % openssl req -verbose -subj '/CN=keycloak' -addext subjectAltName=DNS:rhbk-keycloak.apps.cluster-qtbgp.dynamic.redhatworkshops.io -newkey rsa:2048 -nodes -keyout keycloak-key.pem -x509 -days 365 -out keycloak-cert.pem
    % oc create secret tls keycloak-tls-secret --cert keycloak-cert.pem --key keycloak-key.pem

    Notice that the subjectAltName is set to the route of my Red Hat build of Keycloak instance on OpenShift. You should change this to match the route to your Red Hat build of Keycloak instance.

    You can create the Red Hat build of Keycloak instance using the Keycloak CR. You can use the following repo to deploy PostgreSQL and Red Hat build of Keycloak on OpenShift using the Red Hat build of Keycloak Operator: https://github.com/torbjorndahlen/keycloak-adfs.

    % oc apply -f postgres/postgres.yml
    % oc create secret generic keycloak-db-secret --from-literal=username=keycloak --from-literal=password=keycloak
    % oc apply -f keycloak/keycloak.yml

    Remember to change the hostname of Red Hat build of Keycloak in the CR to the name of your instance.

    In order to set up trust between Red Hat build of Keycloak and AD FS I will copy the keycloak-cert.pem file used for the TLS secret to Windows Server. Then use MMC Certificate snap-in to import the certificate (Figure 2).

    Screen shot showing the certificate import windows of of the MMC Certificate snap-in
    Figure 2: Importing the file containing the TLS certificate for Red Hat build of Keycloak under Trusted Root CAs.

    In Figure 2 I'm using the MMC Certificate snap-in to import the file containing the TLS certificate for Red Hat build of Keycloak under Trusted Root CAs.

    Now there is mutual TLS certificate trust between Windows Server and my Red Hat build of Keycloak instance to HTTPS can be used both ways.

    Configure Red Hat build of Keycloak as Identity Broker

    As the next step, I will use the Identity Brokering menu in Red Hat build of Keycloak to configure AD FS as my SAML 2.0 IdP (Figure 3).

    Screen shot showing the SAML provider configuration page in Red Hat build of Keycloak
    Figure 3: Configuring  AD FS as my SAML 2.0 IdP in Red Hat build of Keycloak.

    In Figure 3, notice the URL to the SAML entity descriptor. The /FederationMetadata/2007-06/FederationMetadata.xml endpoint is provided by AD FS and is preceded with the public DNS entry of my Windows Server. From there, Red Hat build of Keycloak will read the configuration required to set up AD FS as IdP.

    Next, I will configure the Name ID policy format. A corresponding claims mapping rule will be set up in AD FS later. See Figure 4.

    Screen shot showing the Name ID configuration page in Red Hat build of Keycloak
    Figure 4: Configuring the Name ID policy format.

    In Figure 4 I have set the Name ID policy format to Windows Domain Qualified Name, and the Principal type to Subject NameID.

    When created, the AD FS IdP configuration page will contain a SAML 2.0 Service Provider metadata URL that will be used to set up Red Hat build of Keycloak as Relying Party in the next step.

    I'm also setting up a Mapper to transform the username coming from AD FS (Figure 5).

    Screen shot showing the Identity Provide Mapper page in Red Hat build of Keycloak
    Figure 5: Setting up an Identity Provider Mapper.

    In Figure 5, I've used the default Username mapper to transform incoming usernames from AD FS to a format that is accepted by Red Hat build of Keycloak. e.g., ADFS-DEMO\alice is transformed to adfs.adfs-demoalice.

    In the AD FS Relying Party snap-in I will set up Red Hat build of Keycloak as a Claims Aware Relying Party (Figure 6).

    Screen shot showing the AD FS Relying party configuration page
    Figure 6: Setting up Red Hat build of Keycloak as a Claims Aware Relying Party in AD FS.

    In Figure 6, I'm entering the SAML 2.0 Service Provider metadata URL from the Identity Broker configuration page in Red Hat build of Keycloak as source where AD FS can import information about my Red Hat build of Keycloak Relying Party.

    As the final step I will set up a Claims Transformation rule for incoming claims from Red Hat build of Keycloak, as shown in Figure 7.

    Screen shot showing the Claims Transformation rule page in AD FS
    Figure 7: Setting up a Claims Transformation rule.

    In Figure 7, I've created a claims transformation rule that will rewrite a Windows account name, e.g., alice@dfs-demo.local into a Windows Qualified Domain name, e.g., ADFS-DEMO\alice.

    With this configuration done, a user could use their AD credentials to authenticate to a resource protected by Red Hat build of Keycloak. 

    Test the integration

    To test the integration I've created a user, Alice, in AD (Figure 8).

    Screen shot showing the users in Active Directory
    Figure 8: Creating a user in AD.

    In Figure 8, I've created a user called Alice. This user will try to access the built in account page in Red Hat build of Keycloak using her AD credentials (Figure 8).

    Screen shot showing the built in login page in Red Hat build of Keycloak
    Figure 9: User accessing the built in account page in Red Hat build of Keycloak.

    Then, the user is redirected to the login page provided by Red Hat build of Keycloak (Figure 9).

    Screen shot showing the login page in AD FS
    Figure 10: The user is redirected to AD FS to present her credentials.

    In Figure 10, the user is redirected to AD FS to present her credentials (Figure 10).

    Screen shot showing the account update page in Red Hat build of Keycloak
    Figure 11: The user is presented with the Update Account Information page.

    The user is presented with the Update Account Information page before being redirected to the account page (Figure 11).

    Summary

    In this article I have demonstrated how to integrate Red Hat build of Keycloak with AD FS, allowing users having their accounts in AD to access resources on OpenShift protected by Red Hat build of Keycloak. Red Hat build of Keycloak contains built-in Identity Brokering to connect Service Providers with external Identity Providers. The Identity Broker creates a relationship with an external Identity Provider, such as AD FS to use the provider’s user identities to access the services exposed for example on OpenShift.

    Related Posts

    • What's new in the Red Hat build of Keycloak version 22

    • How to integrate Spring Boot 3, Spring Security, and Keycloak

    • Keycloak Identity Brokering with OpenShift

    • How to restrict user authentication in Keycloak during identity brokering

    • Protect applications with Red Hat build of Keycloak using Kerberos & Active Directory

    • How to implement single sign-out in Keycloak with Spring Boot

    Recent Posts

    • A day in the life of an NVIDIA H100 on Red Hat OpenShift 5

    • Migrate BuildConfigs to builds for Red Hat OpenShift with one plug-in install

    • Run Red Hat Enterprise Linux CoreOS on NVIDIA BlueField DPUs

    • Agent harness engineering: Separating model capabilities from enforcement

    • What's new for developers in Red Hat Enterprise Linux 10.3 and 9.9

    What’s up next?

    Enhance security with automation_Share

    Explore strategies for enhancing your security using automation in this short e-book.

    Read the e-book
    Red Hat Developers logo

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    Red Hat Developer

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility
    Ask AI