Skip to content

crypto: fix type in managed JWT Cert reconciliation - #8887

Closed
jejbq wants to merge 1 commit into
goauthentik:mainfrom
jejbq:main
Closed

jejbq wants to merge 1 commit into
goauthentik:mainfrom
jejbq:main

Conversation

@jejbq

@jejbq jejbq commented Mar 12, 2024 •

Copy link
Copy Markdown

Hello,

While trying to fix the deprecated not_valid_before and not_valid_after in Python 3.12, you introduced a typo in authentik/crypto/apps.py with two not_valid_after_utc instead of a range with not_valid_before_utc and not_valid_after_utc.

I guess this regressed the validity of the JWT token and let it expire.
You should probably add a unit test to check not_valid_before as well.

This PR will close #8834

As check and workaround, I used ghcr.io/goauthentik/server:2024.2 docker image and
force replaced /authentik/crypto/apps.py using a volume in my docker stack.

  authentik-server:
    image: ghcr.io/goauthentik/server:2024.2
    command: server
    volumes:     
      - /tmp/apps.py:/authentik/crypto/apps.py:ro
    ...
    
  authentik-worker:
    image: ghcr.io/goauthentik/server:2024.2
    command: worker
    volumes:
      - /tmp/apps.py:/authentik/crypto/apps.py:ro        

N.B. I've also modified authentik/crypto/tests.py to align the "now" variable with the way it's defined in apps.py and rollback the change to use now from django.utils.timezone. I think the two should be unified.

Thank you in advance for considering and resolving this issue.

Related to issue #8834 and pull #8435

@jejbq
jejbq requested a review from a team as a code owner March 12, 2024 10:58
@netlify

netlify Bot commented Mar 12, 2024 •

Copy link
Copy Markdown

❌ Deploy Preview for authentik-storybook failed.

Name Link
🔨 Latest commit eebadd5
🔍 Latest deploy log https://app.netlify.com/sites/authentik-storybook/deploys/65f0355d2ac9e60008942ff2

@netlify

netlify Bot commented Mar 12, 2024 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit eebadd5
🔍 Latest deploy log https://app.netlify.com/sites/authentik-docs/deploys/65f0355d8a5dac0008c5a61c
😎 Deploy Preview https://deploy-preview-8887--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@jejbq
jejbq marked this pull request as draft March 12, 2024 17:33
@jejbq

jejbq commented Mar 12, 2024

Copy link
Copy Markdown
Author

Sorry.

Look like this PR isn't enough to close #8834
JWT Token expires and is not renewed unless we implement eclipse-che/che#22765
I still don't understand what changes between Authentik and 2023.10.7 to 2024.2.2 created this problem.

@BeryJu BeryJu changed the title Fixed a typo in authentik/crypto/apps.py that caused a regression in certificate validity checking crypto: fix type in managed JWT Cert reconciliation Mar 12, 2024
@BeryJu

BeryJu commented Mar 12, 2024 •

Copy link
Copy Markdown
Member

thanks for the PR!

I don't think this will fix the linked issue, as certificate the code validates is not selectable for OAuth providers, and is actually not used at all currently

oh whoops missed your comment above

@codecov

codecov Bot commented Mar 12, 2024 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.07%. Comparing base (cef1d2d) to head (eebadd5).
⚠️ Report is 6237 commits behind head on main.

Files with missing lines Patch % Lines
authentik/crypto/tests.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8887      +/-   ##
==========================================
+ Coverage   46.62%   52.07%   +5.45%     
==========================================
  Files         626      635       +9     
  Lines       30996    31372     +376     
==========================================
+ Hits        14451    16337    +1886     
+ Misses      16545    15035    -1510     
Flag Coverage Δ
e2e 50.53% <0.00%> (+5.82%) ⬆️
integration 26.09% <0.00%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@jejbq

jejbq commented Apr 8, 2024 •

Copy link
Copy Markdown
Author

Is it possible that this JWT expiration problem is related to offline_access (default for new OAuth2 but not for old ones)?

Starting with authentik 2024.2, applications only receive an access token. To receive a refresh token, both applications and authentik must be configured to request the offline_access scope. In authentik this can be done by selecting the offline_access Scope mapping in the provider settings.

refresh_token:
Refresh tokens can be used as long-lived tokens to access user data, and further renew the refresh token down the road.

Starting with authentik 2024.2, this grant requires the offline_access scope.

https://docs.goauthentik.io/docs/providers/oauth2/

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.

JWT expired in Eclipse Che after upgrading from 2023.10.7 to 2024.2.2

2 participants