Adding SetApplicationName seems to have broken token validation for some identity apps on the same host (cannot decrypt new tokens generated after change) #141
-
IdentityServer versionDuende IdentityServer 7.0.8 .NET version.NET 8.0 DescriptionException thrown from In app startup we have configured -
where the Keys folder is local to each ID Server web application. But even though each app has its own Keys folder it does appear that app isolation may have been broken in some way by the change to add SetApplicationName? as it was working on the same host in the earlier version, but since the product upgrade which added that line this issue has been encountered. We cannot reproduce this issue for only one instance of the ID Server web app per host and so we did not encounter it until the production hosting. We may have to issue a patch release to take away the call to SetApplicationName? unless there is something we can do as a workaround? We've tried deleting the contents of the Keys folder. Any info/suggestions much appreciated. Reproduction stepsNo response Expected behaviorNo response LogsNo response Additional contextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 3 replies
-
Before setting the application name, ASP.NET defaulted to using the content root path of your site as the application name. Adding an explicit name now means this has changed, where ASP.NET uses a new data protection key. It may be a good idea to remove the (explicit) application name again in order to restore access to your existing keys. You can then also request the application name ASP.NET uses for the application, e.g. using this code in your startup: // ...
var app = builder.Build();
// ...
var discriminator = app.Services.GetRequiredService<IOptions<DataProtectionOptions>>() .Value.ApplicationDiscriminator;
// discriminator is now the (auto-generated?) application name Regarding isolation: if all your applications are now using |
Beta Was this translation helpful? Give feedback.
-
Many thanks for the response Maarten. What doesn't make sense to me is that apparently the tokens are being encrypted using keys which the application now does not have access to (the "existing" keys) and therefore cannot decrypt them? Is that correct? I was under the impression that given each application instance has its own locally defined Keys folder, and we had deleted them and restarted the id server app, and it apparently generated new keys i.e. new files appeared in its local Keys folder, that it would be able to issue new tokens and decrypt them successfully, but that is not the case, as after doing so the application still cannot decrypt the tokens. So it seems that changing the application name means that instead of just defining new keys as we expected it is still using old keys under the old discriminator, even though it is configured now with a new application name? Also the example on https://docs.duendesoftware.com/identityserver/v7/deployment/data_protection/ states "explicitly set an application name to prevent issues with key isolation", setting this seems to have done the opposite for us. What i mean is, is it true to say that SetApplicationName is a method by which an application can invalidate itself, rather than re-configure itself? |
Beta Was this translation helpful? Give feedback.
-
Going from the default (no discriminator specified) to having an explicit discriminator specified effectively means the keys have changed, and old data can no longer be decrypted. If you have the old data from your keys folder still around, I'd recommend checking the old discriminator name (see my first response) and setting that as the discriminator. If you have lost the data from the keys folder, that would mean you've lost the keys (and thus won't be able to decrypt data that was encrypted before).
Is the assembly name the same for each deployed app? If yes, and they are all stored in the same folder, this effectively means all apps use the same application name. If the assembly name is different, that should be OK and isolated. |
Beta Was this translation helpful? Give feedback.
-
Thanks Maarten, fully understood - each application has its own local separate Keys folder - and in this case the tokens that fail to decrypt are newly generated i.e. after the application has been deployed with the new discriminator configuration, and also after we deleted the contents of the Keys folder and restarted the application, so none of the tokens are "old" tokens encrypted using the old keys - these are new tokens which we tried to use immediately and encountered an exception in ValidateAsync. So what I still don't understand is that the application is configured with an explicit keys path, local to itself, and it was requested to generate a new email confirmation token, which was used immediately afterwards but it failed to decrypt it. |
Beta Was this translation helpful? Give feedback.
-
Got it, thanks! That's slightly different indeed. Do you happen to have the full exception message and stack trace? |
Beta Was this translation helpful? Give feedback.
-
Hi all, I work with @jjts001 . He's on leave this week but we have recently made a discovery which can shed a lot more light on this issue. I'm recording that here, mainly for the benefit of others who might find this conversation in the future and have suffered similar symptoms. That discovery is that our ops team had made a setup/configuration mistake (human error). I think, intending to perform a server migration, they forgot to decommission the old instance. This meant that they had two instances of Identity Server running, on different hosts, with no knowledge of one another, sharing the same persistence database. Edit to clarify: We routinely have multiple ID Servers on the same host, but for different tenants/different databases. This problem was caused by two ID Servers on different hosts, for the same tenant/database. But, being on different hosts they would have been using different operating systems with different private keys and different filesystems where some other data protection material was stored. Once we detected it (whilst working on a different issue), we resolved this configuration error by shutting one of the instances down. The symptom which led to this conversation (tokens in things like passwords reset emails failing to round-trip) then went away with no further change required. I'm not saying that anything said here is explicitly incorrect; but in our case it turns out that the primary culprit was something else entirely! |
Beta Was this translation helpful? Give feedback.
Hi all, I work with @jjts001 . He's on leave this week but we have recently made a discovery which can shed a lot more light on this issue. I'm recording that here, mainly for the benefit of others who might find this conversation in the future and have suffered similar symptoms.
That discovery is that our ops team had made a setup/configuration mistake (human error). I think, intending to perform a server migration, they forgot to decommission the old instance. This meant that they had two instances of Identity Server running, on different hosts, with no knowledge of one another, sharing the same persistence database. Edit to clarify: We routinely have multiple ID Servers on the same hos…