Repository for the project Hybrid Validation of Kubernetes Security Policies using Feature Models and Content Analysis.
fm-security-policies is a validation framework that combines the formal rigor of Feature Models (SPL) with the flexibility of Python-based content analysis to audit Kubernetes configurations against security standards (e.g., Kyverno policies, Pod Security Standards).
Unlike traditional approaches that rely solely on logic solvers (SAT/SMT) —which struggle with string pattern matching, dynamic lists, and complex content rules— this pipeline implements a Hybrid Validation Engine:
- Structural Validation (Z3 Solver): Uses Flamapy to transform UVL constraints into logic formulas to validate boolean properties, field existence, and structural integrity.
- Content Validation (Python Heuristics): A dedicated
ContentPolicyValidatorhandles regex matching, deep recursive inspection, list iterations, and string semantics (e.g., Image Tags, AppArmor profiles, Ingress Classes).
It is designed for research, analysis, and validation scenarios where formal modeling of complex system configurations is required but needs to be augmented with practical content checks.
The system processes Kubernetes configurations (JSON/YAML) through a multi-stage pipeline:
- Policy Inference: Automatically detects which policies apply to the input file based on the Resource Kind (e.g.,
Pod,Service) and Content Heuristics (e.g., presence of images). - Pre-Validation (Python): Executes the
ContentPolicyValidator. If a content rule fails (e.g., an image using:latest), the configuration is rejected immediately (Fail-Fast), avoiding expensive solver calls. - Formal Validation (Z3): If pre-validation passes, the configuration is mapped to feature logic and solved against the
Policies.uvlmodel using the Z3 SMT solver.
- Python 3.9+
- Flamapy (and
flamapy-satplugin) - Git
- Bash or PowerShell for script execution
- Python 3.9+
- Git
- Bash or PowerShell for script execution
-
Install Python 3.9+
-
Clone this repository and enter the project folder:
git clone https://github.com/CAOSD-group/fm-security-policies.git
cd fm-json-kubernetes- Create a virtual environment:
python -m venv envFmSec- Activate the environment:
- Linux:
source envFmSec/bin/activate - Windows:
.\envFmSec\Scripts\Activate
- Install the dependencies:
pip install -r requirements.txtThe validation workflow is designed as a Hybrid Engine, separating structural logic from content analysis to maximize accuracy.
Note on Solver Evolution: Initially, this project utilized a SAT solver (Boolean Satisfiability) via Flamapy. However, due to the increasing complexity of Kubernetes policies (integers, ranges, and non-boolean logic), the core engine was migrated to Z3 (SMT Solver). This transition allows for richer constraints while maintaining the formal verification capabilities of Feature Models.
getValidationConfigurations02_Z3.py: The Main Orchestrator. It loads the UVL feature model, parses the input Kubernetes configurations (JSON/YAML), manages the hybrid validation flow (Python First -> Z3/SAT Second), and aggregates results.scripts/regex_validator.py(ClassContentPolicyValidator): The Content Engine. It handles deep inspection of the configuration files, including:- Recursive search for specific keys (e.g.,
_image,ownerReferences). - Regex pattern matching (e.g., for image tags).
- Complex logic for dynamic types (Lists, Maps, Annotations) that are difficult for SAT solvers.
- Recursive search for specific keys (e.g.,
scripts/_inference_policy.py: The Policy Selector. It determines which policies apply to a specific input file based on structural hints (from UVL constraints) and content discovery hooks (e.g., detecting if an image field exists).
/variability_model/: Contains thePolicies.uvlfeature model (the Single Source of Truth for security rules)./resources/: Dataset containing valid and invalid Kubernetes manifests used for testing and validation./scripts/: Source code for the validation logic, helpers, and inference engines./evaluation/: Generated CSV reports, logs, and performance metrics from mass validation runs.
The framework aggregates security best practices from multiple industry-standard tools (Kyverno, Fairwinds Polaris, Aqua Security Trivy, OPA/Gatekeeper) into a unified Feature Model.
This project relies on the following open-source technologies and standards:
- Flamapy - Python framework for automated analysis of feature models, used here to parse UVL and interface with solvers.
- Kyverno - Kubernetes Native Policy Management. The security policies implemented in this project are based on the Kyverno policy library.
- Trivy - Comprehensive security scanner (formerly OPA/Rego rules).
- Polaris - Validation of best practices and security.
- UVL (Universal Variability Language) - The text-based language used to define the security feature model (
Policies.uvl). - Kubernetes JSON Schema - Used as the baseline for the variability model generation.
Preview of new project to use policies and rules of external tools to check vulnerabilities in configurations with UVL.