In this intermediate lab, you will implement a complete enterprise Single Sign-On (SSO) infrastructure using SAML 2.0 protocol and Keycloak Identity Provider. Building upon the LDAP directory you created in Lab 1, you will deploy Keycloak as your Identity Provider (IdP), federate it with your OpenLDAP directory to import users automatically, configure SAML 2.0 authentication for a sample web application, and test the complete SSO flow from user login to authenticated session. By the end of this lab, you will have a fully functional SSO system where users can authenticate once against Keycloak using their LDAP credentials and gain access to multiple applications—the exact same federated identity architecture used by enterprises to enable seamless access to SaaS applications like Salesforce, ServiceNow, AWS Console, and thousands of others.
You're an IAM Engineer at GlobalTech Corporation, a company with 5,000 employees that recently acquired three SaaS applications: Salesforce for CRM, ServiceNow for IT service management, and Workday for HR. Currently, employees must remember separate credentials for each system, leading to password fatigue, increased helpdesk tickets, and security risks from password reuse.
Your manager assigns you to implement SSO: "We need employees to log in once with their corporate credentials and access all three applications. The board wants this done in 60 days."
This lab teaches you exactly how to accomplish this. The skills you develop directly translate to:
Understand assertions, bindings, and metadata. Essential for integrating any enterprise SaaS application.
Configure Keycloak/Okta/Azure AD. Core skill for any IAM engineer role.
Connect IdPs to LDAP/AD. Required for hybrid cloud identity architectures.
Map identity attributes between systems. Critical for provisioning and authorization.
Debug SAML flows and decode assertions. The #1 skill for IAM support escalations.
Validate signatures, certificates, and bindings. Essential for security assessments.
This lab builds directly on Lab 1: LDAP Fundamentals. You must have a working OpenLDAP server with users before proceeding. If you haven't completed Lab 1, do so now—it takes approximately 3-4 hours.
| Component | Requirement | Purpose |
|---|---|---|
| Lab 1 Completion | OpenLDAP running with 3 users | User source for federation |
| VM RAM | 6 GB minimum (8 GB recommended) | Keycloak requires ~1.5 GB additional |
| VM Disk Space | 10 GB free | Keycloak image + data |
| Docker | Version 24.0+ | Container runtime |
| Web Browser | Chrome, Firefox, or Edge | Keycloak admin console & testing |
If you need to set up a new VM for this lab, you can use either:
Refer to Lab 1 for detailed hypervisor and Ubuntu VM installation instructions.
This diagram shows the complete SSO infrastructure you will build. The SAML authentication flow is highlighted at the bottom.
Port 8080
Identity Provider
SAML 2.0 / OIDC
Port 389
User Directory
dc=identitybytes,dc=lab
Port 8000
Service Provider
SAML Consumer
| Component | Role | SAML Function |
|---|---|---|
| Keycloak | Identity Provider (IdP) | Issues SAML Assertions after authenticating users |
| OpenLDAP | User Directory | Stores user credentials; federated into Keycloak |
| Test Application | Service Provider (SP) | Consumes SAML Assertions to create user sessions |
| Web Browser | User Agent | Carries SAML messages between SP and IdP |
Code blocks in this lab are tagged with badges indicating where to run commands:
Before proceeding, verify that your OpenLDAP container from Lab 1 is running and accessible. Navigate to your Lab 1 docker directory and check the container status. If the container is not running, start it using Docker Compose.
Ubuntu VMExpected output: You should see your three users (jdoe, jsmith, bjohnson) listed. If you see "Can't contact LDAP server", start the container first.
Create a dedicated directory for Lab 2 files. This keeps your lab environments organized and makes cleanup easier. You'll create subdirectories for Docker configurations and application files.
Ubuntu VMKeycloak will need to connect to OpenLDAP. Since both run in Docker, we need to either use Docker networking or get the container's IP address. We'll use Docker's internal DNS for container-to-container communication.
Ubuntu VMWe'll create a shared Docker network so Keycloak can reach OpenLDAP by container name instead of IP address. This is more reliable as IPs can change on container restart.
Create a shared Docker network that will allow Keycloak and OpenLDAP containers to communicate using container names as hostnames. Then connect the existing LDAP container to this network.
Ubuntu VMCreate a Docker Compose file for Keycloak. We'll use Keycloak 23.x (latest stable) with PostgreSQL as the database backend for better performance and persistence. The configuration includes development mode settings suitable for lab environments.
Ubuntu VMLaunch Keycloak and its PostgreSQL database. The first startup takes 2-3 minutes as Keycloak initializes its database schema and imports default configurations. Monitor the logs to confirm successful startup.
Ubuntu VMSuccess indicator: Look for the message "Running the server in development mode" or "Keycloak 23.0 started" in the logs.
Open your web browser and navigate to the Keycloak admin console. You'll log in with the admin credentials specified in the Docker Compose file. The admin console is where you'll configure realms, users, and SAML settings.
Web BrowserYou should now see the Keycloak Admin Console dashboard showing the "master" realm. The master realm is Keycloak's administrative realm—we'll create a separate realm for our application users.
In Keycloak, a Realm is a space where you manage users, credentials, roles, and groups. Think of it as a tenant or namespace. We'll create a dedicated realm called "identitybytes" for our SSO configuration. This separates our lab users from the Keycloak admin users in the master realm.
Keycloak ConsoleUser Federation allows Keycloak to import users from external identity stores like LDAP or Active Directory. Instead of duplicating user accounts, Keycloak authenticates against the federated directory and caches user information locally.
Navigate to User Federation in the Keycloak console and add an LDAP provider. This configuration tells Keycloak how to connect to your OpenLDAP server, where to find users, and how to authenticate them. We'll use the read-only account for browsing and the admin account for user import operations.
Keycloak ConsoleAttribute mappers define how LDAP attributes are translated to Keycloak user attributes. The default mappers handle common attributes, but we'll verify they're correctly configured for our OpenLDAP schema. Navigate to the Mappers tab within your LDAP federation configuration.
Keycloak ConsoleTrigger a full synchronization to import all users from OpenLDAP into Keycloak. After sync completes, verify the users appear in Keycloak's user list. Each user will be marked as federated, indicating their source is the LDAP directory.
Keycloak ConsoleYou should now see 3 users in Keycloak's user list, all showing "OpenLDAP" as their federation link. These users can now authenticate to Keycloak using their LDAP passwords (SecureP@ss2024!).
Now we'll configure a SAML Service Provider (SP) in Keycloak. In production, this would be your enterprise application (Salesforce, ServiceNow, etc.). For this lab, we'll create a test configuration and use a SAML testing tool to simulate the SP.
A "Client" in Keycloak represents an application that can request authentication. We'll create a SAML 2.0 client that represents our Service Provider. The client configuration includes the SP's entity ID, assertion consumer service URL, and attribute mappings.
Keycloak ConsoleAfter creating the client, configure the advanced SAML settings. These include signature requirements, assertion encryption options, and the Assertion Consumer Service (ACS) URL where Keycloak sends SAML responses.
Keycloak ConsoleConfigure which user attributes are included in the SAML assertion. The Service Provider may need attributes like email, first name, last name, and groups to provision user accounts or make authorization decisions. We'll create mappers to include these in the SAML response.
Keycloak ConsoleSAML metadata is an XML document that describes the IdP's endpoints, certificates, and capabilities. Service Providers use this metadata to configure trust with the IdP. Download both the IdP metadata and the realm's signing certificate.
Keycloak ConsoleDeploy a simple Python Flask application that acts as a SAML Service Provider. This application will initiate SAML authentication with Keycloak and display the received SAML assertion. This simulates how a real application would integrate with your SSO system.
Ubuntu VMInstall the Python dependencies and start the test application. The app will listen on port 8000 and provide a simple interface to initiate SAML authentication.
Ubuntu VMNote: Keep this terminal open. Open a new terminal or browser for the next steps.
Now test the complete SSO flow. Open your browser and navigate to the test application. Click "Login with SSO" to initiate SAML authentication. You'll be redirected to Keycloak's login page where you can authenticate with an LDAP user.
Web BrowserTo understand what happens during SAML authentication, use browser developer tools to inspect the SAML messages. The SAML Response contains the assertion with user attributes and signature.
Web BrowserIf you successfully logged in with jdoe's LDAP credentials and were redirected back to the application, your SAML SSO implementation is working! The user authenticated against Keycloak, which validated credentials against OpenLDAP.
Cause: LDAP password not syncing or wrong password
Solution:
ldapwhoami -x -H ldap://localhost -D "uid=jdoe,ou=people,dc=identitybytes,dc=lab" -w "SecureP@ss2024!"Cause: Network connectivity between containers
Solution:
docker network inspect sso-networkdocker exec -it keycloak-idp /bin/bash -c "curl -v telnet://identitybytes-ldap:389"Cause: Database or memory issues
Solution:
docker compose logs keycloakdocker compose logs postgresWhen you're finished with the lab, stop all services. You can choose to keep the data for later or perform a complete cleanup.
Ubuntu VMContinue your SAML and SSO learning journey with these carefully curated resources: