Add sp_cert_multi to facilitate SP cert/key rotation#673
Merged
pitbulk merged 1 commit intoSAML-Toolkits:masterfrom Jul 7, 2024
Merged
Add sp_cert_multi to facilitate SP cert/key rotation#673pitbulk merged 1 commit intoSAML-Toolkits:masterfrom
pitbulk merged 1 commit intoSAML-Toolkits:masterfrom
Conversation
Collaborator
Author
|
@pitbulk this is ready for final review. Let me know what I can do to help get this merged. |
b97bea3 to
a2a0002
Compare
Collaborator
Author
|
FYI I am using this in production now without issues. |
|
I was just looking into how to build multi_cert support for SP signing myself and great to see you already did it @johnnyshields . We're interested in getting this upstream, anything we can support in to move this forward? |
Collaborator
Author
|
@pitbulk what do you think? |
Collaborator
|
I will be adding this on next ruby-saml release. Hopefully soon. |
Collaborator
Author
|
@pitbulk any update? I've been using this in prod for 6 different SAML integrations, with IdPs on Azure AD, PingFederate, etc. I think it's safe to merge. |
10 tasks
pitbulk
approved these changes
Jul 7, 2024
Collaborator
|
Sorry for the delay on merging it, I will be more active now with ruby-saml |
|
Excellent news, thank you! |
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #560
This PR introduces
sp_cert_multiparameter which is analogous toidp_cert_multi. It allows developers to have fine-grained control over SP certs and private keys, including:The changes are summarized as follows:
Add
SamlSettings sp_cert_multiparameter. It has the following shape:(Note: You can use same certs for signing/encryption, and same PK everywhere. It's completely backward compatible with current functionality.)
sp_cert_multiis mutually exclusive with the following:certificate, certificate_new, private_key.If
security[:check_sp_cert_expiry]is true, Ruby Saml automatically uses the first non-expired certificate insp_cert_multi[:signing]for signing, and only uses private keys associated with non-expired certs insp_cert_multi[:encryption]for decryption. This is evaluated in realtime, so as soon as your old cert expires your app automatically starts signing with the new one.The validation error
:check_sp_cert_expirationis now raised only if ALL SP certs are expired. This is a slight behavior change;Settings.certificatewas expired butSettings.certificate_newwas not, an error would be raised.certificate_newfor signing. (This case was not previously in the tests, but I've now added a test for it with the new logic.):check_sp_cert_expirationnow also validates the certificatenot_beforecondition; previously it was only validatingnot_after.If
:check_sp_cert_expirationis true, we now no longer include expired certs in the generated SP metadata. This is a good practice because having expired certs may cause the IdP system to throw an error, depending on how strictly it does its validation.Refactor so that internal references to
get_sp_cert,get_sp_private_key, etc. now point to the new structure of multiple certs.When performing decryption, we now try all private keys under
sp_cert_multi[:encryption](this is analogous to how we try all IDP certs inidp_cert_multi[:signing]when verifiying the IDP signature.)Extract out
OneLogin::RubySaml::Utils.build_cert_objectandbuild_private_key_object.Deprecate the
certificate_newparameter sincesp_cert_multifulfills the same role better. It still works but it is removed from the docs.When there are multiple SP certs, the ordering of SP KeyDescriptor node in the SP metadata XML will now be all signing keys first, and then all encryption keys. (Previously it would be signing, encryption, signing, encryption.) This does not affect XML integrity in any way.
This PR contains unit tests and integration tests for all major SP signing flows (both Redirect and POST). Decryption is covered as well.