cassandra 2.2 启用用户认证
cassandra默认是没有启用用户认证的,为了提高安全性可以开启用户认证
更改配置文件cassandra.yaml的认证选项
1 | authenticator: PasswordAuthenticator |
重启cassandra节点
增加system_auth的复制因子
使用内置超级用户cassandra/cassandra登陆节点,system_auth的replication factor一般每个数据中心设置为3即可,如果节点小于3,则设置实际的节点数。
1 | $ cqlsh -u cassandra -p cassandra host |
The system_auth keyspace uses a QUORUM consistency level when checking authentication for the default cassandra user. For all other users created, superuser or otherwise, a LOCAL_ONE consistency level is used for authenticating.
当认证默认用户cassandra时,system_auth使用QUORUM一致性级别,也就是通过认证的节点要达到法定数的才能登陆集群。对于其他用户,认证时使用LOCAL_ONE一致性级别,也就是只要有一个节点认证通过就可以登陆集群。
当使用cassandra用户登陆不满足一致性级别时,会被拒绝登陆集群:
1 | Connection error: ('Unable to connect to any servers', {'192.168.0.6': AuthenticationFailed('Failed to authenticate to 192.168.0.6: Error from server: code=0100 [Bad credentials] message="Unable to perform authentication: Cannot achieve consistency level QUORUM"',)}) |
Quorum法定数一致性计算公式如下Quorum = (sum_of_replication_factors / 2) + 1
为相应keyspace的复制因子总数除以2再加1
使system_auth的改变扩散到集群其他节点
1 | $ nodetool repair system_auth |
创建新的超级用户
1 | $ cqlsh> CREATE ROLE <new_super_user> WITH PASSWORD = '<some_secure_password>' |
用新的超级用户登录
1 | $ cqlsh -u <new_super_user> -p <some_secure_password> host |
更改默认用户
默认超级管理员用户cassandra是无法删除的,可以为其设置极其复杂的密码,并将其设置为非超级用户来提高系统安全性
1 | cqlsh> ALTER ROLE cassandra WITH PASSWORD='SomeNonsenseThatNoOneWillThinkOf' |
其他节点依次启用密码认证
References: