-
Notifications
You must be signed in to change notification settings - Fork 99
H-4825: Implement initial meta-policy handling #7589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
H-4825: Implement initial meta-policy handling #7589
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds initial support for meta-policy handling by introducing a new Policy
entity in the Cedar schema, meta‐resource constraints, and wiring those through the authorization store and engine.
- Define
Policy
entity type and policy-specific actions (createPolicy
,viewPolicy
, etc.) in the schema. - Implement
MetaResourceConstraint
/MetaResourceFilter
andPolicyMetaResource
for Cedar integration. - Refactor the Postgres policy store to insert, update, archive, and delete policies with meta‐permission checks.
Reviewed Changes
Copilot reviewed 22 out of 23 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
tests/hash-backend-integration/src/tests/graph/authorization/policy.test.ts | Update TS tests to cover web vs. global policy CRUD |
libs/@local/graph/store/src/filter/mod.rs | Extend filter logic to ignore meta constraints for non-policy types |
libs/@local/graph/postgres-store/src/store/postgres/seed_policies.rs | Seed initial meta-policies (system, global, web) |
libs/@local/graph/postgres-store/src/store/postgres/mod.rs | Refactor policy CRUD methods to use meta-components |
libs/@local/graph/authorization/src/policies/store/error.rs | Add NotAuthorized variants for create/update/delete |
libs/@local/graph/authorization/src/policies/resource/meta.rs | New meta-resource filter and constraint definitions |
libs/@local/graph/authorization/src/policies/mod.rs | Register PolicyId and PolicyMetaResource in Cedar |
libs/@local/graph/authorization/schemas/policies.cedarschema | Extend Cedar schema with Policy entity and actions |
Comments suppressed due to low confidence (2)
libs/@local/graph/postgres-store/src/store/postgres/seed_policies.rs:264
- [nitpick] The
authenticated-view-meta
policy name is reused for User, Machine, and Ai actor types. Consider making names unique (e.g., include the actor type) to avoid confusion when debugging or auditing.
name: Some("authenticated-view-meta".to_owned()),
libs/@local/graph/postgres-store/src/store/postgres/seed_policies.rs:507
- [nitpick] The
default-web-meta
policy name for all web roles may conflict if multiple roles seed it. Consider appending the web role name or ID to distinguish these policies.
name: Some("default-web-meta".to_owned()),
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7589 +/- ##
==========================================
- Coverage 55.22% 55.06% -0.16%
==========================================
Files 1082 1083 +1
Lines 94786 95329 +543
Branches 4510 4513 +3
==========================================
+ Hits 52341 52494 +153
- Misses 41461 41848 +387
- Partials 984 987 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
a8ab8d5
to
6d2c302
Compare
60786c7
to
1c0b4be
Compare
1c0b4be
to
736919a
Compare
Benchmark results
|
Function | Value | Mean | Flame graphs |
---|---|---|---|
entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/organization/v/1
|
Flame Graph | |
entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/uk-address/v/1
|
Flame Graph | |
entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/block/v/1
|
Flame Graph | |
entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/book/v/1
|
Flame Graph | |
entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/playlist/v/1
|
Flame Graph | |
entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/song/v/1
|
Flame Graph | |
entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/page/v/2
|
Flame Graph | |
entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/person/v/1
|
Flame Graph | |
entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/building/v/1
|
Flame Graph |
scaling_read_entity_linkless
Function | Value | Mean | Flame graphs |
---|---|---|---|
entity_by_id | 10000 entities | Flame Graph | |
entity_by_id | 1000 entities | Flame Graph | |
entity_by_id | 1 entities | Flame Graph | |
entity_by_id | 10 entities | Flame Graph | |
entity_by_id | 100 entities | Flame Graph |
scaling_read_entity_complete_one_depth
Function | Value | Mean | Flame graphs |
---|---|---|---|
entity_by_id | 1 entities | Flame Graph | |
entity_by_id | 50 entities | Flame Graph | |
entity_by_id | 10 entities | Flame Graph | |
entity_by_id | 25 entities | Flame Graph | |
entity_by_id | 5 entities | Flame Graph |
scaling_read_entity_complete_zero_depth
Function | Value | Mean | Flame graphs |
---|---|---|---|
entity_by_id | 1 entities | Flame Graph | |
entity_by_id | 50 entities | Flame Graph | |
entity_by_id | 10 entities | Flame Graph | |
entity_by_id | 25 entities | Flame Graph | |
entity_by_id | 5 entities | Flame Graph |
representative_read_entity_type
Function | Value | Mean | Flame graphs |
---|---|---|---|
get_entity_type_by_id | Account ID: bf5a9ef5-dc3b-43cf-a291-6210c0321eba
|
Flame Graph |
representative_read_multiple_entities
Function | Value | Mean | Flame graphs |
---|---|---|---|
link_by_source_by_property | depths: DT=2, PT=2, ET=2, E=2 | Flame Graph | |
link_by_source_by_property | depths: DT=0, PT=0, ET=0, E=2 | Flame Graph | |
link_by_source_by_property | depths: DT=255, PT=255, ET=255, E=255 | Flame Graph | |
link_by_source_by_property | depths: DT=0, PT=0, ET=0, E=0 | Flame Graph | |
link_by_source_by_property | depths: DT=0, PT=0, ET=2, E=2 | Flame Graph | |
link_by_source_by_property | depths: DT=0, PT=2, ET=2, E=2 | Flame Graph | |
entity_by_property | depths: DT=2, PT=2, ET=2, E=2 | Flame Graph | |
entity_by_property | depths: DT=0, PT=0, ET=0, E=2 | Flame Graph | |
entity_by_property | depths: DT=255, PT=255, ET=255, E=255 | Flame Graph | |
entity_by_property | depths: DT=0, PT=0, ET=0, E=0 | Flame Graph | |
entity_by_property | depths: DT=0, PT=0, ET=2, E=2 | Flame Graph | |
entity_by_property | depths: DT=0, PT=2, ET=2, E=2 | Flame Graph |
🌟 What is the purpose of this PR?
This PR implements meta-permissions for policy management in HASH's authorization system. It establishes who can create, update, and delete policies by introducing a new
Policy
entity type in Cedar schema and implementing resource constraints that scope policy management permissions to appropriate actor roles.The implementation follows the principle that policy management should be restricted by resource constraints - web administrators can manage policies within their web scope, while preventing unauthorized global policy creation that could lead to privilege escalation.
🔗 Related links
🚫 Blocked by
🔍 What does this change?
Cedar Schema Updates
Policy
entity type withactions: Set<String>
attributecreatePolicy
,viewPolicy
,updatePolicy
,archivePolicy
,deletePolicy
delete
as top-level action (placeholder for future delete actions)Authorization System Enhancements
CreatePolicy
,ViewPolicy
, etc.) as children of base actionsMetaResourceConstraint
andMetaResourceFilter
for policy-based permissionsPolicyMetaResource
for Cedar entity representation of policiesResourceConstraint
enum withMeta
variantPolicy Store Implementation
Security Model
Core Components
libs/@local/graph/authorization/src/policies/resource/meta.rs
: New meta-resource implementationHasAction
filtering🐾 Next steps
🛡 What tests cover this?
tests/hash-backend-integration/src/tests/graph/authorization/policy.test.ts
libs/@local/graph/postgres-store/tests/principals/policies.rs
libs/@local/graph/authorization/src/policies/resource/meta.rs
❓ How to test this?
CreateWeb
(should fail due to global forbid policy)