Catalog
Keycloak
Keycloak
| Pack name | Keycloak |
| Version | 1.0.0 |
| Vendor | Red Hat |
| Capabilities | Parser · Streaming Rules · Correlation Rules · Dashboard |
| Categories | Identity · IAM · Authentication · SSO |
Overview
Pack cung cấp giám sát bảo mật toàn diện cho Keycloak Identity Provider chạy trên Kubernetes, bao gồm:
- Parser — chuẩn hóa Keycloak stdout log (structured events + system logs) sang ECS
- 7 streaming rules — phát hiện login failure, account lockout, token error, registration bất thường, password manipulation, system error
- 2 correlation rules — phát hiện brute-force và account takeover attempt
- 1 dashboard — 12 chart giám sát SOC authentication và IAM
Yêu cầu trước khi cài đặt
| Yêu cầu | Chi tiết |
|---|---|
| Keycloak 18+ (Quarkus) | Hoặc 16–17 (WildFly legacy) |
| Log shipper | Fluentd với kubernetes_metadata_filter hoặc Fluent Bit với kubernetes filter |
| Event listeners | Keycloak event listener jboss-logging phải enabled |
| Audit events | Bật Realm Settings → Events → Save Events trong Keycloak Admin Console |
Định dạng log bắt buộc
{
"app": "keycloak",
"cluster": "prod",
"container_name": "keycloak",
"host": "k8s-worker-01",
"level": "warning",
"message": "<raw Keycloak log line>",
"namespace": "sso",
"pod_name": "sso-0",
"timestamp": "2026-05-21T06:41:59.140Z"
}
Parser xử lý 2 loại message: structured events (có
type="...") và system log (plain text).app = keycloaklà field bắt buộc để parser nhận diện log source.
Ví dụ log hợp lệ
Structured event — Login failure:
{"app":"keycloak","cluster":"prod","container_name":"keycloak","host":"k8s-worker-01","level":"warning","message":"2026-05-21 06:41:56,546 WARN [org.keycloak.events] (executor-thread-105) type=\"LOGIN_ERROR\", realmId=\"abc123\", realmName=\"production\", clientId=\"webapp\", userId=\"null\", ipAddress=\"203.0.113.45\", error=\"invalid_user_credentials\", auth_method=\"openid-connect\", username=\"john.doe\"","namespace":"sso","pod_name":"sso-0","timestamp":"2026-05-21T06:41:59.140Z"}
Structured event — Login success:
{"app":"keycloak","cluster":"prod","container_name":"keycloak","host":"k8s-worker-01","level":"info","message":"2026-05-21 06:42:10,123 INFO [org.keycloak.events] (executor-thread-200) type=\"LOGIN\", realmId=\"abc123\", realmName=\"production\", clientId=\"webapp\", userId=\"user-uuid-123\", ipAddress=\"10.0.1.50\", auth_method=\"openid-connect\", username=\"jane.doe\"","namespace":"sso","pod_name":"sso-0","timestamp":"2026-05-21T06:42:10.123Z"}
System log — error:
{"app":"keycloak","cluster":"prod","container_name":"keycloak","host":"k8s-worker-01","level":"error","message":"2026-05-21 06:45:00,000 ERROR [org.keycloak.services] (executor-thread-1) Failed to send email: Connection refused to mail.example.com:587","namespace":"sso","pod_name":"sso-0","timestamp":"2026-05-21T06:45:00.000Z"}
Message chứa
type="..."→ structured event. Message không cótype=→ system log, được parse vớievent.action = "system_log".
Cài đặt
- Vào Marketplace → tìm "Keycloak Security" → Install
- Kiểm tra Parsers →
keycloak-parserđang active - Kiểm tra Detection Rules → filter tag Keycloak → 9 rules đang enabled
- Mở Dashboards → Keycloak Security Overview
Parser — Các trường ECS chính
| ECS Field | Nguồn | Mô tả |
|---|---|---|
event.action | type= field | login, login_error, logout, register, system_log... |
event.outcome | Derived | success (LOGIN) / failure (LOGIN_ERROR) |
user.name | username= | Tên user thực hiện thao tác |
user.id | userId= | UUID của user trong Keycloak |
source.ip | ipAddress= | IP client thực hiện request |
error.code | error= | Mã lỗi (ví dụ: invalid_user_credentials) |
url.domain | redirect_uri= extracted | Domain của redirect URI |
labels.realm_name | realmName= | Tên Keycloak realm |
Detection Rules
Streaming Rules (7 rules — real-time)
| # | Rule | Severity | Mô tả |
|---|---|---|---|
| 1 | Keycloak Login Failure | Medium | Đăng nhập thất bại — sai mật khẩu hoặc user không tồn tại |
| 2 | Keycloak Account Locked/Disabled | High | Tài khoản bị khóa do nhập sai quá nhiều lần hoặc bị admin disable |
| 3 | Keycloak Invalid/Missing Token | Medium | Token không hợp lệ hoặc hết hạn — nghi ngờ token theft hoặc session hijacking |
| 4 | Keycloak New User Registration | Low | Đăng ký tài khoản mới — giám sát unauthorized self-registration |
| 5 | Keycloak Registration Failure | Medium | Đăng ký thất bại — có thể là bot hoặc credential stuffing attempt |
| 6 | Keycloak Password Update Failure | Medium | Cập nhật mật khẩu thất bại — nghi ngờ unauthorized password change |
| 7 | Keycloak System Component Error | Medium | Lỗi internal Keycloak (DB, mail, LDAP) — ảnh hưởng availability của IAM service |
Correlation Rules (2 rules — pattern)
| # | Rule | Severity | Mô tả | Ngưỡng | Lookback |
|---|---|---|---|---|---|
| 8 | Keycloak Brute Force Login | High | Nhiều lần đăng nhập thất bại từ cùng IP — brute-force password attack | > 10 lần | 5 phút |
| 9 | Keycloak Account Takeover Attempt | High | Nhiều lần thất bại cho cùng username — targeted credential stuffing | > 5 lần | 10 phút |
Dashboard — Keycloak Security Overview
| # | Chart | Loại | Mô tả |
|---|---|---|---|
| 1 | Authentication Events Trend | LINE | Trend login events theo thời gian |
| 2 | Total Auth Events | METRIC | Tổng số authentication events |
| 3 | Login Failures | METRIC | Tổng login thất bại |
| 4 | Token Errors | METRIC | Tổng token validation errors |
| 5 | New Registrations | METRIC | Tổng đăng ký mới |
| 6 | Event Action Distribution | PIE | Phân bố loại action (login, register, logout...) |
| 7 | Event Outcome Distribution | PIE | Success vs Failure |
| 8 | Top Failed Login Source IPs | BAR | IP có nhiều login failure nhất |
| 9 | Top Failed Login Usernames | BAR | Username bị tấn công nhiều nhất |
| 10 | Auth Activity by Component | BAR | Phân bố theo Keycloak realm/client |
| 11 | Recent Login Failures | TABLE | 20 login failure gần nhất |
| 12 | Recent System Errors | TABLE | 20 system error gần nhất |
SOC Triage nhanh:
- Metric 3 → login failures cao → đang bị brute-force
- Chart 8 → một IP chiếm đa số → targeted attack
- Chart 9 → một username bị nhắm nhiều → account takeover
- Table 11 → xác nhận user bị tấn công và IP nguồn
Troubleshooting
| Triệu chứng | Nguyên nhân | Cách xử lý |
|---|---|---|
| Không có event | app field thiếu hoặc sai | JSON envelope phải có "app": "keycloak" |
| Không có login events | Keycloak event listener chưa bật | Bật jboss-logging listener trong Keycloak Admin |
user.name trống | Login event thiếu username= | Kiểm tra Keycloak version — một số version không log username khi user không tồn tại |
| Chỉ có system logs | Structured events không gửi | Bật Save Events trong Realm Settings → Events |
| Parser không khớp | Parser bị tắt | Kiểm tra keycloak-parser.yaml đang active trong Parsers |
Checklist parser:
- JSON envelope có
app = "keycloak",timestamp,message,host - Keycloak event listener
jboss-loggingđang enabled -
Realm Settings → Events → Save Eventsđang bật -
keycloak-parser.yamlđang active
Hỗ trợ
- Lỗi platform: Mở ticket tại SecOps support portal
- Góp ý pack: Dùng tính năng feedback trên trang Marketplace
- Tuning rule: Slack
#detection-engineering
Last updated: 2026-06-04 · Vendor: Red Hat · Author: secops-team