Automatic key management doesn't work as expected #6
Replies: 0 comments 16 replies
-
@ivan-sedlak-visma, thanks for this bug report. We'll investigate and update here soon. |
Beta Was this translation helpful? Give feedback.
-
@ivan-sedlak-visma - so far I've not been able to reproduce this issue in my environment. Can you go into more detail about the values you're using for all the relevant configurations? For anything that you're changing, before and after values would be helpful too. |
Beta Was this translation helpful? Give feedback.
-
Thanks @josephdecock. If the feature is up and running properly on your side it might be something we do with injecting a signing certificate and a validation certificate the manual way or something with our db store. When I get the time I will go in-depth and report back with more info. |
Beta Was this translation helpful? Give feedback.
-
@josephdecock Here are more details. I've noticed that when I run IdentityServer in localhost, with a fresh db instance (no cert data), it generates the RS256 certificate as specified by current configuration (same key management config in all envs):
However, in staging and production environments, where db is not fresh (has data) it still keeps outdated certificate. I enabled the Verbose logging and this is what I got:
Below is the jwks endpoint result. The second key is registered manually, not a part of the key management. The key with id "88CF32355BAE0F4E0DD9E73BFA6E232E" expired on 24th of June 2023. No other keys are registered.
More cert details:
Previous key management config:
Please let me know if you need more details. Thank you. |
Beta Was this translation helpful? Give feedback.
-
I think I have found the bug in KeyManager.cs It happens because the rotation interval was changed to a higher value and the diff is bigger than the propagation interval. In our particular case, the issue should fix itself in approximately 12 days and as long as we don't change the key management config anymore it should keep working as expected from that point on. I guess the proper fix would be to keep the config alongside the generated certificate and check against those values instead of the current ones. I am not sure that is the best strategy so I don't want to create any PRs at this point in time to suggest a bugfix. Here is the code snippet to reproduce:
Result:
|
Beta Was this translation helpful? Give feedback.
-
Signing keys never really expire. They can be stored in an x.509 certificate and that certificate might have an expiration date on it, but IdentityServer isn't validating any of the x.509 certificate details. It's just using the certificate as a container for the key material, and will happily use a certificate regardless of expiration. This is a common point of confusion, and I can see why folks would think "oh, my certificate is about to expire, I have a problem". But as I say, that's not how IdentityServer uses certificates. Given this, do you still think there is a bug? |
Beta Was this translation helpful? Give feedback.
-
In that context, the behavior seems valid, but then why bother with creating a certificate with precise expiration dates? Using an expired certificate might trigger some clients to reject it? Idk seems a bit backward to me but if you think this is expected behavior please feel free to close the issue. Thank you. |
Beta Was this translation helpful? Give feedback.
-
There's not a lot of benefit to creating x509 certificates at all. From a security point of view in OIDC, there's no benefit at all, but saml requires it, and sometimes corporate IT policies will require that as well.
We haven't run into this in practice. Clients in general trust the public key material because they authenticate the server using TLS (they got it over https, so it has to be legit). If you run into a client that is rejecting these certs, we'd be interested to hear about it, and could consider adding additional checks to the rotation based on the expiration of existing certs. In an unusual circumstance like that, there's always the option of manual key management as well. For now, I'll close this issue. Thanks for all your thoughts and feedback! |
Beta Was this translation helpful? Give feedback.
-
Found this when researching an issue we're facing. I want to raise that Microsoft's default token signing key validator does check for lifetime of the signing key's certificate, please see here: https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/blob/dev/src/Microsoft.IdentityModel.Tokens/Validation/Validators.IssuerSigningKey.cs#L68 |
Beta Was this translation helpful? Give feedback.
-
@DenL thanks for your comment. Can you expand a bit more about the issue you're seeing? I just tried getting IdentityServer to generate a key using x.509 and a very short lifetime. Then I changed IdentityServer configuration so that the key with the expired certificate would continue to be used, and then was able to use that key to log in to a client using OpenId Connect built using the ASP.NET Core OIDC handler. At least historically, the typical OAuth and OpenId Connect related code paths haven't run into this check that you've found, so I'm curious what your use case is, and how you're using Microsoft.IdentityModel to cause an issue. |
Beta Was this translation helpful? Give feedback.
-
@josephdecock we use the key to sign a jwt token. That token is used by client elsewhere to authenticate with another app. The app is using jwtbearer to authenticate with TokenValidationParameters.ValidateIssuerSigningKey = true I’m on mobile so apologize for the lack of formatting |
Beta Was this translation helpful? Give feedback.
-
Okay, interesting. And what's the goal of setting that flag in the other app? If you control that app, why not just disable that flag? In general, clients can trust the public key material that IdentityServer serves from the jwks endpoint because the authorization server was authenticated by TLS. |
Beta Was this translation helpful? Give feedback.
-
That was an info sec decision made before my time. I’m guessing it’s to ensure tokens are authentic and actually served by our identity server. |
Beta Was this translation helpful? Give feedback.
-
My advice is to revisit that old info sec decision. There really isn't a security benefit to it in OIDC. You can have confidence in the authenticity of the tokens because you can validate the signature of tokens using public key material that was retrieved over TLS. In other words, you know that you got the JWK from your-identity-server.example.com because it was sent over HTTPS, so only an entity that controls the TLS certificate for that domain could do so. |
Beta Was this translation helpful? Give feedback.
-
We already manually deployed a new valid cert and resolved our issue that
way. I just wanted to bring this to your attention as I imagine it’s a
reasonable expectation that the public key container cert is still valid.
I’m not a security expert but there could be many reasons to enforcing
validity. In our case one of the reasons I’m aware of is to force a
rotation of keys as having one set valid forever means it could eventually
be compromised, and that does not meet compliance standards in our industry.
…On Mon, Feb 3, 2025 at 4:32 PM Joe DeCock ***@***.***> wrote:
My advice is to revisit that old info sec decision. There really isn't a
security benefit to it in OIDC. You can have confidence in the authenticity
of the tokens because you can validate the signature of tokens using public
key material that was retrieved over TLS. In other words, you know that you
got the JWK from your-identity-server.example.com because it was sent
over HTTPS, so only an entity that controls the TLS certificate for that
domain could do so.
—
Reply to this email directly, view it on GitHub
<DuendeArchive/Support#764 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABK7BWZXFKJJHSIOT6SKLOL2N7N5XAVCNFSM6AAAAABVTGALPGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMZSGEZDCOJVGI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
(note: we're moving this issue to our new community discussions) |
Beta Was this translation helpful? Give feedback.
-
Which version of Duende IdentityServer are you using?
6.3.3
Which version of .NET are you using?
.NET 6
Describe the bug
We enabled the automatic key management and initially, it worked as expected, generating new signing keys in db which are visible in the disco doc. We still keep the old key registered manually.
In the meantime, we disabled some of the algorithms and left only the RSA256 (X509). The other autogenerated signing keys disappeared from disco doc, all is good thus far. But the issue is, seems like new keys are not generated as the existing one (autogenerated) already expired. We still sign tokens with our manual key but we can't disable it because new keys are not being announced.
To Reproduce
Expected behavior
Beta Was this translation helpful? Give feedback.
All reactions