As an admin I want to allow users to SSO to Rancher via Zitadel as the central identity auth provider.
Since Rancher has no Zitadel or generic OIDC or SAML auth provider, our trick is to use Keycloak SAML, but connect it to Zitadel.
- Download Rancher's SAML Metadata XML from
https://RANCHERHOST/v1-saml/keycloak/saml/metadata
- Load it into the Zitadel SAML App as XML file. (may need to add .xml to file)
-
Create Keycloak SAML auth provider in Rancher and enter Zitadel's field names as in the screenshot below.
-
Download Zitadel SAML Metadata from
https://ZITADELHOST/saml/v2/metadata
-
Load that into Rancher Metadata XML field
-
Download the Certificate from Zitadel from
http://ZITADELHOST/saml/v2/certificate
-
Load that into the Rancher Certificate field
-
For the Private Key, follow the Rancher Docs, you can simply generate a key by running:
openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout myservice.key -out myservice.cert
- Load the
myservice.key
into the Rancher's Private Key field.
It should look like this in the end:
- Note that UID Field I wanted to use Zitadel's
UserID
, but it could beEmail
as well. - Note there is no Groups field in Zitadel's SAMLResponse but it works nevertheless. If you need to add the user to Rancher groups see notes below.
- Click enable in Rancher, and we are done. We see the auth provider is active:
- Logout, and we should see that we can now also login via our Keycloak provider, which is actually redirecting to our Zitadel SAML app:
- We see our Zitadel user now in the top right corner of our Rancher profile:
- Rancher logs will update the rancher user resource's
principalIds
to includekeycloak_user://265306122980819188
, where the id is the same as the Zitadel user id:
Waring: In my testing it didn't work yet, I need to dig deeper into how Rancher groups work in their docs.
There is no Groups field in Zitadel's SAMLResponse but it works nevertheless. If you need to add the user to Rancher groups you can create an action to add it.
function setCustomAttribute(ctx, api){
api.v1.attributes.setCustomAttribute('Groups', '', 'settings-manage')
}
Any user that can register and login via Zitadel is able to login to Rancher by default. Zitadel Rancher SAML App can be restricted to only certain Zitadel Users that have project/app access.
Rancher log when signin into as a new Zitadel user first time:
2024/05/02 10:26:23 [INFO] Creating user for principal keycloak_user://265329911630135303
2024/05/02 10:26:23 [INFO] Creating globalRoleBindings for u-r3tnxufjdy
2024/05/02 10:26:23 [INFO] Creating new GlobalRoleBinding for GlobalRoleBinding grb-qfhdn
2024/05/02 10:26:23 [INFO] [mgmt-auth-grb-controller] Creating clusterRoleBinding for globalRoleBinding grb-qfhdn for user u-r3tnxufjdy with role cattle-globalrole-user