AD Cloud

Hybrid Identity & SSO Bridge

Bridge On-Premises Active Directory with Cloud Identity

Hybrid Identity Active Directory Cloud SSO LDAP Sync Project I
0

What Are We Building?

Understanding Hybrid Identity Architecture

🔗 Requires: Project A (Authentik SSO) Completed
🌉
Bridge Two Worlds

Connect your on-premises Active Directory to cloud applications. Users login once with their AD credentials and access everything - on-prem AND cloud!

Hybrid Identity Flow

👤
Employee
AD Credentials
🏢
Active Directory
On-Premises
🌉
Identity Bridge
LDAP Sync
☁️
Authentik
Cloud IdP
📱
Cloud Apps
SSO Access

🏢 Enterprise Equivalent: Azure AD Connect

This project teaches Hybrid Identity concepts used in:

Enterprise Solution Our Implementation Skill Transfer
Azure AD Connect Authentik LDAP Provider 90%
AD FS (Federation Services) Authentik SAML/OIDC 85%
Okta AD Agent LDAP Source Integration 90%
Ping Identity AD Connector Directory Synchronization 85%
Password Hash Sync (PHS) LDAP Bind Authentication 80%

What We're Building

🏢
Samba AD DC
On-premises Active Directory Domain Controller
🔄
LDAP Sync
Real-time user & group synchronization
☁️
Authentik IdP
Cloud Identity Provider with SSO
🔐
Pass-Through Auth
Authenticate against AD in real-time
🎫
Token Bridge
AD credentials → Cloud tokens
📱
Cloud Apps
SaaS applications via OIDC/SAML
🎯

What You'll Have When Done

  • Active Directory Domain Controller (Samba)
  • LDAP synchronization to cloud IdP
  • Single Sign-On with AD credentials
  • Pass-through authentication (real-time AD validation)
  • Unified identity across on-prem and cloud
  • Group-based access control synced from AD
  • Audit trail for hybrid identity events
The Problem Hybrid Identity Solves

Without Hybrid Identity:

  • Users have separate passwords for on-prem and cloud
  • IT manages two identity systems independently
  • Password changes don't sync between systems
  • No unified audit trail for access

With Hybrid Identity: One password, one identity, one audit trail - everywhere!

⏱️

Time Investment

Phase Time Difficulty
Understanding Concepts 20-30 min Reading
Samba AD DC Setup 45-60 min Medium
AD Users & Groups 20-30 min Easy
LDAP Source Configuration 30-45 min Medium
SSO Federation Setup 30-45 min Medium
Testing & Validation 30-45 min Easy

Total: 4-5 hours

1

Core Concepts

Understanding Hybrid Identity Architecture

🧠
Learn These First

Hybrid Identity bridges the gap between on-premises and cloud identity systems

🏢
On-Premises AD
Traditional Active Directory running in your datacenter or office
☁️
Cloud IdP
Identity Provider in the cloud (Authentik, Azure AD, Okta)
🔄
Directory Sync
Automatically copy users/groups from AD to cloud
🔐
Pass-Through Auth
Cloud validates password against on-prem AD in real-time
🤝
Federation
Trust relationship between identity providers
🎫
Token Translation
Convert Kerberos tickets to OIDC/SAML tokens
📊

Hybrid Identity Models

Model How It Works We'll Build
Password Hash Sync (PHS) Hash of password copied to cloud
Pass-Through Auth (PTA) Cloud validates against on-prem AD live
Federation (AD FS) On-prem issues tokens, cloud trusts them
Directory Sync Only Users synced, separate passwords
📖

LDAP: The Universal Directory Protocol

LDAP (Lightweight Directory Access Protocol) is how systems talk to directories like Active Directory.

💡
Think of LDAP Like a Phone Book

LDAP is how you search and read a giant phone book of users. Active Directory speaks LDAP, and so does Authentik - they can talk to each other!

LDAP Term Meaning Example
DN Distinguished Name (unique path) CN=John,OU=Users,DC=corp,DC=local
DC Domain Component DC=corp,DC=local
OU Organizational Unit OU=Engineering
CN Common Name CN=John Smith
Bind Authenticate to LDAP Login with username/password

🐧 Why Samba AD Instead of Windows Server?

For this lab, we use Samba AD DC instead of Windows Server:

  • Free & Open Source - No Windows Server license needed ($500+)
  • Full AD Compatibility - Speaks the same LDAP/Kerberos protocols
  • Container-Friendly - Runs in Docker easily
  • Skills Transfer - LDAP concepts work with real Windows AD
2

Prerequisites

What you need before starting

📋
Checklist Before You Begin

This project builds on Project A (Authentik SSO)

Required: Complete Project A First

You must have a working Authentik installation from Project A:

  • Authentik running and accessible
  • Admin account created
  • HTTPS working via Traefik
  • Domain configured (e.g., authentik.yourdomain.com)
🖥️

Additional Server Resources

Resource Additional Need Total with Project A
RAM +2 GB 10 GB recommended
Storage +10 GB 110 GB recommended
CPU Same 4+ cores
🌐

Network Configuration

  • LDAP port 389 accessible internally
  • LDAPS port 636 accessible internally (optional)
  • DNS resolution working
💡
Internal Network Only

LDAP should NOT be exposed to the internet. Keep ports 389/636 on your internal network only!

📝

Plan Your Domain

Before starting, decide on your AD domain name:

Setting Example Your Value
AD Domain Name corp.local __________________
NetBIOS Name CORP __________________
Admin Password (secure password) __________________
⚠️
Use .local for Lab Environments

For home labs, use a .local domain like corp.local. In production, you'd use a real domain subdomain like ad.yourcompany.com.

3

Samba AD Domain Controller

Setting up your on-premises Active Directory

⚠️ Run These Commands ON THE SERVER

SSH into your server from Project A. All commands run on the same server as Authentik.

1
Create Project Directory
⏱️ 1 min
📁 Create Samba AD Directory
# Navigate to your projects folder
cd ~

# Create directory for Samba AD
mkdir -p samba-ad/config samba-ad/data

# Navigate into it
cd samba-ad

# Verify structure
ls -la
# Should show: config/ data/
2
Create Docker Compose File
⏱️ 5 min

Create the Docker Compose configuration for Samba AD:

🐳 docker-compose.yml
# ============================================
# SAMBA ACTIVE DIRECTORY DOMAIN CONTROLLER
# This creates a full AD DC in Docker
# ============================================

version: "3.8"

services:
  # ============================================
  # SAMBA AD DC
  # Full Active Directory Domain Controller
  # ============================================
  samba-ad:
    image: nowsci/samba-domain
    container_name: samba-ad
    hostname: dc1
    # Privileged mode required for AD to work properly
    privileged: true
    restart: unless-stopped
    
    # Environment variables configure the AD domain
    environment:
      # Your AD domain name (e.g., corp.local)
      - DOMAIN=corp.local
      
      # NetBIOS name (short name, max 15 chars)
      - DOMAINPASS=YourSecureP@ssw0rd!
      
      # Administrator password (CHANGE THIS!)
      - DNSFORWARDER=8.8.8.8
      
      # Don't join existing domain - create new one
      - HOSTIP=172.20.0.10
    
    # Expose AD-related ports
    ports:
      # DNS - Required for AD
      - "53:53/udp"
      - "53:53/tcp"
      # LDAP - Directory queries
      - "389:389/tcp"
      - "389:389/udp"
      # LDAPS - Secure LDAP
      - "636:636/tcp"
      # Kerberos - Authentication
      - "88:88/tcp"
      - "88:88/udp"
      # Global Catalog
      - "3268:3268/tcp"
      - "3269:3269/tcp"
    
    # Persistent storage for AD database
    volumes:
      - ./config:/etc/samba/external
      - ./data:/var/lib/samba
    
    # Static IP for reliable LDAP connections
    networks:
      ad-network:
        ipv4_address: 172.20.0.10

# Create isolated network for AD
networks:
  ad-network:
    driver: bridge
    ipam:
      config:
        - subnet: 172.20.0.0/24
🔒
Change the Password!

Replace YourSecureP@ssw0rd! with a strong, unique password. This is your AD Administrator password!

3
Start Samba AD Domain Controller
⏱️ 5 min
🚀 Start Samba AD
# Start the Samba AD container
docker compose up -d

# Wait for domain provisioning (takes 2-3 minutes first time)
echo "Waiting for AD provisioning..."
sleep 60

# Check if container is running
docker ps | grep samba-ad
# Should show: samba-ad ... Up ...

# View logs to confirm domain is ready
docker logs samba-ad 2>&1 | tail -20
# Look for: "Domain provisioned" or similar
4
Verify Active Directory is Working
⏱️ 3 min
Test LDAP Connection
# Install LDAP utilities if not present
sudo apt install -y ldap-utils

# Test LDAP connection to Samba AD
# This searches for the domain base
ldapsearch -x -H ldap://localhost:389 \
  -D "Administrator@corp.local" \
  -w "YourSecureP@ssw0rd!" \
  -b "DC=corp,DC=local" \
  "(objectClass=domain)"

# You should see output like:
# dn: DC=corp,DC=local
# objectClass: domain
# ...
💡
LDAP Search Explained

-x = Simple authentication, -H = LDAP URL, -D = Bind DN (user), -w = Password, -b = Search base

5
Create AD Users and Groups
⏱️ 10 min

Let's create some test users and groups in Active Directory:

👥 Create Organizational Units
# Enter the Samba container
docker exec -it samba-ad bash

# Inside container: Create Organizational Units
# OU for regular users
samba-tool ou create "OU=Employees,DC=corp,DC=local"

# OU for groups
samba-tool ou create "OU=Security Groups,DC=corp,DC=local"

# OU for IT staff
samba-tool ou create "OU=IT,OU=Employees,DC=corp,DC=local"

# OU for Engineering
samba-tool ou create "OU=Engineering,OU=Employees,DC=corp,DC=local"

# Verify OUs created
samba-tool ou list
# Should show: Employees, Security Groups, IT, Engineering
👤 Create Test Users
# Still inside samba-ad container

# Create IT Admin user
samba-tool user create itadmin "ITAdmin@123" \
  --given-name="IT" \
  --surname="Admin" \
  --mail-address="itadmin@corp.local" \
  --userou="OU=IT,OU=Employees"

# Create Developer user
samba-tool user create jsmith "DevUser@123" \
  --given-name="John" \
  --surname="Smith" \
  --mail-address="jsmith@corp.local" \
  --userou="OU=Engineering,OU=Employees"

# Create another Developer
samba-tool user create mjones "DevUser@123" \
  --given-name="Mary" \
  --surname="Jones" \
  --mail-address="mjones@corp.local" \
  --userou="OU=Engineering,OU=Employees"

# Verify users created
samba-tool user list
# Should show: Administrator, itadmin, jsmith, mjones, ...
👥 Create Security Groups
# Still inside samba-ad container

# Create Cloud Apps Access group
samba-tool group add "Cloud-Apps-Users" \
  --groupou="OU=Security Groups" \
  --description="Users allowed to access cloud applications"

# Create IT Admins group
samba-tool group add "IT-Admins" \
  --groupou="OU=Security Groups" \
  --description="IT Administrators with elevated access"

# Create Developers group
samba-tool group add "Developers" \
  --groupou="OU=Security Groups" \
  --description="Software developers"

# Add users to groups
samba-tool group addmembers "Cloud-Apps-Users" itadmin,jsmith,mjones
samba-tool group addmembers "IT-Admins" itadmin
samba-tool group addmembers "Developers" jsmith,mjones

# Verify group membership
samba-tool group listmembers "Cloud-Apps-Users"
# Should show: itadmin, jsmith, mjones

# Exit the container
exit
4

LDAP Source Configuration

Connect Authentik to Active Directory

🔄
Directory Synchronization

Authentik will read users and groups from Active Directory automatically

LDAP Sync Flow

🏢
Samba AD
Source of Truth
🔍
LDAP Query
Every 60 min
☁️
Authentik
Synced Users
1
Get Samba AD Container IP
⏱️ 1 min
🔍 Find Container IP Address
# Get the IP of the Samba AD container
docker inspect samba-ad --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'
# Should show: 172.20.0.10 (from our docker-compose)

# Or get your server's main IP
hostname -I | awk '{print $1}'
# Note this IP - you'll use it in Authentik
2
Create LDAP Source in Authentik
⏱️ 10 min

Open your Authentik admin panel and configure the LDAP source:

  1. Open Authentik Admin: https://authentik.yourdomain.com/if/admin/
  2. Navigate to: Directory → Federation & Social login
  3. Click Create → Select LDAP Source
  4. Fill in the configuration:
Field Value Explanation
Name Corporate AD Friendly name for this source
Slug corporate-ad URL-safe identifier
Server URI ldap://YOUR_SERVER_IP:389 Use your server's IP address
Bind CN Administrator@corp.local Account to query LDAP
Bind Password (your AD admin password) Password for bind account
Base DN DC=corp,DC=local Where to start searching
💡
Server URI Format

If Authentik runs on the same server as Samba AD, you can use ldap://172.20.0.10:389 (the container IP) or your server's LAN IP like ldap://192.168.1.50:389

3
Configure Property Mappings
⏱️ 5 min

Still on the LDAP Source configuration page, scroll down to Property Mappings:

Setting Value
User Property Mappings Select all LDAP Source - * mappings
Group Property Mappings Select all group mappings
User Object Filter (objectClass=user)
Group Object Filter (objectClass=group)
Sync Users ✅ Enabled
Sync Groups ✅ Enabled
Sync Parent Group Select a parent group (optional)
4
Configure Sync Settings
⏱️ 3 min

Scroll down to the Additional Settings section:

Setting Value Purpose
Enabled ✅ Yes Activate this source
Password Login ✅ Yes Allow AD password for login
Sync Interval 60 minutes How often to sync from AD

Click Create to save the LDAP Source.

5
Trigger Initial Sync
⏱️ 2 min
  1. In the LDAP Sources list, find your new Corporate AD source
  2. Click the ⚙️ Actions menu → Sync
  3. Wait 10-30 seconds for sync to complete
  4. Navigate to Directory → Users to see synced users
Verify Users Synced

You should see itadmin, jsmith, and mjones in the Users list. They'll have a badge indicating they came from the LDAP source.

5

SSO Flow Configuration

Enable AD users to access cloud apps

🔐
Pass-Through Authentication

When users login to cloud apps, their password is validated against Active Directory in real-time

1
Create Hybrid Authentication Flow
⏱️ 10 min

Create a custom flow that authenticates against AD:

  1. Navigate to: Flows & Stages → Flows
  2. Click Create
  3. Fill in:
    • Name: hybrid-identity-login
    • Title: Corporate Login (AD)
    • Slug: hybrid-identity-login
    • Designation: Authentication
2
Configure Flow Stages
⏱️ 10 min

Add the following stages to your flow:

Order Stage Type Purpose
10 Identification Stage User enters username
20 Password Stage (LDAP) Validate against AD
30 MFA Validation (optional) TOTP if configured
40 User Login Stage Create session
🏢
Enterprise Equivalent

This is similar to Azure AD's "Pass-Through Authentication" (PTA) where cloud logins validate against on-prem AD in real-time.

3
Configure Password Stage for LDAP
⏱️ 5 min
  1. Navigate to: Flows & Stages → Stages
  2. Create a new Password Stage or edit existing
  3. Under Backends, select:
    • authentik Backends.LDAPBackend
    • authentik Backends.InbuiltBackend (optional, for local users)
💡
Multiple Backends

By selecting both LDAP and Inbuilt backends, users can login with either AD credentials or local Authentik accounts. Great for hybrid scenarios!

6

Cloud Application Federation

Connect applications to use AD identities

🌐
Federated Access

AD users can now access cloud apps with their corporate credentials via OIDC/SAML

Complete Hybrid Identity Flow

👤
Employee
jsmith
📱
Cloud App
Grafana
☁️
Authentik
OIDC
🏢
Samba AD
LDAP Bind

Validated
Token Issued
1
Create Test Application (OIDC)
⏱️ 5 min

Let's create a test application to verify AD users can login:

  1. Navigate to: Applications → Applications
  2. Click Create
  3. Fill in:
    NameTest Hybrid App
    Slugtest-hybrid-app
    ProviderCreate new OAuth2 Provider
    Launch URL(leave blank for now)
2
Configure OAuth2 Provider
⏱️ 5 min
Field Value
Name Test Hybrid OAuth
Authorization Flow hybrid-identity-login
Client Type Confidential
Redirect URIs https://your-app.domain.com/callback
3
Configure Group-Based Access Control
⏱️ 5 min

Restrict application access to specific AD groups:

  1. Edit your application
  2. Under Policy / Group / User Bindings, click Bind existing policy/group
  3. Select the Cloud-Apps-Users group (synced from AD)
  4. Now only members of that AD group can access the app!
💡
AD Groups = Cloud Permissions

Add/remove users from AD groups, and their cloud app access automatically updates. Just like Azure AD!

7

Testing & Validation

Verify your hybrid identity setup works

🧪
Test Your Hybrid Identity

Let's verify AD users can login to cloud apps

1
Test AD User Login
⏱️ 3 min
  1. Open an incognito/private browser window
  2. Navigate to: https://authentik.yourdomain.com/
  3. Login with AD credentials:
    • Username: jsmith
    • Password: DevUser@123
  4. You should be logged into Authentik with your AD account!
Success Indicators

You'll see the user's full name from AD and their synced groups. The password was validated in real-time against Samba AD!

2
Verify LDAP Sync from Command Line
⏱️ 5 min
🔍 Query AD Users via LDAP
# List all users in the Employees OU
ldapsearch -x -H ldap://localhost:389 \
  -D "Administrator@corp.local" \
  -w "YourSecureP@ssw0rd!" \
  -b "OU=Employees,DC=corp,DC=local" \
  "(objectClass=user)" \
  cn mail sAMAccountName

# Expected output:
# dn: CN=IT Admin,OU=IT,OU=Employees,DC=corp,DC=local
# cn: IT Admin
# mail: itadmin@corp.local
# sAMAccountName: itadmin
# ...
👥 Query AD Groups via LDAP
# List all groups and their members
ldapsearch -x -H ldap://localhost:389 \
  -D "Administrator@corp.local" \
  -w "YourSecureP@ssw0rd!" \
  -b "OU=Security Groups,DC=corp,DC=local" \
  "(objectClass=group)" \
  cn member description

# Expected output shows groups with members:
# dn: CN=Cloud-Apps-Users,OU=Security Groups,DC=corp,DC=local
# cn: Cloud-Apps-Users
# member: CN=IT Admin,OU=IT,OU=Employees,DC=corp,DC=local
# member: CN=John Smith,OU=Engineering,OU=Employees,DC=corp,DC=local
# ...
3
Test Password Change Sync
⏱️ 5 min

Verify that AD password changes work immediately:

🔑 Change Password in AD
# Enter the Samba container
docker exec -it samba-ad bash

# Change jsmith's password
samba-tool user setpassword jsmith --newpassword="NewP@ssw0rd123"

# Exit container
exit

# Now try logging into Authentik with the NEW password
# The old password should fail immediately!
💡
Real-Time Password Validation

Because we're using pass-through authentication, password changes in AD take effect immediately for cloud logins. No sync delay!

4
Verify Complete Hybrid Flow
⏱️ 5 min
  • AD users appear in Authentik (Directory → Users)
  • AD groups synced to Authentik (Directory → Groups)
  • AD credentials work for Authentik login
  • Password changes take effect immediately
  • Group-based access control works
  • Audit logs show LDAP authentication events

🔧 Common Issues & Solutions

Issue Solution
LDAP connection failed Check container IP, ensure port 389 is accessible
No users synced Verify Base DN matches your domain (DC=corp,DC=local)
Login fails with correct password Check LDAP Backend is selected in Password Stage
Groups not showing Trigger manual sync, check group filter

What You Learned

Skills gained from this project

🎓

Enterprise Skills Acquired

  • Active Directory: Domain controllers, OUs, users, groups
  • LDAP: Directory protocol, binds, searches, filters
  • Hybrid Identity: Bridging on-prem and cloud identity
  • Pass-Through Auth: Real-time credential validation
  • Directory Sync: Automatic user/group synchronization
  • Federation: Trust relationships between IdPs
  • Group-Based Access: AD groups control cloud permissions
🏢
Enterprise Equivalents

You've implemented concepts used in:

  • Azure AD Connect - Microsoft's hybrid identity solution
  • Okta AD Agent - Okta's on-prem integration
  • Ping Identity AD Connector - PingFederate integration
  • AD FS - Active Directory Federation Services
🚀

Next Steps

  • Add more cloud applications (Grafana, Vault, etc.)
  • Implement conditional access policies
  • Add MFA for hybrid users
  • Set up password writeback (cloud → AD)
  • Configure self-service password reset