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
admin
and passwordunivention
. - Click
Realm settings
on the left menu. - Go to
Events
tab. - Under
User events settings
setSave events
toON
. - You can set an expiration time for events, but it is not needed for local testing.
- For now we only need
LOGIN_ERROR
andLOGIN
, but no need to disable the other 111 event types.
- Access
http://localhost:5050/admin
. - Click
Administration Console
. - Access with user
admin
and passwordunivention
. - Click
Events
on the left menu, towards the bottom. - Go into
Config
tab. - Under
Login Events Settings
, setSave Events
toON
. - 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_ERROR
andLOGIN
, but no need to disable the other 111 event types.
Any changes to
docker-compose.yaml
will affect this steps.
In order for reCaptcha to work, we need to tweak two things on Keycloak:
- Go to
Realm settings > Security Defenses
and set: X-Frame-Options
toALLOW-FROM https://www.google.com
Content-Security-Policy
toframe-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
proxy
andhandler
folders.
- Keycloak event monitoring on Grafana (sucessful logins, failed login attempts...)
- UDM integration
- Whitelists
- Blacklists