Files
regorus/tests/interpreter/cases/target/definitions/complex_target.json
Anand Krishnamoorthi cc917ea75d feat: Complete target system with C# bindings and resource inference (#458)
* feat: Add Schema Registry and Validation Framework

This commit introduces a comprehensive schema registry and validation framework, providing schema-based validation of resources and policy effects.

- Thread-safe, in-memory registry for schema storage and management
- Global registry patterns for effects and resources
- Concurrent access with proper error handling
- Unicode schema names support

- JSON Schema-compliant validation for all primitive types
- Advanced constraint validation (patterns, ranges, length limits)
- Discriminated union support with anyOf schemas
- Detailed error reporting with nested validation paths
- Discriminated subobject validation for polymorphic schemas

- **Registry Tests**: All registry operations
- **Effect Tests**: Policy effect validation
- **Resource Tests**: Resource validation
- **Validation Tests**: Core validation engine
- Thread-safety, error handling, integration scenarios, edge cases

- **Dependencies**: dashmap, once_cell, regex
- **Thread Safety**: Minimal locking with Rc<Schema> sharing
- **Error Types**: TypeMismatch, OutOfRange, PatternMismatch, etc.

- Complete schema registry and validation subsystem
- Comprehensive test coverage
- Foundation for policy validation in Regorus

Benchmarks:

- Criterion benchmarks for basic types, effects and Azure resources
- Performance range: 3.22ns (string) to 34.74µs (Azure VM resource schema validation)
- String withs patterns validation: 30.2µs. Need to explore whether regex caching helps
  bring this down.
- Azure policy effects: 188ns-1.4µs

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>

* feat: Complete target system with C# bindings and resource inference

- Add comprehensive target system with TargetRegistry and target-aware compilation
- Implement resource type inference from policy equality expressions
- Create modular C# bindings with separate wrapper classes for each concept
- Add thread-safe CompiledPolicy with reference counting for safe disposal
- Enhance FFI with detailed error propagation and target functionality
- Create TargetExampleApp demonstrating Azure Policy integration
- Add CI/CD pipeline testing for all C# applications
- Support target definitions with schema validation and resource selectors
- Implement PolicyModule struct and target-aware compilation methods
- Add comprehensive test coverage for target functionality

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>

---------

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2025-08-19 20:23:43 -05:00

196 lines
5.8 KiB
JSON

{
"name": "target.tests.complex_target",
"description": "A complex target for testing advanced features including discriminated unions",
"version": "2.0.0",
"resource_schema_selector": "resourceType",
"resource_schemas": [
{
"type": "object",
"properties": {
"name": { "type": "string" },
"resourceType": { "const": "compute" },
"spec": {
"type": "object",
"properties": {
"cpu": { "type": "integer", "minimum": 1, "maximum": 64 },
"memory": { "type": "string", "pattern": "^[0-9]+[GM]i$" }
},
"required": ["cpu", "memory"]
}
},
"required": ["name", "resourceType", "spec"]
},
{
"type": "object",
"properties": {
"name": { "type": "string" },
"resourceType": { "const": "storage" },
"spec": {
"type": "object",
"properties": {
"size": { "type": "string", "pattern": "^[0-9]+[GTM]i$" },
"type": { "enum": ["ssd", "hdd", "nvme"] }
},
"required": ["size", "type"]
}
},
"required": ["name", "resourceType", "spec"]
},
{
"type": "object",
"properties": {
"name": { "type": "string" },
"resourceType": { "type": "string" },
"spec": { "type": "object" }
},
"required": ["name"],
"additionalProperties": true
}
],
"effects": {
"allow": { "type": "boolean" },
"deny": { "type": "boolean" },
"audit": {
"type": "object",
"properties": {
"action": { "type": "string" },
"severity": { "enum": ["low", "medium", "high", "critical"] },
"details": {
"type": "object",
"properties": {
"eventType": { "type": "string" }
},
"required": ["eventType"],
"allOf": [
{
"if": {
"properties": {
"eventType": { "const": "access" }
}
},
"then": {
"properties": {
"user": { "type": "string" },
"resource": { "type": "string" },
"timestamp": { "type": "string" }
},
"required": ["user", "resource", "timestamp"]
}
},
{
"if": {
"properties": {
"eventType": { "const": "modification" }
}
},
"then": {
"properties": {
"user": { "type": "string" },
"resource": { "type": "string" },
"changes": {
"type": "array",
"items": {
"type": "object",
"properties": {
"field": { "type": "string" },
"oldValue": { "type": "any" },
"newValue": { "type": "any" }
},
"required": ["field", "oldValue", "newValue"]
}
}
},
"required": ["user", "resource", "changes"]
}
},
{
"if": {
"properties": {
"eventType": { "const": "security" }
}
},
"then": {
"properties": {
"threatLevel": { "enum": ["low", "medium", "high"] },
"source": { "type": "string" },
"indicators": {
"type": "array",
"items": { "type": "string" }
}
},
"required": ["threatLevel", "source", "indicators"]
}
}
]
}
},
"required": ["action", "severity", "details"]
},
"remediate": {
"type": "object",
"properties": {
"actionType": { "type": "string" },
"config": {
"type": "object",
"properties": {
"operation": { "type": "string" }
},
"required": ["operation"],
"allOf": [
{
"if": {
"properties": {
"operation": { "const": "quarantine" }
}
},
"then": {
"properties": {
"duration": { "type": "string", "pattern": "^[0-9]+[hmd]$" },
"reason": { "type": "string" }
},
"required": ["duration", "reason"]
}
},
{
"if": {
"properties": {
"operation": { "const": "scale" }
}
},
"then": {
"properties": {
"targetSize": { "type": "integer", "minimum": 0, "maximum": 100 },
"metric": { "enum": ["cpu", "memory", "requests"] }
},
"required": ["targetSize", "metric"]
}
},
{
"if": {
"properties": {
"operation": { "const": "replace" }
}
},
"then": {
"properties": {
"newResource": {
"type": "object",
"properties": {
"type": { "type": "string" },
"spec": { "type": "object" }
},
"required": ["type", "spec"]
},
"preserveData": { "type": "boolean" }
},
"required": ["newResource", "preserveData"]
}
}
]
}
},
"required": ["actionType", "config"]
}
}
}