This project implements a Domain-Specific Language (DSL) that allows network administrators to define access intent in a clean, human-readable text format. The system parses this intent and compiles it into various network configurations, including Cisco ACLs, and Linux firewall rule sets (iptables and nftables).
Additionally, it provides a comprehensive validation and simulation engine to detect misconfigurations, ensuring a DHCP/DNS-aware security design before deployment.
The project is built using Python and consists of the following core modules:
- Parser (
parser.py): Uses theLarklibrary to define the grammar and parse the DSL into an Abstract Syntax Tree (AST). - Model Builder (
model.py): Converts the AST into an intermediate structured dictionary (JSON-friendly format) representing roles, networks, services, and rules. - Rule Compilers: Translates the intermediate model into device-specific syntax.
compiler_acl.py: Generates Cisco IOS ACLs.compiler_iptables.py: Generates Linuxiptablesshell scripts.compiler_nftables.py: Generates Linuxnftablesconfigurations.
- Validator (
validator.py): Checks the intermediate model for logical errors, including:- Conflicts (contradictory rules).
- Duplicates and redundant permits.
- Unreachable rules (shadowed by broader rules).
- Missing infrastructure dependencies (DNS/DHCP).
- Simulator (
simulator.py): Simulates a packet flow through the rule set to predict the outcome (Allow/Deny) and explain which rule was triggered.
The language allows the definition of Roles, Networks, VPN pools, Services, and Access Rules.
- Roles:
role <RoleName>- Example:
role Students
- Example:
- Networks:
network <NetworkName> <CIDR>- Example:
network Student_Net 10.10.10.0/24
- Example:
- VPN Pools:
vpn <VPNRoleName> <CIDR>- Example:
vpn Remote_Staff 10.8.0.0/24
- Example:
- Services:
service <ServiceName> <Protocol> <Port>- Example:
service HTTP tcp 80
- Example:
Rules define the traffic flow from a Source to a Destination using a specific Service.
Syntax: <allow|deny> <SourceRole/Network> -> <DestinationNetwork> service <ServiceName>
- Examples:
allow Students -> Internet service HTTPdeny Guests -> Internal_Network service ANY
The engine is DHCP/DNS-aware. If an administrator allows a role to access an external network (e.g., Internet) but forgets to explicitly allow DNS or DHCP, the validator.py will detect this and flag it as a missing_dependency.
- Python 3.8+
larkparser librarypytest(for running unit tests)
- Create and activate a virtual environment (optional but recommended):
python3 -m venv venv source venv/bin/activate - Install dependencies:
pip install lark pytest
A predefined policy is located in policy.txt. To run the compiler and validation engine, execute:
python3 main.pyThis will:
- Parse the
policy.txtfile. - Output a summary to the console.
- Generate multiple configuration files inside the
outputs/directory:acl.txt(Cisco ACL)firewall.sh(iptables script)firewall.nft(nftables config)model.json(Intermediate JSON Model)validation_matrix.json(A matrix testing all permutations of roles to destinations)report.json(Conflicts, redundancies, and missing dependencies)
To run the automated tests against the parser, simulator, and validator, use:
pytest tests/- ACL logic, VLAN/Wireless roles: Supported via the
networkandroleprimitives. - VPN access policy: Supported natively via the
vpnprimitive which is tracked distinctly in the rule compilation. - Firewall generation: Supports Cisco, Iptables, and Nftables outputs.
- Simulator & Validation Matrix:
validation_matrix()outputs a complete state matrix verifying intended access.