Scrivio Interview library
DebuggingIntermediate7 min read · updated 12 November 2026

SAML logins started failing for all users this morning with 'Invalid signature' after working for two years. Nothing was deployed. What is the most likely cause and how do you prevent a repeat?

The most likely cause is that the identity provider rotated its signing certificate, while our service provider still trusts the old certificate that someone pasted into its configuration two years ago. Every assertion is now signed with a key we do not know, so every signature check fails. We fix it by loading the new certificate, and we prevent a repeat by reading the IdP's metadata from its URL, monitoring certificate expiry on both sides and agreeing a rotation procedure with overlapping validity.

Why this question is asked

SAML outages like this one are frightening because they hit every user at once and nothing in our own change log explains them. Interviewers ask this question to see whether we understand where trust in a SAML login really comes from, and whether we think beyond the quick fix to the process that would have prevented it. In this answer, we will recap how a SAML signature is checked, see why a certificate rotation breaks a statically configured service provider, apply the fix, look at clock skew as the other classic cause of sudden failures, and finish with monitoring and logging that make the next rotation a non-event.

1A Quick Recap of SAML Signatures

In SAML 2.0 there are two parties. The identity provider (IdP), such as Entra ID, Okta or ADFS, authenticates the user. The service provider (SP), our Spring application, trusts what the IdP says. After login, the browser carries a SAML response from the IdP to our assertion consumer service URL, and inside it sits an assertion: an XML document stating who the user is and when the statement is valid.

The SP must be sure the assertion really came from the IdP and was not edited on the way. So the IdP signs the response or the assertion with its private key, and the SP checks that signature with the IdP's public key, which it holds as an X.509 certificate. The SP never contacts the IdP during this check. It simply compares the signature with the certificate it already has. That last detail is the whole story of this outage.

2Why Nothing Deployed Still Means Something Changed

Signing certificates have expiry dates, often one to three years. Before the old one expires, the IdP team generates a new key pair and switches signing to it. Many IdPs publish the new certificate in their metadata weeks in advance, and some switch automatically on a set date. If our SP was configured with the certificate copied into a file, our side never learned about the new key. On the morning of the switch, the IdP starts signing with the new private key, our SP verifies with the old public key, and the math no longer matches.

YAML
# application.yml written two years ago
spring:
security:
saml2:
relyingparty:
registration:
corp:
assertingparty:
entity-id: https://idp.example.com/saml
singlesignon.url: https://idp.example.com/sso
verification.credentials:
- certificate-location: classpath:idp-2024.crt # the old certificate, never updated
Step throughLogin after the IdP rotated its key
BrowserIdPOur SP
Log in
Sign assertion with NEW private key
SAML response
POST /login/saml2/sso/corp
Verify with OLD certificate from file
401: invalid_signature

6 messages in order. Play them, or step through them one at a time.

The IdP did nothing wrong. Our SP is checking against a key the IdP no longer uses.

Notice that this configuration has nothing that could ever change by itself. Spring Security reports the failure as a Saml2AuthenticationException with the error code invalid_signature, and comparing certificate fingerprints confirms the diagnosis in a minute.

3Comparing the Certificates

We extract the certificate from the IdP's metadata (the X509Certificate element under the signing KeyDescriptor) and compare it with ours using openssl.

Properties
openssl x509 -in idp-2024.crt -noout -subject -enddate -fingerprint -sha256
# subject=CN=idp.example.com
# notAfter=Nov 8 23:59:59 2026 GMT
# sha256 Fingerprint=3A:9F:...:C1 <- the one we trust
openssl x509 -in idp-from-metadata.crt -noout -subject -enddate -fingerprint -sha256
# subject=CN=idp.example.com
# notAfter=Nov 2 23:59:59 2029 GMT
# sha256 Fingerprint=7D:22:...:0B <- the one the IdP signs with now

Different fingerprints with the same subject are the signature of a rotation. Notice that the old certificate had not even expired yet: IdPs often switch early. The immediate fix is to add the new certificate to the verification credentials and redeploy. Spring Security accepts a list there, so during a rollover we can trust both the old and the new certificate and avoid a second outage if the IdP has to roll back.

4The Lasting Fix: Read the IdP Metadata From Its URL

A better setup never copies the certificate at all. The IdP publishes metadata, an XML document listing its entity id, endpoints and current signing certificates, at a stable URL. Spring Security can build the whole registration from it.

YAML
spring:
security:
saml2:
relyingparty:
registration:
corp:
assertingparty:
metadata-uri: https://idp.example.com/federationmetadata.xml # certificates come from here

There is a catch. Out of the box, Boot reads the metadata once when the application starts, so a running instance still holds the old certificate until it restarts. To pick up rotations without a restart, we refresh the registrations on a schedule, for example by implementing RelyingPartyRegistrationRepository ourselves and rebuilding entries with RelyingPartyRegistrations.fromMetadataLocation() every few hours. Recent Spring Security versions also ship a caching repository that reloads metadata for us; check your version. Whatever we use, we validate before swapping: the download must be over HTTPS, the XML must parse, and if the IdP signs its metadata we verify that signature too. If a refresh fails, we keep the last good copy and raise an alert instead of dropping the registration, so an IdP website outage cannot become a login outage.

5The Other Morning Surprise: Clock Skew

Some sudden SAML failures are not about keys at all. An assertion carries NotBefore and NotOnOrAfter times, and the SP rejects it outside that window, allowing only a small tolerance for clock skew (a few minutes by default; check your version). If one of our servers loses its NTP time sync and drifts five minutes, logins fail only on that node, typically with an error about the assertion being expired or not yet valid rather than an invalid signature. So the error code matters: invalid_signature points at certificates, while expiry errors point at clocks.

6Preventing a Repeat

Prevention is part technical and part agreement. On the technical side, we monitor expiry dates of every certificate in the federation: the IdP's signing certificate, and also our own SP signing and decryption certificates, which the IdP holds a copy of and which can cause the same outage in the other direction. A daily job that reads the metadata and alerts 60 days and again 14 days before expiry costs an afternoon to build.

On the agreement side, we ask the IdP team, or the customer's IT team, for a rotation procedure with overlapping validity. They publish the new certificate in metadata first, we confirm that we trust both, and only then do they switch signing to the new key. With metadata refresh in place, that confirmation becomes automatic, but the shared calendar entry is still worth having.

Step throughA rotation that causes no outage
  1. IdP publishes new cert in metadataold key still signs
  2. SP refresh picks up both certificatesvalidated, last good copy kept
  3. Both sides confirm trusttest login on staging
  4. IdP switches signing to the new keySP already trusts it
  5. Old certificate removed laterafter the overlap period

5 steps in order. Play them, or step through them one at a time.

7Logging That Helps Without Leaking

During the incident, good logs turn an hour of guessing into a minute of reading. We log the Saml2 error code, the registration id, the issuer, the response id and the fingerprint of the certificate in the response if there is one. We do not log the full assertion: it contains names, email addresses, group memberships and sometimes employee numbers, all personal data, and a log file is the wrong place for it.

8Follow-up questions

How do I tell a signature problem from a clock problem quickly?

Look at the error code Spring Security reports. A signature failure (invalid_signature) means the key used to sign does not match what we trust, which happens on every node at once. Time errors about NotBefore or NotOnOrAfter usually affect only the nodes whose clocks drifted, and they often come and go as the load balancer moves users between nodes.

Why not just disable signature validation until the IdP fixes it?

Because the signature is the only thing that proves the assertion came from the IdP. Without it, anyone can post a hand-written assertion claiming to be any user, including an administrator. The fix takes minutes once we have the new certificate, so there is no situation where switching validation off is the better trade.

9Conclusion

In this answer, we saw that a sudden invalid signature error after years of working almost always means the IdP rotated its signing key while our SP kept a copied certificate. We confirmed it by comparing fingerprints, fixed it by trusting the new certificate, and made it permanent by reading and refreshing the IdP metadata with validation and a last good copy. We also separated clock skew errors from signature errors, and added expiry monitoring, an overlapping rotation procedure and logs that carry error codes and fingerprints but no personal data.

What to say in the interviewAbout 90 seconds aloud

Open with

Since nothing was deployed and every user fails at once with an invalid signature, my first suspicion is that the identity provider rotated its signing certificate and we still trust the old one, because our configuration has the certificate copied into a file.

Then, if they want more

I would confirm it by comparing the SHA-256 fingerprint of the certificate in the IdP's current metadata with the one we ship. The quick fix is to add the new certificate to the verification credentials, keeping the old one as well during the overlap, and redeploy.

The real fix is to stop copying certificates: point Spring Security at the IdP's metadata URL and refresh it on a schedule, validating each download and keeping the last good copy if a refresh fails.

I would also rule out clock skew, since assertion time windows only tolerate a few minutes, but that usually shows as expiry errors on single nodes, not signature errors everywhere.

To prevent a repeat, I would monitor expiry dates of the IdP certificate and our own SP certificates with alerts well ahead of time, and agree a rotation procedure where the new certificate is published first and signing switches only after both sides trust it.

And I would make sure our logs record the error code, registration id and certificate fingerprint, but never the full assertion, because that is personal data.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring Security reference
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "SAML logins started failing for all users this morning with 'Invalid signature' after...": https://scrivio-interview-library.netlify.app/spring-boot/authentication/d55a0906bc/