防止未经授权的成员加入Hazelcast集群

时间:2019-05-20 04:03:42

标签: java hazelcast

我们正在更改应用程序之一以使用Hazelcast 3.11 Community Edition,并在运行于少数主机上的多个JVM之间进行一些锁定。 我们按照以下语法配置集群:

public class HazelcastBuilder {
    private final String name;
    private final String password;
    private final String members;
    private final String hostName;
    private final String applicationName;

    public HazelcastInstance getHazelcastInstance() {
        Config hazelcastConfig = new Config();
        GroupConfig groupConfig = new GroupConfig(name, password);
        hazelcastConfig.setGroupConfig(groupConfig);

        TcpIpConfig tcpIpConfig = new TcpIpConfig();
        tcpIpConfig.setEnabled(true);
        for (String member : members.split(",")) {
            tcpIpConfig.addMember(member.trim());
        }

        hazelcastConfig.getNetworkConfig().getJoin().setTcpIpConfig(tcpIpConfig);
        // By default the multicast config is enabled. Disable it here.
        hazelcastConfig.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
        String instanceName = applicationName + "-" + hostName;
        hazelcastConfig.setInstanceName(instanceName);

        logger.info("Creating hazelcast instance: " + instanceName);
        return Hazelcast.getOrCreateHazelcastInstance(hazelcastConfig);
    }
}

一切正常,可以正确创建群集并按预期工作。

但是,我创建了一个单元测试,并配置了一个与应用程序使用相同名称的本地集群,然后将开发人员计算机添加到其中。一切正常,我的本地主机没有任何问题地加入了应用程序集群。

当然,这种事情在生产环境中是不可接受的,这是我的问题:

给出了可以运行我们的应用程序的主机名列表,这是防止未经授权的成员加入给定的hazelcast群集的最佳方法。

预先感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

如果要搜索安全功能,则应使用Hazelcast Enterprise版本。检查功能列表:

如果只需要防止任意计算机连接到群集,则开源版本中有几个选项:

  • 为每个集群使用唯一的组名;
  • 作为附加保护级别,您可以在配置中定义验证令牌-只需设置 <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity" android:background="@color/backPrimary" android:layout_width="match_parent" android:layout_height="match_parent"> ... content ... <com.google.android.material.bottomappbar.BottomAppBar android:id="@+id/bar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" style="@style/Widget.MaterialComponents.BottomAppBar" app:navigationIcon="@drawable/ic_burger_menu" app:fabAlignmentMode="end" /> <com.google.android.material.floatingactionbutton.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/start_project_day" app:srcCompat="@drawable/ic_next" app:layout_anchor="@id/bar" /> </androidx.coordinatorlayout.widget.CoordinatorLayout> Hazelcast属性(或系统属性)-有关详细信息,请查看reference manual
  • 指定应使用的网络接口(doc),并通过将hazelcast.application.validation.token属性设置为hazelcast.socket.bind.any来禁用对所有本地接口的绑定。通常,您的生产群集在受信任的LAN环境中运行,因此您希望使其只能在该LAN内访问。
  • 多播发现机制(doc)还添加了false配置,可以为您提供帮助。您正在使用TCP发现,因此它不适用于您的情况。

最后说明:在Hazelcast开源版本中未选中组密码字段!

相关问题