SSO with Keycloak
Requirements
- FortiGate with at least FortiOS 7.X
- Keycloak (26.X ideally)
This has been tested with Keycloak 26.X and FortiOS 7.6.6
Realm names in Keycloak are case-sensitive. Ensure all URLs referencing the realm name use the exact same casing (e.g. MyRealm not myrealm).
If you want seperateseparate Permissionspermissions for Admin SSO and e. g. VPN SSO (Regular User) you need two Clients for that!
Keycloak Setup
Keycloak Client Setup (basic)
- Log into Keycloak and go to Clients
- Create a new Client of Type SAML and set Client ID to
http://<your-fortigate-ip-or-fqdn>/metadatametadata/
Note the trailing slash — it must be present. The Client ID must be a byte-for-byte match of the Issuer value sent by FortiGate in its SAMLRequest.
- Finish the Create
clientClient wizard with defaultSettingssettings for now
Keycloak Client Setup (advanced)
- General Settings
- Set a
DisplaydisplayNamename for Name
- Set a
- Access settings
- Set your desired
AccessaccessAddressaddress as Root URL and Home URL - Set
https://<your-fortigate-ip-or-fqdn>/saml/?acsas Valid Redirect URIs - Set
https://<your-fortigate-ip-or-fqdn>/saml/?acsas Master SAML Processing URL
- Set your desired
- SAML capabilities
- Set Name ID Format to username
- Enable Force POST Binding
- Set Name ID Format to username
- Signature and Encryption
- Enable Sign documents
- Enable Sign assertions
- Keys tab
- Set Client Signature Required to Off — FortiGate does not sign AuthnRequests
- Logout settings
- Enable Front channel logout
- Set Logout service POST binding URL to
https://<your-fortigate-ip-or-fqdn>/saml/?sls - Set Logout service Redirect binding URL to
https://<your-fortigate-ip-or-fqdn>/saml/?sls
Keycloak Client Mapper Setup
Without a username mapper, FortiGate will reject the SAML assertion as it contains no username attribute.
- Go to Clients → your FGT client → Client scopes → (client)-dedicated → Add mapper → By configuration
- Select User Property and configure:
- Name:
username - Property:
username - SAML Attribute Name:
username - SAML Attribute NameFormat:
Basic
- Name:
- Save
FortiGate Setup
Preparation
Make sure to download the certificate from your specific realm's metadata endpoint, not the master realm. Each realm has its own signing key.
- Download the X509 Certificate from
https://<your-keycloak-uri>/realms/<realm-name>/protocol/saml/descriptor- Look for the
Valuevalue of<ds:X509Certificate> - Paste that content into a
Filefile with-----BEGIN CERTIFICATE-----as the first line and-----END CERTIFICATE-----as the last
- Look for the
- Log into FortiGate and go to System
-→ Certificates - Click Create/Import and select Remote Certificate
- Upload the previously created
Filefile - Note the name assigned to the certificate — usually
REMOTE_Cert_X
Admin SSO Configuration
- Log into FortiGate and go to Security Fabric
-→ Fabric Connectors - Right-
Clickclick on Security Fabric Setup-→ Edit-→ Single Sign-On Settings- Set Mode to Service Provider (SP)
- Click
onUse current browser address to automatically configure the SP AddressValuevalue - Configure the Default admin profile to your desired
Settingssettings - IdP Settings
- Set IdP type to Custom
- Set IdP certificate to
whatevertheNamename of your previously uploadedCertificatecertificateis. Usually(e.g.REMOTE_Cert_X) - Set IdP entity ID to
https://<your-keycloak-uri>/realms/<realm-name> - Set IdP single sign-on URL to
https://<your-keycloak-uri>/realms/<realm-name>/protocol/saml - Set IdP single logout URL to
https://<your-keycloak-uri>/realms/<realm-name>/protocol/saml