Contents
Cassandra authentication
Web Services supports Cassandra authentication. Authentication validates incoming user connections to the Cassandra database. Implementing Cassandra authentication requires you to do some configuration in Cassandra and in Web Services.
Configure Cassandra
The user login accounts and their passwords required for authentication are managed inside the cassandra.yaml file. In this procedure, we are going to:
- Change the authenticator option to PasswordAuthenticator. By default, the authenticator option is set to AllowAllAuthenticator.
- Increase the replication factor for the system_auth keyspace. The default replication factor is 1, which specifies only one node. Increasing this factor authentication errors if a single node fails.
- Create a superuser account. This step is optional, but highly recommended.
- Setup user accounts and grant permissions to Cassandra database objects.
Procedure
- Modify the cassandra.yaml file:
- Change the authenticator option in the cassandra.yaml to PasswordAuthenticator:
authenticator: PasswordAuthenticator
- Increase the replication factor for the system_auth keyspace to N (number of nodes).
- Change the authenticator option in the cassandra.yaml to PasswordAuthenticator:
- Restart the Cassandra client:
<client startup string> -u cassandra -p cassandra
The default superuser name and password used restart the client is stored in Cassandra.
- Start the cqlsh script using the superuser name and password:
./cqlsh -u cassandra -p cassandra
- Optional, but recommended. Configure a new superuser account:
- Create another superuser.
Do not name the superuser cassandra.
- Log in as that new superuser.
- Change the Cassandra user password.
Ensure that the password is long and complex. Once the password is set, you will not require the password again.
- Remove the cassandra user's superuser status.
- Create another superuser.
- Repeat the procedure to set up user accounts and then grant permissions to access the database objects.
Web Services configuration
To support Cassandra authentication, open the application.yaml file and provide the appropriate credentials. For example:
cassandraCluster:
thrift_port: 9160
jmx_port: 7199
keyspace: sipfs
...
userName: <super user name>
password: <super user password>
...Implementation
In CassandraClusterHA class inside the initCluster method, extend the ConnectionPoolConfigurationImpl object instance as follows:
ConnectionPoolConfigurationImpl connectionPoolConfiguration = new ConnectionPoolConfigurationImpl("myConnection")
.setPort(cassandraClusterSettings.getThriftPort())
.setMaxConnsPerHost(cassandraClusterSettings.getMaxConnectionsPerHost())
.setMaxConns(cassandraClusterSettings.getMaxConnections())
.setMaxPendingConnectionsPerHost(cassandraClusterSettings.getMaxPendingConnectionsPerHost())
.setMaxBlockedThreadsPerHost(cassandraClusterSettings.getMaxBlockedThreadsPerHost());
if (StringUtils.isNotBlank(cassandraClusterSettings.getUserName()) &&
StringUtils.isNotBlank(cassandraClusterSettings.getPassword()))
{
connectionPoolConfiguration.setAuthenticationCredentials(
new SimpleAuthenticationCredentials(cassandraClusterSettings.getUserName(), cassandraClusterSettings.getPassword()));
}