microsoft-identity-web
microsoft-identity-web copied to clipboard
[Feature Request] Load multiple enabled versions of the same certificate for easy rollover for token decryption
Is your feature request related to a problem? Please describe. Today, rotation of token encryption/decryption certificates is very complex (in our case for first-party). This is because, if I am using the AKV to generate my certificates, I need to achieve following manual steps during rotation:
- The API code will have 2 certificates for decryption:
C1
andC2
. Upon a fresh start it will only load the latest versions of these certificates (let's sayv1
in both the cases). - The AAD portal can only use one certificate to encrypt. Therefore,
C1.v1
will be uploaded to the portal and chosen for encryption. - Now, the AKV mails us for arrival of expiry date of
C1.v1
certificate. We go ahead and uploadC2.v1
(assuming it has enough time before its own expiry) set it as the encryption certificate in the AAD portal. - Now the AAD app will start encrypting tokens using
C2.v1
. But the API service will not fail because it already had the configuration to useC2
's latest version. In the worst case, we may have to restart service once, if a new version of C2 was issued before uploading to the AAD portal. - At this point we validate that APIs are working correctly and that the token encryption happens through
C2.v1
. - Now, we come back to AKV and issue a new version of the certificate
C1
, updating it tov2
. And restart app service manually to reload theC1
certificate with versionv2
. - Next we go to the AAD portal, upload the
C1.v2
certificate and set it to be used for encryption. - An token issued after this will be encrypted by
C1.v2
and the API service would also be decrypt it correctly.
Now, these involve lot of manual steps because of 2 reasons:
- AAD does not support auto-rotation for token encryption certificates.
- MSAL library - even though allows loading more than 1 decryption certificates, it is not guaranteed that it will keep using previous
x
versions for the certificate. This is needed because, let's say, I just generated new version of the encryption certificate in the AKV, and my app service restarted for some reason, then it would only fetch the latest version of the encryption certificate and scenarios will break until I alter the AAD to use the new version of the certificate for encryption.
Describe the solution you'd like
IMO, the library should fetch the previous x
versions of the certificates, which may be enabled and not expired and try decrypting the token using any one of those certificates. This will help a lot, in terms of simplifying the rotation process as follows: Even though I generate a new version of the encryption certificate when old one is close to expiry, and by chance if the app service has restarted, it may fetch both the valid versions of the certificate and decryption of token will work just fine. I can then safely upload the new version to the AAD and set it to be used for encryption.
This saves the burden of maintaining primary and secondary certificates and several manual steps in their time-to-time rotation.
Describe alternatives you've considered It would be good to understand the priority of visualizing this feature. Because alternate routes include:
- Manual approach as described above.
- Developing teams need to write middleware to fetch the required versions and instances of certificates and use code configuration to perform token decryption.
While the first option is primary reason for this feature ask, the second option requires teams to manage additional code and ensure the reliability of certificate management.
Please let me know your thoughts with respect to the points here or if I am missing something that can help our scenario.
Hi Team,
I wanted to check for any update on this. It would be really useful to have this feature as it will get us closer to what auto-rotation would look like. Any thoughts on this would be really useful.
Regards, Chintan Rajvir