This is the repository for Keycloak Extensions, currently being:
- Brute-Force Protection
- New Device Login
This extension aims to protect Keycloak from brute-force attacks.
In cryptography, a brute-force attack consists of an attacker submitting many passwords or passphrases with the hope of eventually guessing correctly.
This extension aims to notify users by email when they login from a new device.
We need user events to be enabled. In order to do so:
- Access
http://localhost:5050/admin. - Click
Administration Console. - Access with user
adminand passwordunivention. - Click
Realm settingson the left menu. - Go to
Eventstab. - Under
User events settingssetSave eventstoON. - You can set an expiration time for events, but it is not needed for local testing.
- For now we only need
LOGIN_ERRORandLOGIN, but no need to disable the other 111 event types.
- Access
http://localhost:5050/admin. - Click
Administration Console. - Access with user
adminand passwordunivention. - Click
Eventson the left menu, towards the bottom. - Go into
Configtab. - Under
Login Events Settings, setSave EventstoON. - Save.
- (Not needed) You can set an expiration time for events, but it is not needed for local testing.
- (Not needed) For now we only need
LOGIN_ERRORandLOGIN, but no need to disable the other 111 event types.
Any changes to
docker-compose.yamlwill affect this steps.
In order for reCaptcha to work, we need to tweak two things on Keycloak:
- Go to
Realm settings > Security Defensesand set: X-Frame-OptionstoALLOW-FROM https://www.google.comContent-Security-Policytoframe-src 'self' https://www.google.com; frame-ancestors 'self'; object-src 'none';- Save.
Now you need to check that your proxy gets the environment variable CAPTCHA_SITE_KEY.
For localhost, I lend you this one: 6LcUyZkiAAAAAHo98CowhZFoc-E-3yeo38Hs1HSB, but you
may want to grab one from here.
Currently only Google reCaptcha is supported, but Cloudflare and others are easy to integrate.
A docker-compose.yaml file is provided in the root folder of the repository to ease running the application locally. You can get the application running by:
docker compose up -d keycloak database
docker compose up -d proxy handler
Notice the commands are separated, due to an entrypoint not existing to handle awaiting for containers to be ready.
You can access:
- Keycloak at
http://localhost:5050(only for configuration). - Proxied Keycloak at
http://localhost:8181(protected by proxy). - Handler will be polling Keycloak directly (without the proxy).
You may find more documentation about each component inside
proxyandhandlerfolders.
- Keycloak event monitoring on Grafana (sucessful logins, failed login attempts...)
- UDM integration
- Whitelists
- Blacklists
