~roadmr/canonical-identity-provider/non-drifting-totp

« back to all changes in this revision

Viewing changes to src/ubuntu_sso_saml/processors.py

Actually honor SAML AuthnRequests' NameIDPolicy format.

This was done to accommodate SPs (Bomgar) which request persistent names,
indicating so in their AuthnRequest. SSO usually ignores this and always
sends "email"-policy names, which most SPs handle fine but Bomgar fails with.

The fully-correct thing to do would be to always honor the AuthnRequest and
support most/all of the SAML-specified policies, but that'd be a large effort
and risks changing semantics for other SPs, which would prevent people from
logging in, which would be bad.

Another quirk is that, while we respond saying we're giving a persistent
identifier, our identifier (the e-mail address) does NOT actually conform
to persistent semantics per SAML spec's section 8.3; we are sending the
same value (the e-mail address), just saying it's "persistent" as requested
by the SP. We do have a persistent identifier (the OpenID) but we can't send that
because then it gets sent as the username, identifier, and email address. Again,
support for this can be added to our django-saml2-idp fork but it's more work
for something that at the moment is required only by one SP.

Due do the above, in order to support Bomgar (and possibly other SPs) in a more
selective way, we only honor a non-email NameIDPolicy if:
    - the SP is configured to honor this (a boolean in the SPConfig)
    - the requested NameID policy is "persistent".

This allows us to switch this on only for very specific SPs for which we
have more control and fully understand the consequences of "lying" with our
"persistent" support.

In all other cases, we continue ignoring/overriding this and always sending
our response with "email" policy.

(As a rant, the best thing to do would be to trash our hacky SAML library
and integrate OneLogin's SAML library which is fully standards-compliant,
which is however a huge undertaking we would have to consider and prioritize)


Merged from https://code.launchpad.net/~roadmr/canonical-identity-provider/support-saml-persistent-nameid-policy-format/+merge/361982

Show diffs side-by-side

added added

removed removed

Lines of Context:
338
338
        params['PROVIDER_NAME'] = request.get('providername', '')
339
339
        self._request_params = params
340
340
 
 
341
        # Use a different nameid format if the spconfig allows honoring it
 
342
        # and the requested format is supported (currently only "email" and
 
343
        # "persistent").
 
344
        sp_config = get_config_from_processor(self)
 
345
        if (sp_config is not None and
 
346
                sp_config.honor_authnrequest_nameidpolicy_format):
 
347
            nameidpolicy = request.findChild('samlp:nameidpolicy')
 
348
            if nameidpolicy is not None:
 
349
                requested_format = nameidpolicy.get('format', 'email')
 
350
                requested_format = requested_format.split(":")[-1]
 
351
                if requested_format not in ("email", "persistent"):
 
352
                    requested_format = "email"
 
353
                template = 'urn:oasis:names:tc:SAML:2.0:nameid-format:{fmt}'
 
354
                self._subject_format = template.format(fmt=requested_format)
 
355
 
341
356
    def _determine_audience(self):
342
357
        self._audience = super(CanonicalProcessor, self)._determine_audience()
343
358