Cassandra的数据审计

sum*_*n j 6 cassandra cassandra-2.0

如何实现cassandra数据的审计?我正在寻找一个开源选项.

是否有任何cassandra功能可以帮助审核?我可以使用触发器将记录记录到表中吗?我按照触发器示例,triggers_log当更新发生在另一个表上时,能够将记录插入到表中.但不确定如何捕获user/session触发更新的详细信息.我有从CQLSH终端,创建userstrigger_log table

create table AUDIT_LOG ( 
       transaction_id int,
       entries map<text, text>,  --> to capture the modifications done to the tables
       user varchar,  //authenticated user
       time timestamp, 
       primary key(transaction_id));
CREATE TABLE users (
  user_id int PRIMARY KEY,
  fname text,
  lname text
);

使用CREATE TRIGGER语法从用户表定义触发器cqlsh

目前为止下面的代码.

public class AuditTrigger implements ITrigger {

    @Override
    public Collection<RowMutation> augment(ByteBuffer key, ColumnFamily update) {

        List<RowMutation> mutations = new ArrayList<RowMutation>();
        for (Column column : update) {
            if (column.value().remaining() > 0) {
                RowMutation mutation = new RowMutation("mykeyspace", key);
           //What do I need here to capture the updates to users 
           //table and log the updates into various columns of audit_log
                mutations.add(mutation);
            }
        }
        return mutations;
    }
}
Run Code Online (Sandbox Code Playgroud)

如果触发器不是正确的方法(任何弹簧AOP方法?),请建议替代方案.我也尝试过Cassandra vs日志记录活动解决方案,但它不会打印sql执行的,经过身份验证的用户信息.

小智 7

不幸的是,此时,触发器不能用作您需要的ClientState,它包含用户信息并且不会传递给触发器.

我能想到两种方法.(您需要查看Cassandra代码库以更好地理解这些方法)

一种方法是AOP,即添加AOP并使用Agent启动Cassandra的代理.需要切入点的类是QueryProcessor#processStatement方法.对此方法的调用将使用预准备语句和QueryState作为参数.从PreparedStatement中,您可以识别用户的意图.QueryState.getClientState将返回用户信息所在的ClientState.

另一种方法涉及自定义验证器和授权器.这里描述了在Cassandra中配置它.

http://www.datastax.com/documentation/cassandra/2.0/cassandra/security/secure_about_native_authenticate_c.html

您可以使用自定义授权程序扩展AllowAllAuthorizer(这将禁用权限缓存).每当您在Authorizer上获得授权请求时,您都可以记录它.这种方法的缺点是你不知道用户打算对表做什么,只是他要求对它进行一些授权.权限是包含他想要对表执行的操作的权限,但不会传递给授权人.

如果您决定使用其中任何一种方法,如果您需要更多详细信息,可以自由发布后续内容.