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

Add in support for rotating the salt but allow older records to still be read #1

Merged
merged 2 commits into from
Dec 9, 2021
Merged

Conversation

StevenMapes
Copy link
Contributor

This commit adds in support for the SALT to be rotated by defining a list of salts within settings.py where the newer salts are added to the start.

The first key will be used to encrypt all new data, and decryption of existing values will be attempted with all given keys in order. This is useful for key rotation: place a new key at the head of the list for use with all new or changed data, but existing values encrypted with old keys will still be accessible

This is based of django-fernet-fields which is a dead package but has some useful features such as this to allow the salt to be rotated in the future for a stronger salt.

To make it work SALT_KEY should be defined as a list. If you defining it as a string then it's converted into a list within the code so it's backward compatible. Below is an example of when a new salt is added but the previous salt is kept at the end of the list so that the old records will be read.

SALT_KEY = [
    'my-newer-salt',
    'the-original-salt'
]

I've added in a new testcase with a test that creates a record with one salt, then switches salts, and fetches the old value as well as saving a new one and making sure the saved values are different

This commit adds in support for the SALT to be rotated by defining a list of salts within settings.py where the newer salts are added to the start.  

The first key will be used to encrypt all new data, and decryption of existing values will be attempted with all given keys in order. This is useful for key rotation: place a new key at the head of the list for use with all new or changed data, but existing values encrypted with old keys will still be accessible

This is based of django-fernet-fields which is a dead package but has some useful features such as this to allow the salt to be rotated in the future for a stronger salt.

```
SALT_KEY = [
    'my-newer-salt',
    'the-original-salt'
]
```
@frgmt
Copy link
Collaborator

frgmt commented Dec 9, 2021

@StevenMapes Thank you for your nice approach!

@frgmt frgmt merged commit 3c9a6b9 into jazzband:main Dec 9, 2021
frgmt pushed a commit that referenced this pull request Dec 19, 2021
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.

None yet

2 participants