|
| 1 | +# FreeIPA integration with Keycloak using ipa-tuura bridge |
| 2 | + |
| 3 | +This lab sets up an environment that integrates [FreeIPA](https://freeipa.org) and [Keycloak](https://keycloak.org) identity management deployments using the **ipa-tuura** bridge via Keycloak's User Federation feature. |
| 4 | + |
| 5 | +**ipa-tuura** is a service that exposes identity and authentication domains through a set of Django applications, enabling centralized management of users, groups, and authentication methods. |
| 6 | + |
| 7 | + |
| 8 | +## Preparing the environment |
| 9 | + |
| 10 | +Create the configuration: |
| 11 | + |
| 12 | +``` |
| 13 | +python3 -m venv /tmp/ipalab |
| 14 | +. /tmp/ipalab/bin/activate |
| 15 | +pip install -r requirements.txt |
| 16 | +``` |
| 17 | + |
| 18 | +Build the container image and instantiate containers: |
| 19 | + |
| 20 | +``` |
| 21 | +ipalab-config lab_ipa_tuura.yml |
| 22 | +cd ipa-tuura-keycloak |
| 23 | +podman-compose build |
| 24 | +podman-compose up -d |
| 25 | +``` |
| 26 | + |
| 27 | +At this stage, the environment consists of three containers: |
| 28 | +- A container based on the official Keycloak image |
| 29 | +- A container ready for deploying FreeIPA |
| 30 | +- The **ipa-tuura** service container, which bridges FreeIPA and Keycloak by integrating them through Keycloak's User Federation storage |
| 31 | + |
| 32 | +Deploy the IPA cluster using |
| 33 | +[ansible-freeipa](https://gtihub.com/freeipa/ansible-freeipa): |
| 34 | + |
| 35 | +``` |
| 36 | +ansible-galaxy collection install \ |
| 37 | + freeipa.ansible_freeipa \ |
| 38 | + containers.podman |
| 39 | +ansible-playbook -i inventory.yml \ |
| 40 | + ${HOME}/.ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/install-cluster.yml |
| 41 | +``` |
| 42 | + |
| 43 | +The provided Keycloak container uses a self-signed certificate that is |
| 44 | +unkown to the ipa-tuura container. The certificate is found in the container |
| 45 | +`keycloak` at the path `/opt/keycloak/conf/cert.pem`. This certificate |
| 46 | +must be added to the list of trusted certificates on the ipa-tuura |
| 47 | +container. This can be achieved by executing: |
| 48 | + |
| 49 | +``` |
| 50 | +keycloak/trust_keycloak.sh ipatuura |
| 51 | +``` |
| 52 | + |
| 53 | +## Using Keycloak web interface |
| 54 | + |
| 55 | +Since the whole environment runs using rootles containers, in a Podman |
| 56 | +virtual network, direct access to the host ports is not possible, but |
| 57 | +can be achieved using `podman unshare`. For example, to _ssh_ into the |
| 58 | +container (if `sshd` is available) or to access the `httpd` server. |
| 59 | + |
| 60 | +When using [Firefox](https://mozilla.org/firefox) a profile is needed |
| 61 | +to access the containers URLs, and to ease access the script |
| 62 | +`scripts/open-firefox.sh` is provided. This script will manage the |
| 63 | +Firefox profile and call `firefox` with the proper configuration for |
| 64 | +`podman unshare`, allowing access to Keycloak and WebUI. |
| 65 | + |
| 66 | +Before starting Firefox, add the entries found in the generated `hosts` |
| 67 | +file to your machine `/etc/hosts` so the host names can be resolved. The |
| 68 | +file `hosts` has all the containers entries needed, add it with: |
| 69 | + |
| 70 | +``` |
| 71 | +sudo bash -c "cat hosts >> /etc/hosts" |
| 72 | +``` |
| 73 | + |
| 74 | +Start the Keycloak web interface with: |
| 75 | + |
| 76 | +``` |
| 77 | +scripts/open-firefox.sh https://keycloak.example.test:8443 |
| 78 | +``` |
| 79 | + |
| 80 | +Start the IPA WebUI with: |
| 81 | + |
| 82 | +``` |
| 83 | +scripts/open-firefox.sh https://server.ipa.test:443 |
| 84 | +``` |
| 85 | + |
| 86 | +In a similar fashion you can access the Bridge API with: |
| 87 | + |
| 88 | +``` |
| 89 | +scripts/open-firefox.sh https://ipatuura.ipa.test:443 |
| 90 | +``` |
| 91 | + |
| 92 | + |
| 93 | +## Setting up Keycloak's User Federation Storage |
| 94 | + |
| 95 | + |
| 96 | +In order to interconnect both identity management systems, the **ipa-tuura** service must be added as part of Keycloak's *User Federation* storage. |
| 97 | + |
| 98 | +```json |
| 99 | + ./kcadm.sh create components \ |
| 100 | + -r master \ |
| 101 | + -s name=scimipa \ |
| 102 | + -s providerId=scim \ |
| 103 | + -s providerType=org.keycloak.storage.UserStorageProvider \ |
| 104 | + -s 'config.scimurl=["bridge.ipa.test"]' \ |
| 105 | + -s 'config.loginusername=["scim"]' \ |
| 106 | + -s 'config.loginpassword=["Secret123"]' \ |
| 107 | + -s 'config.domain=["ipa.test"]' \ |
| 108 | + -s 'config.domainname=["ipa.test"]' \ |
| 109 | + -s 'config.domaindesc=["Bridge_to_ipa"]' \ |
| 110 | + -s 'config.domainurl=["https://idm.ipa.test"]' \ |
| 111 | + -s 'config.domainclientid=["admin"]' \ |
| 112 | + -s 'config.domainclientsecret=["Secret123"]' \ |
| 113 | + -s 'config.idprovider=["ipa"]' \ |
| 114 | + -s 'config.cacert=["/etc/ipa/ca.crt"]' \ |
| 115 | + -s 'config.users_dn=["ou=people,dc=ipa,dc=test"]' \ |
| 116 | + -s 'config.extraattrs=["mail:mail, sn:sn, givenname:givenname"]' \ |
| 117 | + -s 'config.addintgdomain=["True"]' \ |
| 118 | + -s 'config.enabled=["True"]' \ |
| 119 | + -s 'config.keycloak_hostname=["keycloak.ipa.test"]' |
| 120 | +``` |
| 121 | + |
| 122 | +CHECK IF WE CAN CREATE A JSON and rely on kcreg: |
| 123 | + |
| 124 | +```json |
| 125 | +{ |
| 126 | + "enabled" : true, |
| 127 | + "clientAuthenticatorType" : "client-secret", |
| 128 | + "redirectUris" : [ "https://${IPASERVER}/ipa/idp/*" ], |
| 129 | + "webOrigins" : [ "https://${IPASERVER}" ], |
| 130 | + "protocol" : "openid-connect", |
| 131 | + "attributes" : { |
| 132 | + "oauth2.device.authorization.grant.enabled" : "true", |
| 133 | + "oauth2.device.polling.interval": "5" |
| 134 | + } |
| 135 | +} |
| 136 | +``` |
| 137 | + |
| 138 | + |
| 139 | +To create the OIDC client for Keycloak, you can use the script provided |
| 140 | +by `ipalab-config`. The script requires the IPA FQDN, an OIDC client ID |
| 141 | +and the OIDC client password. Execute: |
| 142 | + |
| 143 | +``` |
| 144 | +keycloak/keycloak_add_oidc_client.sh \ |
| 145 | + server.ipa.test \ |
| 146 | + ipa_oidc_client \ |
| 147 | + Secret123 |
| 148 | +``` |
| 149 | + |
| 150 | +Now, we can start adding some users to IPA deploytment, and check if they are automatically provisioned in Keycloak by running: |
| 151 | + |
| 152 | +``` |
| 153 | +ansible-playbook -i inventory.yml playbooks/add_ipa_users.yml |
| 154 | +``` |
| 155 | + |
| 156 | +## Testing the setup |
| 157 | + |
| 158 | +To test the setup, create a user on IPA using: |
| 159 | + |
| 160 | +``` |
| 161 | +ansible-playbook -i inventory.yml playbooks/add_user_auth_idp.yml |
| 162 | +``` |
| 163 | + |
| 164 | +Perform login with user `jdoe` on Keycloak web interface: |
| 165 | + |
| 166 | +``` |
| 167 | +scripts/open-firefox.sh https://keycloak.example.test:8443/realms/master/account |
| 168 | +``` |
| 169 | + |
| 170 | + |
| 171 | +## Troubleshooting |
| 172 | + |
| 173 | +ADD ipa-tuura troubleshooting |
| 174 | + |
| 175 | +If anything goes wrong, you can search `journalctl` for `ipa-otpd` |
| 176 | +entries. |
| 177 | + |
| 178 | +To increase the log level, set the `oidc_child` debug level in |
| 179 | +`/etc/ipa/default.conf` by setting: |
| 180 | + |
| 181 | +``` |
| 182 | +[global] |
| 183 | +oidc_child_debug_level=10 |
| 184 | +``` |
| 185 | + |
| 186 | +Valid values are between 0 and 10 and any value above 6 includes debug |
| 187 | +output from `libcurl` utility. |
0 commit comments