Skip to content

Non backwards compatible upgrade with token_checksum. #1495

@matejsp

Description

@matejsp

Describe the bug
We have couple of servers in load balanced style running in 24/7 doing rolling upgrades almost every day without affecting the running application. Like any modern system. With upgrading to latest django-oauth-toolkit this is impossible.

There was upgrade to add token_checksum but it's value is required for working correctly.

When doing rolling upgrades you first update database with hashes generate.
But because old instances are still running you are getting null values inserted.
When you upgrade first instance it only accepts migrated access tokens and starts rejecting ones
created after migration but before first instance upgrade with null values.

To Reproduce
Have running django app with old django oauth toolkit version. Do migration.
Generate new token with old version. Upgrade to latest version. Try using a token.

Problematic PR:
https://github.com/jazzband/django-oauth-toolkit/pull/1447/files

Expected behavior
I would expect modern library to cautious of upgrade plan and be backwards compatible in line with modern systems architecture and practices. For pet projects it's fine because you can take the whole application offline. Lot of production apps nowadays need to run 24/7 with planned downtime months in advance.

Options:

  1. fallback _load_access_token to query both hash and token value.
    select * from access_token where token_checksum='hash' or (token_checksum is None and token = 'token_val')
    or two selects so we don't feed jwt token to DB via wire if not necesery.
  2. configuration to switch from old select via token to new checksum style
  3. trigger on database to calc
    CREATE TRIGGER oauth2_provider_accesstoken_checksum BEFORE INSERT ON oauth2_provider_accesstoken FOR EACH ROW SET NEW.token_checksum = SHA2(NEW.token, 256);

Version
2.3.0 -> 3.0.1

  • I have tested with the latest published release and it's still a problem.
  • I have tested with the master branch and it's still a problem.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions