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

Keycloak Identity Brokering with OpenShift

December 6, 2017
David Martin
Related topics:
Kubernetes
Related products:
Red Hat OpenShift Container Platform

    This article discusses how to set up and configure a Keycloak instance to use OpenShift for authentication via Identity Brokering. This allows for Single Sign On between the OpenShift cluster and the Keycloak instance. The Keycloak instance will be running on the OpenShift cluster and leverage a ServiceAccount OAuth Client.

    Provisioning Keycloak to your OpenShift namespace

    Use the below command to create the Keycloak resources in your OpenShift project.

     oc process -f https://raw.githubusercontent.com/david-martin/keycloak-with-openshift-auth-provider/0.0.2/keycloak-with-openshift-auth-provider.yaml | oc create -f -
    
    

    IMPORTANT: This template is intended for demonstration purposes only.

    This will create the following resources:

    • DeploymentConfig - Defines the Keycloak image to use and other Pod & container settings.
    • Service - Defines a Service in front of the Keycloak Pod.
    • Route - Exposes the Keycloak Service at an externally available hostname.
    • ServiceAccount - Defines a constrained form of OAuth Client in our namespace.

    For more info on the ServiceAccount OAuth Client, see https://docs.openshift.com/container-platform/3.7/architecture/additional_concepts/authentication.html#service-accounts-as-oauth-clients.

    After provisioning, the Keycloak service will be available at the exposed Route. Use the below command to get the route and sign in to the Administration Console.

    oc get route keycloak --template "http://{{.spec.host}} "

    You can sign in initially using the 'admin' user and the generated password stored in the 'KEYCLOAK_PASSWORD' environment variable.

    oc env dc/keycloak --list | grep KEYCLOAK_PASSWORD

    Creating a new Realm

    The 'admin' user will be signed in to the 'master' realm. This user has full control over the Keycloak instance. We can create a dedicated realm for our OpenShift project and allow OpenShift users to administer the realm. Only users who can access our OpenShift cluster will be able to sign in to Keycloak.

    Create a realm, and name it after our OpenShift Project.

    Configuring Keycloak to use OpenShift for Identity Brokering

    After creating the realm, the context should switch to the new realm. From the 'Identity Providers' menu, choose to 'Add provider...' and select 'OpenShift v3'. Fill in the below fields.

    openshift v3 provider

    Client ID

    This field is the OAuth Client identifier in OpenShift. As we're using a ServiceAccount OAuth Client, the id will be in the below format:

    system:serviceaccount::keycloak

    For example, if our project had an id of 'myproject', the Client ID would be:

    system:serviceaccount:myproject:keycloak

    Client Secret

    The secret is stored as a token for the ServiceAccount in OpenShift. To retrieve the secret, execute the following:

    oc sa get-token keycloak

    Base URL

    The Base URL is the OpenShift Master URL e.g. https://openshift.example.com.

    IMPORTANT: The OpenShift Master URL will need to have a trusted CA-signed certificate for Keycloak to successfully call the OAuth callback endpoint.

    Default Scopes

    These are the scopes to send to OpenShift when authorizing the user. As we're only interested in authentication, and not making modifications to OpenShift on behalf of users, we can just use the 'user:info' scope.

    After filling in all the above fields, the Provider can be created.

    Giving your OpenShift user a Role in Keycloak

    If you attempt to sign in to the realm now, any user who successfully signs in will *only* be able to manage their own account in Keycloak. To allow users to manage the realm, they'll need additional permission. There are two approaches to giving Users extra permissions:

    • Setting Default Roles/Groups for every user.
    • Explicitly setting Roles per user.

    Explicit Roles can be managed from the 'Users' menu after Users have signed in at least once.
    However, we're going to set up Default Roles so Users have roles on first sign in.

    To set a Default Role, choose the 'Default Roles' tab from the 'Roles' menu. Then choose the 'realm-management' Client Role and add the 'manage-realm' role to the 'Client Default Roles'. You may want to choose different or more restrictive roles depending on your requirements.

    realm roles

    Trying it out

    Try it out by navigating to the Realm Admin Console page in a new browser session or incognito window. The URL for the Realm Admin Console page can found in the 'Clients' menu as the Base URL for the 'security-admin-console' Client ID.

    realm client

    This will show a login screen with an 'Openshift v3' option. Choosing the 'Openshift v3' option should open an OpenShift login page.

    openshift v3 provider

    Login to OpenShift and you should eventually be redirected back to Keycloak and be able to manage the Realm. You may need to fill in some account details on the first login.

    Where to go from here?

    If you'd like to have more control over the permissions OpenShift users have in your Keycloak instance, you may want to remove the Default Roles. This would be particularly important if you don't know or trust all OpenShift users. In that case, you could remove the Default Roles, and only add specific Roles to users you trust. You could also create a Group with specific Roles to make it more manageable.

    The OpenShift template used in this article is available at https://github.com/david-martin/keycloak-with-openshift-auth-provider.


    The Red Hat OpenShift Container Platform is available for download.

    Last updated: December 4, 2017

    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

    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