Keycloak Email Event Listener

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a keycloak email event listener by turning on event providers in your realm. This setup sends an email to users or admins when key account actions happen. Teams often use this feature to watch for strange login attempts or password updates. Still, many teams pair these login alerts with broad database or server roles. Once a user logs in, those broad roles let them run any command they want. How a keycloak email event listener works Keycloak tracks user actions and admin changes th

Keycloak + Security Information & Event Management (SIEM): the complete guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free white paper. No spam. Unsubscribe anytime.

You set up a keycloak email event listener by turning on event providers in your realm. This setup sends an email to users or admins when key account actions happen. Teams often use this feature to watch for strange login attempts or password updates. Still, many teams pair these login alerts with broad database or server roles. Once a user logs in, those broad roles let them run any command they want.

How a keycloak email event listener works

Keycloak tracks user actions and admin changes through an internal event system. Every time a user logs in or resets a password, the server creates an event. The keycloak email event listener watches this stream for specific actions you want to track.

To make this work, you first set up an email server in your realm settings. Next, you turn on the email listener in the realm event settings. The listener matches user actions against a set of built-in templates. When a match happens, Keycloak formats a message and sends it to the user's email address.

Teams also build custom listeners when the built-in templates do not fit their needs. A custom listener lets your team send alerts to a central security inbox. You can watch for failed logins, new token requests, or role changes made by admins. Each alert holds the user ID, the time, the IP address, and the event type.

What login email alerts solve and what they miss

Email listeners are great for catching bad login attempts at the front door. If an attacker guesses a password, the real user gets an email right away. Admins can also spot strange changes to realm rules before they cause wider problems. This gives your team a basic record of who entered your systems and when.

Still, a login alert only tells you what happened at the start of a session. It does not tell you what the user does after they get inside. Once Keycloak hands out a valid token, its job for that session is mostly done. The user then connects to your databases, cloud consoles, or internal servers.

Keycloak + Security Information & Event Management (SIEM): architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Inside those systems, users often share wide static roles with way too much power. An email listener cannot see the SQL queries an engineer runs on a production database. It cannot stop a script from reading customer emails, phone numbers, or card numbers. It also cannot ask a manager to approve a risky command before it runs.

Why teams need controls beyond login events

Relying only on login alerts leaves a blind spot during active work sessions. Security teams end up chasing old email logs after a mistake has already happened. If a user drops a table by accident, the login email will not help you.

Real safety requires checking every single command and query while the session is live. Teams need a way to tie the Keycloak user identity to each database statement. They also need rules that rewrite sensitive fields like national IDs in query results. By combining identity checks with live session rules, teams close the gap after login.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

What events can trigger an email in Keycloak?

The built-in listener sends emails for actions like password updates, failed logins, and account removals. Custom listeners can also watch admin changes, such as adding new roles or changing realm rules.

Why are my Keycloak event emails not sending?

First, check that your realm has valid mail server settings and a working sender address. Second, make sure the user profile has a valid email address saved on their account.

Does a Keycloak event listener log database queries?

No, Keycloak only tracks login actions, token requests, and changes inside its own admin console. It cannot see or control what commands a user runs inside your databases or servers.

Save the open-source gateway.

hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.