-
Notifications
You must be signed in to change notification settings - Fork 174
Cedarling: Design for `default_entities` support in Policy Store
This feature adds support for default_entities in the policy store specification, enabling applications to define static entities that are loaded by the Cedarling on startup. This addresses the common need for organizational data, role-capability mappings, and other static reference information that policies can reference during authorization decisions.
The feature extends the existing policy store format to include a new default_entities section containing base64-encoded entity data with unique identifiers, making it easier to manage static application context without requiring dynamic token-based entity creation.
User Story: As a policy administrator, I want to define static entities in the policy store, so that I can reference organizational data and capability mappings in my authorization policies without requiring dynamic entity creation.
- WHEN a policy store is created THEN the system SHALL support an optional
default_entitiesfield in the policy store JSON structure - WHEN
default_entitiesare defined THEN each entity SHALL have a unique identifier as the key - WHEN
default_entitiesare defined THEN each entity value SHALL be base64-encoded entity JSON content - WHEN a policy store contains
default_entitiesTHEN the structure SHALL follow the format:"default_entities": {"entity_id": "base64-content", ...}
User Story: As a Cedarling runtime, I want to automatically load default entities on startup, so that they are available for policy evaluation without additional configuration steps.
- WHEN the Cedarling starts up THEN it SHALL automatically load all entities from the
default_entitiessection of the policy store - WHEN loading default entities THEN the Cedarling SHALL decode the base64 content and parse it as valid Cedar entity JSON
- WHEN default entities are loaded THEN they SHALL be available in the entity store for policy evaluation
- IF the
default_entitiessection is missing THEN the Cedarling SHALL continue normal operation without error - IF a default entity fails to load THEN the Cedarling SHALL log an error and continue loading other entities
User Story: As a policy author, I want to reference default entities in my policies, so that I can create authorization rules based on static organizational data and capability mappings.
- WHEN writing policies THEN authors SHALL be able to reference default entities using standard Cedar entity syntax
- WHEN a policy references a default entity THEN the entity SHALL be available during policy evaluation
- WHEN policies use default entities THEN they SHALL support attribute access and parent relationship traversal
- WHEN default entities have parent relationships THEN the policy engine SHALL correctly resolve hierarchical queries
User Story: As a system integrator, I want default entities to support complex data structures, so that I can model organizational hierarchies, product catalogs, and role-capability mappings effectively.
- WHEN defining default entities THEN they SHALL support all standard Cedar entity attributes including strings, numbers, booleans, and sets
- WHEN defining default entities THEN they SHALL support parent-child relationships through the
parentsfield - WHEN defining default entities THEN they SHALL support custom attributes relevant to the application domain
- WHEN default entities contain nested data THEN the policy engine SHALL correctly access nested attributes in policy conditions
User Story: As a policy store administrator, I want default entities to be versioned with the policy store, so that entity changes are tracked and can be reviewed alongside policy changes.
- WHEN a policy store is updated THEN changes to
default_entitiesSHALL be included in the policy store version - WHEN reviewing policy store changes THEN administrators SHALL be able to see modifications to default entities
- WHEN deploying policy stores THEN default entities SHALL be deployed atomically with policies and schema
- WHEN rolling back policy stores THEN default entities SHALL be rolled back to the previous version
User Story: As a security administrator, I want default entities to be validated against the schema, so that I can ensure data integrity and prevent runtime errors.
- WHEN default entities are loaded THEN they SHALL be validated against the Cedar schema if present
- WHEN a default entity violates the schema THEN the system SHALL reject the entity and log a validation error
- WHEN entity types in default entities are referenced THEN they SHALL match entity types defined in the schema
- WHEN default entities have attributes THEN the attributes SHALL conform to the schema attribute definitions
The default_entities feature extends the Cedar policy store specification to support static entity definitions that are loaded by the Cedarling at startup. This design addresses the need for applications to reference organizational data, role-capability mappings, and other static context in authorization policies without requiring dynamic entity creation from tokens.
The feature introduces a new optional default_entities section in the policy store JSON format, where entities are stored as base64-encoded JSON with unique identifiers. The Cedarling will automatically decode and load these entities into its entity store during initialization, making them available for policy evaluation.
The existing policy store format will be extended to include an optional default_entities field:
{
"cedar_version": "4.4.0",
"policy_stores": {
"store_id": {
"name": "Application Policy Store",
"description": "Policy store with default entities",
"policies": {
"policy_id": "base64-encoded-policy-content"
},
"trusted_issuers": {
"issuer_config": "..."
},
"schema": "base64-encoded-schema-content",
"default_entities": {
"entity_uuid_1": "base64-encoded-entity-json",
"entity_uuid_2": "base64-encoded-entity-json"
}
}
}
}Each default entity is stored with a unique identifier (UUID) as the key and base64-encoded entity JSON as the value. The decoded entity JSON follows the standard Cedar entity format:
{
"uid": { "type": "EntityType", "id": "entity_id" },
"attrs": {
"attribute_name": "attribute_value",
"nested_attr": {
"sub_attr": "value"
}
},
"parents": [
{ "type": "ParentType", "id": "parent_id" }
]
}The Cedarling will be enhanced with a new component responsible for loading default entities during startup:
graph TD
A[Cedarling Startup] --> B[Load Policy Store]
B --> C{Default Entities Present?}
C -->|Yes| D[Decode Base64 Content]
C -->|No| H[Continue Normal Startup]
D --> E[Parse Entity JSON]
E --> F[Validate Against Schema]
F --> G[Load into Entity Store]
G --> H[Continue Normal Startup]
E -->|Parse Error| I[Log Error & Skip Entity]
F -->|Validation Error| I
I --> J{More Entities?}
J -->|Yes| D
J -->|No| H
Interface: PolicyStoreParser
public interface PolicyStoreParser {
PolicyStore parse(String policyStoreJson) throws PolicyStoreParseException;
// New method for default entities
Map<String, DefaultEntity> parseDefaultEntities(JsonNode defaultEntitiesNode)
throws DefaultEntityParseException;
}Responsibilities:
- Parse the
default_entitiessection from policy store JSON - Decode base64-encoded entity content
- Convert JSON to internal entity representation
- Handle parsing errors gracefully
Interface: DefaultEntityLoader
public interface DefaultEntityLoader {
void loadDefaultEntities(Map<String, DefaultEntity> entities, EntityStore entityStore)
throws EntityLoadException;
boolean validateEntity(DefaultEntity entity, Schema schema);
void logLoadingResults(LoadingResults results);
}Responsibilities:
- Load parsed default entities into the Cedarling entity store
- Validate entities against the Cedar schema
- Handle loading errors and continue with remaining entities
- Provide detailed logging for troubleshooting
Interface: EntityStore (Enhanced)
public interface EntityStore {
// Existing methods...
// New methods for default entities
void addDefaultEntity(String entityId, Entity entity) throws EntityStoreException;
void addDefaultEntities(Map<String, Entity> entities) throws EntityStoreException;
boolean hasDefaultEntity(String entityId);
Set<String> getDefaultEntityIds();
}Responsibilities:
- Store default entities separately from runtime entities
- Provide efficient lookup for policy evaluation
- Support entity hierarchy traversal
- Maintain entity relationships and attributes
public class DefaultEntity {
private final String id;
private final EntityUid uid;
private final Map<String, AttributeValue> attributes;
private final Set<EntityUid> parents;
private final String originalJson;
// Constructor, getters, validation methods
}public class LoadingResults {
private final int totalEntities;
private final int successfullyLoaded;
private final int failed;
private final List<LoadingError> errors;
// Methods for reporting and logging
}public class DefaultEntityConfig {
private final boolean enabled;
private final boolean strictValidation;
private final boolean failOnError;
private final int maxEntities;
// Configuration for default entity behavior
}-
Parse Errors
- Invalid base64 encoding
- Malformed JSON structure
- Missing required fields
-
Validation Errors
- Schema validation failures
- Invalid entity type references
- Circular parent relationships
-
Loading Errors
- Entity store capacity limits
- Duplicate entity IDs
- System resource constraints
- Graceful Degradation: Continue loading other entities when one fails
- Detailed Logging: Log specific error details for troubleshooting
- Configuration Options: Allow strict vs. lenient validation modes
- Startup Behavior: Never fail Cedarling startup due to default entity errors
-
Policy Store Parser Tests
- Valid default entities parsing
- Invalid JSON handling
- Base64 decoding edge cases
- Empty default entities section
-
Entity Loader Tests
- Successful entity loading
- Schema validation scenarios
- Error handling and recovery
- Performance with large entity sets
-
Entity Store Integration Tests
- Entity storage and retrieval
- Parent relationship resolution
- Attribute access patterns
- Memory usage optimization
-
End-to-End Policy Evaluation
- Policies referencing default entities
- Complex entity hierarchies
- Attribute-based authorization
- Performance under load
-
Schema Compatibility Testing
- Entity validation against various schemas
- Schema evolution scenarios
- Backward compatibility verification
-
Startup Performance
- Loading time with various entity counts
- Memory usage patterns
- Concurrent loading scenarios
-
Runtime Performance
- Policy evaluation with default entities
- Entity lookup performance
- Memory footprint analysis
- Base64 Encoding: Ensures safe transport and storage of entity data
- Schema Validation: Prevents malformed entities from affecting policy evaluation
- Input Sanitization: Validate all entity attributes and relationships
- Policy Store Security: Default entities inherit policy store access controls
- Entity Visibility: Default entities are available to all policies in the store
- Audit Trail: Log all default entity loading activities
- Memory Limits: Implement configurable limits on entity count and size
- Loading Timeouts: Prevent indefinite loading operations
- Error Boundaries: Isolate default entity failures from core Cedarling functionality
-
Optional Feature:
default_entitiessection is completely optional - Existing Behavior: No changes to current policy store functionality
- Version Support: Compatible with existing Cedar versions
-
Phase 1: Add
default_entitiessupport to policy store parser - Phase 2: Implement entity loading in Cedarling
- Phase 3: Enable schema validation for default entities
- Phase 4: Add management tools and utilities
- Feature Flags: Allow enabling/disabling default entity support
- Gradual Rollout: Deploy to test environments first
- Monitoring: Track loading performance and error rates
- Rollback Plan: Ability to disable feature if issues arise
-
1. Create core data models and interfaces
- Define DefaultEntity, LoadingResults, and DefaultEntityConfig data models
- Create PolicyStoreParser interface with default entities parsing methods
- Create DefaultEntityLoader interface for entity loading operations
- Extend EntityStore interface to support default entity storage
- Requirements: 1.1, 1.2, 1.3, 1.4
-
2. Implement policy store parser enhancements
- Add parseDefaultEntities method to handle base64 decoding and JSON parsing
- Implement error handling for malformed JSON and invalid base64 content
- Create unit tests for parsing valid and invalid default entities sections
- Add validation for entity JSON structure and required fields
- Requirements: 1.1, 1.2, 1.3, 2.2, 6.1
-
3. Develop default entity loader component
- Implement DefaultEntityLoader with entity validation against Cedar schema
- Create entity loading logic that handles errors gracefully and continues processing
- Add detailed logging for successful loads, validation failures, and parse errors
- Implement configuration options for strict vs lenient validation modes
- Requirements: 2.1, 2.4, 2.5, 6.2, 6.3
-
4. Enhance entity store for default entity support
- Extend EntityStore implementation to store default entities separately from runtime entities
- Implement efficient lookup methods for default entities during policy evaluation
- Add support for entity hierarchy traversal and parent relationship resolution
- Create methods to check entity existence and retrieve entity collections
- Requirements: 2.3, 3.2, 3.3, 4.2, 4.3
-
5. Integrate default entity loading into Cedarling startup
- Modify Cedarling initialization to detect and load default entities from policy store
- Implement startup flow that loads entities after policy store parsing but before policy evaluation
- Add configuration options to enable/disable default entity loading
- Ensure Cedarling startup never fails due to default entity loading errors
- Requirements: 2.1, 2.4, 2.5
-
6. Implement schema validation for default entities
- Create entity validation logic that checks entities against the Cedar schema
- Implement validation for entity types, attributes, and parent relationships
- Add support for optional vs required attribute validation
- Create detailed validation error messages for troubleshooting
- Requirements: 6.1, 6.2, 6.3, 6.4
-
7. Add comprehensive error handling and logging
- Implement LoadingResults model to track successful and failed entity loads
- Create detailed error logging for parse failures, validation errors, and loading issues
- Add performance metrics logging for entity loading times and memory usage
- Implement error recovery that continues loading remaining entities after failures
- Requirements: 2.5, 6.2
-
8. Create unit tests for core components
- Write unit tests for DefaultEntity model validation and attribute access
- Create tests for PolicyStoreParser default entities parsing with various input scenarios
- Implement tests for DefaultEntityLoader covering successful loads and error conditions
- Add tests for EntityStore default entity storage and retrieval operations
- Requirements: 1.1, 1.2, 1.3, 2.2, 2.3
-
9. Develop integration tests for policy evaluation
- Create test policies that reference default entities in authorization decisions
- Implement tests for entity hierarchy traversal in policy conditions
- Add tests for attribute-based authorization using default entity attributes
- Create performance tests for policy evaluation with large numbers of default entities
- Requirements: 3.1, 3.2, 3.3, 4.1, 4.2
-
10. Add configuration and feature management
- Implement DefaultEntityConfig with options for enabling/disabling the feature
- Add configuration for maximum entity limits and validation strictness
- Create feature flags to control default entity loading behavior
- Implement configuration validation and default value handling
- Requirements: 2.4, 2.5
-
11. Implement backward compatibility safeguards
- Ensure policy stores without default_entities section continue to work unchanged
- Add version compatibility checks for Cedar schema and policy store format
- Create migration utilities for existing policy stores
- Implement graceful handling of unsupported default entity features
- Requirements: 5.1, 5.2, 5.3, 5.4
-
12. Create comprehensive test suite and documentation
- Develop end-to-end tests covering complete default entity lifecycle
- Create performance benchmarks for entity loading and policy evaluation
- Write integration tests for various entity hierarchy and attribute scenarios
- Add stress tests for large entity sets and concurrent access patterns
- Requirements: 2.1, 2.2, 2.3, 3.1, 3.2, 4.1