SSO场景系列:实现Shibboleth+Ldap到阿里云的单点登录

Shibboleth简介

Shibboleth是一个基于标准的,实现组织内部或跨组织的网页单点登录的开源软件包。它允许站点为处于私有保护方式下的受保护的在线资源做出被通知的认证决定。

Shibboleth软件工具广泛使用联合的身份标准,主要是OASIS安全声称标记语言(SAML),来提供一个联合单点登录和属性交换框架。一个用户用他的组织的证书认证,组织(或IdP)传送最少的必要的身份信息给SP实现认证决定。Shibboleth也提供扩展的隐私功能,允许一个用户和他们的主站点来控制释放给每一个应用的属性。

Shibboleth项目作为一个Internet2中间件活动启动于2000年,这年晚些时候该项目和OASIS SAML工作组的工作相联系。Shibboleth1.0 于2003年发布,并快速被全世界的研究和教育机构使用。随着2005年SAML2.0的发布,2006年Shibboleth2.0也发布,SAML标准升级到包含所有的多边,由Shibboleth首创的元数据驱动方法。

Shibboleth作为开源软件开发,在Apache 软件许可证下发布。关于个别部件的更多信息可以在产品页面看到。

配置 Shibboleth

可将 Shibboleth 配置为 阿里云 中企业登录的身份提供者 (IDP)。配置过程包含两个主要步骤:将企业级 IDP 注册到 阿里云,以及将 阿里云 注册到企业级 IDP。

前提条件

当以Shibboleth 配置为阿里云中企业登录的身份提供者(IDP)时,登陆者身份需要在阿里云存在,例如如果以abc@testdomain.com身份登录,那么在阿里云上必须绑定testdomain.com的域名并验证,并且存在abc这个用户。

阿里云需要的信息

当用户使用企业登录帐户进行登录时,阿里云 需要从 IDP 处接收某些属性信息。NameID 属性为强制属性,并且必须由您的 IDP 在 SAML 响应中发送,才能使 阿里云 的联合身份验证起作用。由于 阿里云 使用 NameID 的值唯一标识指定用户,因此建议使用常量值来唯一标识用户。

注册Shibboleth为阿里云IDP

将%{idp.home}/metadata/idp-metadata.xml上传到阿里云。操作步骤:进入RAM控制台,选择人员管理 -> 设置-> 高级设置 -> SSO登录设置,在“编辑SSO登录设置”中上传idp-metadata.xml文件,并开启SSO登录。

将阿里云注册到Shibboleth

1.将阿里云配置为Shibboleth的依赖方:

配置metadata-providers.xml

<MetadataProvider id="AliyunMetadata"  xsi:type="FilesystemMetadataProvider" metadataFile="%{idp.home}/metadata/aliyun-metadata.xml"/>

先下载阿里云账号的SP Metadata XML文档:进入RAM控制台 > 人员管理 > 设置 > 高级设置,在SSO 登录设置下可以查看当前云账号的SAML 服务提供方元数据 URL。从该URL下载内容并保存为aliyun-metadata.xml,并拷贝到%{idp.home}/metadata/aliyun-metadata.xml。

2.配置用户身份验证

idp.authn.LDAP.authenticator = bindSearchAuthenticator

idp.authn.LDAP.ldapURL = ldaps://myldap.example.org:port

idp.authn.LDAP.baseDN = dc=example,dc=org
idp.authn.LDAP.subtreeSearch = true

idp.authn.LDAP.userFilter= (sAMAccountName={user})
idp.attribute.resolver.LDAP.searchFilter =(sAMAccountName=$resolutionContext.principal)
idp.authn.LDAP.bindDN = cn=readonlyuser,cn=Users,dc=example,dc=org

idp.authn.LDAP.bindDNCredential = userpassword

3.配置将由Shibboleth返回的用户属性
a)

vim /opt/shibboleth/conf/services.xml
把
<value>%{idp.home}/conf/attribute-resolver.xml</value>
修改为
<value>%{idp.home}/conf/attribute-resolver-full.xml</value>

b)attribute-resolver-full.xml
增加ldap解析NameID映射过来的属性,例如以mail为NameID则增加属性

<AttributeDefinition xsi:type="Simple" id="mail" sourceAttributeID="userPrincipalName">
        <Dependency ref="myLDAP" />
        <AttributeEncoder xsi:type="SAML1String" name="urn:mace:dir:attribute-def:mail" encodeType="false" />
        <AttributeEncoder xsi:type="SAML2String" name="urn:oid:0.9.2342.19200300.100.1.3" friendlyName="mail" encodeType="false" />
    </AttributeDefinition>

修改开启ldapConnector并将StartTls证书配置关掉

 <!-- Example LDAP Connector -->
    <DataConnector id="myLDAP" xsi:type="LDAPDirectory"
        ldapURL="%{idp.attribute.resolver.LDAP.ldapURL}"
        baseDN="%{idp.attribute.resolver.LDAP.baseDN}"
        principal="%{idp.attribute.resolver.LDAP.bindDN}"
        principalCredential="%{idp.attribute.resolver.LDAP.bindDNCredential}"
        useStartTLS="%{idp.attribute.resolver.LDAP.useStartTLS:true}"
        connectTimeout="%{idp.attribute.resolver.LDAP.connectTimeout}"
        responseTimeout="%{idp.attribute.resolver.LDAP.responseTimeout}">
        <FilterTemplate>
            <![CDATA[
                %{idp.attribute.resolver.LDAP.searchFilter}
            ]]>
        </FilterTemplate>
        <!--
        <StartTLSTrustCredential id="LDAPtoIdPCredential" xsi:type="sec:X509ResourceBacked">
            <sec:Certificate>%{idp.attribute.resolver.LDAP.trustCertificates}</sec:Certificate>
        </StartTLSTrustCredential>
        -->
    </DataConnector>

c)attribute-filter.xml
增加属性过滤器

其中<account-id>换成你的云账号id
<AttributeFilterPolicy id="aliyun">
        <PolicyRequirementRule xsi:type="Requester" value="https://signin.aliyun.com/<account-id>/saml/SSO" />
                    <AttributeRule attributeID="mail">
                <PermitValueRule xsi:type="ANY" />
            </AttributeRule>
            <AttributeRule attributeID="givenName">
                <PermitValueRule xsi:type="ANY" />
            </AttributeRule>
        </AttributeFilterPolicy>

4.修改relying-party.xml

其中<account-id>换成你的云账号id
<util:list id="shibboleth.RelyingPartyOverrides">
       <!--Add Aliyun RelyintParty -->
       <bean parent="RelyingPartyByName" c:relyingPartyIds="https://signin.aliyun.com/<account-id>/saml/SSO">
           <property name="profileConfigurations">
               <list>
                   <bean parent="SAML2.SSO" p:encryptAssertions="false" p:nameIDFormatPrecedence="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress" />
               </list>
           </property>
       </bean>
       <!--Add Done -->
</util:list>

5.修改saml-nameid.xml
配置NameID产生的方式

  <util:list id="shibboleth.SAML2NameIDGenerators">      
        <bean parent="shibboleth.SAML2AttributeSourcedGenerator"
            p:omitQualifiers="true"
            p:format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
            p:attributeSourceIds="#{ {'mail'} }" />           
    </util:list>

    <!-- SAML 1 NameIdentifier Generation -->
    <util:list id="shibboleth.SAML1NameIdentifierGenerators">                                                                                                               
        <bean parent="shibboleth.SAML1AttributeSourcedGenerator"
            p:omitQualifiers="true"
            p:format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
            p:attributeSourceIds="#{ {'mail'} }" />
                    
    </util:list>

6.修改saml-nameid.properties文件

idp.persistentId.useUnfilteredAttributes = true
idp.persistentId.encoding = BASE32
idp.nameid.saml2.default = urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress

7.重新启动 Shibboleth后台程序(Linux)或者(Windows)服务

小结

到此 我们完成了Shibboleth到阿里云的打通过程,效果如下
SSO场景系列:实现Shibboleth+Ldap到阿里云的单点登录
SSO场景系列:实现Shibboleth+Ldap到阿里云的单点登录
SSO场景系列:实现Shibboleth+Ldap到阿里云的单点登录

上一篇:批处理打开SQL端口


下一篇:《NoSQL权威指南》——1.9 为什么在这些场景下SQL不能发挥作用