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

Fix load_samples to correctly collect & load sample connections with "False" secret values #5828

Merged
merged 7 commits into from
Mar 1, 2025

Conversation

NevilleS
Copy link
Contributor

@NevilleS NevilleS commented Feb 28, 2025

Description Of Changes

When FIDES__DATABASE__LOAD_SAMPLES is set, the load_samples function will run at startup to load sample resources: systems, datasets, etc. It also loads various sample connections (e.g. Postgres, Mongo, Stripe), but it does this conditionally only if the environment is configured with all the expected secrets for each connection.

This logic had a subtle footgun; if a secret value was a boolean like FIDES_DEPLOY__CONNECTORS__POSTGRES__SSH_REQUIRED=False, the code would interpret that as a missing secret and skip the sample connection! Whoops.

Code Changes

  • Fix load_sample_connections_from_project() to only ignore None or "" as missing secrets
  • Improve DEBUG logs to indicate exactly what sample connections are found, skipped, and collected

Steps to Confirm

  1. Set FIDES_DEPLOY__CONNECTORS__POSTGRES__SSH_REQUIRED=False and confirm that the Postgres sample connection is configured
  2. Remove FIDES_DEPLOY__CONNECTORS__POSTGRES__SSH_REQUIRED and confirm that the Postgres sample connection is skipped

Pre-Merge Checklist

  • Issue requirements met
  • All CI pipelines succeeded
  • CHANGELOG.md updated
    • Add a db-migration This indicates that a change includes a database migration label to the entry if your change includes a DB migration
    • Add a high-risk This issue suggests changes that have a high-probability of breaking existing code label to the entry if your change includes a high-risk change (i.e. potential for performance impact or unexpected regression) that should be flagged
  • Followup issues:
    • Followup issues created (include link)
    • No followup issues
  • Database migrations:
    • Ensure that your downrev is up to date with the latest revision on main
    • Ensure that your downgrade() migration is correct and works
      • If a downgrade migration is not possible for this change, please call this out in the PR description!
    • No migrations
  • Documentation:
    • Documentation complete, PR opened in fidesdocs
    • Documentation issue created in fidesdocs
    • If there are any new client scopes created as part of the pull request, remember to update public-facing documentation that references our scope registry
    • No documentation updates required

Verified

This commit was signed with the committer’s verified signature.
ricardobranco777 Ricardo Branco
…is "false"...
@NevilleS NevilleS added the do not merge Please don't merge yet, bad things will happen if you do label Feb 28, 2025
Copy link

vercel bot commented Feb 28, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fides-privacy-center ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 1, 2025 1:44am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
fides-plus-nightly ⬜️ Ignored (Inspect) Visit Preview Mar 1, 2025 1:44am

@NevilleS NevilleS changed the title Check to see if sample connections fail to load if a required secret is false Fix load_samples to correctly collect & load sample connections with "False" secret values Feb 28, 2025

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
Copy link
Contributor Author

@NevilleS NevilleS left a comment

Choose a reason for hiding this comment

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

Few comments!

Comment on lines -115 to -117
# Check if all secret values are present and non-empty
if all(value and value != "" for value in connection.secrets.values()): # type: ignore
valid_connections.append(connection)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the bug: when value == False intentionally, this doesn't work, because all([False, "localhost", "fides", ...]) will be false.

When a secret value isn't set in the ENV, it'll be None (or maybe ""), so this check needed to be fixed. Whoops

Comment on lines +143 to +145
log.info(
f"Collected {len(valid_connections)} sample connections with configured ENV secrets: {[connection.key for connection in valid_connections]}"
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

nb. this is the only INFO log in this function, so for regular usage you should just see a log that tells you $N connections were collected and the list of expected connection keys.

DEBUG logs explain why each connection was either included or skipped

missing_keys = [
key
for key, value in connection.secrets.items() # type: ignore
if value is None or value == ""
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the right way to check if the secret value was found 👍

@@ -460,7 +460,7 @@ class TestLoadSamples:
"FIDES_DEPLOY__CONNECTORS__POSTGRES__DBNAME": "test-var-db",
"FIDES_DEPLOY__CONNECTORS__POSTGRES__USERNAME": "test-var-user",
"FIDES_DEPLOY__CONNECTORS__POSTGRES__PASSWORD": "test-var-password",
"FIDES_DEPLOY__CONNECTORS__POSTGRES__SSH_REQUIRED": "True",
"FIDES_DEPLOY__CONNECTORS__POSTGRES__SSH_REQUIRED": "false",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Going forward, this test now reproduces the error we saw when deploying this too

@NevilleS NevilleS marked this pull request as ready for review February 28, 2025 23:06
@NevilleS NevilleS removed the do not merge Please don't merge yet, bad things will happen if you do label Feb 28, 2025
Copy link

codecov bot commented Mar 1, 2025

Codecov Report

Attention: Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 86.94%. Comparing base (3924ebe) to head (12c0ab4).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/fides/api/db/samples.py 83.33% 2 Missing ⚠️

❌ Your patch status has failed because the patch coverage (83.33%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5828   +/-   ##
=======================================
  Coverage   86.94%   86.94%           
=======================================
  Files         406      406           
  Lines       25007    25017   +10     
  Branches     2695     2695           
=======================================
+ Hits        21743    21752    +9     
- Misses       2682     2683    +1     
  Partials      582      582           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@galvana galvana self-requested a review March 1, 2025 01:44
@galvana galvana added the run unsafe ci checks Runs fides-related CI checks that require sensitive credentials label Mar 1, 2025
@galvana galvana merged commit c51cd94 into main Mar 1, 2025
37 of 38 checks passed
@galvana galvana deleted the ns-fix-sample-connections branch March 1, 2025 02:15
galvana pushed a commit that referenced this pull request Mar 1, 2025
Copy link

cypress bot commented Mar 1, 2025

fides    Run #12615

Run Properties:  status check passed Passed #12615  •  git commit c51cd94585: Fix load_samples to correctly collect & load sample connections with "False" sec...
Project fides
Branch Review main
Run status status check passed Passed #12615
Run duration 00m 48s
Commit git commit c51cd94585: Fix load_samples to correctly collect & load sample connections with "False" sec...
Committer Neville Samuell
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 5
View all changes introduced in this branch ↗︎

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
Development

Successfully merging this pull request may close these issues.

None yet

2 participants