Hi Martin,
On 2 Feb 2017, at 01:00 AM, Martin Fraser <
martind...@gmail.com> wrote:
> Thanks for clarifying, that was my understanding. Reviewing the attached log file I can see six <samlp:AuthnRequest> coming in as well as six lines which read:
> SAML2.0 - IdP.SSOService: incoming authentication
Counting authentication requests and specific log lines is not enough. You should be able to follow the log from the authentication request to the authentication response to verify that what’s happening is indeed an SP-initiated authentication. If you do that, you will see it’s not the case:
—8<—
Here you get the first AuthnRequest with ID "_48FCA075-DD82-4BAB-8425-BC4894478298":
> Jan 27 16:40:28 simplesamlphp INFO [db5aebdb83] SAML2.0 - IdP.SSOService: Accessing SAML 2.0 IdP endpoint SSOService
> Jan 27 16:40:28 simplesamlphp DEBUG [db5aebdb83] Received message:
> Jan 27 16:40:28 simplesamlphp DEBUG [db5aebdb83] <samlp:AuthnRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" Version="2.0" ID="_48FCA075-DD82-4BAB-8425-BC4894478298" IssueInstant="2017-01-27T16:40:27.825Z" Destination="
https://staging.entrepreneurialscotland.com/simplesaml/saml2/idp/SSOService.php">
> Jan 27 16:40:28 simplesamlphp DEBUG [db5aebdb83] <saml:Issuer>
https://app.staging.goodpractice.net</saml:Issuer>
> Jan 27 16:40:28 simplesamlphp DEBUG [db5aebdb83] <samlp:NameIDPolicy AllowCreate="true"/>
> Jan 27 16:40:28 simplesamlphp DEBUG [db5aebdb83] </samlp:AuthnRequest>
> Jan 27 16:40:28 simplesamlphp INFO [db5aebdb83] SAML2.0 - IdP.SSOService: incoming authentication request: '
https://app.staging.goodpractice.net’
Here, however, something went wrong and you didn’t continue SSO. Instead, you get yet another AuthnRequest with ID "_8545DE70-01EF-4484-976B-B706D8773991”. Note also that the “track ID” (the code in brackets right after the log level) changes:
> Jan 27 16:40:52 simplesamlphp DEBUG [101cbb7a76] Session: 'drupal-userpass' not valid because we are not authenticated.
> Jan 27 16:40:52 simplesamlphp DEBUG [101cbb7a76] Saved state: '_94c513cdb4dac3930fd823d13485954814937872c6:
https://staging.entrepreneurialscotland.com/simplesaml/saml2/idp/SSOService.php?spentityid=https%3A%2F%2Fapp.staging.goodpractice.net&cookieTime=1485535252'
> Jan 27 16:40:52 simplesamlphp WARNING [101cbb7a76] The class or interface 'SimpleSAML_Module' is now using namespaces, please use 'SimpleSAML\Module'.
> Jan 27 16:40:52 simplesamlphp INFO [101cbb7a76] SAML2.0 - IdP.SSOService: Accessing SAML 2.0 IdP endpoint SSOService
> Jan 27 16:40:52 simplesamlphp DEBUG [101cbb7a76] Received message:
> Jan 27 16:40:52 simplesamlphp DEBUG [101cbb7a76] <samlp:AuthnRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" Version="2.0" ID="_8545DE70-01EF-4484-976B-B706D8773991" IssueInstant="2017-01-27T16:40:51.348Z" Destination="
https://staging.entrepreneurialscotland.com/simplesaml/saml2/idp/SSOService.php">
> Jan 27 16:40:52 simplesamlphp DEBUG [101cbb7a76] <saml:Issuer>
https://app.staging.goodpractice.net</saml:Issuer>
> Jan 27 16:40:52 simplesamlphp DEBUG [101cbb7a76] <samlp:NameIDPolicy AllowCreate="true"/>
> Jan 27 16:40:52 simplesamlphp DEBUG [101cbb7a76] </samlp:AuthnRequest>
> Jan 27 16:40:52 simplesamlphp INFO [101cbb7a76] SAML2.0 - IdP.SSOService: incoming authentication request: '
https://app.staging.goodpractice.net’
Here, SimpleSAMLphp tries to load the state with ID “_94c513cdb4dac3930fd823d13485954814937872c6”. The “track ID” changes again. Note that part of the state is the SSO URL of your IdP with a parameter indicating the entity ID of the service that requested authentication. As it reads from the documentation, this is the URL for IdP-initiated authentication:
https://simplesamlphp.org/docs/stable/simplesamlphp-idp#section_11
> Jan 27 16:40:53 simplesamlphp DEBUG [d9b47223e8] Loading state: '_94c513cdb4dac3930fd823d13485954814937872c6:
https://staging.entrepreneurialscotland.com/simplesaml/saml2/idp/SSOService.php?spentityid=https%3A%2F%2Fapp.staging.goodpractice.net&cookieTime=1485535252'
Finally, you get a log line clearly stating that you are starting IdP-initiated authentication. Next, authentication succeeds and a SAMLResponse is sent back to the SP, WITHOUT the InResponseTo attribute, as expected from an IdP-initiated authentication. Note that the “track ID” changes again.
> Jan 27 16:40:53 simplesamlphp INFO [1afdf257bc] SAML2.0 - IdP.SSOService: IdP initiated authentication: '
https://app.staging.goodpractice.net’
—>8—
> This to me indicates that all six of my test requests as described above are SP initiated, as expected.
As we have just seen, no, it’s not like that. You don’t even need to perform the same analysis I just did, it’s even easier. If you search for SAML responses, there are 6 of them. Now, you can search for “IdP initiated authentication” messages, and you will see that there are indeed 4 of them:
> Jan 27 16:40:53 simplesamlphp INFO [1afdf257bc] SAML2.0 - IdP.SSOService: IdP initiated authentication: '
https://app.staging.goodpractice.net'
> Jan 27 16:41:33 simplesamlphp INFO [83fe050075] SAML2.0 - IdP.SSOService: IdP initiated authentication: '
https://app.staging.goodpractice.net'
> Jan 27 16:42:33 simplesamlphp INFO [15607e1c63] SAML2.0 - IdP.SSOService: IdP initiated authentication: '
https://app.staging.goodpractice.net'
> Jan 27 16:43:16 simplesamlphp INFO [6149e9a67f] SAML2.0 - IdP.SSOService: IdP initiated authentication: '
https://app.staging.goodpractice.net'
> So the question remains, why is there no InResponseTo attribute in the response when all six of the requests from SP have an ID attribute?
Because 4 out of 6 requests are not replied to, and instead, an IdP-initiated authentication is performed, where no InResponseTo attribute can be available.
Now, once we know why there’s no InResponseTo attribute in 4 out of 6 SAML responses, what we need to find out is why 4 of 6 requests are failing and SimpleSAMLphp is resorting to IdP-initiated authentication. In the example I just used, this happened right after a debug message saying it was trying to load the sate with ID “_94c513cdb4dac3930fd823d13485954814937872c6”. SimpleSAMLphp redirects to the IdP-initiated authentication when it fails to load the state, meaning at that point the state was missing for some reason.
Additionally, I noted in the example every time the "track ID” changed. I did this because the "track ID” should NEVER change, unless the session is lost. The "track ID” is tied to the session, and the session is kept ALWAYS, surviving authentication and logout, so the "track ID” must survive also. However, you can see lots of changes of the "track ID” in your log, which makes sense if you are removing the session cookies, but not in the middle of an authentication flow, as we have seen it happening.
This indicates that you are having issues with your sessions. Given that you are using external authentication with its own session management, it looks pretty clear that something in the external authentication mechanism is breaking the SimpleSAMLphp session. I would recommend you to install memcache and change your SimpleSAMLphp configuration to use it as the session backend. If your problems disappear, my diagnose will be confirmed.