Two Factor Auth using Duo with Keycloak¶
These are the steps to setup two factor authentication with Duo using Keycloak.
Install Keycloak Duo SPI¶
Clone the Keycloak Duo SPI repo
git clone https://github.com/OSC/keycloak-duo-spi.git cd keycloak-duo-spi git submodule update --init
Edit
pom.xmland ensurekeycloak.versionmatches the version of Keycloak you are running.Build (with Docker) - produces
target/keycloak-duo-spi-jar-with-dependencies.jardocker run --rm -it -v $(pwd):/keycloak-duo-spi -w /keycloak-duo-spi \ ohiosupercomputer/keycloak_duo_spi_buildbox:latest mvn clean test package
Build (without Docker) - produces
target/keycloak-duo-spi-jar-with-dependencies.jaryum -y install maven cd build/duo_java/DuoWeb mvn clean test install cd ../../.. mvn clean test package
Copy the JAR file and necessary template files to Keycloak and instruct Keycloak to install the SPI
sudo install -o keycloak -g keycloak -m 0644 target/keycloak-duo-spi-jar-with-dependencies.jar \ /opt/keycloak-9.0.0/standalone/deployments/keycloak-duo-spi-jar-with-dependencies.jar sudo install -o keycloak -g keycloak -m 0644 src/main/resources/duo-mfa.ftl \ /opt/keycloak-9.0.0/themes/base/login/duo-mfa.ftl sudo install -o keycloak -g keycloak -m 0644 /dev/null \ /opt/keycloak-9.0.0/standalone/deployments/keycloak-duo-spi-jar-with-dependencies.jar.dodeploy
Configure Duo SPI¶
- Log into your Keycloak instance
- Choose the realm to configure in upper left corner, eg
ondemand - Choose
Realm Settingsin the left menu thenSecurity Defensestab - Add
frame-src https://*.duosecurity.com/ 'self';to the beginning of the value forContent-Security-Policy - Choose
Authenticationin the left menu - While on
Flowstab ensure the dropdown for the flow name isBrowserand clickCopy - Name the new flow
browser-with-duo - For all items below
Username Password Formdelete them by choosingActionsthenDelete - Choose
ActionsforBrowser-with-duo Formsand chooseAdd Execution - Select the
Duo MFAprovider and clickSave - Click
ActionsforDuo MFAand selectConfig. Fill in all values as appropriate and selectSave. - Select
RequiredforDuo MFA - Choose the
Bindingstab and setBrowser Flowtobrowser-with-duoand chooseSave
Users logging into Keycloak will be required to verify their identity using Duo.