ENG-2194: Add custom default policy configuration support#7323
ENG-2194: Add custom default policy configuration support#7323
Conversation
Allow configuring custom default policies per action type via ApplicationConfig. Falls back to system defaults if custom default is missing or invalid. Co-authored-by: Cursor <cursoragent@cursor.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
Co-authored-by: Cursor <cursoragent@cursor.com>
|
Deployment failed with the following error: |
….com:ethyca/fides into ENG-2194-be-default-policy-configuration-api
Greptile OverviewGreptile SummaryThis PR adds support for custom per-action default policies via It also extends location convenience-field resolution to support location groups/regulations, updates specificity/tiebreaking to treat those fields as mutually exclusive with other location selectors, and updates the policy list endpoint to eager-load Main issue to address before merge: the new Confidence Score: 4/5
Important Files Changed
|
|
@greptile please review |
|
@greptile please review |
src/fides/api/task/conditional_dependencies/privacy_request/convenience_fields.py
Show resolved
Hide resolved
src/fides/api/task/conditional_dependencies/policy_evaluation.py
Outdated
Show resolved
Hide resolved
|
@greptile please review |
src/fides/api/task/conditional_dependencies/policy_evaluation.py
Outdated
Show resolved
Hide resolved
|
@greptile please review |
|
@greptile please review |
src/fides/api/task/conditional_dependencies/privacy_request/convenience_fields.py
Show resolved
Hide resolved
|
@greptile please review and take comments into account |
johnewart
left a comment
There was a problem hiding this comment.
Looks good - the questions I had we talked about out-of-band 👍
Ticket
ENG-2194
Description Of Changes
Custom Default Policy Configuration
Add support for custom default policies per action type via
ApplicationConfig. When no policy conditions match a privacy request, thePolicyEvaluatornow:ApplicationConfig.api_set)This enables administrators to override the system default policies (
default_access_policy,default_erasure_policy,default_consent_policy) with organization-specific defaults.Policy Conditions in API Responses
The policy list endpoint now eagerly loads and returns policy conditions in the response.
PolicyResponseincludes a newconditionsfield populated via a model validator that extracts the condition tree from the ORM relationship.Location Groups & Regulations Support
Expanded location convenience field resolution to support location groups (e.g.,
"us","ca"as groups, not just individual locations). TheMUTUALLY_EXCLUSIVE_FIELDSset now includeslocation_groupsandlocation_regulationsfor proper condition tiebreaking.Code Changes
src/fides/api/task/conditional_dependencies/policy_evaluation.py_get_configured_default_policy_key()method and updated_get_default_policy()to check custom defaults first; addedlocation_groupsandlocation_regulationstoMUTUALLY_EXCLUSIVE_FIELDSsrc/fides/api/schemas/policy.pyconditionsfield toPolicyResponsewithextract_conditionsmodel validator; modernized type hints (List→list,Dict→dict)src/fides/api/api/v1/endpoints/policy_endpoints.pyjoinedload(Policy.conditions)to policy list query for eager loadingsrc/fides/api/task/conditional_dependencies/privacy_request/convenience_fields.pylocation_groupslookup before country code fallback in convenience field resolutionsrc/fides/api/util/default_policy_config.pyDEFAULT_POLICY_CONFIG_KEYconstant shared between fides and fidesplustests/api/task/conditional_dependencies/test_policy_evaluation.pyTestCustomDefaultPolicytest class (5 tests); expandedtest_routes_by_locationandtest_ambiguous_tie_raises_errorto parameterize over all location field types (location, country, groups, regulations)tests/ops/api/v1/endpoints/privacy_request/test_privacy_request_endpoints.py"conditions": {}changelog/7323.yamlSteps to Confirm
Prerequisites: Create policies with conditions using the policy conditions endpoints from #3031.
Verify policy conditions are returned in the policy list using
GET /api/v1/dsr/policyExpected: Each policy includes a conditions field containing its condition tree ({} if no conditions).
Set a custom default policy using
PUT /api/v1/plus/dsr/policy/default{ "action_type": "access", "policy_key": "my_custom_access_policy"}Expected: 200 response with updated config showing the custom policy key for access.
Verify custom default is used when no conditions match using
POST /api/v1/privacy-request[ { "identity": {"email": "test@example.com"}, "location": "XX", "action_type": "access" }]Expected: Request created using my_custom_access_policy (not default_access_policy).
Reset to system default using
PUT /api/v1/plus/dsr/policy/default{ "action_type": "access", "policy_key": null}Expected: 200 response. Subsequent privacy requests with no matching conditions fall back to default_access_policy.
Verify location group matching - Create a policy with a location_groups = eea condition, then
POST /api/v1/privacy-request[ { "identity": {"email": "test@example.com"}, "location": "FR", "action_type": "access" }]Expected: France resolves to the eea group and matches the policy.
Verify location regulation matching - Create a policy with a
location_regulations = gdprcondition, thenPOST /api/v1/privacy-request[{"identity": {"email": "test@example.com"}, "location": "FR", "action_type": "access" }]Expected: France resolves to the gdpr regulation and matches the policy.
Read the current default config using
GET /api/v1/plus/dsr/policy/defaultExpected: Returns access, erasure, and consent fields (each null for system default or a policy key for custom).
Pre-Merge Checklist
CHANGELOG.mdupdatedMade with Cursor