Part One : How to enable authentication on a Cassandra node
- Edit conf/storage.xml
Change
<Authenticator>
org.apache.cassandra.auth.AllowAllAuthenticator
</Authenticator>
to
<Authenticator>
org.apache.cassandra.auth.SimpleAuthenticator
</Authenticator>
- Edit conf/access.properties
Append
Keyspace=Username
- Edit conf/passwd.properties
Append
Username=Password
(Password can be either clear or MD5 encrypted)
- Edit bin/cassandra.in.sh
Append :
-Dpasswd.properties=$cassandra_home/conf/passwd.properties \
-Daccess.properties=$cassandra_home/conf/access.properties"
If you previously set Password was MD5 encrypted, append :
-Dpasswd.mode=MD5
You can now restart your Cassandra node and use the command line tool `cassandra-cli’ to ensure this have been taken into consideration.
Note, in opposition to MySQL :
- Connection and keyspaces listing can be done without authentication:
./bin/cassandra-cli -host=127.0.0.1 -port=9160
>show keyspaces
Standard1
- Getters and Setters cannot be used this way: you have to authenticate using:
./bin/cassandra-cli -host=127.0.0.1 -port=9160 -username Username -password Password -keyspace KeySpace
Part Two : Ruby Cassandra Gem with authentication
To connect to my cassandra node, I use ruby client gem cassandra
However, even if the Thrift API contains a login method (see below), there is no login in cassandra.rb to Authenticate you.
def login(keyspace, auth_request)
send_login(keyspace, auth_request)
recv_login()
end
Authentication can be achieved via several ways. One of them, described here under: extending Cassandra class:
require 'rubygems'
gem 'cassandra'
require 'cassandra'
class Cassandra
def login(username, pwd)
auth_info = CassandraThrift::AuthenticationRequest.new()
auth_info.credentials = {'username' => username, 'password' => pwd}
client.login(@keyspace, auth_info)
end
end
cc = Cassandra.new("Standard1", "127.0.0.1:9160")
cc.login("myUsername", "myPassword")