spid-keycloak-provider
Italian SPID authentication provider for Keycloak (https://www.keycloak.org/)
Project details
This custom authentication provider for Keycloak enables easy integration of SPID with existing applications by leveraging Keycloak identity brokering features. Keycloak is a nice product, but still lacking on some aspects of SAML2 compatibility, and the SPID specifications deviate from the SAML2 standard in some key aspects.
Besides the SPID-SAML2 protocol differences, some of the SP behaviors are hardcoded to work with simple IdPs only (i.e. there is no support for generating SP metadata that joins multiple SPs) . Keycloak is slowly improving on this aspect, so over time this plugin will become simpler and targeted on implementing only the specific changes required by SPID.
I have documented a reference configuration for SPID and the workarounds required in the project wiki (https://github.com/italia/spid-keycloak-provider/wiki). Please make sure to read it and understand the config steps and the open issues and limitations before planning your Production environment.
Generating a self-signed RSA X509 certificate compliant with SPID specifications
Public administrations in Italy are allowed to use self-signed certificates for SPID/SAML signatures.
This plugin implements an alternative to the keycloak's rsa-generated provider, which generates a self-signed RSA X509 certificate compliant with SPID specifications.
You can select this provider by going to the Keys tab of the Keycloak admin console, clicking on Add provider and selecting SPID RSA Generated from the popup menu.
You must enable the new provider and set it as active, as well as setting it as the default RSA signature provider by doing one of the following:
- setting a higher priority for the new provider compared to the default one
- disabling the default provider
- deleting the default provider
Status
This project is still at a development stage but it has been successfully tested for SPID validation and it's currently used in Production.
Until the project gets to a stable release, it will be targeting the most recent release
of Keycloak as published on the website (see property version.keycloak in file pom.xml).
Do not use the latest release with previous versions of Keycloak, it won't work!
Since this plugin uses some Keycloak internal modules, versions of this plugin are coupled to Keycloak versions. After (major) Keycloak upgrades, you will almost certainly have also to update this provider.
Compatibility
| Keycloak | Plugin release | Notes |
|---|---|---|
| 26.6.x | 26.6.2 |
|
| 26.5.x | 26.5.6 |
|
| 26.4.x | 26.4.2 |
|
| 26.3.x | 26.3.1 |
|
| 26.2.x | 26.2.3 |
|
| 26.1.x | 26.1.4 |
|
| 26.0.x | 26.0.5 |
|
| 25.x.x | 25.0.1 |
|
| 24.x.x | 24.0.1 |
Web UI configuration restored; provider ID changed from spid to spid-saml (see migration note below) |
| 23.x.x | 1.0.17 |
Web UI configuration not available — use REST API only |
| 19.x.x | 1.0.16 |
Configuration
Given SPID requires hundreds of different parameters, to avoid errors it's strongly recommended to use keycloak-spid-provider-configuration-client to configure the plugin correctly.
Upgrading from release 1.0.17 to 24.0.1+
Provider ID was changed from spid to spid-saml to account for hardcoded Keycloak 24.x behavior. Before upgrading, run this SQL query against the Keycloak database:
UPDATE IDENTITY_PROVIDER SET PROVIDER_ID="spid-saml" WHERE PROVIDER_ID="spid"
Build (without docker)
Requirements:
- git
- JDK17+
- Maven
Just run:
git clone https://github.com/italia/spid-keycloak-provider.git
cd spid-keycloak-provider
mvn clean package
The output package will be generated under target/spid-provider.jar.
Build (with docker)
Requirements:
- Docker
Just run:
git clone https://github.com/italia/spid-keycloak-provider.git
cd spid-keycloak-provider
docker run --rm -v $(pwd):/opt/spid-keycloak-provider -w /opt/spid-keycloak-provider maven:3.8.6-openjdk-18-slim bash -c "mvn clean package"
The output package will be generated under target/spid-provider.jar.
Deployment
This provider should be deployed as a module, i.e. copied under
{$KEYCLOAK_PATH}/providers/, with the right permissions.
Keycloak will take care of loading the module, no restart needed.
Use this command for reference:
mvn clean package && \
sudo install -C -o keycloak -g keycloak target/spid-provider.jar /opt/keycloak/standalone/deployments/
If successful you will find a new provider type called SPID in the
Add Provider drop down list in the Identity Provider configuration screen.
Upgrading from previous versions
Upgrades are usually seamless, just repeat the deployment command.
Then restart Keycloak and it will reload the resources from the packages. Make sure you also clear
your browser caches or use incognito mode when verifying the correct deployment.
After the first reload you can turn back on the caches and restart Keycloak again.
If you are upgrading to Keycloak v19.x and later, please keep in mind that Keycloak switched the admin console to the new "keycloak.v2" theme. This plugin is not yet compatible with the new Admin console theme, so you'll have to switch the Admin Console Theme to the older "keycloak" one in order to configure the SPID-related settings. This issue is tracked at https://github.com/keycloak/keycloak/issues/15344.
Open issues and limitations
Please read the appropriate page on the project wiki (https://github.com/italia/spid-keycloak-provider/wiki/Open-issues-and-limitations). If your problem is not mentioned there, feel free to open an issue on GitHub.
Related projects
If you are interested in Keycloak plugins for the various Italian national auth systems, you may be interested also in:
-
Keycloak SPID Provider - https://github.com/italia/spid-keycloak-provider/
A Keycloak provider for the SPID federation -
Keycloak CIE ID Provider - https://github.com/lscorcia/keycloak-cieid-provider/
A Keycloak provider for the CIE ID federation -
Keycloak CNS Authenticator - https://github.com/lscorcia/keycloak-cns-authenticator/
A Keycloak authenticator to login using CNS tokens and smart cards
Acknowledgements
The basic idea behind this project came from the experimental SPID integration for older Keycloak versions developed by redhat-italy at https://github.com/redhat-italy/keycloak-spid-provider.
This project is released under the Apache License 2.0, same as the main Keycloak package.