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 repository.
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, e.g.,
ondemandChoose
Realm Settingsin the left menu thenSecurity DefensestabAdd
frame-src https://*.duosecurity.com/ 'self';to the beginning of the value forContent-Security-PolicyChoose
Authenticationin the left menuWhile on
Flowstab ensure the drop-down for the flow name isBrowserand clickCopyName the new flow
browser-with-duoFor all items below
Username Password Formdelete them by choosingActionsthenDeleteChoose
ActionsforBrowser-with-duo Formsand chooseAdd ExecutionSelect the
Duo MFAprovider and clickSaveClick
ActionsforDuo MFAand selectConfig. Fill in all values as appropriate and selectSave.Select
RequiredforDuo MFAChoose the
Bindingstab and setBrowser Flowtobrowser-with-duoand chooseSave
Users logging into Keycloak will be required to verify their identity using Duo.