iam-rs
STILL IN DEVELOPMENT AND VERIFICATION - DO NOT USE YET
STILL IN DEVELOPMENT AND VERIFICATION - DO NOT USE YET
STILL IN DEVELOPMENT AND VERIFICATION - DO NOT USE YET
STILL IN DEVELOPMENT AND VERIFICATION - DO NOT USE YET
STILL IN DEVELOPMENT AND VERIFICATION - DO NOT USE YET
STILL IN DEVELOPMENT AND VERIFICATION - DO NOT USE YET
STILL IN DEVELOPMENT AND VERIFICATION - DO NOT USE YET
A complete Rust library for parsing, validating, and evaluating IAM (Identity and Access Management) policies. Provider-agnostic and designed for building flexible authorization systems with full AWS IAM compatibility.
Features
- ๐ Provider-agnostic: Works with any AWS IAM-compatible JSON-based policy format
- ๐ Full IAM Support: Complete implementation of IAM policy including conditions, principals, actions, and resources
- ๐ท๏ธ ARN Validation: Comprehensive ARN parsing, validation, and wildcard matching
- โ๏ธ Policy Evaluation: Complete policy evaluation engine with Allow/Deny decisions
- ๐ฏ Condition Engine: Support for all AWS condition operators (String, Numeric, Date, Boolean, IP, ARN, Null)
- ๐ Type-safe: Strong typing with comprehensive enums and structs
- ๐ง Builder Pattern: Fluent API for constructing policies programmatically
- ๐ฆ Serde Integration: Built-in JSON serialization and deserialization
- โก Zero Dependencies: Minimal dependencies (only
serde
and serde-libs) - ๐งช Well Tested: Comprehensive test suite with 100+ tests
Installation
Add iam-rs
to your Cargo project:
Quick Start
Policy Evaluation (Authorization)
use ;
// Create a policy
let policy = new
.add_statement;
// Create an authorization request
let request = simple;
// Evaluate the request against the policy
match evaluate_policy?
Creating a Policy
use ;
use json;
let policy = new
.with_id
.add_statement;
// Serialize to JSON
let policy_json = policy.to_json.unwrap;
println!;
Parsing from JSON
use IAMPolicy;
let json_policy = r#"
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::example-bucket/*"
}
]
}
"#;
let policy = from_json.unwrap;
println!;
Core Types
IAMPolicy
The root policy document containing version, optional ID, and statements.
use ;
let policy = new
.with_version
.with_id;
IAMStatement
Individual policy statements with effect, principals, actions, resources, and conditions.
use ;
use HashMap;
let mut principal_map = new;
principal_map.insert;
let statement = new
.with_sid
.with_principal
.with_action
.with_resource;
Policy Evaluation Engine
The library includes a complete policy evaluation engine that implements AWS IAM logic for authorization decisions.
Simple Evaluation
use ;
// Simple authorization check
let decision = evaluate_policy?;
match decision
Advanced Evaluation with Context
use ;
// Create request context for condition evaluation
let mut context = empty;
context.insert;
context.insert;
let request = new;
// Advanced evaluation with multiple policies
let evaluator = with_policies
.with_options;
let result = evaluator.evaluate?;
println!;
for statement_match in result.matched_statements
IAM Logic Support
The evaluation engine properly implements AWS IAM precedence rules:
- Explicit Deny always overrides Allow
- Conditions must be satisfied for statement to apply
- Wildcard matching for actions, resources, and principals
- Multiple policies are combined with proper precedence
ARN (Amazon Resource Name)
Comprehensive ARN parsing, validation, and wildcard matching.
use Arn;
// Parse an ARN
let arn = parse?;
println!;
println!;
// Validate ARN format
assert!;
// Wildcard matching
let pattern = "arn:aws:s3:::my-bucket/*";
assert!;
// Extract resource information
if let Some = arn.resource_type
if let Some = arn.resource_id
Advanced Usage
ARN Validation and Matching
use Arn;
// Parse and validate ARNs
let arn = parse?;
// Wildcard pattern matching
let patterns = vec!;
for pattern in patterns
// Extract resource components
if let Some = arn.resource_type
if let Some = arn.resource_id
Multiple Actions and Resources
use ;
let actions = Multiple;
let resources = Multiple;
Complex Conditions
use ;
use json;
let statement = new
.with_action
.with_resource
.with_condition
.with_condition;
Principal Types
use ;
use HashMap;
// Wildcard principal (allows any principal)
let wildcard = Wildcard;
// AWS principal mapping
let mut aws_map = new;
aws_map.insert;
let aws_principal = Mapped;
// Multiple principals in a service mapping
let mut service_map = new;
service_map.insert;
let multiple_principals = Mapped;
"arn:aws:iam::123456789012:user/bob".to_string,
]);
// Wildcard (anyone)
let wildcard = Wildcard;
// Service principal with mapping
let mut service_map = new;
service_map.insert;
let service = Mapped;
Examples
The library includes comprehensive examples demonstrating all features:
Running Examples
# ARN parsing and validation
# Policy validation
# Policy evaluation engine
Example Scenarios
The evaluation demo showcases:
- โ Simple Allow/Deny policies
- โ Wildcard action and resource matching
- โ Condition-based authorization (String, Numeric, Date)
- โ Explicit deny precedence (IAM compliance)
- โ Multiple policy evaluation
- โ Detailed evaluation with match information
- โ Resource pattern matching
- โ Context-aware authorization
JSON Schema Compatibility
This library follows the standard IAM policy JSON schema and is compatible with:
- AWS IAM policies
- AWS resource-based policies
- Custom authorization systems using IAM-like policies
Example of a complete policy:
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.