NACM Validator
A Rust implementation of NACM (Network Access Control Model) validator as defined in RFC 8341, with support for Tail-f ACM extensions for command-based access control. This library and CLI tool demonstrate parsing real NACM XML configurations and validating access requests against defined rules.
Installation
The NACM Validator provides both a library (nacm-validator) for developers and a command-line tool (nacm-validator) for end users.
Installing the CLI Tool
The CLI tool is not yet published to crates.io as a separate package. Install from source:
# Clone the repository
# Install the CLI tool globally
# This installs the 'nacm-validator' binary to ~/.cargo/bin/
# Make sure ~/.cargo/bin is in your PATH
After installation, you can run the tool from anywhere:
Using the Library
To use the validator library in your own Rust project, add it to your Cargo.toml:
[]
= "0.1"
You can also use the git dependency for the latest development version:
[]
# For the latest published version (recommended):
= "0.1"
# Or for the latest development version:
# nacm-validator = { git = "https://github.com/etnt/nacm-validator.git", package = "nacm-validator" }
Then import the library in your Rust code:
use ;
Development Setup
If you want to develop or contribute to the project:
# Clone the repository
# Build the workspace (both library and CLI)
# Run tests
# Build documentation
# Run examples
Quick Start
CLI Tool - Traditional NACM
# Build the CLI tool (if developing from source)
# Test data access (standard NACM)
# Output: PERMIT
# Test with denied user
# Output: DENY (exit code 1)
CLI Tool - Tail-f ACM Extensions
# Test command-based access control
# Output: PERMIT [LOGGED]
# Test context-aware access
# Output: PERMIT [LOGGED]
# JSON batch processing with enhanced fields
| \
# Output: {"decision":"permit","user":"alice","context":"cli","command":"show status","should_log":true,...}
Library Usage
use ;
let config = from_xml?;
let context = CLI;
let request = AccessRequest ;
let result = config.validate;
println!;
Run Examples
# Comprehensive feature demonstration
# Interactive shell examples
&&
# JSON batch processing
&&
๐ Features
Standard NACM (RFC 8341)
- XML Configuration Parsing: Parse real-world NACM XML configurations
- Rule-based Access Control: Support for permit/deny rules with precedence
- Group Management: User groups with inheritance
- Operation Support: Read, Create, Update, Delete, and Exec operations
- Path Matching: XPath-style path matching for fine-grained access control
- RPC-level Control: Control access to specific NETCONF RPCs
- Module-based Rules: Control access to specific YANG modules
Tail-f ACM Extensions
- Command Rules: Access control for CLI and Web UI operations (
<cmdrule>) - Enhanced Logging: Fine-grained logging control with
log-if-permit/log-if-deny - Context-Aware Rules: Different rules for NETCONF, CLI, WebUI contexts
- Group ID Mapping: OS-level group integration with
<gid>mapping - Command Default Policies: Separate default policies for command operations
- Symmetric Logging: Control logging for both permit and deny decisions
๐ Prerequisites
- Rust toolchain (1.70 or later recommended)
- Cargo package manager
๐ง Building the Project
# Clone the repository
# Build the project (library and CLI tool)
# Build in release mode (optimized)
# Build just the CLI tool
# Build just the library
๐งช Running Tests
The project includes comprehensive tests covering XML parsing and access validation:
# Run all tests
# Run tests with detailed output
# Run a specific test
# Run tests and show successful test output
Test Coverage
The tests include:
- โ XML parsing validation
- โ Basic rule matching
- โ Real-world NACM configuration parsing
- โ Access validation scenarios
- โ Group membership resolution
๐ Running Examples
Access Validation Example
The main example demonstrates parsing a real NACM XML file and validating various access scenarios:
This example shows:
- Loading NACM configuration from XML
- Validating different user access scenarios
- Demonstrating permit/deny decisions based on rules
Tail-f ACM Extensions Demo
Run the comprehensive Tail-f ACM demo to see all the advanced features in action:
This demo showcases:
- Command rules with context awareness (CLI, WebUI, NETCONF)
- Enhanced logging configuration and validation
- Group ID (GID) mapping for external authentication
- ValidationResult with both access decision and logging information
- Context-specific access control policies
Example Output:
๐ง Tail-f ACM Configuration loaded:
- NACM enabled: true
- Default policies:
* Data: read=Deny, write=Deny, exec=Deny
* Commands: cmd_read=Deny, cmd_exec=Deny
- Logging: default_permit=true, default_deny=true
- Groups: ["operators", "admin"]
* operators (GID: 1000): ["alice", "bob"]
* admin (GID: 0): ["admin"]
- Rule lists: 2
๐ Command access validation results:
โ
Alice (operator) - CLI show status: PERMIT ๐[LOG]
โ Bob (operator) - CLI reboot: DENY ๐[LOG]
โ
Admin - WebUI config backup: PERMIT
...
Example Output:
NACM Configuration loaded:
- NACM enabled: true
- Default policies: read=Deny, write=Deny, exec=Deny
- Groups: ["oper", "admin"]
- Rule lists: 3
Access validation results:
- Admin executing edit-config: โ
PERMIT
- Oper executing edit-config: โ DENY
- Oper modifying NACM config: โ DENY
- Guest reading example/misc/data: โ
PERMIT
- Guest creating example/misc: โ
PERMIT
- Unknown user reading data: โ
PERMIT
๐ Project Structure
nacm-validator/
โโโ src/
โ โโโ lib.rs # Main library with Tail-f ACM extensions
โ โโโ bin/
โ โโโ nacm-validator.rs # Enhanced CLI tool with context support
โโโ examples/
โ โโโ validate_access.rs # Basic access validation example
โ โโโ tailf_acm_demo.rs # Tail-f ACM features demonstration
โ โโโ tailf_acm_comprehensive_demo.rs # Comprehensive feature showcase
โ โโโ bash_examples.sh # Bash integration with Tail-f ACM
โ โโโ json_batch_example.sh # JSON batch processing example
โ โโโ README.md # Examples documentation
โ โโโ data/
โ โโโ aaa_ncm_init.xml # Basic NACM configuration (insecure)
โ โโโ aaa_ncm_init_secure.xml # Secure NACM configuration
โ โโโ tailf_acm_example.xml # Comprehensive Tail-f ACM example
โโโ doc/
โ โโโ rfc-tailf-acm-proposal.md # Tail-f ACM RFC proposal document
โโโ Cargo.toml # Project configuration
โโโ README.md # This file
โ ๏ธ Security Note
The original aaa_ncm_init.xml contains a security vulnerability - it has a catch-all rule that permits access for any user (including unknown users). This is dangerous:
any-access
permit
Testing the Security Issue
# โ INSECURE: Unknown user 'bill' gets access with original config
# Output: PERMIT (this is wrong!)
# โ
SECURE: Unknown user 'bill' denied with secure config
# Output: DENY (this is correct!)
Always use aaa_ncm_init_secure.xml for production-like testing.
๐ ๏ธ Using as a Library
Add this to your Cargo.toml:
[]
= "0.1.0"
Basic Library Usage
use ;
Advanced Library Usage with Context Awareness
use ;
The validate() method returns a ValidationResult struct containing:
effect:RuleEffect::PermitorRuleEffect::Denyshould_log: Whether this decision should be logged based on the rule's logging configuration (Tail-f ACM extension)
Key Tail-f ACM Features
Command Rules Priority
Command rules take priority over data access rules when a command is specified:
let request = AccessRequest ;
// The validator will check command rules first, then fall back to data rules
let result = config.validate;
Enhanced Logging Control
Rules can specify granular logging behavior:
// Check if access decision should be logged
let result = config.validate;
if result.should_log
Group ID Integration
Groups can include GID mapping for OS-level integration:
// Configuration parsing includes GID information
let config = from_xml?;
for in &config.groups
Quick CLI Usage
# Build the CLI tool
# Validate a simple request (using secure config)
# Output: PERMIT (exit code 0)
# Test denied access
# Output: DENY (exit code 1)
# Test unknown user (should be denied)
# Output: DENY (exit code 1)
๐ API Documentation
Generate and view the complete API documentation:
This opens the documentation in your browser, showing all available types, traits, and functions.
๐งฉ Core Types
Key Structures
Standard NACM Types
NacmConfig: Main configuration containing groups, rule lists, and policiesNacmRule: Individual data access control ruleNacmRuleList: Named collection of rules applying to specific groupsNacmGroup: User group definition with member listAccessRequest: Represents an access attempt with context informationRuleEffect: Permit or Deny decisionOperation: CRUD + Exec operations
Tail-f ACM Extensions
NacmCommandRule: Command-based access control ruleRequestContext: Management interface context (CLI, NETCONF, WebUI)ValidationResult: Enhanced result with access decision and logging flag
Enhanced AccessRequest Structure
AccessRequest
Enhanced ValidationResult
ValidationResult
Example Rule Structures
Standard Data Access Rule
NacmRule
Tail-f ACM Command Rule
NacmCommandRule
Enhanced Group with GID
NacmGroup
Request Context Enum
// Context matching supports wildcards
context.matches // Matches any context
context.matches // Matches CLI exactly
๏ฟฝ๏ธ Command Line Interface
The project includes a powerful CLI tool with full support for Tail-f ACM extensions, enabling both traditional data access validation and command-based access control from bash scripts and automation.
Building the CLI
# Build the CLI tool
# Build optimized version
# The binary will be available at:
# ./target/debug/nacm-validator (debug build)
# ./target/release/nacm-validator (release build)
Basic Usage
# Standard NACM data access validation
# Tail-f ACM command access validation
# Context-aware data access
# Output: PERMIT [LOGGED] or DENY [LOGGED] - shows logging indicator
CLI Options
Options:
-c, --config <CONFIG> Path to the NACM XML configuration file
-u, --user <USER> Username making the request
-m, --module <MODULE> Module name (optional)
-r, --rpc <RPC> RPC name (optional)
-o, --operation <OPERATION> Operation type [read, create, update, delete, exec]
-p, --path <PATH> Path (optional)
-x, --context <CONTEXT> Request context [netconf, cli, webui] (Tail-f ACM)
-C, --command <COMMAND> Command being executed (Tail-f ACM)
--format <FORMAT> Output format [text, json, exit-code]
-v, --verbose Verbose output
--json-input JSON input mode - read requests from stdin
Enhanced Features
Context-Aware Validation
# Different contexts may have different access policies
# Output: PERMIT [LOGGED]
# Output: PERMIT [LOGGED]
Enhanced JSON I/O
# JSON input with Tail-f ACM fields
| \
# Output includes enhanced fields:
{
}
Bash Script Integration
Exit Code Based Validation with Context
#!/bin/bash
CONFIG="examples/data/tailf_acm_example.xml"
# Command-based validation
if ; then
else
fi
# Context-aware function
JSON Processing with Enhanced Fields
# Process enhanced JSON output
JSON_OUTPUT=
# Extract enhanced fields
DECISION=
SHOULD_LOG=
CONTEXT=
COMMAND=
Batch Processing with Tail-f ACM
# Create batch requests with enhanced fields
# Process batch requests
# Output shows enhanced information:
}
}
}
}
Example Scripts and Programs
The project includes comprehensive working examples demonstrating all features:
Rust Examples
# Standard NACM access validation with context awareness
# Focused Tail-f ACM extensions demonstration
# Comprehensive Tail-f ACM feature showcase
Shell Script Examples
# Interactive bash integration examples with Tail-f ACM
&&
# JSON batch processing with enhanced fields
&&
Example Outputs
Standard Validation:
NACM Configuration loaded:
- NACM enabled: true
- Standard defaults: read=Deny, write=Deny, exec=Deny
- Command defaults: cmd_read=Permit, cmd_exec=Permit
- Groups: ["oper", "admin"]
- Rule lists: 3
Access validation results:
- Admin executing edit-config (NETCONF): โ
PERMIT
- Alice - CLI read interfaces (no command rule): โ DENY [LOGGED]
- Admin via WebUI (no command - should use data rules): โ
PERMIT
Comprehensive Tail-f ACM Demo:
๐ง Comprehensive Tail-f ACM Extensions Demo
==================================================
๐ Configuration Summary:
- NACM enabled: true
- Standard defaults: read=Deny, write=Deny, exec=Deny
- Command defaults: cmd_read=Deny, cmd_exec=Deny
- Logging: default_permit=true, default_deny=true
๐ฅ Groups:
operators (GID: 1000): ["alice", "bob"]
admin (GID: 0): ["admin"]
๐ Rule Lists:
1. operator-rules (groups: ["operators"])
- Standard rules: 1
โข read-interfaces -> Permit [context: netconf]
- Command rules: 4
โข cli-show-status -> Permit [context: cli] [command: show status]
โข any-help -> Permit [context: *] [command: help]
๐งช Test Scenarios:
1๏ธโฃ Command-Based Access Control:
โ
alice (operator) - CLI 'show status': Permit ๐
โ charlie (not in group) - CLI 'show status': Deny ๐
โ
admin - CLI 'reboot' (exec operation): Permit
2๏ธโฃ Context-Aware Data Access:
โ
alice - NETCONF read interfaces: Permit ๐
โ alice - CLI read interfaces (no command rule): Deny ๐
โ alice - WebUI read interfaces (no command rule): Deny ๐
These examples demonstrate:
- โ Standard NACM access validation with real configurations
- โ Tail-f ACM command rules with context awareness
- โ ValidationResult usage with logging information
- โ CLI integration with exit codes and enhanced output
- โ JSON I/O processing with extended fields
- โ Batch request processing with context support
- โ Error handling for invalid contexts and commands
- โ Multi-interface access control simulation
- โ Group ID mapping and OS integration patterns
๐ Development
Adding New Tests
Tests are located in src/lib.rs within the #[cfg(test)] module:
Creating New Examples
Add new examples in the examples/ directory:
// examples/my_example.rs
use *;
Run with: cargo run --example my_example
๐ License
This project is licensed under the Mozilla Public License 2.0 (MPL-2.0). See the LICENSE file for details.
This is a prototype implementation for educational and research purposes.
๐ค Contributing
This is a prototype project. Feel free to experiment and extend the functionality!
Development Commands
# Format code
# Run clippy for lints
# Check without building
# Clean build artifacts
๐ References
- RFC 8341 - Network Configuration Access Control Model
- YANG Data Modeling Language
- NETCONF Protocol
- Tail-f ACM Extensions Proposal
โจ What Makes This Implementation Special
๐ฏ Production-Ready Features
- Real-World XML Parsing: Handles actual NACM configurations from network devices
- Comprehensive Rule Support: All RFC 8341 rule types with proper precedence
- Robust Error Handling: Graceful parsing errors and validation feedback
- Performance Optimized: Rust's zero-cost abstractions for high-performance validation
๐ Advanced Tail-f ACM Extensions
- Command-Based Rules: First-class support for CLI/WebUI command validation
- Context Awareness: Different policies for different management interfaces
- Enhanced Logging: Granular audit trail control with
log-if-permit/log-if-deny - OS Integration: Group ID mapping for external authentication systems
- Backward Compatible: Seamless integration with existing NACM deployments
๐ ๏ธ Developer Experience
- Dual Interface: Both library API and CLI tool for maximum flexibility
- Rich Documentation: Comprehensive examples and API documentation
- Type Safety: Rust's type system prevents common access control bugs
- Test Coverage: Extensive test suite with real-world scenarios
- Shell Integration: Exit codes and JSON I/O for seamless automation
๐ Integration Patterns
- Shell Scripting: Exit codes and silent modes for bash automation
- Web APIs: JSON batch processing for REST service integration
- CLI Tools: Context-aware validation for management interface security
- Audit Systems: Enhanced logging for compliance and security monitoring
- Multi-Tenant: Group-based access control for shared infrastructure
This implementation bridges the gap between academic NACM specifications and real-world network device security requirements, making enterprise-grade access control accessible to Rust developers and system integrators.