This guide will walk you through creating and assigning distinct forwardAuth middlewares for different domains, allowing you to direct authentication requests to the appropriate portal.
Guide: Implementing Domain-Specific Authentication
This guide addresses the challenge of handling SSO authentication for services spread across multiple, unrelated domains. The goal is to stop redirecting users from one domain to another for authentication and instead use a dedicated authentication portal for each domain.
We will achieve this by creating separate forwardAuth middlewares for each domain and assigning them to the corresponding resources.
The Strategy
The core of the solution is to override the default, global SSO behavior for specific resources. Instead of relying on a single, platform-wide authentication middleware, you will define multiple forwardAuth middlewares. Each middleware will point to the correct authentication URL for a specific domain.
- Create Domain-Specific Middlewares: You will create at least two
forwardAuthmiddlewares.- One for
domain1.compointing toproxy.domain1.com. - Another for
domain2.compointing toproxy.domain2.com.
- One for
- Assign Middlewares to Resources: You will use the Middleware Manager UI to assign the correct middleware to each resource based on its domain.
Prerequisites
- You have two or more separate authentication portals running (e.g.,
proxy.domain1.comandproxy.domain2.com). Middleware Manager will direct traffic to these portals but does not host the authentication service itself. - Your Middleware Manager is correctly configured to watch for resources from your data source (Pangolin or Traefik).
Step-by-Step Instructions
Step 1: Create the forwardAuth Middlewares
First, you need to define a unique forwardAuth middleware for each of your authentication portals.
-
Navigate to Middlewares: From the main dashboard, go to the Middlewares page using the header navigation.
-
Create Middleware for Domain 1:
-
Click the Create Middleware button.
-
Name:
Auth via Domain1 -
Type: Select
forwardAuthfrom the dropdown list. -
Configuration: Enter the JSON configuration pointing to your first domain’s authentication service.
{ "address": "http://proxy.domain1.com/sso/auth", "trustForwardHeader": true, "authResponseHeaders": [ "Remote-User", "Remote-Groups", "Remote-Name", "Remote-Email" ] } -
Click Create Middleware to save it.
-
-
Create Middleware for Domain 2:
-
Click Create Middleware again.
-
Name:
Auth via Domain2 -
Type:
forwardAuth -
Configuration: Enter the JSON configuration pointing to your second domain’s authentication service.
{ "address": "http://proxy.domain2.com/sso/auth", "trustForwardHeader": true, "authResponseHeaders": [ "Remote-User", "Remote-Groups", "Remote-Name", "Remote-Email" ] } -
Click Create Middleware to save.
-
You will now have two distinct middleware definitions, each tailored for a specific authentication flow.
Step 2: Assign Middlewares to Your Resources
Next, assign the appropriate middleware to the resources on each domain.
- Navigate to Resources: Go to the Resources page from the header navigation.
- Select a Resource: Find a resource you want to secure with your new authentication, for example, a service on
subdomain.domain2.com. Click Manage to go to its detail page. - Assign the Middleware:
- On the Resource Detail page, scroll down to the Attached Middlewares card.
- Click the Add Middleware button.
- In the modal, select the appropriate middleware (e.g., Auth via Domain2) from the list.
- Set a Priority. A higher number (e.g.,
150) can help ensure it overrides any default middlewares. - Click Assign Selected.
- Repeat for Other Resources: Repeat this process for all other resources, assigning
Auth via Domain1to services ondomain1.comandAuth via Domain2to services ondomain2.com.
Step 3: Verification
Once the configuration is generated, you need to verify that the correct authentication flow is being triggered.
- Check Traefik Dashboard: Open your Traefik dashboard and inspect the router associated with your resource (e.g.,
subdomain.domain2.com). Verify that the list of middlewares for that router includesAuth-via-Domain2@file. The@fileprovider indicates that the middleware generated by Middleware Manager is being correctly applied. - Test the Authentication Flow:
- Access a service on
domain2.com(e.g.,https://subdomain.domain2.com). You should be redirected toproxy.domain2.comfor authentication. - Access a service on
domain1.com. You should be redirected toproxy.domain1.comfor authentication.
- Access a service on
By following these steps, you have successfully configured domain-specific authentication, providing a more intuitive and secure experience for your users.