【问题标题】:How to setup a single SAML app for all the tenants of multi-tenant app(having different domain urls)?如何为多租户应用程序的所有租户(具有不同的域 url)设置单个 SAML 应用程序?
【发布时间】:2021-04-04 23:33:12
【问题描述】:

应用架构:

  • 我们有一个多租户设置,每个租户都有自己的 URL。
  • 每个租户都有自己的架构和配置。

问题:

我们需要一个可以与所有租户集成的单一 SAML 应用程序。

租户 URL 示例:tenant1.myapp.com、tenant2.myapp.com、tenant3.myapp.com 等

我们希望我们的所有租户都与单个 SAML 应用集成,以验证这些租户中存在的用户。

             |---------------- SAML App -----------------|
             |                     |                     |
             |                     |                     |
             |                     |                     |
          Tenant 1              Tenant 2              Tenant 3
     (tenant1.myapp.com)   (tenant2.myapp.com)   (tenant3.myapp.com)

通常情况下,我们可以为不同的租户提供不同的 SAML 应用程序,但这导致我们需要维护大量 SAML 应用程序,这是我们想要避免的。

我们正在尝试一些解决方案。如果任何解决方案有效,我们将在此处更新答案。同时,如果有人有任何建议,请帮助。

【问题讨论】:

    标签: security single-sign-on saml saml-2.0 idp


    【解决方案1】:

    我们已经找到了解决这个问题的方法。 在重定向到 IdP 登录页面期间,我们将租户 URL 作为请求中的 RelayState 参数发送,该参数在 IdP 到我们的 SP 的 SAML 断言请求正文中返回给我们。

    • 我们编写了一个 AWS Lambda(连同 API Gateway)来将 SAML 断言请求重新路由到所需的租户。
    • 我们使用此RelayState 参数来了解此请求来自哪个租户。
    • 我们将指向 lambda(SSO 路由器)的 API Gateway URL 配置为 SAML 应用程序中的 ACS URL。

    Lambda 的功能: 它从 SAML 断言请求正文中选择 RelayState 参数,并将请求重定向到所需的租户 URL(存在于 RelayState 中)。

    Login to the App(any Tenant) ==> Redirection to Login Page ==> (On successful login) Redirected to Lambda(SSO Router) ==> Redirected to the tenant URL(present in the RelayState)

    我们已经用 Python 编写了 Lambda。这是示例代码:

        def lambda_handler(event, context):
            body = event.get('body')
            redirect_host = body.split('RelayState=https%3A%2F%2F')[1].split('%2')[0]
            # Here the request body is urlencoded and the URL will be of the form https://tenant1.myapp.com/ - we are only picking tenant1.myapp.com from the RelayState
            redirect_url = 'https://' + redirect_host + '/saml/?acs'
            # Our SAML redirection URL is of the form https://tenant1.myapp.com/saml/?acs
            logger.info(f"Redirecting To: {redirect_url}")
            return {
                'statusCode': 307, # Status code 307 is to preserve the method by which this URL was called. Using 302 changes the method to GET whereas the SAML request comes as a POST
                'headers': {
                    'Location': redirect_url,
                    'Content-Type': 'application/x-www-form-urlencoded',
                    'Access-Control-Allow-Origin': '*',
                },
                'body': body,
            }
    

    【讨论】:

      猜你喜欢
      • 2018-04-05
      • 1970-01-01
      • 1970-01-01
      • 2012-05-11
      • 2014-02-10
      • 2011-02-27
      • 1970-01-01
      • 2016-06-08
      • 1970-01-01
      相关资源
      最近更新 更多