-
Notifications
You must be signed in to change notification settings - Fork 887
"Token not active" error when logging in via OIDC #8537
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
Comments
I can confirm this happened again today. OIDC token for Coder is expired, but I've logged myself into a new session with Keycloak via another application and Coder doesn't catch that I'm logged in to a new Keycloak session and gives me the error above. If I delete only the Coder cookie and hit the "Open ID Connect" button, then I'm directly logged in (so no additional login). After that, everything works as it should. To note once more, this login process was working perfectly before 0.25. Scott |
Update. Yesterday although I was already logged in, Coder logged me out after several hours (not sure how many, but more than 5, and less than 10), despite the refresh token from Keycloak being set for 10 hours. So, I clicked on the "Open ID Connect" button to log in and got the error above, deleted the cookie, got the Keycloak login screen (although my Keycloak session was active) and logged in and was in. This morning, I logged in via a different app with Keycloak as I usually do, then moved to our Coder instance and clicked the "Open ID Connect" button and was immediately logged in, as if nothing was broken. I'll report again tomorrow about how the login goes again. Question or suggestion though, couldn't Coder follow the refresh timeout of the Keycloak (OIDC provider) token to log me out, when the token expires expires? Scott |
Ok. Last report. This morning everything worked like it should. Clicked on the "Open ID Connect" button in Coder after logging in via another app and I was immediately logged in. I'm closing this issue. If I can figure out why I was having the issue initially, I'll report back again, but I doubt I will. Sorry to have wasted anyone's time. Scott |
Hmm... thanks for the rundown and sorry that you're running into issues. If this happens again, could you ensure |
@bpmct - Sure thing Ben. Willdo. Scott |
Small update: Got this refreshing the workspaces page with an expired token. Refreshed the page, hit the "Open ID Connect" button and was faced with this again. I didn't have the logs set to verbose. Doing that now. I'll report back again, once I have the logs. I'll leave it to you all to open the issue up again or not. 😁 Scott |
Ok. This is the log (in VERBOSE mode) in the coder server, when I try to log in and get the error shown in the OP. Can't say I can see that it sheds any light on the situation. But, for sure I'm very far from any expert. 😁
Scott |
When you login with OIDC we generate a coder API key with fixed lifespan (not affected by the OIDC expiry) and store an "oauth link" in the DB with the access token, refresh token and expiry from the provider. The Coder API key's lifespan is increased automatically when you make requests. When you make a request using an API key generated through OIDC login, we verify that the OIDC access token hasn't expired yet, and if it has we will try to refresh it. If the refresh fails then we delete the API key which logs you out. The Searching online for keycloak "Token is not active" says that it could be an issue with the server time/timezone, or it could be an issue with the "SSO session time" and "revoke refresh token" settings. |
I'd like to agree it could be a Keycloak issue, but the OIDC login with Coder with an OIDC session already started was working perfectly before upgrading to 0.25. It seems to me, once logged out, instead of requesting a new refresh token, Coder is trying to refresh with the old token. Could that be? You wrote:
If I'm logged out of Coder, there should be no current (active or inactive/ expired) token AFAIK. Or, let me ask, which token are you speaking of? I believe, if I'm already logged in via an OIDC session to Keycloak, Coder should ping Keycloak and since I'm already logged in, Coder should get a brand new token. Or, put another way. once logged out of Coder and I don't have an OIDC session open, then I should get the Keycloak login screen. This works correctly. At that point, I can log into Keycloak and I'm successfully logged in to Coder with a new token and a new OIDC session. After that, I can also go and do "SSO" logins with my other apps with no issues. Unfortunately, it doesn't work the other way around with Coder and it did before 0.25. And I'm pretty much certain I've made no changes to Keycloak to possibly break the SSO login via OIDC (session) either. Scott |
I just noticed something. My usual morning routine is to reopen the windows in Chrome I had open the day before. When I get to Coder, it redirects me to the login page with
Today, on a whim, I decided to just go back to the URL only, so I shortened the URL to I'll experiment some more tomorrow and report back. Scott |
Today, because I had overwritten my Chrome history and couldn't open up the whole window of tabs, I opened a brand new window and went to my Coder instance (after getting a new OIDC session via another app) and the log in worked as it should with one click. So, I believe the issue is when I access a page other than the index page in Coder and the process of the redirect to the login page isn't doing what it should. The issue also happened to me yesterday, after a few hours of non-use of Coder. Navigating to another page ended up in the redirect to the login page, which ended up in the error after pressing the "Open ID Connect" button. My OIDC sessions are set to 10 hours, so the session was still active. Is there a way to extend Coder's session timeout to match the OIDC's session timeout? If that should be another issue (suggestion), please let me know. Scott |
@smolinari to set coder session duration you can use https://coder.com/docs/v2/latest/cli/server#--session-duration |
@matifali - Thanks. According to those docs, the session timeout is 24 hours. I'm not seeing that. It's much shorter. Like 4 hours. Could that be? I'll set it to the same 10 hours as the OIDC session and see what happens. Scott |
So, after setting Coder's token session duration to 10 hours, I could log in normally after Coder redirected me from the workspaces page (which was saved as an open tab) to the login page. I'll continue to monitor this for a couple of days and if all works as it should, I think we can close this issue again. Scott |
Today I opened a "history" page in the browser of our coder instance, one from two days ago and with definitely old cookies. It caused a redirect to the login page. And, I was met with the error in the OP. Instead of deleting all cookies, I went into dev tools and deleted cookies one by one to see which one was the culprit. It was the Scott |
This definitely seems like a bug in Coder, I'm running several other ODIC apps like GitLab, WikiJS, and Rancher and none of them do this. It seems like Coder should force a re-login when this happens instead of making the user have to manually delete the cookie from their browser. A token being expired is a normal occurrence and could happen for any number of reasons such as a forced logout on the IDM side. Issue 8179 is probably the same issue. Verified this is still happening in v0.27.2 |
Same behavior with our system |
@smolinari, problem is probably resolved in 2.0.0. i haven't had any issues since the update. |
We've just updated to v2.0.0, but we're still facing the issue with the token. First, we receive this message in Coder when the window is not in focus for a while:
Upon reloading the page, we get logged out. After logging back in, we encounter the following error: maybe it is connected to this issue (but I am not sure) #8179 |
Confirming this still happens on 2.0.0 for me as well. Only fix is to delete the cookie or users can't login ever again. |
I upgraded to 2.0.2 and the issue is now gone. Thank you for the fix! Scott |
With 2.0.2 we have no more problems either. A big thanks to you guys! |
Hi,
Before 0.25, I could log in to my Keycloak instance via another application and then come to my Coder instance and click on the "Open ID Connect" button and since my OIDC session was already started, I would be logged in immediately.
Now, when I click the button, I get this:
If I delete all cookies, I get the Keycloak log in screen, and I can log in (again) via Keycloak and then everything works as it should.
I believe something is (still?) wrong with the OIDC refresh process and I'm uncertain it is now my setup or an actual issue.
Scott
Coder version: 0.26.1
Environment: k8s
The text was updated successfully, but these errors were encountered: