ENG-3517: Upload and promotion for user uploaded files - schema variant, storage util, hooks, config#8113
Open
mikeGarifullin wants to merge 2 commits intoENG-3517-2from
Open
ENG-3517: Upload and promotion for user uploaded files - schema variant, storage util, hooks, config#8113mikeGarifullin wants to merge 2 commits intoENG-3517-2from
mikeGarifullin wants to merge 2 commits intoENG-3517-2from
Conversation
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## ENG-3517-2 #8113 +/- ##
==============================================
- Coverage 85.26% 85.25% -0.01%
==============================================
Files 641 642 +1
Lines 42091 42213 +122
Branches 4941 4948 +7
==============================================
+ Hits 35888 35990 +102
- Misses 5096 5114 +18
- Partials 1107 1109 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
9dd46c8 to
3294cad
Compare
9d8d72e to
96eecd0
Compare
e6f0a43 to
f28be72
Compare
f321175 to
41ef133
Compare
…fig, and tests - Add domain exceptions for the attachments service - Add schema variant (attachment.py), storage util, extension hooks in privacy_request_service - Add config toggles (allow_custom_privacy_request_file_upload, security settings) - Cover new code with unit tests (exceptions, security/execution settings, storage util)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ticket ENG-3517
Description Of Changes
Schema + storage + service-extension half of the upload foundation. Pairs with the data-layer PR (#8110); the upload service and endpoint live in fidesplus and consume both.
Adds the Privacy Center config variant for file fields, a magic-byte sniff catalog so the upload route can verify a payload's claimed type at byte-zero (client-supplied
Content-Typeis not trusted), two config knobs for the global upload ceilings, and twoPrivacyRequestServicehook points so fidesplus can plug attachment-resolve and attachment-promote into the existing submission flow without overridingcreate_privacy_requestwholesale.Code Changes
schemas/privacy_center_config.py:FileUploadCustomPrivacyRequestFielddiscriminated-union variant (field_type="file",max_size_bytes > 0,allowed_file_typesnon-empty + must be a subset ofAllowedFileType).schemas/attachment.py:AttachmentUploadResponse(the{id: "att_..."}payload returned by the fidesplus upload route).service/storage/util.py:FilesMagicBytes— known signatures (pdf,jpg/jpeg,png,gif, ...) andfrom_bytes(...)for byte-zero detection.AllowedFileType.mime_types(),MIME_TO_EXTENSION,extension_for_mime(...)helpers.FileUploadConstraints— runtime-validated config bag (per-field cap + allowed types) reused by the upload route and the schema validator.service/privacy_request/privacy_request_service.py:_resolve_attachment_state(submitted_data, *, db)and_promote_attachment_state(privacy_request, state)— overridable no-op hooks on the OSS service. Default impls do nothing so OSS behavior is unchanged.create_privacy_requestcalls_resolve_attachment_statebefore persisting and_promote_attachment_stateafter caching/masking-secrets. On promotion failure the request row is deleted (clear_cached_values()runs as part ofdelete()) and the original error is rewrapped asPrivacyRequestError.common/urn_registry.py: route constant for the future fidesplus upload endpoint.config/security_settings.py:request_attachment_max_bytesglobal ceiling (caps the per-fieldmax_size_bytes).config/execution_settings.py:attachment_orphan_ttl_secondsfor the orphan-cleanup sweep.FileUploadConstraints.Steps to Confirm
nox -s "pytest(ops-unit-non-api)" -- tests/ops/schemas/test_attachment.py tests/ops/schemas/test_privacy_center_config.py tests/ops/service/storage/test_util.py— all green.FileUploadCustomPrivacyRequestFieldwithmax_size_bytes=0orallowed_file_types=[]— pydantic should reject. Construct one with an extension outsideAllowedFileType— pydantic should reject.FilesMagicBytes.from_bytes(open("sample.pdf","rb").read(8))returns thepdfmember. The same call against random bytes returnsNone.PrivacyRequestServiceand callcreate_privacy_request(...)with a non-file payload — flow runs unchanged (hooks are no-ops).FileUploadConstraints,FilesMagicBytes, and the new hook points — verify in the companion fidesplus PR.Pre-Merge Checklist
CHANGELOG.mdupdatedmaindowngrade()migration is correct and works