Skip to content

SAML2 authentication with MS Azure AD intermittently fails with error AADSTS7500529 #5548

Closed

Description

@kohrar
ISSUE TYPE
  • Bug Report
COMPONENT NAME
SAML/SSO
CLOUDSTACK VERSION
4.15.2
CONFIGURATION

Enabled SAML plugin and configured it to authenticate against Azure AD.

STEPS TO REPRODUCE

SAML authentication fails intermittently depending on the SAML request ID that is generated. Depending on your luck, you might get a random request ID that begins with something between A-Z. In such cases, the authentication request goes through as expected. On the chance that the generated number begins with 0-9, the authentication request fails with an error similar to:

AADSTS7500529: The value '692rv91k6dgmdas33vr3b2keahr4lqjv' is not a valid SAML ID. The ID must not begin with a number.

As per Azure AD's documentation, an acceptable request ID must not start with a number.

ID must not begin with a number, so a common strategy is to prepend a string like "id" to the string representation of a GUID. For example, id6c1c178c166d486687be4aaf5e482730 is a valid ID.
https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/active-directory/develop/single-sign-on-saml-protocol.md

The CloudStack implementation generates the random ID string with the following method in SAMLUtils and has no ability to prefix the SAML ID string as recommended by Azure AD's documentation.

100 public class SAMLUtils {
101     public static final Logger s_logger = Logger.getLogger(SAMLUtils.class);
102
103     public static String generateSecureRandomId() {
104         return new BigInteger(160, new SecureRandom()).toString(32);
105     }
EXPECTED RESULTS

Successful authentication with SAML and Azure AD.

ACTUAL RESULTS

Intermittent authentication failure with SAML and Azure AD.

Activity

  1. yadvr commented on Oct 5, 2021

    @yadvr
    Member

    Thanks for reporting @kohrar - the current SAML auth plugin is only tested against Shibboleth and keycloak, I've heard MS AD as well. I quickly checked some forums and https://docs.microsoft.com/en-us/azure/active-directory/develop/single-sign-on-saml-protocol and it seems a limitation of Microsoft's SAML spec/implementation only (not a bug in CloudStack or opensaml library).

  2. kohrar commented on Oct 5, 2021

    @kohrar
    ContributorAuthor

    Yes, the limitation is on Microsoft's side where the SAML request ID cannot start with a digit. While this isn't strictly a bug in CloudStack, it also means that Azure AD isn't completely supported with the current implementation. The documentation does suggest prepending the request ID with a string such as 'id'.

    Would an appropriate 'fix' be to add an optional prefix as a global setting to CoudStack which will then be prepended to the generated request IDs? Or is there a better solution that you can think of?

    I'm currently setting up a build environment for CloudStack so I can hopefully try a few things. Thanks!

  3. yadvr commented on Oct 6, 2021

    @yadvr
    Member

    @kohrar was this done for testing/learning sake or are you trying to integrate CloudStack SAML based SSO with Azure AD? I suppose if this is a requirement, we can look into generating random string IDs that start with an alphabet (a-zA-Z).

  4. kohrar commented on Oct 6, 2021

    @kohrar
    ContributorAuthor

    I'm still testing out and assessing CloudStack but I'd like to use CloudStack in our University research environment to allow some of our researchers to spin up VMs as needed. As such, we'd like to leverage our existing SSO infrastructure which is currently hosted on Azure AD.

    I've got a build environment set up and modified the code to prepend "id" to the random request ID. I can confirm that works as a fix and it's indeed the starting digits in the request IDs that are the issue.

    Would you be against the idea of having something like a "saml2.sp.prepend" config key that an admin could specify in global settings?

  5. yadvr commented on Oct 11, 2021

    @yadvr
    Member

    @kohrar yes that might work, or even changing the default random string generator to generate first character as an alphabet than number.

  6. added this to the 4.17.0.0 milestone on Mar 17, 2022
  7. moved this from Todo to Ready For Review in Apache CloudStack 4.17.0on Mar 25, 2022
  8. Repository owner moved this from Ready For Review to Done in Apache CloudStack 4.17.0on Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions