mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-02-06 09:09:38 +03:00
OIDC with Zitadel SaaS stops working after some time (signature could not be validated using the provided keys) #4810
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @baua1310 on GitHub (Jun 4, 2024).
Describe the Bug
When Zitadel SaaS is used for authentication with OIDC in Bookstack, it will stop working after some time, at the latest after 24 hours, and the following error message is shown:
ID token validation failed with error: Token signature could not be validated using the provided keys.Workaround: Deleting the bookstack docker container and recreating it fixes the error for some hours.
Steps to Reproduce
ID token validation failed with error: Token signature could not be validated using the provided keysExpected Behaviour
When set up correctly, authentication with OIDC in bookstack works also after 24 hours.
Screenshots or Additional Context
Browser Details
Brave (1.66.118 Chromium: 125.0.6422.147 (Official Build) (64-bit)) on Windows 11 Version 23H2 (Build 22631.3593)
Exact BookStack Version
v24.05.1
@ssddanbrown commented on GitHub (Jun 4, 2024):
As mentioned in #4682, BookStack does cache discovered details but only for 15 minutes.
First, it would be good to test/rule-out instance cache issues.
Can you try setting the cache to be database based.
This is done by setting
CACHE_DRIVER=databasein your existing.envfile, or by settingCACHE_DRIVER=databaseto the environment for your BookStack app container. Remember to re-create the container if altering container environment options.@baua1310 commented on GitHub (Jun 8, 2024):
@ssddanbrown I have set the suggested environment variable:
Unfortunately, the error pattern persists. Even recreating the container does not solve the problem. This means that signing in with OIDC is not possible at all.
@ssddanbrown commented on GitHub (Jun 8, 2024):
@baua1310 Does it start working again after removing the
CACHE_DRIVERoption again, and a container recreate?@baua1310 commented on GitHub (Jun 10, 2024):
@ssddanbrown Yes after removing
CACHE_DRIVERand recreating the container sign in with OIDC started working again.@PandieTech commented on GitHub (Jul 27, 2024):
Just wanted to +1, I have the exact same problem after implementing a fresh Bookstack instance using Zitadel as my IDP, albeit mine is self hosted not SaaS Zitadel. Followed the same path from the other issue #4682, and now after some time, not necessarily 24 hours, I get the

ID token validation failed with error: Token signature could not be validated using the provided keyserror.Edit: I have not restarted / rebuilt my Bookstack container, and after waiting a while after experiencing the error, it did start working again, probably when that cache expired and it renegotiated.
To add some more possibly worthwhile info, certain OIDC token settings can be modified in Zitadel (at least in self hosted, can't speak for SaaS). @ssddanbrown would you normally expect other OIDC IDPs to have a longer access, or in this case probably more relevant ID token expiry?
And apologies for my novice showing, but initially I did not include the Refresh Token grant type, will adding that have any bearing on this ID token issue?
Ultimately I suppose it would be nice, selfishly for this scenario, for this error to then prompt Bookstack to clear that cache and retrieve it fresh, but I'm sure it's easier said than done.
@ssddanbrown commented on GitHub (Jul 27, 2024):
@pandieme
Those settings don't really matter in the context of BookStack's use. We don't hold on to tokens for refresh, I believe we just go through the original process direct with the auth provided at login time.
The BookStack cache should only remain for 15 minutes, that's what I can't understand and need to dive deeper into. The above tests indicate it's not being cleared (not expiring), but I feel this would have show up in other auth providers/scenarios if our cache system was fundementally not listening to cache lifetime.
Out of interest, can you describe your environment too (BookStack hosting environment& install method) just so I can guage any potential patterns?
@PandieTech commented on GitHub (Jul 28, 2024):
@ssddanbrown
Ours is running on a Debian 12 VM, hosted on an XCP-ng pool, using Docker compose and behind a Caddy reverse proxy also running in a container on a shared Docker network.
Docker versions
Bookstack
Container info
Docker Compose
.env
Custom theme function
As described in this issue #4682 we added the following file to our bookstack containers volume to
Replace multiple aud values with single azp valueto cater for Zitadel's returned array.Caddy (Reverse Proxy)
Caddyfile
Docker Compose
@Rob787 commented on GitHub (Sep 25, 2024):
+1 for this issue also with self-hosted Zitadel
@ssddanbrown commented on GitHub (Sep 26, 2024):
@Rob787 Are you also using the linuxserver docker image?
@Rob787 commented on GitHub (Sep 30, 2024):
@ssddanbrown For Bookstack? Yes, the linuxserver Docker image indeed.
@cybrwshl commented on GitHub (Feb 28, 2025):
@ssddanbrown have you had time to take a closer look at the problem?
@baua1310 commented on GitHub (Feb 28, 2025):
Hi, just a quick update from my side: As the problem with OIDC and Zitadel had not been solved, I switched to SAML 2.0.
SAML 2.0 and Zitadel is working fine since a few months. Here is my configuration:
To map Zitadel roles to bookstack groups I added added a custom script in Zitadel called "samlRoles" inside Actions and added the script in the flow "Complement SAMLResponse" to the trigger "Pre SAMLResponse creation".
@cybrwshl commented on GitHub (Mar 8, 2025):
Thanks @baua1310, works like a charm! Except for the logout process, but that's no problem.
@AndrinGautschi commented on GitHub (Jun 5, 2025):
Just ran into the same issue. Zitadel is self-hosted (and configured to rewrite the roles into a roles array) in a k3s cluster, as is bookstack (via linuxserver image with the same theme-hack concerning the audience array as pointed out above). Accordingly, the behaviour is also the same: After a day or so the login (which previously has worked fine after a fresh install) stops working with "ID token validation failed with error: Token signature could not be validated using the provided keys". Interestingly, it seems to work again after approximately 15minutes (pretty much the time it took me to find this thread and read through).
The zitadel logs say: "2025/06/05 13:09:26 ERROR: Failed to extract ServerMetadata from context"
nginx access.log of bookstack:
@ssddanbrown Have you ever had the chance to look into your suggested caching issue? (btw: I think you do a great job, whether this issue gets resolved or not!)
PS: There is one thing that I've configured different than my predecessors; Bookstack is registered within Zitadel as PKCE app. Since zitadel does not provide a client secret for such cases and bookstack needs one, I had to generate a random value by myself which I feed into the bookstack container on startup.
@ssddanbrown commented on GitHub (Jun 5, 2025):
@AndrinGautschi Not yet. To be honest it's an awkward one to attempt to replicate due to needing to be done over time, and since I think there's a fair chance of this being something Zitadel specific (just based upon not having this ever reported for another OIDC system). Just need to properly dedicate the time needed.
Do you get that zitadel log error message every time this occurs? Just trying to understand how connected that is to what's happening in BookStack.
As an aside, Zitadel has recently taken millions in VC funding, and has just switched their licensing to AGPLv3+CLA. Can't speak specifically to the project or its owners or management, but this is usually an indicator that the project is going in a certain growth-focus direction which often impacts users eventually. The funding provided by the same which funded Minio, which has been in the news recently for its open-source-user unfriendly changes.
@ssddanbrown commented on GitHub (Jun 5, 2025):
Not validated, but potentially related to https://github.com/zitadel/zitadel/discussions/2042.
Might be just that Zitadel (compared to others) has no smooth key rotation (Direct change with no/minimal crossover period) leading to no available keys for a moment, and in which case we should maybe (following the spec's advice) re-fetch the keys on unfamiliar key if we've used our own cache values.
@AndrinGautschi commented on GitHub (Jun 18, 2025):
Thanks. Unfortunately, I'm very busy right now with something else. I'll come back with proper telemetry data as soon as I've found time to investigate further.
@AndrinGautschi commented on GitHub (Aug 27, 2025):
Due to other issues with Zitadel, especially concerning their newest update, we internally changed products and moved to Authentik. So far, this seems to work perfectly fine. So for anyone who struggles implementing auth between Zitadel and Bookstack: SAML2.0 seems, according to https://github.com/BookStackApp/BookStack/issues/5049#issuecomment-2691032746, work fine.