Skip to content
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

TCF Backend #3804

Merged
merged 81 commits into from
Sep 20, 2023
Merged

TCF Backend #3804

merged 81 commits into from
Sep 20, 2023

Conversation

pattisdr
Copy link
Contributor

@pattisdr pattisdr commented Jul 18, 2023

Closes #3817
Closes #3822
Closes #3876
Closes #3935
Closes https://github.com/ethyca/fidesplus/issues/1051

❗ Contains migration; bump downrev before merge

Description Of Changes

Adds the backend for being able to build a TCF overlay.

Importantly:

  • Adds a new type of experience: the TCF Overlay, that is only returned when the customer has TCF enabled and the user is in an EEA country.
  • The contents for the TCF overlay are generated at runtime by looking at what data uses are on current systems (and soon) what features are on systems, to return Purposes, Special Purposes, Vendors (where we have a vendor_id, in other words, we know what type of system we have), Features and Special Features, and Systems (no vendor id).
    • There are no Privacy Notices associated with a TCF experience. You save preferences against TCF components directly.
    • Data uses need to be an "exact match" unlike Privacy Notices where we allow hierarchy-matching on data use
  • Adds the ability to save preferences with respect to individual TCF purposes, special purposes, vendors, special features, and features, and systems.
  • Adds the ability to save when individual TCF components were served.
  • When building the TCF Experience, surfaces any previously-saved or previously-served details alongside the TCF data.
  • Relaxes constraints on PrivacyPreferenceHistory, ServedNoticeHistory, CurrentPrivacyPreference, and LastServedNotice to use these tables to store when preferences were saved and served against not just notices, but TCF components as well.

Code Changes

  • Add a new ConsentSettings table and endpoints to enable TCF - this table will have gpp settings added in the future
  • Update GET Privacy Experience to be able to return a TCF overlay instead of a regular overlay provided TCF is enabled and the customer is in an EEA country
    • Existing has_notices param's meaning has been extended to mean "does the experience have content?" - so does it have notices or TCF content
    • Method added: embed_experience_details that either populates the Experience with either TCF content, or with notices (existing behavior), depending on the type of experience
    • New method: cache_saved_and_served_on_consent_record that pulls previous records where consent was saved and served both for privacy notices or individual TCF components
  • purpose, special_purpose, feature, special_feature, system and vendor columns added to PrivacyPreferenceHistory (tracks all saved preferences), ServedNoticeHistory (tracks all served records), CurrentPrivacyPreference (tracks most current preference across version/time/multiple identities for the same user), and LastServedNotice (tracks most current served across version/time/multiple identities) tables to record serving or saving consent against individual TCF components, not just privacy notices
    • Makes privacy notice related fields nullable since these tables are no longer just for privacy notices exclusively
    • Updates PrivacyPreferenceHistory.create to save preferences against privacy notices or individual TCF components
    • Updates ServedNoticeHistory.create to save that notices or individual TCF components were served
    • Updates upsert_last_saved_record to be more generic - we have records of when consent was last saved or served to make for a faster query when building Experiences. These records are upserted every time consent is saved or served. Modify to share between notices and individual TCF components
    • Changes to internal method around saving when notices were served as these tables are now shared with preferences. Table names and endpoints have the same name still.
  • Updates the meaning of the PrivacyPreferenceHistory.relevant_systems column to be any systems related to that preference calculated at runtime, removing the logic that it needed to be a system for which we were also propagating backend consent
  • Ensure that preferences saved against TCF components are not propagated to backend systems for now

Steps to Confirm

  • You need to be coming in from a region in the EEA like France
  • Also, tcf_enabled needs to be set to True: make a PATCH to /consent-settings and set tcf_enabled: true in the request body
  • You need a system with at least one data use that belongs to a GVL purpose or special purpose. For example, data_use: "essential.fraud_detection" maps to Special Purpose #1
  • That data use also needs to have a legal basis for processing of "Consent" or "Legitimate interests"
  • If you want a system to show up under "tcf_vendors", add a vendor_id to the system in the backend. Otherwise it will show up under "tcf_systems"

Pre-Merge Checklist

- Privacy Notices are not needed for the TCF Experience.  Instead, the content is generated at runtime by looking at what TCF data uses are on current systems.
- Add a new experience type: the TCF overlay.
- Expands the abilities to retrieve and save consent preferences with respect to "vendors", "data_uses" and "features", not just "privacy notices".
- Relaxes constraints on PrivacyPreferenceHistory, ServedNoticeHistory, CurrentPrivacyPreference, and LastServedNotice to use these tables to store when preferences were saved and served against not just notices, but vendors, data uses, and features.
…s/vendors.

Improve logic around loading tcf data uses.
… need to track consent mechanism, enforcement level, or has_gpc_flag.

- Start drying up code related to saving privacy preferences and unit testing w.r.t data use, vendor, or feature.
@cypress
Copy link

cypress bot commented Jul 18, 2023

Passing run #4242 ↗︎

0 4 0 0 Flakiness 0
⚠️ You've recorded test results over your free plan limit.
Upgrade your plan to view test results.

Details:

Merge ff1e9c9 into b9efa45...
Project: fides Commit: 2013be19ab ℹ️
Status: Passed Duration: 01:12 💡
Started: Sep 20, 2023 2:04 PM Ended: Sep 20, 2023 2:06 PM

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings.

…notices were served for various identities. Refactor methods now that we're sharing a lot of code here.
- Split TCF schemas into their own file
- Add test verifying that we can't create PrivacyPreferenceHistory records against multiple preference types.
- Rename schemas for saving/serializing that notices were served to be more generic.
- Write unit test for saving that tcf items were served.
@pattisdr pattisdr changed the title TCF Backend POC TCF Data Model and Endpoint Updates Jul 19, 2023
…with many data uses, rather than a "data use" directly, as a purpose can be associated with many data uses.

- Temporarily pin to a fideslang commit on a branch and pull in the tcf purpose mapping from there.
…thod.

- Fix bug with saving current privacy preferences with respect to a special purpose and special feature.
- Fix duplicate region in EEA_COUNTRIES
- Add test for ConsentSetting model
- Add test for PrivacyExperience.get_should_show_banner in the case where it is a TCF overlay - I return True here
- Add test for PrivacyExperience.get_related_privacy_notices for TCF overlay - exits early with an empty list - not relevant here!
- Add method tests for cache_saved_and_served_on_consent_record for special purpose, notice, and vendor
- Add docstrings to TCF schemas and move TCFExperienceContents out of the file for schemas that are returned via the API
- Add test for PrivacyPrefenceHistory.preference_type property
- Add some checks on PrivacyPreferenceHistory and CurrentPrivacyPreference records on create
- Rename PreferenceType enum and preference_type property to be more generic since they're also shared with served notices
- Docstrings for schemas
- Updated to TCF_COMPONENT_MAPPING and TCF_PREFERENCES_FIELD_MAPPING
- Add test for privacy_notice_id - that it works w/ TCF too
- Added more fields to the vendor record
- "has_notices" flag now also takes into account if TCF content exists too.
- Tried to take care of areas accessing info off of the privacy notice history
- "relevant_systems" definition has changed, and also now factors in TCF components.
- Fix bug where wrong field is returned in historical report
- Add validation on purposes and special purposes and duplicates for both saving preferences and serving TCF components
- Surface tcf version in consent report
- Fix bug related to Consent Settings scope name, copy/paste error
- Fix test that relaxes returning systems as related even if they do not have system wide enforcement
@pattisdr pattisdr marked this pull request as ready for review July 28, 2023 14:23
@pattisdr pattisdr changed the title TCF Data Model and Endpoint Updates TCF Backend: Purposes, Special Purposes, and Vendors Jul 28, 2023
…ng) work with TCF without error.

- Don't return TCF data in the privacy center unless TCF is turned on. (hopefully the FE is just looking at privacy preferences saved against notices).
@pattisdr pattisdr added the run unsafe ci checks Runs fides-related CI checks that require sensitive credentials label Sep 1, 2023
@pattisdr
Copy link
Contributor Author

pattisdr commented Sep 5, 2023

@adamsachs hoping you could review TCF backend this week! I've added vendors, features/special features, and did a sweep to see what remaining items needed to be addressed regarding code sharing with notices/experiences and the new tcf components. I'll annotate the PR with areas to focus on tomorrow 9/5

requirements.txt Outdated Show resolved Hide resolved
src/fides/api/models/privacy_experience.py Show resolved Hide resolved
src/fides/api/util/consent_util.py Show resolved Hide resolved
src/fides/api/schemas/privacy_preference.py Show resolved Hide resolved
src/fides/api/schemas/privacy_experience.py Show resolved Hide resolved
@pattisdr
Copy link
Contributor Author

pattisdr commented Sep 8, 2023

TODO:

Copy link
Contributor

@adamsachs adamsachs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pattisdr high level this is looking great! nothing stands out to me as particularly problematic.

i still haven't been able to get down to the level of detail i'd like to in a few areas, namely around the TCF overlay rendering logic. i do think that's worth a thorough review, i just didn't get the time for it today. i'll look to circle back to that on monday, but in the mean time wanted to leave you with some of the comments i had in the meantime!

Copy link
Contributor

@adamsachs adamsachs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK! i took a deeper dive into the TCF overlay population logic and it looks great 👍 really nice job taking a lot of care to get that right, there's a lot packed in there.

i just had some minor comments that may help to improve readability, though by and large this is quite readable for the complexity involved.

i'd also like to get your thoughts on the broader comment i have about a future refactor, it'd be good to align on how we see this shaping up for future iterations!

src/fides/api/util/tcf_util.py Show resolved Hide resolved
src/fides/api/util/tcf_util.py Outdated Show resolved Hide resolved
tests/ops/util/test_tcf_util.py Outdated Show resolved Hide resolved
tests/ops/util/test_tcf_util.py Show resolved Hide resolved
# Conflicts:
#	requirements.txt

Pin fideslang to TCF work branched off of 1.4.6.  Bump downrev of tcf columns.
- Removing auto-generated messaging template commits from my already-large migration.
- Revert consent settings endpoint to being public again
- Add an alias to for has_notices query param.
- Try to better clarify when saving TCF preferences that nothing is saved if preferences are an empty list.
- Fix mypy region issue
- Add code comments to automatically generated migration that adds a lot of new columns
- Get rid of _clone_top_level_record_then_add_legal_bases function
- Add assert_length_of_tcf_sections helper, and add an auto use fixture for clearing the cache
- "..ad_serving" is not a fideslang data use
# Conflicts:
#	requirements.txt
#	tests/fixtures/application_fixtures.py
- Update features to v3
- Get rid of lru_cache.
- Rearrange where we're extending legal bases
Copy link
Contributor

@adamsachs adamsachs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we're ready to go! amazing work, this is a milestone PR. really exciting to have this coming into main! 🙌

thanks for bearing with me on some of the nits 😄

@pattisdr
Copy link
Contributor Author

great thanks for your comments @adamsachs plan to merge tomorrow after 2.20 is released

@pattisdr
Copy link
Contributor Author

Getting up to date with main again, error with migration heads -

Conflicts: Changelog, migrations.
@pattisdr pattisdr merged commit e279130 into main Sep 20, 2023
46 of 50 checks passed
@pattisdr pattisdr deleted the tcf_backend_poc branch September 20, 2023 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run unsafe ci checks Runs fides-related CI checks that require sensitive credentials
Projects
None yet
3 participants