MA-RAG: Automating Role Engineering for RESTful APIs with Multi-Head Attention and Retrieval-Augmented Generation

Yang Luo, Qingni Shen, Zhonghai WuIJCAI 2025 · DOI

Introduction

In modern software security, Role-Based Access Control (RBAC) remains the gold standard for managing permissions. However, the process of "Role Engineering"—defining user roles and their associated permissions—is a significant bottleneck. Traditional approaches are either top-down, requiring expensive manual expert intervention, or bottom-up, relying on historical user-permission logs that are often unavailable for new systems (the "cold start" problem). Furthermore, existing automated methods frequently overlook the rich semantic information embedded in source code and struggle to balance conflicting objectives, such as minimizing role count while adhering to the principle of least privilege.

MA-RAG addresses these challenges by treating the system's source code as the ground truth for role discovery. It leverages fine-grained control flow analysis, Multi-Head Attention (MHA), and Retrieval-Augmented Generation (RAG) to automate the generation of interpretable and efficient access control structures.

Methodology

The MA-RAG framework employs a multi-stage pipeline to transform raw source code into a structured role hierarchy.

The MA-RAG pipeline architecture, illustrating the flow from code base to resulting roles.
  1. Permission Extraction & Embedding: The system uses static control flow analysis and Large Language Models (LLMs) to map front-end UI controls to back-end API handlers. Code "basic blocks" are converted into semantic vectors using pre-trained code models.
  2. Retrieval-Augmented Generation (RAG): To ensure scalability, these vectors are managed via a RAG model. This allows the system to reuse embeddings for similar code blocks, significantly reducing redundant computational overhead.
  3. Call Chain Construction: For each API permission, MA-RAG constructs a "call chain tree" to track interactions across the codebase.
  4. Multi-Head Attention (MHA) Aggregation: At the core of MA-RAG are four attention heads, each optimized for a specific role engineering goal: minimizing role count, maximizing coverage, minimizing permission overlap, and maximizing intra-role cohesion.
  5. Self-Supervised Clustering: Finally, the system uses contrastive learning and spectral clustering to adaptively determine the optimal number of roles and assign permissions.

Evaluation and Results

The researchers evaluated MA-RAG on a dataset of 284 real-world open-source systems from GitHub, spanning various domains (e-commerce, finance, etc.) and languages (Java, Python, JavaScript, C#). The systems ranged in size from 42K to 1.7M lines of code.

MA-RAG demonstrated superior performance compared to state-of-the-art baselines like CRE, Spectral, and GNRM.

Comparison of MA-RAG against baseline methods in terms of the number of generated roles and permission overlap.

Key results include:

  • Efficiency: MA-RAG reduced time overhead by an average of 46.2%, processing systems in approximately 25.7 minutes.
  • Role Quality: The system generated an average of 15.8 roles with a remarkably low permission overlap of 6.7%, significantly outperforming baselines which ranged from 24% to 33% overlap.
  • Interpretability: In a blind study with 30 software engineers, MA-RAG achieved an average interpretability score of 4.24/5. Experts noted that generated roles (e.g., "Network Admin" in OpenStack) closely aligned with real-world business logic.

Discussion and Future Work

MA-RAG demonstrates that the call graph of a program inherently contains the business logic necessary for defining roles. By using Multi-Head Attention, the model effectively balances conflicting security and usability requirements. The integration of RAG ensures the approach scales near-linearly with code size, making it practical for massive enterprise systems.

Future work will focus on bridging the "semantic gap" between technical API roles and high-level business ontologies, adaptively determining the number of attention heads, and extending the framework to microservices and serverless architectures.

Summary updated

BibTeX
@inproceedings{luo2025ma,
  author = {Yang Luo and Qingni Shen and Zhonghai Wu},
  title = {{MA-RAG: Automating Role Engineering for RESTful APIs with Multi-Head Attention and Retrieval-Augmented Generation}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {2025},
  doi = {10.24963/ijcai.2025/846},
}
Figure