全部产品
Search
文档中心

访问控制:使用Shibboleth进行角色SSO的示例

更新时间:Sep 17, 2025

本文提供一个以Shibboleth与阿里云进行角色SSO的示例,帮助您理解企业IdP与阿里云进行角色SSO的端到端配置流程。

准备工作

  1. 安装Shibboleth、Tomcat和LDAP Server。

  2. 配置LDAP Server。

    为了更好地演示示例,在LDAP中添加一个管理员账号,DN为uid=admin,ou=system,密码为secret

    在LDAP中添加一个测试账号,DN为cn=Test User,ou=users,dc=wimpi,dc=net,密码为secret,具体信息如下图所示。

    image.png

    用户信息字段:

    • mail:对应阿里云的RAM用户登录名称。

    • memberof:对应于阿里云的RAM角色名称。

    • samaccountname:用于配置登录Shibboleth的用户名。

    • userpassword:登录的密码。

  3. 配置Shibboleth连接LDAP Server。

    修改/opt/shibboleth-idp/conf/ldap.properties文件的以下数据:

    # LDAP认证模式 idp.authn.LDAP.authenticator = bindSearchAuthenticator # LDAP的地址 idp.authn.LDAP.ldapURL = ldaps://[LDAP服务地址]:389 # 禁用TSL和SSL idp.authn.LDAP.useStartTLS = false idp.authn.LDAP.useSSL = false # 基本搜索目录 idp.authn.LDAP.baseDN = dc=wimpi,dc=net idp.authn.LDAP.subtreeSearch = true # 登录匹配规则,samaccountname是用户数据中的字段,用于登录LDAP。 idp.authn.LDAP.userFilter= (samaccountname={user}) # admin账户和密码 idp.authn.LDAP.bindDN = uid=admin,ou=system idp.authn.LDAP.bindDNCredential = secret idp.attribute.resolver.LDAP.searchFilter =(samaccountname=$resolutionContext.principal)
说明

本文中涉及的Shibboleth配置部分属于建议,仅用于帮助理解阿里云SSO登录的端到端配置流程,阿里云不提供Shibboleth配置的咨询服务。

步骤一:在阿里云获取SAML服务提供商元数据

  1. 使用RAM管理员登录RAM控制台

  2. 在左侧导航栏,选择集成管理 > SSO管理

  3. 角色SSO页签,单击SAML页签,复制阿里云SAML服务提供商元数据URL。

  4. 在新的浏览器窗口中打开复制的链接,将元数据XML文件另存到/opt/shibboleth-idp/metadata/aliyun-ram-role-metadata.xml

    说明

    元数据XML文件保存了阿里云作为一个SAML服务提供商的访问信息。您需要记录XML文件中EntityDescriptor元素的entityID属性值,以便后续在Shibboleth的配置中使用。

步骤二:将阿里云注册到Shibboleth

配置/opt/shibboleth-idp/conf/metadata-providers.xml,指定步骤一:在阿里云获取SAML服务提供商元数据获取的元数据文件,将阿里云注册到Shibboleth。

<!-- <MetadataProvider id="LocalMetadata" xsi:type="FilesystemMetadataProvider" metadataFile="PATH_TO_YOUR_METADATA"/> --> <!-- 找到上方注释代码,替换为下方代码 --> <MetadataProvider id="AliyunMetadata" xsi:type="FilesystemMetadataProvider" metadataFile="%{idp.home}/metadata/aliyun-ram-role-metadata.xml"/>

步骤三:在Shibboleth获取SAML IdP元数据

  1. 重启Tomcat,使前面的配置生效。

  2. 访问https:///<您的服务器地址>/idp/shibboleth,将元数据文件保存到本地。

步骤四:在阿里云创建SAML身份提供商

  1. 使用阿里云账号登录RAM控制台

  2. 在左侧导航栏,选择集成管理>SSO管理

  3. 角色SSO页签,单击SAML页签,然后单击创建身份提供商

  4. 创建身份提供商页面,输入身份提供商名称(shibboleth-provider)和备注

  5. 元数据文档区域,单击上传元数据,上传从步骤三:在Shibboleth获取SAML IdP元数据获取的IdP元数据。

  6. 单击创建身份提供商

查看新创建的身份提供商详情,记录其ARN,方便您后续使用。

步骤五:在阿里云创建RAM角色

  1. 在RAM控制台的左侧导航栏,选择身份管理 > 角色

  2. 角色页面,单击创建角色

  3. 创建角色页面的右上角,单击切换编辑器

  4. 在编辑器中指定具体的SAML身份提供商。

    编辑器支持可视化编辑和脚本编辑两种模式,您可以任选其一。以可视化编辑模式为例,您需要在主体中指定从步骤四:在阿里云创建SAML身份提供商中创建的身份提供商(shibboleth-provider),身份提供商类型选择SAML

  5. 在编辑器中设置限制条件saml:recipient,取值为https://signin.alibabacloud.com/saml-role/sso

  6. 创建角色对话框,输入角色名称(worker),然后单击确定

查看新创建的RAM角色详情,记录其ARN,方便您后续使用。

步骤六:配置Shibboleth返回的用户属性

  1. 修改/opt/shibboleth/conf/services.xml

    原版使用的是attribute-resolver.xml配置文件,包含的配置信息不够,需要启动完整版的配置,将其替换为attribute-resolver-full.xml

    <value>%{idp.home}/conf/attribute-resolver.xml</value> <!-- 找到上方代码,替换为下方代码 --> <value>%{idp.home}/conf/attribute-resolver-full.xml</value>
  2. 修改/opt/shibboleth/conf/attribute-resolver-full.xml

    1. 在该文件中配置用户信息中返回的属性。本示例中选择mail字段和memberof作为返回属性。

      其中,memberof属性的idrole,代表用户的角色。ReturnValue标签的值为<角色ARN除了角色名(worker)的部分+'$1'>,<服务提供商ARN><服务提供商ARN>步骤四:在阿里云创建SAML身份提供商中获取,角色ARN步骤五:在阿里云创建RAM角色中获取。

      说明

      角色名使用$1代替是为了适配多个角色身份,可以通过调整用户信息中的memberof字段调整用户的角色。

      注意该memberof属性是自行添加的用户属性,非内部属性。您也可以修改为其他能表明用户角色的属性值。

      <!-- ========================================== --> <!-- Attribute Definitions --> <!-- ========================================== --> <!-- Schema: Core schema attributes--> <!-- 找到上方注释代码,在后面加入下方代码 --> <AttributeDefinition xsi:type="Simple" id="mail"> <InputDataConnector ref="myLDAP" attributeNames="mail" /> <AttributeEncoder xsi:type="SAML1String" name="urn:mace:dir:attribute-def:mail" encodeType="false" /> <AttributeEncoder xsi:type="SAML2String" name="https://www.aliyun.com/SAML-Role/Attributes/RoleSessionName" friendlyName="mail" encodeType="false" /> </AttributeDefinition> <AttributeDefinition xsi:type="Mapped" id="role"> <InputDataConnector ref="myLDAP" attributeNames="memberof" /> <AttributeEncoder xsi:type="SAML1String" name="urn:mace:dir:attribute-def:role" encodeType="false" /> <AttributeEncoder xsi:type="SAML2String" name="https://www.aliyun.com/SAML-Role/Attributes/Role" friendlyName="role" encodeType="false" /> <ValueMap> <ReturnValue>acs:ram::114*******71701:role/$1,acs:ram::114*******71701:saml-provider/shibboleth-provider</ReturnValue> <SourceValue>(.+)</SourceValue> </ValueMap> </AttributeDefinition>
    2. 在该文件中读取/opt/shibboleth/conf/ldap.properties中配置的信息,进行LDAP连接的创建。

      <!-- 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}"	...省略...	</DataConnector> --> <!-- 找到上方示例代码,将其替换为下方代码 --> <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}" connectTimeout="%{idp.attribute.resolver.LDAP.connectTimeout}" responseTimeout="%{idp.attribute.resolver.LDAP.responseTimeout}">	<FilterTemplate>	<![CDATA[	%{idp.attribute.resolver.LDAP.searchFilter}	]]>	</FilterTemplate> </DataConnector>
  3. 修改/opt/shibboleth/conf/attribute-filter.xml,添加属性过滤器。

    PolicyRequirementRule标签中的value属性替换为步骤一:在阿里云获取SAML服务提供商元数据中的阿里云entityID

    <AttributeFilterPolicyGroup id="ShibbolethFilterPolicy"	xmlns="urn:mace:shibboleth:2.0:afp"	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"	xsi:schemaLocation="urn:mace:shibboleth:2.0:afp http://shibboleth.net/schema/idp/shibboleth-afp.xsd"> <!-- 找到上方代码,在后面加入下方代码 --> <AttributeFilterPolicy id="aliyun">	<PolicyRequirementRule xsi:type="Requester" value="[entityID]" />	<AttributeRule attributeID="mail">	<PermitValueRule xsi:type="ANY" />	</AttributeRule>	<AttributeRule attributeID="role">	<PermitValueRule xsi:type="ANY" />	</AttributeRule> </AttributeFilterPolicy>

步骤七:配置SAML响应的NameID

  1. 修改/opt/shibboleth/conf/relying-party.xml,为阿里云建立NameID的配置。

    bean标签中的relyingPartyIds属性替换为步骤一:在阿里云获取SAML服务提供商元数据中的阿里云entityID

    <!--	Override example that identifies a single RP by name and configures it	for SAML 2 SSO without encryption. This is a common "vendor" scenario. --> <!-- <bean parent="RelyingPartyByName" c:relyingPartyIds="https://sp.example.org">	<property name="profileConfigurations">	<list>	<bean parent="SAML2.SSO" p:encryptAssertions="false" />	</list>	</property> </bean> --> <!-- 找到上方注释代码,替换为下方代码 --> <bean parent="RelyingPartyByName" c:relyingPartyIds="[entityID]"> <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>
  2. 修改/opt/shibboleth/conf/saml-nameid.xml,配置NameID的生成方式。

    <!-- 找到下方两处代码,将其注释取消,使之生效 --> <bean parent="shibboleth.SAML2AttributeSourcedGenerator" p:omitQualifiers="true" p:format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress" p:attributeSourceIds="#{ {'mail'} }" /> <bean parent="shibboleth.SAML1AttributeSourcedGenerator" p:omitQualifiers="true" p:format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress" p:attributeSourceIds="#{ {'mail'} }" />
  3. 修改/opt/shibboleth/conf/saml-nameid.properties,配置NameID的相关属性。

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

步骤八:启动Shibboleth

重启Tomcat,使前面的配置生效。

结果验证

完成上述配置后,您可以从Shibboleth发起SSO登录。

  1. 访问https://<您的服务器地址>/idp/profile/SAML2/Unsolicited/SSO?providerId=<entityID>

    链接中的<entityID>步骤一:在阿里云获取SAML服务提供商元数据中的阿里云entityID

  2. 在Shibboleth的登录界面,输入用户名和密码,单击登录

    系统将自动进行SSO登录,以角色(worker)身份登录到阿里云控制台首页。

常见问题

结果验证时如果遇到问题,您可以查看/opt/shibboleth-idp/logs/idp-process.log,通过日志分析问题原因。常见问题如下:

Shibboleth用户名密码正确,但是登录后提示异常。

查看/opt/shibboleth-idp/logs/idp-process.log中的报错信息,如果是与ValidateUsernamePassword错误有关,则重点检查IDAP的连接配置和部署情况,重点查看是否将注释去除,且不能输入多余空格。

登录后无响应,提示unable to connect to the ldap

检查ldap.propertiesattribute-resolver-full.xml文件中LDAP连接的相关配置。

登录后转跳阿里云,提示The NameID is missing

检查步骤六:配置Shibboleth返回的用户属性中是否正确将用户信息中的mail映射为属性,检查步骤七:配置SAML响应的NameIDNameID配置是否正确。

访问https://<您的服务器地址>/idp/profile/SAML2/Unsolicited/SSO?providerId=<entityID>时提示Unsupported Request

检查entityId是否配置正确。metadata文件夹下的元数据、attribute-filter.xmlrelying-party.xml三处中的entityId必须保持一致。

登录后转跳阿里云,提示Can not find SAML role attribute which is required

检查步骤六:配置Shibboleth返回的用户属性中是否正确将用户信息中的memberof映射成role,仔细校对ReturnValue标签中的值。

登录后转跳阿里云,提示Can not find SAML role session name attribute which is required

检查步骤六:配置Shibboleth返回的用户属性mail属性的name是否为https://www.aliyun.com/SAML-Role/Attributes/RoleSessionName。部分用户可能在尝试用户SSO后直接在原配置上修改为角色SSO,容易忘记修改name的值。

登录后转跳阿里云,提示The response signature is invalid

重新将Shibboleth的元数据文件上传到阿里云。