Development with an OIDC server
This document describes the steps needed to enable External Authentication (httpd), running an OIDC server and Apache on a local development setup.
-
Ensure you have the guides repo cloned locally, then
cd guides/external_auth
-
Launch KeyCloak
docker run --rm --name keycloak \ -p 8443:8443 \ -v $(pwd)/certs:/etc/x509/https \ -v $(pwd)/realms:/tmp/realms \ -e JAVA_OPTS="-Dkeycloak.profile.feature.scripts=enabled -Dkeycloak.profile.feature.upload_scripts=enabled" \ -e KEYCLOAK_IMPORT=/tmp/realms/ManageIQ-realm.json \ -e KEYCLOAK_USER=admin \ -e KEYCLOAK_PASSWORD=smartvm \ -e DB_VENDOR=h2 \ quay.io/keycloak/keycloak:12.0.4
When it completes startup, go to
https://127.0.0.1.nip.io:8443
and login withadmin
/smartvm
to verify it’s working. You should see a realm forManageIQ
. -
Launch the httpd container
docker run --rm -it --name httpd \ -p 80:80 \ -v $(pwd)/oidc-httpd-configs:/etc/httpd/conf.d \ -e HTTPD_AUTH_OIDC_CLIENT_ID=manageiq-oidc-client \ -e HTTPD_AUTH_OIDC_CLIENT_SECRET=3167ae6f-762d-49cd-b246-ef8856315957 \ -e HTTPD_AUTH_HOST=127.0.0.1.nip.io \ --add-host=127.0.0.1.nip.io:192.168.65.2 \ manageiq/httpd:latest
-
Launch ManageIQ
Run your Rails server as you normally would for development, however, instead of accessing via the browser at
https://localhost:3000
, usehttp://127.0.0.1.nip.io
(noticehttp
as opposed tohttps
).If ManageIQ is not yet configured for OIDC, do the following:
- Login as
admin
/smartvm
- Go to
Settings
->Application Settings
->Authentication
-
Change the following:
Mode External (httpd)
Enable Single Sign-On checked Provider Type Enable OpenID-Connect
Get User Groups from External Authentication (httpd) checked - Logout
- Click
Log In to Corporate System
- Login as
Updating KeyCloak data
Export data from a running KeyCloak
If you’ve made changes in KeyCloak that you’d like to save, leave KeyCloak running and in another terminal run:
docker exec -it keycloak /opt/jboss/keycloak/bin/standalone.sh \
-Djboss.socket.binding.port-offset=100 \
-Dkeycloak.migration.action=export \
-Dkeycloak.migration.provider=singleFile \
-Dkeycloak.migration.realmName=ManageIQ \
-Dkeycloak.migration.usersExportStrategy=REALM_FILE \
-Dkeycloak.migration.file=/tmp/realms/ManageIQ-realm.json
When it completes, Ctrl-C
to end the process and the realms/ManageIQ-realm.json
file will be updated.
Recreating KeyCloak setup from scratch
-
Ensure you have a
certs
directory andrealms
directorymkdir certs mkdir realms
-
Generate a cert and key
openssl req -x509 -newkey rsa:4096 -keyout certs/tls.key -out certs/tls.crt -days 3650 -nodes
-
Launch KeyCloak
docker run --rm --name keycloak \ -p 8443:8443 \ -v $(pwd)/certs:/etc/x509/https \ -v $(pwd)/realms:/tmp/realms \ -e KEYCLOAK_USER=admin \ -e KEYCLOAK_PASSWORD=smartvm \ -e DB_VENDOR=h2 \ quay.io/keycloak/keycloak:12.0.4
-
Go to
https://127.0.0.1.nip.io:8443
and login withadmin
/smartvm
-
Create a Realm
Name ManageIQ
Note: realm name is case-sensitive in URLs!
-
Create an OIDC Client
Client ID manageiq-oidc-client
Client Protocol openid-connect
Once created, go to the credentials tab and copy down the generated
Secret
value. -
Configure the OIDC Client
-
Settings
Access Type confidential
Service Accounts Enabled ON
Authorization Enabled ON
Valid Redirect URIs http://127.0.0.1.nip.io/*
-
Mappers -> Create
Name groups
Mapper Type Group Membership
Token Claim Name groups
Full group path OFF
-
-
Create a group
Name EvmGroup-super_administrator
-
Create a user
Name user1
Email user1@manageiq.org
First Name User
Last Name One
Email Verified ON
-
Configure the user
-
Credentials
Password smartvm
Password Confirmation smartvm
Temporary OFF
-
Groups
Put the user into a group by clicking the group, then clicking
Join
.
-
-
Verify the setup
Be sure you have your OIDC client secret from step 6.
${client_secret}
below is a reference to that value. The client secret value from the current ManageIQ Realm export is3167ae6f-762d-49cd-b246-ef8856315957
.-
Fetch the configuration
curl -s -k https://127.0.0.1.nip.io:8443/auth/realms/ManageIQ/.well-known/openid-configuration | jq
-
Get an access token
token=$(curl -s -k -X POST https://127.0.0.1.nip.io:8443/auth/realms/ManageIQ/protocol/openid-connect/token \ -H "Content-Type: application/x-www-form-urlencoded" \ -u manageiq-oidc-client:${client_secret} \ -d username=user1 \ -d password=smartvm \ -d grant_type=password | jq -r ".access_token")
-
Introspect the access token
curl -s -k -X POST https://127.0.0.1.nip.io:8443/auth/realms/ManageIQ/protocol/openid-connect/token/introspect \ -H "Content-Type: application/x-www-form-urlencoded" \ -u manageiq-oidc-client:${client_secret} \ -d "token=${token}" | jq
-
-
Export the realm file. If you plan to commit this, be sure to also update the client secret values in this documentation.