如何使用证书获取keycloak的saml元数据作为sp

how to get saml-metadata for keycloak as sp with certificate

我已经设置了一个 keycloak 服务器。然后我创建了一个领域,在该领域中创建了一个 SAML-IDP。所以我的 keycloak 服务器是一个使用 IDP 进行身份验证的 SAML-SP。 IDP 需要 SAML 元数据。我可以在 IDP 条目的 "export" 选项卡中的 keycloak 管理控制台中导出它。我也可以在这里下载:

http[s]://{host:port}/auth/realms/{realm-name}/broker/{broker-alias}/endpoint/descriptor

但元数据不包含 X509 证书:

<EntityDescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata" entityID="https://keycloak.sample/auth/realms/nodejs-example">
    <SPSSODescriptor AuthnRequestsSigned="false" WantAssertionsSigned="false"
            protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol urn:oasis:names:tc:SAML:1.1:protocol http://schemas.xmlsoap.org/ws/2003/07/secext">
        <SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="https://keycloak.sample/auth/realms/nodejs-example/broker/idp.devel/endpoint"/>
        <NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:persistent
        </NameIDFormat>
        <AssertionConsumerService
                Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="https://keycloak.sample/auth/realms/nodejs-example/broker/idp.devel/endpoint"
                index="1" isDefault="true" />
    </SPSSODescriptor>
</EntityDescriptor>

如何将一个放入元数据?

问题: SAML SP 元数据不包含 X509 证书。

如何将一个放入元数据?

回答:

Keycloak 的 SAML SP 元数据 NOT 包含 X509 证书是可以的,如果 (I) Keycloak SAML SP NOT 需要签署 SAML 身份验证请求或 (II) SAML IdP NOT 需要为 Keycloak SAML SP 加密 SAML 断言。

(1) SAML SP 元数据不一定 包含 X509 证书。也就是说,X509 证书对于 SAML SP 元数据不是强制性的。

例如,Google G Suite 和 ComponentSpace 都提供没有 X509 证书的 SAML SP 元数据。

(I) Google G Suite does NOT contain a X509 certificate. I uploaded SAML SP metadata of Google G Suite into Shibboleth SAML IdP server 的 SAML SP 元数据,然后通过 Shibboleth SAML IdP 提供的 SAML 身份验证成功登录 Google G Suite。

为了让您参考没有 X509 证书的 SAML SP 元数据,我在 GitHub 存储库中创建了 the 14th commit to upload the Google G Suite SAML SP metadata and corresponding SAML configuration to How to build and run Shibboleth SAML IdP and SP using Docker container

(二)ComponentSpace开发提供the guidance on how to generates SAML service provider metadata with no certificates.

未指定签名或加密证书,因此生成的元数据中未包含任何证书。

ExportMetadata.exe
SAML configuration file to export [saml.config]:
X.509 signature certificate file [None]:
X.509 encryption certificate file [None]:
Assertion Consumer Service URL [None]: http://localhost:51901/SAML/AssertionConsumerService.aspx
Single Logout Service URL [None]:
Partner Identity Provider Name [None]:
SAML metadata file [metadata.xml]:

(2) 如果 SAML SP 需要签署 SAML 身份验证请求或 SAML IdP 需要加密 SAML 断言,SAML SP 元数据需要包含 X509 证书。

(3) 与 SAML SP 完全不同,SAML IdP 元数据应包含至少一个用于签署 SAML 的 X509 证书 response/assertion.

Galdor提供的后续回答

如果您需要 SAML IdP 为 Keycloak SAML SP 加密 SAML 断言

(I) 将 IDP-Configuration 中的 "Want Assertions Encrypted" 设置为 ON,X509Certificate 条目立即出现在 Export 中标签。

(二)下载Keycloak的SAML SP元数据,其中应包含X509证书进行加密。

根据 winstonhongs 的回答,keycloak 服务器在此配置中不需要证书。 我将 IDP 配置中的 "Want Assertions Encrypted" 设置为 ON,X509Certificate 条目立即出现在“导出”选项卡中。

您现在可以在 KC 13.0.1 中使用您的领域密钥对发送您的元数据。 在此处查看更多信息:https://www.keycloak.org/docs/latest/server_admin/#saml-v2-0-identity-providers

签署服务提供商元数据 - 如果为真,它将使用领域的密钥对签署 SAML 服务提供商元数据描述符。