Location Research Breakthrough Possible @S-Logix pro@slogix.in

Transformer-Based Detection of Account-Takeover Attempts in Keycloak Identity and Access Management Through Sequential Authentication-Event Analysis

Description

Identity and Access Management (IAM) platforms control user authentication and access to protected applications. Keycloak is an open-source IAM platform that provides user authentication, identity federation, single sign-on, and access-management capabilities. It records authentication-related events that can be used to examine login activity and investigate suspicious account-access behavior.

Account-takeover attacks occur when an unauthorized person gains access to a legitimate user's account. Such activity may involve the use of compromised credentials, authentication from unfamiliar clients, unusual login sequences, or changes in previously observed login behavior. A login attempt using valid credentials may still be suspicious if its surrounding behavioral characteristics differ from the account's normal activity.

Conventional authentication mechanisms primarily verify credentials and apply configured authentication policies. Although these controls are essential, credential verification alone does not establish whether a login attempt originates from the legitimate account owner. Sequential authentication analysis provides an additional approach for identifying suspicious patterns across multiple login events.

In this use case, Keycloak is deployed in an isolated Ubuntu and Kali Linux laboratory environment. Keycloak manages designated test accounts and generates authentication events during normal operations and controlled security testing.

An existing public authentication-event dataset is used as the data source for machine-learning training and evaluation. The dataset is inspected to identify available authentication attributes and account-takeover labels. Suitable records are processed to construct sequential login features for the Transformer model.

A Transformer-based classification model is trained using the selected labelled authentication sequences. The model learns relationships between events in a sequence and generates predictions for authentication behavior that may be associated with account-takeover activity.

A controlled account-takeover scenario is then reproduced against the laboratory Keycloak environment. Authentication events are collected from the controlled scenario and processed through a compatible feature-extraction pipeline. The trained Transformer model evaluates the resulting login sequence and generates a classification prediction.

The model prediction is compared with the known laboratory test condition to evaluate the detection workflow. The Transformer model operates as a separate Python-based detection component; it is not presented as a built-in Keycloak feature.

The complete workflow is:
Public Authentication-Event Dataset
→
Data Inspection
→
Label Identification
→
Data Preprocessing
→
Sequential Login Feature Extraction
→
Transformer Model Training
→
Model Evaluation
→
Keycloak IAM Deployment
→
Controlled Account-Takeover Simulation
→
Authentication Event Collection
→
Sequential Feature Extraction
→
Transformer Analysis
→
Suspicious Login Detection
→
Account-Takeover Validation

Existing Security Problem

Application : Keycloak Identity and Access Management

Keycloak is the target IAM application in this use case. It provides authentication and identity-management functionality for designated laboratory users and client applications.

Keycloak is deployed only within the authorized laboratory environment so that normal authentication activity and controlled suspicious login scenarios can be generated and analyzed.

Existing Problem :

Keycloak verifies authentication requests according to its configured authentication flows, credentials, and security policies. However, a valid authentication event does not necessarily establish that the person attempting to access the account is its legitimate owner.

If an unauthorized person obtains valid credentials, the authentication request may satisfy the configured credential-verification requirements. Suspicious behavior may instead become apparent through a sequence of events, such as unusual login timing, changes in client attributes, or an unexpected pattern of authentication outcomes.

Without an additional behavioral-analysis component, suspicious sequences may require further examination by a security analyst.

The existing problem is:

Keycloak IAM

↓

User Authentication Request

↓

Configured Credential Verification

↓

Authentication Event Generation

↓

Potential Use of Compromised Credentials

↓

Unauthorized Account-Access Attempt

↓

Suspicious Login-Sequence Characteristics

↓

Potential Account-Takeover Activity

↓

Requirement for Sequential Behavioral Analysis

The proposed solution introduces a separate Transformer-based detection component that analyzes collected Keycloak authentication events. The model learns patterns from an existing public authentication-event dataset and evaluates compatible login sequences for behavior associated with account-takeover activity.

Attack

Specific Attack : Controlled Account-Takeover Attempt Against Keycloak IAM

The controlled attack scenario evaluates whether the proposed detection workflow can identify suspicious authentication sequences generated against Keycloak.

A designated test account is used to establish normal authentication behavior. A

separate controlled scenario is then conducted to represent suspicious account access, using an unfamiliar laboratory client or an unusual sequence of authentication attempts.

The test is restricted to the isolated Keycloak environment. It does not target real users, production identity systems, or external accounts, and it does not require the use of real stolen credentials.

The purpose is to generate authentication-event evidence that can be collected, transformed into sequential features, analyzed by the trained Transformer model, and compared with the known laboratory test condition.

The public dataset supplies the existing labelled records used for machine-learning development. The controlled Keycloak scenario provides separate laboratory evidence for evaluating the detection workflow.

Attack Behavior :
Keycloak Test Account Created
→
Normal Authentication Activity Recorded
→
Baseline Login Behavior Established
→
Controlled Suspicious Login Scenario Prepared
→
Authentication Requests Sent to Keycloak
→
Keycloak Processes Authentication Requests
→
Authentication Events Recorded
→
Event Sequence Constructed
→
Sequential Feature Extraction
→
Transformer-Based Login Analysis
→
Suspicious Behavior Prediction
→
Prediction Compared with the Known Test Condition
→
Account-Takeover Detection Result Recorded

Security Concept

Transformer-Based Sequential Authentication Analysis for Keycloak Account-Takeover Detection

The primary security concept combines sequential authentication-event analysis with Transformer-based classification to identify login behavior that may be associated with account-takeover activity in Keycloak.

Authentication-Event Data Preparation : Existing public authentication-event data is inspected to identify usable fields and labels. Suitable records are cleaned, transformed, and organized into sequences for model training and evaluation.

Transformer-Based Sequential Classification : The Transformer model learns relationships between authentication events within a sequence. It evaluates the prepared sequence and produces a prediction based on the patterns learned from the training data.

Keycloak Event Analysis and Validation : Authentication events generated by Keycloak during normal and controlled suspicious activity are collected and processed using a compatible feature-extraction pipeline. The model prediction is compared with the documented laboratory test condition to evaluate whether the detection workflow identifies the intended suspicious behavior.

The assessment follows:
Public Authentication-Event Data Review
→
Label and Feature Identification
→
Authentication Data Preprocessing
→
Sequential Login Feature Extraction
→
Transformer Model Training
→
Model Evaluation on Unseen Data
→
Keycloak Authentication Testing
→
Authentication Event Collection
→
Sequential Behavior Analysis
→
Account-Takeover Classification
→
Detection Result Validation

Defensive Mechanism

The security concept defines the overall security strategy.

The following are the specific defensive mechanisms implemented.

Sequential Authentication-Behavior Analysis :

Authentication events are organized into sequences using available timestamps, account-related identifiers, and compatible event attributes. The sequences are analyzed by the trained Transformer model.

Purpose: Identify patterns across multiple authentication events that may indicate suspicious account-access behavior.

Transformer-Based Threat Classification

The trained Transformer model evaluates a processed login sequence and generates a classification prediction.

Purpose
  • Classify authentication sequences according to the patterns learned from the labelled training data.

Consistent Feature Extraction

The public training data and newly collected Keycloak events are processed using compatible feature-extraction procedures.

Purpose
  • Maintain consistent model inputs during training, evaluation, and laboratory inference.

Risk-Based Authentication Signal

The Transformer prediction is treated as an additional signal for evaluating whether an authentication sequence requires further review.

Purpose
  • Support the identification of potentially suspicious login activity without treating a model prediction as conclusive proof of an attack.

Suspicious Authentication-Event Flagging

Login sequences classified as suspicious are recorded and presented for security review.

Purpose
  • Login sequences classified as suspicious are recorded and presented for security review.

Authentication Event Monitoring

Relevant Keycloak authentication events are collected during normal activity and controlled security testing.

Purpose
  • Ensure that detection conclusions are based on the available authentication evidence.

Security Tools

Primary IAM Application: Keycloak

Keycloak provides the identity and authentication environment used for the account-takeover detection experiment.

Purpose
  • Manage designated laboratory test accounts.
  • Process normal and controlled authentication requests.
  • Generate authentication events for analysis.
  • Provide the specific target application for security testing.

Operating System: Ubuntu Linux

Ubuntu hosts Keycloak and supports the data-processing and Transformer-based detection components.

Purpose
  • Run the Keycloak application.
  • Execute Python-based event processing.
  • Support model inference and result analysis.
  • Maintain the controlled application environment.

Security Testing Platform: Kali Linux

Kali Linux is used as the controlled testing system for sending authorized authentication requests to the laboratory Keycloak instance.

Purpose
  • Generate legitimate test login requests.
  • Reproduce controlled suspicious authentication scenarios.
  • Observe application responses.
  • Support repeatable laboratory testing.

Virtualization Platform: VirtualBox

VirtualBox provides the isolated virtual-machine environment for the application and testing systems.

Purpose
  • Host Ubuntu and Kali Linux virtual machines.
  • Separate the application and testing environments.
  • Support repeatable security experiments.
  • Reduce unintended interaction with external systems.

Programming Environment: Python

Python provides the main implementation environment for dataset processing, sequential feature extraction, Transformer training, classification, and evaluation.

Purpose
  • Implement the detection workflow.
  • Process public and laboratory authentication records.
  • Integrate feature extraction with model inference.
  • Record and analyze detection results.

Data Processing Tool: Pandas

Pandas is used to load, inspect, filter, and organize the existing public authentication-event data and collected Keycloak events.

Purpose
  • Inspect dataset fields and labels.
  • Prepare authentication records for preprocessing.
  • Organize training and evaluation data.
  • Analyze model predictions and validation results.

Numerical Processing Tool: NumPy

NumPy supports numerical operations required for feature preparation and model-data processing.

Purpose
  • Perform numerical feature transformations.
  • Prepare numerical representations of authentication attributes.
  • Support the processing of sequential model inputs.

Deep Learning Framework: PyTorch

PyTorch is used to implement and train the Transformer-based classification model.

Purpose
  • Implement the Transformer architecture.
  • Process sequential authentication features.
  • Train the model using labelled records.
  • Generate predictions for previously unseen login sequences.

Machine-Learning Evaluation Tool: Scikit-learn

Scikit-learn provides utilities for data partitioning and classification evaluation.

Purpose
  • Prepare suitable training and evaluation partitions.
  • Calculate precision, recall, F1-score, and confusion matrix.
  • Evaluate model predictions against known labels.
  • Support analysis of class imbalance and prediction errors.

Authentication Event Collection: Keycloak Event Logging

Keycloak's authentication-event logging provides the event evidence used by the detection workflow. The exact event fields depend on the Keycloak configuration and the collection method selected for the laboratory.

Purpose
  • Collect relevant authentication events.
  • Preserve available login outcomes and event information.
  • Provide event records for sequential processing.
  • Support correlation between the test scenario and the model prediction.

HTTP Testing Tool: cURL

cURL is used to send controlled HTTP requests to the laboratory authentication environment where appropriate.

Purpose
  • Generate repeatable HTTP requests.
  • Observe HTTP responses.
  • Support controlled authentication testing.
  • Provide request-level evidence where applicable.

Web Security Testing Tool: OWASP ZAP

OWASP ZAP can be used to inspect HTTP traffic exchanged with the authorized laboratory application.

Purpose
  • Inspect requests and responses.
  • Preserve relevant HTTP traffic evidence.
  • Support controlled web-application testing.
  • Assist in verifying observed authentication behavior.

Event Storage: SQLite

SQLite stores the relevant laboratory authentication records and associated model predictions.

Purpose
  • Store collected authentication-event records.
  • Preserve classification results.
  • Maintain records of controlled test scenarios.
  • Support subsequent analysis and review.

Dashboard Framework: Streamlit

Streamlit provides an interface for displaying authentication sequences, Transformer predictions, and evaluation results.

Purpose
  • Display collected Keycloak authentication events.
  • Present model classifications.
  • Show suspicious login sequences for review.
  • Support examination of detection results.

Process

STEP 01

Prepare the Isolated Laboratory Environment

  • Create the laboratory environment using VirtualBox.
  • Configure Ubuntu Linux as the application and machine-learning environment.
  • Configure Kali Linux as the controlled security-testing environment.
  • Establish the intended network connectivity between the virtual machines.
  • Verify that Kali Linux can reach the local Keycloak instance.
  • Confirm that testing is restricted to the authorized laboratory environment.
Tools: VirtualBox + Ubuntu Linux + Kali Linux
STEP 02

Deploy Keycloak IAM

  • Deploy Keycloak within the Ubuntu laboratory environment.
  • Configure the required Keycloak service and its database.
  • Start the Keycloak instance and verify that its administration interface is accessible.
  • Create a dedicated laboratory realm for the experiment.
  • Configure the required authentication flow and a test client.
  • Create designated test accounts for normal authentication and controlled validation.
  • Verify that legitimate login requests can be processed successfully.
Tools: Keycloak + Ubuntu Linux
STEP 03

Establish the Normal Authentication Baseline

  • Use the designated test account to perform legitimate authentication through Keycloak.
  • Generate normal login activity from the designated laboratory client.
  • Record the available authentication events and their timestamps.
  • Repeat normal authentication operations to obtain representative baseline events.
  • Inspect the event records to identify which attributes Keycloak provides under the selected configuration.
  • Preserve the normal authentication records for later comparison.
Tools: Keycloak + Python + cURL
STEP 04

Identify the Laboratory Service Exposure

  • Identify the authorized Ubuntu laboratory target from Kali Linux.
  • Perform controlled service discovery against the laboratory environment.
  • Identify the Keycloak service and its listening port.
  • Verify that the service is reachable from the intended testing network.
  • Record the observed service exposure.
  • Confirm that no unrelated systems are included in the testing scope.
Tools: Kali Linux + Nmap
STEP 05

Prepare the Existing Public Authentication-Event Dataset

  • Obtain the existing public authentication-event dataset required for the machine-learning experiment.
  • Load the available records into Python.
  • Inspect the dataset structure and identify its authentication-related fields.
  • Identify the available account-takeover or security-related labels.
  • Review the data types, missing values, and class distribution.
  • Determine whether the available attributes support sequential login-behavior analysis.
  • Preserve the original labels and data structure for evaluation.
Tools: Python + Pandas + NumPy
STEP 06

Select Suitable Authentication Records

  • Review the public dataset and identify records with usable labels.
  • Determine which records represent the available normal and account-takeover categories.
  • Select records appropriate for model development.
  • Exclude records that cannot be reliably interpreted or processed.
  • Check whether the selected attributes can be converted into a consistent feature representation.
  • Document the selection criteria and preserve the corresponding labels.
Tools: Python + Pandas
STEP 07

Preprocess the Authentication Data

  • Inspect the selected records for missing or inconsistent values.
  • Handle unsuitable records according to the documented preprocessing procedure.
  • Convert timestamps into a consistent representation.
  • Process categorical attributes such as login outcomes, device information, and client characteristics where available.
  • Encode suitable categorical attributes into numerical representations.
  • Ensure that evaluation labels are not used as model input features.
  • Record the transformations so that compatible Keycloak events can be processed through the same procedure.
Tools: Python + Pandas + NumPy + Scikit-learn
STEP 08

Extract Sequential Login Features

  • Identify the authentication attributes suitable for sequential analysis.
  • Organize login events into sequences using available timestamps and account-related identifiers.
  • Select relevant fields such as event order, login outcome, client attributes, and time related information where supported by the data.
  • Convert the selected attributes into the numerical representations required by the Transformer model.
  • Define a consistent sequence length and padding or truncation strategy.
  • Preserve chronological order when constructing the sequences.
  • Avoid using future events as input when evaluating an earlier authentication decision.
  • Verify that the resulting sequences are compatible with the Transformer architecture.
  • Document any differences between the public dataset's fields and the attributes available from Keycloak.
Tools: Python + Pandas + NumPy + PyTorch
STEP 09

Prepare Training and Evaluation Data

  • Separate the prepared authentication sequences into training, validation, and test partitions as appropriate.
  • Preserve the labels associated with the selected sequences.
  • Prevent overlapping sequences from causing information leakage between training and evaluation partitions.
  • Where account identifiers are available, consider account-level separation to reduce the risk of memorizing account-specific patterns.
  • Review the distribution of normal and account-takeover labels.
  • Determine whether class imbalance requires suitable training or evaluation strategies.
  • Record the splitting method and the number of records assigned to each partition.
Tools: Python + Pandas + Scikit-learn + NumPy
STEP 10

Build the Transformer Classification Model

  • Implement the Transformer-based classification model using PyTorch.
  • Configure the input layer to accept the prepared sequential authentication features.
  • Apply appropriate embedding or feature-projection operations to represent the input attributes.
  • Configure positional information so that the model can account for the order of
  • authentication events.
  • Implement the Transformer encoder components required to learn relationships between events in a sequence.
  • Add a classification layer corresponding to the available security labels.
  • Configure the loss function and optimization procedure for the selected classification task.
  • Verify that a sample authentication sequence passes through the model without dimensional or data-type errors.
Tools: Python + PyTorch + NumPy
STEP 11

Train the Transformer Model

  • Provide the prepared training sequences to the Transformer model.
  • Supply the corresponding training labels.
  • Train the model to learn patterns associated with the available authentication categories.
  • Monitor training loss and validation performance.
  • Check whether the model is overfitting or failing to learn the minority class.
  • Apply appropriate class-imbalance handling where supported by the training setup.
  • Preserve the trained model and its preprocessing configuration.
  • Record the training process so that the experiment can be reproduced.
Tools: Python + PyTorch
STEP 12

Evaluate the Trained Model

  • Load the trained Transformer model.
  • Provide evaluation sequences that were not used during training.
  • Generate predictions for the selected authentication sequences.
  • Compare the predictions with the known labels.
  • Calculate precision, recall, F1-score, and confusion matrix.
  • Review performance separately for the normal and account-takeover categories.
  • Examine false-positive and false-negative cases.
  • Record the actual evaluation results without assuming a particular detection rate.
Tools: Python + PyTorch + Scikit-learn + Pandas
STEP 13

Collect Keycloak Authentication Events

  • Use the designated test account to generate legitimate authentication requests against Keycloak.
  • Collect the corresponding authentication events using the configured event-collection method.
  • Perform the controlled suspicious-login scenario using the authorized laboratory client.
  • Capture the resulting event information, including timestamps, login outcomes, and available client attributes.
  • Verify that the events correspond to the intended laboratory test condition.
  • Preserve the original event records for subsequent analysis.
Tools: Keycloak + Python + cURL + OWASP ZAP
STEP 14

Preprocess the Keycloak Authentication Events

  • Load the collected Keycloak authentication events into Python.
  • Inspect the available fields and compare them with the features supported by the trained model.
  • Apply the compatible preprocessing procedure established during model development.
  • Convert the available categorical attributes into the same numerical representation used during training.
  • Organize the events into chronological sequences.
  • Apply the same sequence-length and padding strategy used by the model.
  • Verify that the resulting feature sequences match the trained model's expected input format.
  • Document any differences between Keycloak's event attributes and the public dataset's attributes.
  • If the fields cannot be mapped consistently, revise the feature design or collect compatible data before claiming cross-dataset detection.
Tools: Python + Pandas + NumPy + PyTorch
STEP 15

Perform Transformer-Based Login-Sequence Analysis

  • Load the trained Transformer model.
  • Provide the processed Keycloak authentication sequence to the model.
  • Generate a classification prediction for the sequence.
  • Record the predicted category and associated confidence information where available.
  • Review the prediction alongside the original authentication events.
  • Determine whether the model classifies the controlled suspicious sequence as potentially associated with account-takeover activity.
  • Preserve the model output for validation.
Tools: Python + PyTorch + NumPy
STEP 16

Validate the Controlled Account-Takeover Detection

  • Review the documented condition of the controlled laboratory test.
  • Compare the model prediction with the known test scenario.
  • Determine whether the model identified the suspicious login sequence.
  • Repeat the workflow with normal authentication sequences to examine false-positive behavior.
  • Record predictions for both normal and controlled suspicious scenarios.
  • Compare the laboratory findings with the model's evaluation results on the public dataset.
  • Document whether the results support the intended detection objective.
  • Do not treat a suspicious prediction alone as proof that an actual account takeover occurred.
Tools: Python + PyTorch + Scikit-learn + Keycloak
STEP 17

Store and Display the Detection Evidence

  • Organize the original Keycloak authentication events, processed sequences, and model predictions.
  • Store the relevant laboratory events and prediction results in SQLite.
  • Associate each prediction with its corresponding test scenario and event sequence.
  • Create Streamlit views for displaying authentication activity and model results.
  • Display the predicted category and supporting event information.
  • Distinguish model predictions from the known laboratory test condition.
  • Verify that the stored records and displayed results correspond to the original evidence.
Tools: Python + SQLite + Streamlit + Pandas
STEP 18

Perform Final Detection Validation and Security Review

  • Repeat the normal authentication tests and controlled suspicious-login tests where required.
  • Review the public-dataset evaluation results.
  • Review the collected Keycloak authentication sequences and their model predictions.
  • Compare the model classifications with the documented laboratory test conditions.
  • Examine false-positive and false-negative cases.
  • Verify that training and laboratory inference use compatible feature representations.
  • Review the effects of class imbalance and the limitations of the available dataset.
  • Document the actual detection results, experimental limitations, and potential improvements.
  • Finalize the assessment of the Transformer-based account-takeover detection workflow for Keycloak IAM.
Tools: Keycloak + Python + PyTorch + Scikit-learn + SQLite + Streamlit + Kali Linux

Outcome

Keycloak Identity and Access Management is deployed within an isolated Ubuntu and Kali Linux laboratory environment to provide the specific target application for account-takeover detection research.

An existing public authentication-event dataset is inspected and processed to identify the available login attributes and labelled records suitable for sequential machine-learning analysis.

Authentication records are transformed into sequential numerical features, providing a consistent representation for Transformer model training and inference.

A Transformer-based classification model is trained using the selected labelled authentication sequences and evaluated using records that were not used during training.

The model's classification performance is assessed using precision, recall, F1-score, and confusion matrix, providing measurable evidence of its ability to distinguish the available authentication categories.

Normal authentication activity and a controlled suspicious-login scenario are generated against the laboratory Keycloak instance, providing authentication-event evidence for evaluating the detection workflow.

The collected Keycloak events are processed using the compatible feature-extraction procedure and analyzed by the trained Transformer model to generate predictions for the observed login sequences.

The model predictions are compared with the known laboratory test conditions, allowing the experiment to document detected suspicious sequences, false positives, and false negatives.

SQLite stores relevant authentication events and model predictions, while Streamlit presents the sequential login information and detection results for review and verification.

The complete workflow demonstrates the integration of public authentication-data processing, Transformer-based sequential login analysis, Keycloak authentication testing, controlled account-takeover validation, measurable model evaluation, and evidence-based security review within an isolated laboratory environment.