Keycloak客户端部署最佳实践

Keycloak client deployment best practice

所以我想为不同的公司部署一个客户端应用程序(java,具有 spring 安全性,如果这很重要)。 keycloak 显然会 运行 在我组织的服务器上,但客户端应用程序会 运行 在客户公司的服务器上。

  1. keycloak-client 的访问类型应该是 public 还是机密?
  2. 即client-secret 的用途是什么? (加密)?
  3. 如果公司管理员理论上可以通过反编译我给他们的客户端应用程序的 jar 来读取秘密,那么这是否是一个问题?

关于有效的重定向 URI:理想情况下,我想使用 grant-type: password,这样公司的用户将他的凭据输入公司部署的客户端应用程序的前端,然后登录到 keycloak。公司部署的客户端应用程序可能只能从公司内部网访问。

  1. 对于这种情况,重定向 URI 可以是什么?
  1. Should the keycloak-client's access type be public or confidential?

RFC 6749 OAuth 2.0 specification可以读到:

confidential

  Clients capable of maintaining the confidentiality of their
  credentials (e.g., client implemented on a secure server with
  restricted access to the client credentials), or capable of secure
  client authentication using other means.

public

  Clients incapable of maintaining the confidentiality of their
  credentials (e.g., clients executing on the device used by the
  resource owner, such as an installed native application or a web
  browser-based application), and incapable of secure client

因为您使用的不是 网络浏览器应用程序或移动 phone,而是具有 安全后端的网络应用程序,你应该使用 confidential client.

i.e. what is the client-secret used for? (Encryption)?

来自 Keycloak 文档:

Confidential clients are required to provide a client secret when they exchange the temporary codes for tokens. Public clients are not required to provide this client secret.

因此,您需要client-secret,因为您选择了confidential client。使用 client-secret 以便可以正确验证从 Keycloak 请求访问令牌的应用程序。在您的情况下,来自公司的服务器(使用您的应用程序)从 Keycloak 请求访问令牌。因此,Keycloak 必须确保发出请求的服务器是 合法 .

这就是 client-secret 的目的。这类似于当您去 ATM 取款时,银行 知道 您是该资源的所有者(即, 银行帐户)如果您插入了正确的代码(即类似于客户密码)。

Is it therefore a problem if the companies admins can theoretically read the secret by decompiling the jar of the client-app I give them?

请求令牌的应用程序(公司)和授权服务器(钥匙斗篷)。所以理论上,如果公司不 介意 他们的管理员可以访问此类信息,那对您来说应该没问题。归根结底,client-secret 无论如何都必须被双方知道。减轻客户端机密泄露的潜在问题的一种方法是偶尔更改客户端机密,并将该更改传达给感兴趣的各方。

只要一家公司不能对另一家公司的客户机密进行逆向工程,您应该没问题。

What can the redirect URI be for this case?

应该是部署client-app的公司前端首页,认证成功后URL

但是请记住:

You should take extra precautions when registering valid redirect URI patterns. If you make them too general you are vulnerable to attacks. See Threat Model Mitigation chapter for more information.

(source)