简体   繁体   English

从公共访问中隐藏 Keycloak 管理控制台

[英]Hide Keycloak admin console from public access

We are considering using Keycloak for our public REST APIs (mostly Spring boot apps) to authorize and authenticate our users.我们正在考虑为我们的公共 REST API(主要是 Spring 启动应用程序)使用 Keycloak 来授权和验证我们的用户。

In order not to make the admin UI publicly available we want to restrict it.为了不让管理 UI 公开可用,我们想对其进行限制。 Our idea is to create two instances but access the same database.我们的想法是创建两个实例但访问同一个数据库。

  1. the public Keycloak instance, which only publishes what is necessary eg the admin path is not accessible.公共 Keycloak 实例,它只发布必要的内容,例如管理路径不可访问。 In this instance only paths should be accessible like these recommended here: https://www.keycloak.org/server/reverseproxy#_exposed_path_recommendations .在这种情况下,只能访问此处推荐的路径: https://www.keycloak.org/server/reverseproxy#_exposed_path_recommendations

  2. a private Keycloak instance, which is only accessible from the internal.network, but offers the admin UI (console).私有 Keycloak 实例,只能从 internal.network 访问,但提供管理 UI(控制台)。 With which one can then manage the users/permissions.然后可以用它来管理用户/权限。

Is this a valid solution to have two different instances but with the same database or are there other best practices here to not publish the admin ui/paths?这是具有两个不同实例但具有相同数据库的有效解决方案,还是这里有其他最佳实践不发布管理用户界面/路径?

Yes, this is definitely a common setup.是的,这绝对是一个常见的设置。 Depending on your requirements, it is always recommended to have more than one instance of Keycloak on the same database, for availability reasons.根据您的要求,出于可用性原因,始终建议在同一数据库上拥有多个 Keycloak 实例。 Keycloak shares some in memory data (like sessions) in an Infinispan Cache, which is shared between one or more instances of Keycloak (generally referred to as a cluster) Keycloak在一个Infinispan Cache中共享memory中的一些数据(如session),在一个或多个Keycloak实例(一般称为集群)之间共享

You would then use a load balancer (like haproxy, nginx, apache, the choices are practically endless) and configure it to send requests to the actual Keycloak instances.然后,您将使用负载均衡器(如 haproxy、nginx、apache,选择实际上是无穷无尽的)并将其配置为将请求发送到实际的 Keycloak 实例。

A possible setup could be the following: Using 4 Keycloak instances on 4 servers:可能的设置如下:在 4 个服务器上使用 4 个 Keycloak 实例:

  • public-keycloak-1.internal.example.com public-keycloak-1.internal.example.com
  • public-keycloak-2.internal.example.com public-keycloak-2.internal.example.com
  • private-keycloak-1.internal.example.com私钥斗篷-1.internal.example.com
  • private-keycloak-2.internal.example.com private-keycloak-2.internal.example.com

You can then add 2 load balancers:然后您可以添加 2 个负载均衡器:

  • keycloak.example.com (sending requests to public-keycloak-*) keycloak.example.com(发送请求到 public-keycloak-*)
  • keycloak.internal.example.com (sending requests to private-keycloak-*) keycloak.internal.example.com(向private-keycloak-*发送请求)

In this example, keycloak.internal.example.com would be the instance you connect to, in order to perform administrative tasks in Keycloak via the Admin Console, or the Admin API, and keycloak.example.com would be the host that you use for Auth{n,z} for your applications.在此示例中,keycloak.internal.example.com 将是您连接到的实例,以便通过管理控制台或 Admin API 在 Keycloak 中执行管理任务,而 keycloak.example.com 将是您使用的主机用于您的应用程序的 Auth{n,z}。

Restricting access to the Admin API and Admin Console can be done at the load balancer level (restricting requests to those paths), but since Keycloak 20, it is also possible to completely disable the Admin API and Admin console.可以在负载均衡器级别限制对 Admin API 和 Admin Console 的访问(限制对这些路径的请求),但是从 Keycloak 20 开始,也可以完全禁用 Admin API 和 Admin Console。 This is done through the disabling the respective features seen in the documentation .这是通过禁用文档中显示的相应功能来完成的。 That way, you can disable the features "admin-api", "admin" and "admin2".这样,您就可以禁用功能“admin-api”、“admin”和“admin2”。 If you do this on the public-keycloak-* instances, then requests to the public load balancer can never end up touching the Admin API or Console, because Keycloak is configured to simply not serve those requests in the first place.如果您在 public-keycloak-* 实例上执行此操作,那么对公共负载均衡器的请求永远不会触及 Admin API 或控制台,因为 Keycloak 配置为根本不首先处理这些请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM