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

Switch to AES-256-GCM encryption for secrets #3356

Merged
merged 2 commits into from
May 22, 2024
Merged

Switch to AES-256-GCM encryption for secrets #3356

merged 2 commits into from
May 22, 2024

Conversation

dmjb
Copy link
Contributor

@dmjb dmjb commented May 17, 2024

[Ignore the name of the branch, this branch started out as something else originally]

Fixes #3315

This PR should not be merged until the changes in #3351 have been rolled out into production.

Use GCM encryption as the default encryption algorithm for Minder. At this
point, we now have a hard requirement to use the new EncryptedData structure in
the database - the old columns (for the access token, and for the redirect URL)
do not track the algorithm used and therefore they are not useful letting us know
which algorithm to use during decryption. As part of the migration away from the
old columns, I have made the following changes in this PR:

  1. Make the old columns nullable
  2. Stop writing to the old columns
  3. Change all unit tests which relied on the old columns

Tested locally with a mix of new and old providers.

Summary

Provide a brief overview of the changes and the issue being addressed.
Explain the rationale and any background necessary for understanding the changes.
List dependencies required by this change, if any.

Fixes #(related issue)

Change Type

Mark the type of change your PR introduces:

  • Bug fix (resolves an issue without affecting existing features)
  • Feature (adds new functionality without breaking changes)
  • Breaking change (may impact existing functionalities or require documentation updates)
  • Documentation (updates or additions to documentation)
  • Refactoring or test improvements (no bug fixes or new functionality)

Testing

Outline how the changes were tested, including steps to reproduce and any relevant configurations.
Attach screenshots if helpful.

Review Checklist:

  • Reviewed my own code for quality and clarity.
  • Added comments to complex or tricky code sections.
  • Updated any affected documentation.
  • Included tests that validate the fix or feature.
  • Checked that related changes are merged.

@dmjb dmjb requested a review from a team as a code owner May 17, 2024 09:15
Copy link
Contributor

@stacklokbot stacklokbot left a comment

Choose a reason for hiding this comment

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

✅ No Invisible Unicode Characters Detected.

@dmjb dmjb changed the title Generate random salt per key. [DO NOT MERGE] Generate random salt per key. May 17, 2024
Copy link
Contributor

@stacklokbot stacklokbot left a comment

Choose a reason for hiding this comment

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

✅ No Invisible Unicode Characters Detected.

Copy link
Contributor

@stacklokbot stacklokbot left a comment

Choose a reason for hiding this comment

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

✅ No Mixed Scripts Detected.

@dmjb dmjb marked this pull request as draft May 17, 2024 10:02
Copy link
Contributor

@stacklokbot stacklokbot left a comment

Choose a reason for hiding this comment

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

✅ No Invisible Unicode Characters Detected.

Copy link
Contributor

@stacklokbot stacklokbot left a comment

Choose a reason for hiding this comment

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

✅ No Mixed Scripts Detected.

Copy link
Contributor

@stacklokbot stacklokbot left a comment

Choose a reason for hiding this comment

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

✅ No Invisible Unicode Characters Detected.

Copy link
Contributor

@stacklokbot stacklokbot left a comment

Choose a reason for hiding this comment

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

✅ No Mixed Scripts Detected.

Copy link
Contributor

@stacklokbot stacklokbot left a comment

Choose a reason for hiding this comment

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

✅ No Invisible Unicode Characters Detected.

Copy link
Contributor

@stacklokbot stacklokbot left a comment

Choose a reason for hiding this comment

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

✅ No Mixed Scripts Detected.

Copy link
Contributor

@stacklokbot stacklokbot left a comment

Choose a reason for hiding this comment

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

✅ No Invisible Unicode Characters Detected.

Copy link
Contributor

@stacklokbot stacklokbot left a comment

Choose a reason for hiding this comment

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

✅ No Mixed Scripts Detected.

@dmjb dmjb marked this pull request as ready for review May 17, 2024 11:53
@coveralls
Copy link

coveralls commented May 17, 2024

Coverage Status

coverage: 51.915% (+0.03%) from 51.889%
when pulling 11285ae on random-salt
into beba799 on main.

@dmjb dmjb changed the title [DO NOT MERGE] Generate random salt per key. [DO NOT MERGE] Generate random salt per key, stop writing to old DB columns May 17, 2024
@dmjb dmjb marked this pull request as draft May 17, 2024 13:33
@dmjb dmjb changed the title [DO NOT MERGE] Generate random salt per key, stop writing to old DB columns [DO NOT MERGE] Stop storing secrets in old DB columns May 17, 2024
@dmjb dmjb force-pushed the random-salt branch 6 times, most recently from 26078a2 to efa7b1c Compare May 21, 2024 16:25
@dmjb dmjb changed the title [DO NOT MERGE] Stop storing secrets in old DB columns Switch to AES-256-GCM encryption for secrets May 21, 2024
@dmjb dmjb marked this pull request as ready for review May 21, 2024 16:57
Fixes #3317

Use GCM encryption as the default encryption algorithm for Minder. At this
point, we now have a hard requirement to use the new EncryptedData structure in
the database - the old columns (for the access token, and for the redirect URL)
do not track the algorithm used. As part of the migration away from the old
columns, I have made the following changes in this PR:

1. Make the old columns nullable
2. Stop writing to the old columns
3. Change all unit tests which relied on the old columns
Copy link
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

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

I tested enrolling an OAuth provider with the old code and then using it with the new code as well as enrolling with the new code.
The change in migration looks saas-safe, too (we drop NULL, but the old code would still write non-null values).

-> ACK

@dmjb dmjb merged commit e707a98 into main May 22, 2024
21 checks passed
@dmjb dmjb deleted the random-salt branch May 22, 2024 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate encrypted data in database to new encryption structure
4 participants