Skip to content

flows: fix flow executor authentication with jwt - #16646

Merged
BeryJu merged 10 commits into
goauthentik:mainfrom
lemoer:pr_hotfix_flow_executor_jwt
Jun 30, 2026
Merged

BeryJu merged 10 commits into
goauthentik:mainfrom
lemoer:pr_hotfix_flow_executor_jwt

Conversation

@lemoer

@lemoer lemoer commented Sep 5, 2025 •

Copy link
Copy Markdown
Contributor

Details

As described in issue #15747, the authentication with a JWT for the flow executor was broken. This PR fixes that. Furthermore, a unit test is added that catches this error.

I am happy to receive some feedback from the authentik devs. This mostly a proof of concept to show a way how this issue COULD be solved. If another solution is preferred, we could also go for that.


Checklist

  • Local tests pass (ak test authentik/)
  • The code has been formatted (make lint-fix)

closes #15747

@lemoer
lemoer requested a review from a team as a code owner September 5, 2025 19:40
@netlify

netlify Bot commented Sep 5, 2025 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs canceled.

Name Link
🔨 Latest commit af8f4c2
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/691a468b26ecb500086408a6

@netlify

netlify Bot commented Sep 5, 2025 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit b8b2d7b
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/6a43c3af345adb0008ee953d
😎 Deploy Preview https://deploy-preview-16646--authentik-storybook.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 project configuration.

@netlify

netlify Bot commented Sep 5, 2025 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-integrations canceled.

Name Link
🔨 Latest commit af8f4c2
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/691a468b16fe31000864f509

@lemoer
lemoer force-pushed the pr_hotfix_flow_executor_jwt branch 2 times, most recently from ac784cc to 377e77c Compare September 5, 2025 19:43
@codecov

codecov Bot commented Sep 5, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.22%. Comparing base (f539c29) to head (b8b2d7b).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16646      +/-   ##
==========================================
+ Coverage   93.09%   93.22%   +0.13%     
==========================================
  Files        1038     1038              
  Lines       60744    60777      +33     
  Branches      400      400              
==========================================
+ Hits        56549    56659     +110     
+ Misses       4195     4118      -77     
Flag Coverage Δ
conformance 36.31% <11.42%> (-0.02%) ⬇️
e2e 41.50% <11.42%> (+0.59%) ⬆️
integration 32.27% <2.85%> (-0.51%) ⬇️
rust 0.00% <ø> (ø)
unit 92.29% <100.00%> (+<0.01%) ⬆️
unit-migrate 92.33% <100.00%> (+0.02%) ⬆️

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

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

@lemoer
lemoer force-pushed the pr_hotfix_flow_executor_jwt branch 3 times, most recently from 3fbd5ab to 65801b0 Compare September 5, 2025 20:06
Comment thread authentik/rbac/middleware.py Resolved
@rissson
rissson requested a review from a team September 15, 2025 11:41
@lemoer
lemoer force-pushed the pr_hotfix_flow_executor_jwt branch from 65801b0 to 788f26e Compare September 16, 2025 07:58
@lemoer

lemoer commented Sep 16, 2025 •

Copy link
Copy Markdown
Contributor Author

I rebased the branch on the current main branch.

@lemoer

lemoer commented Nov 4, 2025 •

Copy link
Copy Markdown
Contributor Author

So far, I have not noticed interest by the authentik team.

Can I have a signal from the team if it is worth to rebase this (again)?

@rissson
rissson requested a review from BeryJu November 13, 2025 01:25
@lemoer
lemoer force-pushed the pr_hotfix_flow_executor_jwt branch from 788f26e to 5e2f6b3 Compare November 16, 2025 21:37
With this commit, we move the session authentication logic from
the dispatch() method to perform_authentication() method, which
is now also overridden from the APIView parent class.

The major difference here is the order in which things are called
now.

The most important point is that the django request object is
wrapped by the django rest framework in APIView.dispatch() by
calling APIView.initialize_request(). This method returns a
wrapped version of the request (of type rest_framework.Request).
This wrapper class implicitly performs the authentication
from the authentication_classes, when request.user is accessed.

Before this commit, the original django request object
was passed to FlowPlanner._check_authentication() before
it was wrapped into a rest_framework.Request, which led
to the authentication_classes not been recognized.

The call chain was:
    FlowExecutorView.dispatch()
      FlowExecutorView._initiate_plan()
        FlowPlanner.plan()
          FlowPlanner._check_authentication()
      APIView.dispatch()
    APIView.initialize_request()

With this commit, the flow session logic is moved to
FlowExecutorView.perform_authentication() such that
the wrapped request instance is properly passed down
to FlowPlanner._check_authentication()

The new call chain is then:
    FlowExecutorView.dispatch()
      APIView.dispatch()
        APIView.initialize_request()
        APIView.initial()
          FlowExecutorView.perform_authentication()
            FlowExecutorView._initiate_plan()
              FlowPlanner.plan()
                FlowPlanner._check_authentication()

Since we can not return HttpResponses from
FlowExecutorView.perform_authentication() some exception
handlers remain in the dispatch() method. Additionally,
two new exceptions are introduced which are raised
in perform_authentication() and caught in dispatch() to
be transformed into HttpResponses.

Fixes goauthentik#15747
We can use handle_exception() instead...
@lemoer
lemoer force-pushed the pr_hotfix_flow_executor_jwt branch from 5e2f6b3 to af8f4c2 Compare November 16, 2025 21:47
@rissson rissson added this to the Release 2025.12 milestone Nov 17, 2025
@rissson rissson moved this from Todo to Needs review in authentik Core Nov 25, 2025
@soundstorm

Copy link
Copy Markdown

Seems like a long backlog 🥲

@soundstorm

Copy link
Copy Markdown

@rissson 2026.2.1 is released, this one is stuck on 2025.12.4 milestone. Will this ever get merged?

@dewi-tik dewi-tik removed this from the Release 2025.12.4 milestone Apr 2, 2026
@dewi-tik

dewi-tik commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

@BeryJu is looking into this and will feedback

@lemoer

lemoer commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

Hi again. Can we provide any help to bring this forward. :)?

BeryJu added 3 commits June 3, 2026 11:20
Signed-off-by: Jens Langhammer <[email protected]>

# Conflicts:
#	authentik/flows/tests/test_executor.py
Signed-off-by: Jens Langhammer <[email protected]>
Signed-off-by: Jens Langhammer <[email protected]>

@BeryJu BeryJu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry it took so long to get around to this, I rewrote the PR a bit to minimise the changes but kept the test the same

@github-project-automation github-project-automation Bot moved this from Needs review to In Progress in authentik Core Jun 3, 2026
Signed-off-by: Jens Langhammer <[email protected]>
@macmoritz

Copy link
Copy Markdown
Contributor

Looking forward for a merge @BeryJu.
Thanks for fixing a 1-year old bug @lemoer!

@BeryJu
BeryJu merged commit b8d547d into goauthentik:main Jun 30, 2026
105 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in authentik Core Jun 30, 2026
@lemoer

lemoer commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

I'd now suggest to revert #15252, since this is no longer true with this being merged.

@dewi-tik dewi-tik mentioned this pull request Jun 30, 2026
2 tasks done
kensternberg-authentik added a commit that referenced this pull request Jun 30, 2026
…yers' into web/css/enabling-layers

* refs/remotes/origin/web/css/enabling-layers: (23 commits)
  flows: fix flow executor authentication with jwt  (#16646)
  web: bump playwright from 1.60.0 to 1.61.0 in /web (#23542)
  core, web: update translations (#23534)
  web: bump the eslint group across 1 directory with 3 updates (#23538)
  web: bump type-fest from 5.6.0 to 5.7.0 in /web (#23544)
  lifecycle/aws: bump aws-cdk from 2.1128.0 to 2.1128.1 in /lifecycle/aws (#23535)
  core: bump deepmerge from 2.0 to 2.1.0 (#23539)
  root: fix "make gen" failing with "the input device is not a TTY" (#23546)
  core: bump library/golang from `76a2924` to `68b7145` in /lifecycle/container (#23536)
  core: bump goauthentik/fips-python from `15f00f3` to `6067443` in /lifecycle/container (#23537)
  website/integrations: fix logo missing (#23548)
  translate: Updates for project authentik and language ar_AA (#23516)
  Web/maintenance/explicit model endpoints (#22897)
  providers/oauth: Properly return error via post and for request objects (#23037)
  providers/oauth: Logout remove static html (#23002)
  core: bump dramatiq from 2.1.0 to 2.2.0 (#23381)
  website: bump semver from 7.8.4 to 7.8.5 in /website (#23299)
  web/flows: fix untranslated user field labels in identification stage (#23518)
  tasks/schedules: fix paused schedules getting unpaused on startup (#23521)
  sources/ldap: avoid re-creating connections to LDAP server (#23520)
  ...
kensternberg-authentik added a commit that referenced this pull request Jun 30, 2026
* main: (415 commits)
  Web/maintenance: Replace routine form endpoints (#23554)
  root: move server and worker healthcheck to rust (#23556)
  website/docs: api: remove note (#23555)
  web: bump @playwright/test from 1.60.0 to 1.61.0 in /web (#23545)
  providers/scim: fix enum warning when de-serializing (#23553)
  flows: fix flow executor authentication with jwt  (#16646)
  web: bump playwright from 1.60.0 to 1.61.0 in /web (#23542)
  core, web: update translations (#23534)
  web: bump the eslint group across 1 directory with 3 updates (#23538)
  web: bump type-fest from 5.6.0 to 5.7.0 in /web (#23544)
  lifecycle/aws: bump aws-cdk from 2.1128.0 to 2.1128.1 in /lifecycle/aws (#23535)
  core: bump deepmerge from 2.0 to 2.1.0 (#23539)
  root: fix "make gen" failing with "the input device is not a TTY" (#23546)
  core: bump library/golang from `76a2924` to `68b7145` in /lifecycle/container (#23536)
  core: bump goauthentik/fips-python from `15f00f3` to `6067443` in /lifecycle/container (#23537)
  website/integrations: fix logo missing (#23548)
  translate: Updates for project authentik and language ar_AA (#23516)
  Web/maintenance/explicit model endpoints (#22897)
  providers/oauth: Properly return error via post and for request objects (#23037)
  providers/oauth: Logout remove static html (#23002)
  ...
kensternberg-authentik added a commit that referenced this pull request Jun 30, 2026
* main: (487 commits)
  Web/maintenance: Replace routine form endpoints (#23554)
  root: move server and worker healthcheck to rust (#23556)
  website/docs: api: remove note (#23555)
  web: bump @playwright/test from 1.60.0 to 1.61.0 in /web (#23545)
  providers/scim: fix enum warning when de-serializing (#23553)
  flows: fix flow executor authentication with jwt  (#16646)
  web: bump playwright from 1.60.0 to 1.61.0 in /web (#23542)
  core, web: update translations (#23534)
  web: bump the eslint group across 1 directory with 3 updates (#23538)
  web: bump type-fest from 5.6.0 to 5.7.0 in /web (#23544)
  lifecycle/aws: bump aws-cdk from 2.1128.0 to 2.1128.1 in /lifecycle/aws (#23535)
  core: bump deepmerge from 2.0 to 2.1.0 (#23539)
  root: fix "make gen" failing with "the input device is not a TTY" (#23546)
  core: bump library/golang from `76a2924` to `68b7145` in /lifecycle/container (#23536)
  core: bump goauthentik/fips-python from `15f00f3` to `6067443` in /lifecycle/container (#23537)
  website/integrations: fix logo missing (#23548)
  translate: Updates for project authentik and language ar_AA (#23516)
  Web/maintenance/explicit model endpoints (#22897)
  providers/oauth: Properly return error via post and for request objects (#23037)
  providers/oauth: Logout remove static html (#23002)
  ...
kensternberg-authentik added a commit that referenced this pull request Jun 30, 2026
* main:
  Web/maintenance: Replace routine form endpoints (#23554)
  root: move server and worker healthcheck to rust (#23556)
  website/docs: api: remove note (#23555)
  web: bump @playwright/test from 1.60.0 to 1.61.0 in /web (#23545)
  providers/scim: fix enum warning when de-serializing (#23553)
  flows: fix flow executor authentication with jwt  (#16646)
  web: bump playwright from 1.60.0 to 1.61.0 in /web (#23542)
  core, web: update translations (#23534)
  web: bump the eslint group across 1 directory with 3 updates (#23538)
  web: bump type-fest from 5.6.0 to 5.7.0 in /web (#23544)
  lifecycle/aws: bump aws-cdk from 2.1128.0 to 2.1128.1 in /lifecycle/aws (#23535)
  core: bump deepmerge from 2.0 to 2.1.0 (#23539)
  root: fix "make gen" failing with "the input device is not a TTY" (#23546)
  core: bump library/golang from `76a2924` to `68b7145` in /lifecycle/container (#23536)
  core: bump goauthentik/fips-python from `15f00f3` to `6067443` in /lifecycle/container (#23537)
  website/integrations: fix logo missing (#23548)
  translate: Updates for project authentik and language ar_AA (#23516)
  Web/maintenance/explicit model endpoints (#22897)
  providers/oauth: Properly return error via post and for request objects (#23037)
  providers/oauth: Logout remove static html (#23002)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Using flow executor with JWT is broken

6 participants