Skip to content

1459 login problems intermittent#1489

Merged
jchate6 merged 43 commits into
version-3-0-alphafrom
1459-login-problems-intermittent
Jun 8, 2026
Merged

1459 login problems intermittent#1489
jchate6 merged 43 commits into
version-3-0-alphafrom
1459-login-problems-intermittent

Conversation

@phycodurus

@phycodurus phycodurus commented Mar 30, 2026

Copy link
Copy Markdown
Member

We now derive the encryption cipher from the settings.SECRET_KEY. The EncryptableModelMixin class is no longer necessary because the encryption is not user-specific. Updated docs explain it all.

closes #1459

TOMTOOKIT_FIELD_ENCRYPTION_KEY is used as the master encryption
key to encrypt/decrypt each User's encrypted_data_encryption_key,
which is saved in the Profile model.
This is the user-specific, envelope-encrypted (by the master cipher),
Data Encryption Field (DEK). It is created with the user's Profile and
encrypted with the master cipher (created with the master
TOMTOOLKIT_FIELD_ENCRYPTION_KEY). If that master key changes, then
each user's Profile.encrypted_dek must be re-encrypted, but that
user's encrypted-data itself doesn't have to change.
the (way better) envelope encryption scheme doesn't save
anything to the session
(I gather that) the term of art in envelope encryption is to
wrap(encrypt) and unwrap(decrypt) the secret encryption keys
(with the TOMTOOLKIT_FIELD_ENCRYPTION_KEY-created cipher in
our case). This commit removes that conceptual jargon in favor
of what's literally going on: encrypting and decrypting.
@phycodurus phycodurus linked an issue Mar 30, 2026 that may be closed by this pull request
@jchate6 jchate6 moved this to Needs Review in TOM Toolkit Apr 1, 2026
Shorten the comment and add a note explaining that BinaryField is
excluded by Django's model_to_dict(), which is why encrypted_dek
intentionally does not appear on the user Profile card.
This warning isn't needed with the new ecryption scheme.
Add a check in TomCommonConfig.ready() that raises
ImproperlyConfigured if the encryption key is missing. This prevents
the TOM from starting in a half-configured state where logins would
crash when the signal tries to generate a DEK.

The error message includes step-by-step instructions for generating
and configuring the key.
Naming Rationale:
The new name is more descriptive because in the "envelope encryption"
scheme, the TOMTOOLKIT_DEK_ENCRYPTION_KEY is the encryption key that
encrypts and decrypts the user's DEK (data encryption key). So it's
the user-DEK encryptiion key for TOM Toolkit.
@phycodurus phycodurus requested review from Fingel and jchate6 April 1, 2026 20:31
@phycodurus phycodurus marked this pull request as ready for review April 1, 2026 21:10
phycodurus and others added 4 commits April 1, 2026 15:31
There were some straggling references to the "field"
encryption key that are now changed to "DEK" encryption
key (including the name of the key rotation management
command).

@jchate6 jchate6 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's talk about this before we publish it.

Comment thread tom_common/apps.py Outdated
Comment thread docs/customization/encrypted_model_fields.rst
Comment thread tom_common/management/commands/rotate_dek_encryption_key.py Outdated
Comment thread tom_common/management/commands/rotate_dek_encryption_key.py Outdated
Comment thread tom_common/session_utils.py Outdated
@jchate6 jchate6 changed the base branch from dev to version-3-0-alpha April 22, 2026 17:27
@jchate6

jchate6 commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Preferred changes:

  • Simplify key generation process to have a single management command that creates the key, and instructs the user to add it to their environment.
  • Create documentation for the encryption process with resources on how to add keys to environment for different deploys
  • link to docs in error messages rather than contain docs
  • Have default key added to default settings that can and should be overwritten in settings.py (allow users with no encryption to use their toms)
    • Add warning to profile page UI or logs when default key is being used so people are aware of what they need to do. (Link to docs)

@jchate6

jchate6 commented May 14, 2026

Copy link
Copy Markdown
Contributor

We should add some docs about the new password partial @Fingel just merged along with the changes here.

There is now one single DEK for all the encrypted fields and
it is derived from the Django `settings.SECRET_KEY`. All changes
in this commit simplify the encryption scheme implementation
accordingly.

@jchate6 jchate6 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd like to more reliably understand how to implement this.
See TOMToolkit/tom_demoapp#28

Comment thread docs/deployment/deployment_tips.rst Outdated
Comment thread docs/deployment/encryption.rst Outdated
Comment thread docs/customization/encrypted_model_fields.rst Outdated
@phycodurus phycodurus requested a review from jchate6 May 29, 2026 22:25
phycodurus and others added 11 commits June 4, 2026 15:29
You can't just clear out the value and submit because
a cleared-out FormField is interpreted as "leave the
value un-altered". So, the checkbox does this instead.
This add flags that indicate the state of the
Form field and the clear-the-field checkbox, which
can't be passed through normally because of how we
interpret empty fields (i.e. empty means leave unaltered).
jchate6
jchate6 previously requested changes Jun 8, 2026
Comment thread tom_setup/templates/tom_setup/settings.tmpl Outdated
@jchate6 jchate6 dismissed their stale review June 8, 2026 21:24

resolved

@jchate6 jchate6 merged commit 1ee60fd into version-3-0-alpha Jun 8, 2026
22 of 23 checks passed
@github-project-automation github-project-automation Bot moved this from Needs Review to Merged (to dev) in TOM Toolkit Jun 8, 2026
@jchate6 jchate6 deleted the 1459-login-problems-intermittent branch June 8, 2026 21:28
@jchate6 jchate6 moved this from Merged (to dev) to Released in TOM Toolkit Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Released

Development

Successfully merging this pull request may close these issues.

TOMToolkit Login problems (intermittent)

4 participants