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

Logging out from authentik should invalidate sessions of proxied applications #2023

Open
rperpe opened this issue Dec 27, 2021 · 59 comments · Fixed by #4605
Open

Logging out from authentik should invalidate sessions of proxied applications #2023

rperpe opened this issue Dec 27, 2021 · 59 comments · Fixed by #4605
Labels
enhancement/confirmed Enhancements that will be implemented in the future enhancement New feature or request

Comments

@rperpe
Copy link

rperpe commented Dec 27, 2021

Is your feature request related to a problem? Please describe.
If users logout from authentik they expect that they're logged out from proxied applications (using embedded outpost and integrated proxy provider) too - without GETting /akprox/sign_out on every single application. It's a security risk if users don't consider this.

Describe the solution you'd like
As soon as https://authentik.tld/flows/-/default/invalidation/ is called, all sessions on proxied applications must be invalidated immediately (probably via OIDC back-channel logout?).
Same is expected if forward auth proxy provider is used (assuming there exists the same issue).

Describe alternatives you've considered
Are there any alternatives/workarounds (instructing users to manually logout from every single application isn't considered as a workaround)?

Additional context
N/A

PS: Many thanks to @BeryJu for his hard work and sharing authentik on GitHub!

@xpufx
Copy link
Contributor

xpufx commented Jan 16, 2022

I do agree that it's a security issue when the user logs out of one app and calls it a day not realizing all it would take to log back in is to go to the login page again. Same for other apps they haven't even considered the fate of.

However it would also confuse a lot of users when they log out of their webmail account and now their kanban software is logged out too.

The other thing is, the applications need to play along with this as well. Not all apps allow you to change what happens when you hit that log out button. Authentik needs to know when it happens for it to be able to do something, no?

This doesn't look like as straight forward as it might seem at first. If it were to be implemented somehow, I'd like the behavior to be configurable.

@BeryJu
Copy link
Member

BeryJu commented Jan 17, 2022

I agree that this should at least be configurable, if not default. There are two reasons why it isnt currently possible:

  • authentik doesnt support OAuth Backchannel Logout, which is how authentik would tell an outpost that a user logged out.

This isn't the case because relatively few applications and libraries support it, so I haven't gotten around to implementing it

  • The authentik Outpost can't remove sessions in the background

Because the way sessions work with gorilla/sessions, the outpost can only delete a session in the context of an HTTP request, and can only delete the session of that specific HTTP request. I briefly looked for an alternative library but didnt find anything with the required features (ability to remove sessions without HTTP request, Redis and FS Storage)

@BeryJu BeryJu added the enhancement/confirmed Enhancements that will be implemented in the future label Jan 17, 2022
@PrivatePuffin
Copy link

PrivatePuffin commented Sep 30, 2022

I see some confusion about SLO (Single Log Out)
Lets seperate a few things:

  1. Proxied applications and apps using forwardAuth with multiple authentik applications defined
  2. SAML/OIDC
  3. LDAP

  1. It should be possible to invalidate other authentik applications, when one of them is logged out. forwardAuth definately supports this.

  2. When a logout request from a SAML/OIDC application hits, we can also logout applications using proxied/forwardAuth applications. However, indeed not all SAML/OIDC applications support backchannel logout and SLO (or rather: most do not)

  3. LDAP does not support SLO afaik, as it just says "YAY or NAY" and sends some userdetails, so case closed (basically)

It should be relatively easy to do SLO for applications using proxied/forwardAuth, by allowing administrators to set "logout groups" for Apps that need to be logged-out together.

For SAML/OIDC this gets weird, some users might want to logout a proxygroup together with a SAML/OIDC logout, but some might not realise other SAML/OIDC sessions are not logged-out at the same time. But I think the option to also logout a group of proxied/forwardAuth applications cán technically be offered.

@QuarkZ26
Copy link

So, am I to understand that logging out of Authentik doesn't really do anything? when I log out and go back to the app, I'm still not prompted.
It seems like a major issue to me, what if I log into some public machine? Even restarting the browser doesn't do anything.

@oomenit
Copy link

oomenit commented Dec 31, 2022

I just noticed this as well. This is quite a security concern. All my forwardAuth'ed apps are staying logged in, even though I'm explicitly logging out through Authentik.

I was under the impression that every request made to subdomain.domain.tld would check authentication against Authentik?

I'm coming from Authelia, and with the same forwardAuth-style authentication, Authelia does redirect me to the login page on all forwardAuth'ed apps as soon as I'm logged out of Authelia itself.

Or should I need to play around with the token validity?

@slimshizn
Copy link

slimshizn commented Dec 31, 2022 via email

@QuarkZ26
Copy link

I just noticed this as well. This is quite a security concern. All my forwardAuth'ed apps are staying logged in, even though I'm explicitly logging out through Authentik.

I was under the impression that every request made to subdomain.domain.tld would check authentication against Authentik?

I'm coming from Authelia, and with the same forwardAuth-style authentication, Authelia does redirect me to the login page on all forwardAuth'ed apps as soon as I'm logged out of Authelia itself.

Or should I need to play around with the token validity?

I went back to Authelia, personally. Given the last response that was given here almost a year ago. It seems crazy to me to leave something like this without any resolution. This plus other issues made me move back.

@PrivatePuffin
Copy link

I just noticed this as well. This is quite a security concern. All my forwardAuth'ed apps are staying logged in, even though I'm explicitly logging out through Authentik.
I was under the impression that every request made to subdomain.domain.tld would check authentication against Authentik?
I'm coming from Authelia, and with the same forwardAuth-style authentication, Authelia does redirect me to the login page on all forwardAuth'ed apps as soon as I'm logged out of Authelia itself.
Or should I need to play around with the token validity?

I went back to Authelia, personally. Given the last response that was given here almost a year ago. It seems crazy to me to leave something like this without any resolution. This plus other issues made me move back.

Same here, Authelia is a slow-simply-and-steady development. But it at least does, what it does, well and trustworthy.

@mrjk
Copy link

mrjk commented Jan 11, 2023

Just here as well to bump this issue, it's pretty annoying problem and a quite big security issue from my point of view. Maybe this behavior should be manageable with a switch ?

But for now, this is really annoying.

@mrjk
Copy link

mrjk commented Jan 13, 2023

I found an ugly workaround. The idea is a simple HTML page that will delete all cookies of the domain, you just need to host that page under the domain you manage, ie: https://logout.company.com/logout.html?d=company.com. For the POC, it ask you before actually logoff, I guess this page could be fully parametrized, but just here to validate poc workaround.

<!DOCTYPE html>
<html>
<head>
  <title>AK Logout</title>
</head>
<body>

<script>

  var query = window.location.search.substring(1);
  var url = new URLSearchParams(query);
  var domain = url.get("d");
  var logout_url = "https://accounts." + domain + "/flows/-/default/invalidation/";

  // Delete all cookies
  function clean_cookies(domain) {
    var cookies = document.cookie.split(";");
    for (var i = 0; i < cookies.length; i++) {
      var cookie = cookies[i];
      var eqPos = cookie.indexOf("=");
      var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
      var result = name + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; domain=" + domain;
      console.log(result);
      document.cookie = result;
    }

  }

  // Confirm user
  if (confirm('You will be disconected of all "' + domain + '" applications.')) {
      clean_cookies(domain)
      window.location.href = logout_url;
  } else {
    console.log('User aborted logout.');
  }

</script>

<p><a href="javascript:window.location.href=window.location.href">Refresh this page</a></p>
</body>
</html>

As you guessed, I'm not a frontend dev :')

@github-cli
Copy link

That would "only" delete the cookies, the actual token would still be valid, meaning if someone had that, they could still access the site for as long as the token is valid :-(

I am not so sure people are even aware of this!
I have been using authentik for a year now and was unaware of it until yesterday.
Even manually "logging out" via https://authentik.fqdn.com/application/o//end-session that you place on your website does not actually log you out (you get a confirmation screen but even if you also log out of authentik itself, the session stays valid). The flow to "invalidate" a session actually does not invalidate the sessions...
It does give the impression that it should work and you should be logged out but as Berry mentioned, this "feature" (being able to log out, aka invalidating sessions) will not be implemented as its currently not possible to do so with the architecture of the outposts.

I am still a bit baffled as this would be a basic mandatory "feature" I would just assume to work.

Does anyone have any actual workarounds to this?

@PrivatePuffin
Copy link

as its currently not possible to do so with the architecture of the outposts.

This is basically the big problem why I cannot use Authentic for any significant professional usecase.

@github-cli
Copy link

^^ jumping in circles ^^
yeehaw! seems maybe this will be added
such a relief!!

@slimshizn
Copy link

@BeryJu was the recent fix supposed to log out proxied applications? E.g Say I use authentik proxy provider in front of a website with no auth. If I add a user, the user has access to said website.

If I remove the user, delete their session, remove the explicit consent, the user then should not have access to said website. I'm still seeing the same behavior as before, where the user is still able to access the website, even after removed, or logged out.

@wrt54gl
Copy link

wrt54gl commented Mar 18, 2023

@BeryJu was the recent fix supposed to log out proxied applications? E.g Say I use authentik proxy provider in front of a website with no auth. If I add a user, the user has access to said website.

If I remove the user, delete their session, remove the explicit consent, the user then should not have access to said website. I'm still seeing the same behavior as before, where the user is still able to access the website, even after removed, or logged out.

I am having this problem as well.

@Liquidtouch
Copy link

Same here. If I log out of Authentik it appears that I have logged out but If I navigate to "app.domain.com" afterwards which is using Authentik for authentication I still have access to the site. This seems like it would be a massive security issue.

@hacustom
Copy link

hacustom commented Apr 6, 2023

Seeing the same behavior on my instance. Got things setup behind Nginx, loving the ease of setup and how well it works. I tested out multiple methods of invalidating the user/session/token - deleting the user, changing token longevity, logging out of Authentik but was always still authenticating.

@HipyCas
Copy link

HipyCas commented Apr 15, 2023

I see that this seems fixed with PR #4605, and the only thing I could find about this in the documentation is this (in the User login stage:

Terminate other sessions

When enabled, previous sessions of the user logging in will be revoked. This has no affect on OAuth refresh tokens.

Yet when modifying the user login stage, there is no option for updating this setting. How can I configure this?

@oblivioncth
Copy link

Some clarification on the current state of affairs with this, and how in practice to ensure access to a page is revoked once a user has been logged out would be appreciated. The issue has been closed due to the aforementioned PR, but it doesn't seem like it's currently possible to directly take advantage of the changes given that the initially reported behavior appears to remain.

I've confirmed in my own setup that logging out does not invalidate access to domains behind forward auth (per-application).

@franciscomfcmaia
Copy link

Not working, currently using 2023.4.1.

I assume that #4605 should fix this? I see this is still an issue. Someone correct me if I'm wrong.

Apart from setting sessions to 1 hour does anyone else have any solutions?

@stignarnia
Copy link

Still not working in 2023.5.0

@github-cli
Copy link

Works for me ever since this PR was implemented. My setup is just the integrated outpost on docker with forward auth from nginx. If I go to authentik and manually log out, new connections will not be authenticated anymore.
I have not tested a logout url specific to the application, I only tested a complete logout from authentik.

if you have a more advanced setup, maybe post some details of your setup and also the exact details/files used for forward auth as improper config could have an impact here as well. Steps to reproduce the issue

@technodrome
Copy link

A SSO system which does not log you out globally, having a high-priority bug open for two years without anyone clearly stating when the fix will land? Sure, I'll use it...

@skiwheelr
Copy link

I wish there was a solution for this. All i can do during testing is use incognito windows.
Is there something in the authentik script section to use or can i put some html to invalidate cache when /logout uri is hit?

@chris13524
Copy link

chris13524 commented Oct 7, 2023

JWT is the fundamentally wrong approach to user auth it seems: https://evertpot.com/jwt-is-a-bad-default/

@HilkopterBob
Copy link

We want to implement authentik in our Enterprie-Environment, but without global, centralized logouts, this simply isnt possible.

@BeryJu
Copy link
Member

BeryJu commented Oct 18, 2023

Most of the comments in this thread are not helpful, especially since competing solutions like keycloak + oauth2_proxy behave the same way. Regardless, the PR linked above (#7099) will improve this behaviour with the next release.

Aside from that we want to do some changes to the OAuth2 client in the outpost to further improve this, but there are also some challenges there that need solving (for example supporting multiple outpost instances while being able to lock sessions to prevent OAuth tokens from refreshing multiple times, for which oauth2_proxy uses redis, but I'd like to avoid adding as a dependency to the outpost)

@HilkopterBob
Copy link

We temporarily resolved the issue with a logout button that manually triggers the "outpost-logout" call. Centralized user logouts are still a highly desired feature, but we already have a test deployment of our web app that enforces user redirection centrally.

To the Authentik team,

I wanted to express my gratitude for your open ears, assistance, and code work. Your support has been invaluable, and I truly appreciate your efforts. Thank you for your help!

Warm regards,
Nick

@paulcsiki
Copy link

I can confirm that the outpost logout url work as expected however it would be nice if said url would have been visible somewhere in the Authentik Admin UI.

@stignarnia
Copy link

Where is this new button / URL? I think I didn't find it because the normal logout button still only logs out from the Authentik UI and not proxied services, at least in my testing but maybe I did something wrong

@whg517
Copy link

whg517 commented Nov 30, 2023

I am looking for a unified way to log out of sessions based on the oidc approach. When I initiate logout on the front end, I still need to choose whether to log out of the authentik account in authentik.

@katzecz
Copy link

katzecz commented Dec 18, 2023

Version 2023.10 added this feature to auto terminate all sessions when logging out via user interface logout button, but since 2023.10.3 it´s not working anymore. However, outpost logout URL does. Or am I just missing something?

@technodrome
Copy link

"Most of the comments in this thread are not helpful, especially since competing solutions like keycloak + oauth2_proxy behave the same way."

Looks like their communication and solution is not helpful, either.

@ksaadDE
Copy link

ksaadDE commented May 15, 2024

"Most of the comments in this thread are not helpful, especially since competing solutions like keycloak + oauth2_proxy behave the same way."

Keycloak terminates the session when you use the ODIC logout url, even from all Apps. So I am not sure if you are referring to a technical detail or you mean logging out from all apps (or individual Apps) in general.

Proxy provider logout improvements (2023.2)
In previous versions, logging out of a single proxied application would only invalidate that application's session. Starting with this release, when logging out of a proxied application (via the /outpost.goauthentik.io/sign_out URL), all the users session within the outpost are terminated. Sessions in other outposts and with other protocols are unaffected.
Additionally, different providers now have different cookies, instead of all using the same "authentik_proxy" token.
https://docs.goauthentik.io/docs/releases/2023.2

Is this fixed, is it not? 🤔

@ksaadDE
Copy link

ksaadDE commented May 15, 2024

Opened a discussion on this #9737

@LokeYourC3PH
Copy link

Up until finding this post, I thought I had misconfigured something, but seems like I didn't. I also would like to solve this problem, especially with NextCloud where if user1 logs in, then goes to NextCloud, calls it a day and closes the NextCloud tab but logs out of Authentik, then user2 logs in on Authentik and also clicks on NextCloud, he apparently gets logged into user1's NextCloud account. Has anyone found a fix for this yet?

@rouke-broersma
Copy link

Up until finding this post, I thought I had misconfigured something, but seems like I didn't. I also would like to solve this problem, especially with NextCloud where if user1 logs in, then goes to NextCloud, calls it a day and closes the NextCloud tab but logs out of Authentik, then user2 logs in on Authentik and also clicks on NextCloud, he apparently gets logged into user1's NextCloud account. Has anyone found a fix for this yet?

That... Sounds like a significant bug in nextcloud.. That has nothing to do with this..

@LokeYourC3PH
Copy link

LokeYourC3PH commented Sep 9, 2024

Up until finding this post, I thought I had misconfigured something, but seems like I didn't. I also would like to solve this problem, especially with NextCloud where if user1 logs in, then goes to NextCloud, calls it a day and closes the NextCloud tab but logs out of Authentik, then user2 logs in on Authentik and also clicks on NextCloud, he apparently gets logged into user1's NextCloud account. Has anyone found a fix for this yet?

That... Sounds like a significant bug in nextcloud.. That has nothing to do with this..

It stems from the same issue that if you do not explicitly click the "Logout" button in NextCloud to return to Authentik, then Authentik does not log out of the account via Backchannel or even just by sending the SLO when clicking the Logout button in Authentik.

EDIT: I have tried this with Kimai, which uses SAML instead of OpenID/OIDC/OAuth2, and as soon as I click the Kimai link in the Dashboard, it goes through the Authorization flow again, thereby ensuring the correct account gets logged in. With NextCloud using OIDC however, it does not go through the Authorization flow again unless the account was previously explicitly logged out. As such, it should be possible to fix this by calling the Logout URL manually before the Authorization flow, thereby invalidating previous logins. No?

@Ma27
Copy link

Ma27 commented Sep 9, 2024

That... Sounds like a significant bug in nextcloud

How is Nextcloud supposed to know that you logged out of Authentik without being told to do so (which is basically this feature request)?

@LokeYourC3PH
Copy link

LokeYourC3PH commented Sep 9, 2024

That... Sounds like a significant bug in nextcloud

How is Nextcloud supposed to know that you logged out of Authentik without being told to do so (which is basically this feature request)?

Exactly, thank you. A workaround I considered was running a dedicated invalidation flow running right before the upcoming authorization flow, but I am too much of a noob with Authentik yet to set that up properly. If anyone could advise, I'd much appreciate it 🙏

PS: If you read my update to the answer above, you'll see that it does work with SAML. The problem is that NextCloud's SAML app is an absolute catastrophe and I will never touch it again because it breaks all the time, OIDC works almost perfect except for the problem that I am facing with the logout of the old session.

@rouke-broersma
Copy link

That... Sounds like a significant bug in nextcloud

How is Nextcloud supposed to know that you logged out of Authentik without being told to do so (which is basically this feature request)?

then user2 logs in on Authentik and also clicks on NextCloud, he apparently gets logged into user1's NextCloud account.

Unless they are talking about a shared device for some reason, logging in to another users account on nextcloud has nothing to do with authentik.

@LokeYourC3PH
Copy link

That... Sounds like a significant bug in nextcloud

How is Nextcloud supposed to know that you logged out of Authentik without being told to do so (which is basically this feature request)?

then user2 logs in on Authentik and also clicks on NextCloud, he apparently gets logged into user1's NextCloud account.

Unless they are talking about a shared device for some reason, logging in to another users account on nextcloud has nothing to do with authentik.

Absolutely correct, it's a shared device. In my test cases where I use my personal account, and then a test account, this does occur. If I only were to ever use my own account on my own device it wouldn't be a problem, but this is for a shared device as you astutely observed. As far as I'm concerned, the entire usecase for this feature would mostly be for that exact reason, but keep in mind that this occurs with any OIDC/OAuth2 app, not just NextCloud, and so since some other companies also use OIDC/OAuth2 for shared devices, this has to be taken care of somehow. Once again, the best way I can imagine to workaround this right now is by making a flow which invalidates currently logged in sessions, the problem is that I have no idea how I would go about doing that.

@rouke-broersma
Copy link

I don't think you can solve this with a flow in authentik because the authentik session is actually already invalidated correctly. The issue is that authentik does not notify the oidc relying party so the for example nextcloud session is not invalidated as well. For a shared device perhaps it would be simplest to just configure the device to wipe session data upon closing the browser until authentik supports back channel logout.

@LokeYourC3PH
Copy link

I don't think you can solve this with a flow in authentik because the authentik session is actually already invalidated correctly. The issue is that authentik does not notify the oidc relying party so the for example nextcloud session is not invalidated as well. For a shared device perhaps it would be simplest to just configure the device to wipe session data upon closing the browser until authentik supports back channel logout.

Not feasible sadly, as the Browser is used for more than just that. Also, people don't habitually close the Browser when done, they usually leave it open for the next person (it's an open terminal to be used).

@ksaadDE
Copy link

ksaadDE commented Sep 25, 2024

@LokeYourC3PH the problem you have encountered is exactly the same issue with outline wiki. It has nothing to do with these Apps. Sure the Apps call also a logout route but then the Authentication provider takes over.

Authentik has this middleware site where you can re-login in the user1 account (as in your example) despite you are user2 because Authentik seemingly does not handle the logout properly.

As Authentik (see discussion) has two logout systems in place. One for the "logout from all" and one "logout from app". Which is really weird.

Logout from all does the trick for you, so you don't get the "re-login" site. It's a bit counter-intuitive. The disadvantage is that you literally log out from all apps, and this means you can't just hop over to your other app via SSO.

@Crashman1983
Copy link

This behaviour should be fixed! I also expect a global logout when using such a system.

@danohn
Copy link

danohn commented Dec 21, 2024

I'm curious to know why Single Logout works fine for me when using Incognito but doesn't work when using a normal browser session.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement/confirmed Enhancements that will be implemented in the future enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.