Policy as Code (PaC) is a paradigm that encodes security and compliance policies into machine-readable formats, enabling automated enforcement in Infrastructure as Code (IaC) environments. However, its adoption is hindered by the complexity of policy languages and the risk of misconfigurations. In this work, we present ARPaCCino, an agentic system that combines Large Language Models (LLMs), Retrieval-Augmented-Generation (RAG), and tool-based validation to automate the generation and verification of PaC rules. Given natural language descriptions of the desired policies, ARPaCCino generates formal Rego rules, assesses IaC compliance, and iteratively refines the IaC configurations to ensure conformance. Thanks to its modular agentic architecture and integration with external tools and knowledge bases, ARPaCCino supports policy validation across a wide range of technologies, including niche or emerging IaC frameworks. Experimental evaluation involving a Terraform-based case study demonstrates ARPaCCino's effectiveness in generating syntactically and semantically correct policies, identifying non-compliant infrastructures, and applying corrective modifications, even when using smaller, open-weight LLMs. Our results highlight the potential of agentic RAG architectures to enhance the automation, reliability, and accessibility of PaC workflows.
翻译:代码即策略(Policy as Code,PaC)是一种将安全与合规策略编码为机器可读格式的范式,可在基础设施即代码(Infrastructure as Code,IaC)环境中实现自动化执行。然而,策略语言的复杂性和配置错误的风险阻碍了其广泛应用。本研究提出ARPaCCino,一个融合大型语言模型(LLMs)、检索增强生成(RAG)与基于工具的验证的智能代理系统,旨在自动化生成和验证PaC规则。给定期望策略的自然语言描述,ARPaCCino能够生成正式的Rego规则,评估IaC合规性,并迭代优化IaC配置以确保一致性。得益于其模块化的智能代理架构以及与外部工具和知识库的集成,ARPaCCino支持跨多种技术(包括小众或新兴的IaC框架)的策略验证。基于Terraform的案例实验评估表明,ARPaCCino在生成语法和语义正确的策略、识别不合规基础设施以及实施修正性调整方面具有显著效果,即使使用规模较小、开放权重的LLMs亦然。我们的研究结果凸显了智能RAG架构在提升PaC工作流程自动化水平、可靠性和可访问性方面的潜力。