Catalog

Keycloak

Keycloak

Pack nameKeycloak
Version1.0.0
VendorRed Hat
CapabilitiesParser · Streaming Rules · Correlation Rules · Dashboard
CategoriesIdentity · 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ầuChi tiết
Keycloak 18+ (Quarkus)Hoặc 16–17 (WildFly legacy)
Log shipperFluentd với kubernetes_metadata_filter hoặc Fluent Bit với kubernetes filter
Event listenersKeycloak event listener jboss-logging phải enabled
Audit eventsBậ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 = keycloak là 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ới event.action = "system_log".


Cài đặt

  1. Vào Marketplace → tìm "Keycloak Security"Install
  2. Kiểm tra Parserskeycloak-parser đang active
  3. Kiểm tra Detection Rules → filter tag Keycloak → 9 rules đang enabled
  4. Mở DashboardsKeycloak Security Overview

Parser — Các trường ECS chính

ECS FieldNguồnMô tả
event.actiontype= fieldlogin, login_error, logout, register, system_log...
event.outcomeDerivedsuccess (LOGIN) / failure (LOGIN_ERROR)
user.nameusername=Tên user thực hiện thao tác
user.iduserId=UUID của user trong Keycloak
source.ipipAddress=IP client thực hiện request
error.codeerror=Mã lỗi (ví dụ: invalid_user_credentials)
url.domainredirect_uri= extractedDomain của redirect URI
labels.realm_namerealmName=Tên Keycloak realm

Detection Rules

Streaming Rules (7 rules — real-time)

#RuleSeverityMô tả
1Keycloak Login FailureMediumĐăng nhập thất bại — sai mật khẩu hoặc user không tồn tại
2Keycloak Account Locked/DisabledHighTài khoản bị khóa do nhập sai quá nhiều lần hoặc bị admin disable
3Keycloak Invalid/Missing TokenMediumToken không hợp lệ hoặc hết hạn — nghi ngờ token theft hoặc session hijacking
4Keycloak New User RegistrationLowĐăng ký tài khoản mới — giám sát unauthorized self-registration
5Keycloak Registration FailureMediumĐăng ký thất bại — có thể là bot hoặc credential stuffing attempt
6Keycloak Password Update FailureMediumCập nhật mật khẩu thất bại — nghi ngờ unauthorized password change
7Keycloak System Component ErrorMediumLỗi internal Keycloak (DB, mail, LDAP) — ảnh hưởng availability của IAM service

Correlation Rules (2 rules — pattern)

#RuleSeverityMô tảNgưỡngLookback
8Keycloak Brute Force LoginHighNhiều lần đăng nhập thất bại từ cùng IP — brute-force password attack> 10 lần5 phút
9Keycloak Account Takeover AttemptHighNhiều lần thất bại cho cùng username — targeted credential stuffing> 5 lần10 phút

Dashboard — Keycloak Security Overview

#ChartLoạiMô tả
1Authentication Events TrendLINETrend login events theo thời gian
2Total Auth EventsMETRICTổng số authentication events
3Login FailuresMETRICTổng login thất bại
4Token ErrorsMETRICTổng token validation errors
5New RegistrationsMETRICTổng đăng ký mới
6Event Action DistributionPIEPhân bố loại action (login, register, logout...)
7Event Outcome DistributionPIESuccess vs Failure
8Top Failed Login Source IPsBARIP có nhiều login failure nhất
9Top Failed Login UsernamesBARUsername bị tấn công nhiều nhất
10Auth Activity by ComponentBARPhân bố theo Keycloak realm/client
11Recent Login FailuresTABLE20 login failure gần nhất
12Recent System ErrorsTABLE20 system error gần nhất

SOC Triage nhanh:

  1. Metric 3 → login failures cao → đang bị brute-force
  2. Chart 8 → một IP chiếm đa số → targeted attack
  3. Chart 9 → một username bị nhắm nhiều → account takeover
  4. Table 11 → xác nhận user bị tấn công và IP nguồn

Troubleshooting

Triệu chứngNguyên nhânCách xử lý
Không có eventapp field thiếu hoặc saiJSON envelope phải có "app": "keycloak"
Không có login eventsKeycloak event listener chưa bậtBật jboss-logging listener trong Keycloak Admin
user.name trốngLogin 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 logsStructured events không gửiBật Save Events trong Realm Settings → Events
Parser không khớpParser bị tắtKiể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