You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by el...@apache.org on 2015/08/20 06:40:00 UTC
[01/10] accumulo git commit: ACCUMULO-3946 Added missing audits on
security operations.
Repository: accumulo
Updated Branches:
refs/heads/1.5 262decd3c -> dad7c7c93
refs/heads/1.6 6425c37dc -> 00c275b1f
refs/heads/1.7 e4f1df327 -> d5d883cbb
refs/heads/master 89f44e24f -> 7c146e0fc
ACCUMULO-3946 Added missing audits on security operations.
Signed-off-by: Josh Elser <el...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/dad7c7c9
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/dad7c7c9
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/dad7c7c9
Branch: refs/heads/1.5
Commit: dad7c7c93a7825dd967d42a99380ccd8beb06e24
Parents: 262decd
Author: jamesmello <ja...@atsid.com>
Authored: Tue Aug 11 13:21:04 2015 -0700
Committer: Josh Elser <el...@apache.org>
Committed: Wed Aug 19 21:47:44 2015 -0400
----------------------------------------------------------------------
.../apache/accumulo/server/master/Master.java | 21 +-
.../security/AuditedSecurityOperation.java | 355 ++++++++++++++++++-
.../server/security/SecurityOperation.java | 10 +-
.../test/randomwalk/security/CreateTable.java | 2 +-
.../test/randomwalk/security/TableOp.java | 4 +-
5 files changed, 370 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/dad7c7c9/server/src/main/java/org/apache/accumulo/server/master/Master.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/master/Master.java b/server/src/main/java/org/apache/accumulo/server/master/Master.java
index dd94683..924e120 100644
--- a/server/src/main/java/org/apache/accumulo/server/master/Master.java
+++ b/server/src/main/java/org/apache/accumulo/server/master/Master.java
@@ -857,15 +857,16 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
switch (op) {
case CREATE: {
String tableName = ByteBufferUtil.toString(arguments.get(0));
- if (!security.canCreateTable(c))
+ if (!security.canCreateTable(c, tableName))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
+
checkNotMetadataTable(tableName, TableOperation.CREATE);
checkTableName(tableName, TableOperation.CREATE);
org.apache.accumulo.core.client.admin.TimeType timeType = org.apache.accumulo.core.client.admin.TimeType.valueOf(ByteBufferUtil.toString(arguments
.get(1)));
- fate.seedTransaction(opid, new TraceRepo<Master>(new CreateTable(c.getPrincipal(), tableName, timeType, options)), autoCleanup);
+ fate.seedTransaction(opid, new TraceRepo<Master>(new CreateTable(c.getPrincipal(), tableName, timeType, options)), autoCleanup);
break;
}
case RENAME: {
@@ -879,7 +880,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
final boolean canRename;
try {
- canRename = security.canRenameTable(c, tableId);
+ canRename = security.canRenameTable(c, tableId, newTableName, oldTableName);
} catch (ThriftSecurityException e) {
throwIfTableMissingSecurityException(e, tableId, oldTableName, TableOperation.RENAME);
throw e;
@@ -926,7 +927,6 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
propertiesToSet.put(entry.getKey(), entry.getValue());
}
-
fate.seedTransaction(opid, new TraceRepo<Master>(new CloneTable(c.getPrincipal(), srcTableId, tableName, propertiesToSet, propertiesToExclude)),
autoCleanup);
@@ -1051,7 +1051,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
final boolean canBulkImport;
try {
- canBulkImport = security.canBulkImport(c, tableId);
+ canBulkImport = security.canBulkImport(c, tableId, dir);
} catch (ThriftSecurityException e) {
throwIfTableMissingSecurityException(e, tableId, tableName, TableOperation.BULK_IMPORT);
throw e;
@@ -1104,7 +1104,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
String tableName = ByteBufferUtil.toString(arguments.get(0));
String exportDir = ByteBufferUtil.toString(arguments.get(1));
- if (!security.canImport(c))
+ if (!security.canImport(c, tableName, exportDir))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
checkNotMetadataTable(tableName, TableOperation.CREATE);
@@ -1121,7 +1121,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
final boolean canExport;
try {
- canExport = security.canExport(c, tableId);
+ canExport = security.canExport(c, tableId, exportDir);
} catch (ThriftSecurityException e) {
throwIfTableMissingSecurityException(e, tableId, tableName, TableOperation.EXPORT);
throw e;
@@ -2308,12 +2308,9 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
});
TCredentials systemAuths = SecurityConstants.getSystemCredentials();
- final TabletStateStore stores[] = {
- new ZooTabletStateStore(new ZooStore(zroot)),
+ final TabletStateStore stores[] = {new ZooTabletStateStore(new ZooStore(zroot)),
// ACCUMULO-3580 ACCUMULO-3618 disable metadata table scanning optimizations
- new RootTabletStateStore(instance, systemAuths, null),
- new MetaDataStateStore(instance, systemAuths, null)
- };
+ new RootTabletStateStore(instance, systemAuths, null), new MetaDataStateStore(instance, systemAuths, null)};
watchers.add(new TabletGroupWatcher(stores[2], null));
watchers.add(new TabletGroupWatcher(stores[1], watchers.get(0)));
watchers.add(new TabletGroupWatcher(stores[0], watchers.get(1)));
http://git-wip-us.apache.org/repos/asf/accumulo/blob/dad7c7c9/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java b/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
index b2e810d..68dcb27 100644
--- a/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
+++ b/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
@@ -201,10 +201,13 @@ public class AuditedSecurityOperation extends SecurityOperation {
public boolean hasSystemPermission(TCredentials credentials, String user, SystemPermission permission) throws ThriftSecurityException {
try {
boolean result = super.hasSystemPermission(credentials, user, permission);
- audit(credentials, "checked permission %s on %s", permission, user);
+ if (result)
+ audit(credentials, "checked permission %s on %s", permission, user);
+ else
+ audit(credentials, "checked permission %s on %s denied", permission, user);
return result;
} catch (ThriftSecurityException ex) {
- audit(credentials, ex, "checking permission %s on %s", permission, user);
+ audit(credentials, ex, "checking permission %s on %s denied", permission, user);
log.debug(ex);
throw ex;
}
@@ -249,6 +252,354 @@ public class AuditedSecurityOperation extends SecurityOperation {
}
@Override
+ public boolean canCreateTable(TCredentials c, String tablename) throws ThriftSecurityException {
+ try {
+ boolean result = super.canCreateTable(c, tablename);
+ if (result)
+ audit(c, "create table %s allowed", tablename);
+ else
+ audit(c, "create table %s denied", tablename);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "create table %s denied", tablename);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canRenameTable(TCredentials c, String tableId, String newTableName, String oldTableName) throws ThriftSecurityException {
+ try {
+ boolean result = super.canRenameTable(c, tableId, newTableName, oldTableName);
+ if (result)
+ audit(c, "rename table on tableId %s from %s to %s allowed", tableId, oldTableName, newTableName);
+ else
+ audit(c, "rename table on tableId %s from %s to %s denied", tableId, oldTableName, newTableName);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "rename table on tableId %s from %s to %s denied", tableId, oldTableName, newTableName);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canSplitTablet(TCredentials credentials, String table) throws ThriftSecurityException {
+ try {
+ boolean result = super.canSplitTablet(credentials, table);
+ if (result)
+ audit(credentials, "split tablet on table %s allowed", table);
+ else
+ audit(credentials, "split tablet on table %s denied", table);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, "split tablet on table %s denied", table);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canPerformSystemActions(TCredentials credentials) throws ThriftSecurityException {
+ try {
+ boolean result = super.canPerformSystemActions(credentials);
+ if (result)
+ audit(credentials, "system action allowed");
+ else
+ audit(credentials, "system action denied");
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, "system action denied");
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canFlush(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canFlush(c, tableId);
+ if (result)
+ audit(c, "flush on tableId %s allowed ", tableId);
+ else
+ audit(c, "flush on tableId %s denied ", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "flush on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canAlterTable(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canAlterTable(c, tableId);
+ if (result)
+ audit(c, "alter table on tableId %s allowed", tableId);
+ else
+ audit(c, "alter table on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "alter table on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canCloneTable(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canCloneTable(c, tableId);
+ if (result)
+ audit(c, "clone table on tableId %s allowed", tableId);
+ else
+ audit(c, "clone table on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "clone table on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canDeleteTable(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canDeleteTable(c, tableId);
+ if (result)
+ audit(c, "delete table on tableId %s allowed", tableId);
+ else
+ audit(c, "delete table on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "delete table on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canOnlineOfflineTable(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canOnlineOfflineTable(c, tableId);
+ if (result)
+ audit(c, "offline table on tableId %s allowed", tableId);
+ else
+ audit(c, "offline table on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "offline table on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canMerge(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canMerge(c, tableId);
+ if (result)
+ audit(c, "merge table on tableId %s allowed", tableId);
+ else
+ audit(c, "merge table on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "merge table on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canDeleteRange(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canDeleteRange(c, tableId);
+ if (result)
+ audit(c, "delete range on tableId %s allowed", tableId);
+ else
+ audit(c, "delete range on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "delete range on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canBulkImport(TCredentials c, String tableId, String importDir) throws ThriftSecurityException {
+ try {
+ boolean result = super.canBulkImport(c, tableId, importDir);
+ if (result)
+ audit(c, "bulk import on tableId %s from directory %s allowed", tableId, importDir);
+ else
+ audit(c, "bulk import on tableId %s from directory %s denied", tableId, importDir);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "bulk import on tableId %s from directory %s denied", tableId, importDir);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canCompact(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canCompact(c, tableId);
+ if (result)
+ audit(c, "compact on tableId %s allowed", tableId);
+ else
+ audit(c, "compact on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "compact on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canChangeAuthorizations(TCredentials c, String user) throws ThriftSecurityException {
+ try {
+ boolean result = super.canChangeAuthorizations(c, user);
+ if (result)
+ audit(c, "change authorizations on user %s allowed", user);
+ else
+ audit(c, "change authorizations on user %s denied", user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "change authorizations on user %s denied", user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canChangePassword(TCredentials c, String user) throws ThriftSecurityException {
+ try {
+ boolean result = super.canChangePassword(c, user);
+ if (result)
+ audit(c, "change password on user %s allowed", user);
+ else
+ audit(c, "change password on user %s denied", user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "change password on user %s denied", user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canCreateUser(TCredentials c, String user) throws ThriftSecurityException {
+ try {
+ boolean result = super.canCreateUser(c, user);
+ if (result)
+ audit(c, "create user on user %s allowed", user);
+ else
+ audit(c, "create user on user %s denied", user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "create user on user %s denied", user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canDropUser(TCredentials c, String user) throws ThriftSecurityException {
+ try {
+ boolean result = super.canDropUser(c, user);
+ if (result)
+ audit(c, "drop user on user %s allowed", user);
+ else
+ audit(c, "drop user on user %s denied", user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "drop user on user %s denied", user);
+
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canGrantSystem(TCredentials c, String user, SystemPermission sysPerm) throws ThriftSecurityException {
+ try {
+ boolean result = super.canGrantSystem(c, user, sysPerm);
+ if (result)
+ audit(c, "grant system permission %s for user %s allowed", sysPerm, user);
+ else
+ audit(c, "grant system permission %s for user %s denied", sysPerm, user);
+ return result;
+
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "grant system permission %s for user %s denied", sysPerm, user);
+
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canGrantTable(TCredentials c, String user, String table) throws ThriftSecurityException {
+ try {
+ boolean result = super.canGrantTable(c, user, table);
+ if (result)
+ audit(c, "grant table on table %s for user %s allowed", table, user);
+ else
+ audit(c, "grant table on table %s for user %s denied", table, user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "grant table on table %s for user %s denied", table, user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canRevokeSystem(TCredentials c, String user, SystemPermission sysPerm) throws ThriftSecurityException {
+ try {
+ boolean result = super.canRevokeSystem(c, user, sysPerm);
+ if (result)
+ audit(c, "revoke system permission %s for user %s allowed", sysPerm, user);
+ else
+ audit(c, "revoke system permission %s for user %s denied", sysPerm, user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "revoke system permission %s for user %s denied", sysPerm, user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canRevokeTable(TCredentials c, String user, String table) throws ThriftSecurityException {
+ try {
+ boolean result = super.canRevokeTable(c, user, table);
+ if (result)
+ audit(c, "revoke table on table %s for user %s allowed", table, user);
+ else
+ audit(c, "revoke table on table %s for user %s denied", table, user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "revoke table on table %s for user %s denied", table, user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canExport(TCredentials credentials, String tableId, String exportDir) throws ThriftSecurityException {
+ try {
+ boolean result = super.canExport(credentials, tableId, exportDir);
+ if (result)
+ audit(credentials, "export table on tableId %s to directory %s allowed", tableId, exportDir);
+ else
+ audit(credentials, "export table on tableId %s to directory %s denied", tableId, exportDir);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, "export table on tableId %s to directory %s denied", tableId, exportDir);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canImport(TCredentials credentials, String tableName, String importDir) throws ThriftSecurityException {
+ try {
+ boolean result = super.canImport(credentials, tableName, importDir);
+ if (result)
+ audit(credentials, "import table %s from directory %s allowed", tableName, importDir);
+ else
+ audit(credentials, "import table %s from directory %s denied", tableName, importDir);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, "import table %s from directory %s denied", tableName, importDir);
+ throw ex;
+ }
+ }
+
+ @Override
public void initializeSecurity(TCredentials credentials, String principal, byte[] token) throws AccumuloSecurityException, ThriftSecurityException {
super.initializeSecurity(credentials, principal, token);
log.info("Initialized root user with username: " + principal + " at the request of user " + credentials.getPrincipal());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/dad7c7c9/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java b/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
index 13d1c32..6a817f2 100644
--- a/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
+++ b/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
@@ -314,12 +314,12 @@ public class SecurityOperation {
|| hasSystemPermission(c.getPrincipal(), SystemPermission.ALTER_TABLE, false);
}
- public boolean canCreateTable(TCredentials c) throws ThriftSecurityException {
+ public boolean canCreateTable(TCredentials c, String tablename) throws ThriftSecurityException {
authenticate(c);
return hasSystemPermission(c.getPrincipal(), SystemPermission.CREATE_TABLE, false);
}
- public boolean canRenameTable(TCredentials c, String tableId) throws ThriftSecurityException {
+ public boolean canRenameTable(TCredentials c, String tableId, String newTableName, String oldTableName) throws ThriftSecurityException {
authenticate(c);
return hasSystemPermission(c.getPrincipal(), SystemPermission.ALTER_TABLE, false)
|| hasTablePermission(c.getPrincipal(), tableId, TablePermission.ALTER_TABLE, false);
@@ -354,7 +354,7 @@ public class SecurityOperation {
return hasSystemPermission(c.getPrincipal(), SystemPermission.SYSTEM, false) || hasTablePermission(c.getPrincipal(), tableId, TablePermission.WRITE, false);
}
- public boolean canBulkImport(TCredentials c, String tableId) throws ThriftSecurityException {
+ public boolean canBulkImport(TCredentials c, String tableId, String importDir) throws ThriftSecurityException {
authenticate(c);
return hasTablePermission(c.getPrincipal(), tableId, TablePermission.BULK_IMPORT, false);
}
@@ -601,12 +601,12 @@ public class SecurityOperation {
}
}
- public boolean canExport(TCredentials credentials, String tableId) throws ThriftSecurityException {
+ public boolean canExport(TCredentials credentials, String tableId, String exportDir) throws ThriftSecurityException {
authenticate(credentials);
return hasTablePermission(credentials.getPrincipal(), tableId, TablePermission.READ, false);
}
- public boolean canImport(TCredentials credentials) throws ThriftSecurityException {
+ public boolean canImport(TCredentials credentials, String tableName, String importDir) throws ThriftSecurityException {
authenticate(credentials);
return hasSystemPermission(credentials.getPrincipal(), SystemPermission.CREATE_TABLE, false);
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/dad7c7c9/test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java b/test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java
index 61b146a..318c2a6 100644
--- a/test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java
+++ b/test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java
@@ -36,7 +36,7 @@ public class CreateTable extends Test {
String tableName = WalkingSecurity.get(state).getTableName();
boolean exists = WalkingSecurity.get(state).getTableExists();
- boolean hasPermission = WalkingSecurity.get(state).canCreateTable(WalkingSecurity.get(state).getSysCredentials());
+ boolean hasPermission = WalkingSecurity.get(state).canCreateTable(WalkingSecurity.get(state).getSysCredentials(), tableName);
try {
conn.tableOperations().create(tableName);
http://git-wip-us.apache.org/repos/asf/accumulo/blob/dad7c7c9/test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java b/test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java
index 6db56b2..dfe9c15 100644
--- a/test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java
+++ b/test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java
@@ -216,7 +216,7 @@ public class TableOp extends Test {
return;
} catch (AccumuloSecurityException ae) {
if (ae.getSecurityErrorCode().equals(SecurityErrorCode.PERMISSION_DENIED)) {
- if (WalkingSecurity.get(state).canBulkImport(WalkingSecurity.get(state).getTabCredentials(), tableName))
+ if (WalkingSecurity.get(state).canBulkImport(WalkingSecurity.get(state).getTabCredentials(), tableName, dir.getName()))
throw new AccumuloException("Bulk Import failed when it should have worked: " + tableName);
return;
} else if (ae.getSecurityErrorCode().equals(SecurityErrorCode.BAD_CREDENTIALS)) {
@@ -230,7 +230,7 @@ public class TableOp extends Test {
fs.delete(dir, true);
fs.delete(fail, true);
- if (!WalkingSecurity.get(state).canBulkImport(WalkingSecurity.get(state).getTabCredentials(), tableName))
+ if (!WalkingSecurity.get(state).canBulkImport(WalkingSecurity.get(state).getTabCredentials(), tableName, dir.getName()))
throw new AccumuloException("Bulk Import succeeded when it should have failed: " + dir + " table " + tableName);
break;
case ALTER_TABLE:
[10/10] accumulo git commit: Merge branch '1.7'
Posted by el...@apache.org.
Merge branch '1.7'
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/7c146e0f
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/7c146e0f
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/7c146e0f
Branch: refs/heads/master
Commit: 7c146e0fc8e3842e0992bf5e29ba2a790c2438a9
Parents: 89f44e2 d5d883c
Author: Josh Elser <el...@apache.org>
Authored: Wed Aug 19 23:38:52 2015 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Wed Aug 19 23:38:52 2015 -0400
----------------------------------------------------------------------
.../security/AuditedSecurityOperation.java | 213 +++++++++++++++++++
1 file changed, 213 insertions(+)
----------------------------------------------------------------------
[04/10] accumulo git commit: ACCUMULO-3946 Added missing audits on
security operations.
Posted by el...@apache.org.
ACCUMULO-3946 Added missing audits on security operations.
Signed-off-by: Josh Elser <el...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/dad7c7c9
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/dad7c7c9
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/dad7c7c9
Branch: refs/heads/master
Commit: dad7c7c93a7825dd967d42a99380ccd8beb06e24
Parents: 262decd
Author: jamesmello <ja...@atsid.com>
Authored: Tue Aug 11 13:21:04 2015 -0700
Committer: Josh Elser <el...@apache.org>
Committed: Wed Aug 19 21:47:44 2015 -0400
----------------------------------------------------------------------
.../apache/accumulo/server/master/Master.java | 21 +-
.../security/AuditedSecurityOperation.java | 355 ++++++++++++++++++-
.../server/security/SecurityOperation.java | 10 +-
.../test/randomwalk/security/CreateTable.java | 2 +-
.../test/randomwalk/security/TableOp.java | 4 +-
5 files changed, 370 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/dad7c7c9/server/src/main/java/org/apache/accumulo/server/master/Master.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/master/Master.java b/server/src/main/java/org/apache/accumulo/server/master/Master.java
index dd94683..924e120 100644
--- a/server/src/main/java/org/apache/accumulo/server/master/Master.java
+++ b/server/src/main/java/org/apache/accumulo/server/master/Master.java
@@ -857,15 +857,16 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
switch (op) {
case CREATE: {
String tableName = ByteBufferUtil.toString(arguments.get(0));
- if (!security.canCreateTable(c))
+ if (!security.canCreateTable(c, tableName))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
+
checkNotMetadataTable(tableName, TableOperation.CREATE);
checkTableName(tableName, TableOperation.CREATE);
org.apache.accumulo.core.client.admin.TimeType timeType = org.apache.accumulo.core.client.admin.TimeType.valueOf(ByteBufferUtil.toString(arguments
.get(1)));
- fate.seedTransaction(opid, new TraceRepo<Master>(new CreateTable(c.getPrincipal(), tableName, timeType, options)), autoCleanup);
+ fate.seedTransaction(opid, new TraceRepo<Master>(new CreateTable(c.getPrincipal(), tableName, timeType, options)), autoCleanup);
break;
}
case RENAME: {
@@ -879,7 +880,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
final boolean canRename;
try {
- canRename = security.canRenameTable(c, tableId);
+ canRename = security.canRenameTable(c, tableId, newTableName, oldTableName);
} catch (ThriftSecurityException e) {
throwIfTableMissingSecurityException(e, tableId, oldTableName, TableOperation.RENAME);
throw e;
@@ -926,7 +927,6 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
propertiesToSet.put(entry.getKey(), entry.getValue());
}
-
fate.seedTransaction(opid, new TraceRepo<Master>(new CloneTable(c.getPrincipal(), srcTableId, tableName, propertiesToSet, propertiesToExclude)),
autoCleanup);
@@ -1051,7 +1051,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
final boolean canBulkImport;
try {
- canBulkImport = security.canBulkImport(c, tableId);
+ canBulkImport = security.canBulkImport(c, tableId, dir);
} catch (ThriftSecurityException e) {
throwIfTableMissingSecurityException(e, tableId, tableName, TableOperation.BULK_IMPORT);
throw e;
@@ -1104,7 +1104,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
String tableName = ByteBufferUtil.toString(arguments.get(0));
String exportDir = ByteBufferUtil.toString(arguments.get(1));
- if (!security.canImport(c))
+ if (!security.canImport(c, tableName, exportDir))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
checkNotMetadataTable(tableName, TableOperation.CREATE);
@@ -1121,7 +1121,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
final boolean canExport;
try {
- canExport = security.canExport(c, tableId);
+ canExport = security.canExport(c, tableId, exportDir);
} catch (ThriftSecurityException e) {
throwIfTableMissingSecurityException(e, tableId, tableName, TableOperation.EXPORT);
throw e;
@@ -2308,12 +2308,9 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
});
TCredentials systemAuths = SecurityConstants.getSystemCredentials();
- final TabletStateStore stores[] = {
- new ZooTabletStateStore(new ZooStore(zroot)),
+ final TabletStateStore stores[] = {new ZooTabletStateStore(new ZooStore(zroot)),
// ACCUMULO-3580 ACCUMULO-3618 disable metadata table scanning optimizations
- new RootTabletStateStore(instance, systemAuths, null),
- new MetaDataStateStore(instance, systemAuths, null)
- };
+ new RootTabletStateStore(instance, systemAuths, null), new MetaDataStateStore(instance, systemAuths, null)};
watchers.add(new TabletGroupWatcher(stores[2], null));
watchers.add(new TabletGroupWatcher(stores[1], watchers.get(0)));
watchers.add(new TabletGroupWatcher(stores[0], watchers.get(1)));
http://git-wip-us.apache.org/repos/asf/accumulo/blob/dad7c7c9/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java b/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
index b2e810d..68dcb27 100644
--- a/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
+++ b/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
@@ -201,10 +201,13 @@ public class AuditedSecurityOperation extends SecurityOperation {
public boolean hasSystemPermission(TCredentials credentials, String user, SystemPermission permission) throws ThriftSecurityException {
try {
boolean result = super.hasSystemPermission(credentials, user, permission);
- audit(credentials, "checked permission %s on %s", permission, user);
+ if (result)
+ audit(credentials, "checked permission %s on %s", permission, user);
+ else
+ audit(credentials, "checked permission %s on %s denied", permission, user);
return result;
} catch (ThriftSecurityException ex) {
- audit(credentials, ex, "checking permission %s on %s", permission, user);
+ audit(credentials, ex, "checking permission %s on %s denied", permission, user);
log.debug(ex);
throw ex;
}
@@ -249,6 +252,354 @@ public class AuditedSecurityOperation extends SecurityOperation {
}
@Override
+ public boolean canCreateTable(TCredentials c, String tablename) throws ThriftSecurityException {
+ try {
+ boolean result = super.canCreateTable(c, tablename);
+ if (result)
+ audit(c, "create table %s allowed", tablename);
+ else
+ audit(c, "create table %s denied", tablename);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "create table %s denied", tablename);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canRenameTable(TCredentials c, String tableId, String newTableName, String oldTableName) throws ThriftSecurityException {
+ try {
+ boolean result = super.canRenameTable(c, tableId, newTableName, oldTableName);
+ if (result)
+ audit(c, "rename table on tableId %s from %s to %s allowed", tableId, oldTableName, newTableName);
+ else
+ audit(c, "rename table on tableId %s from %s to %s denied", tableId, oldTableName, newTableName);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "rename table on tableId %s from %s to %s denied", tableId, oldTableName, newTableName);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canSplitTablet(TCredentials credentials, String table) throws ThriftSecurityException {
+ try {
+ boolean result = super.canSplitTablet(credentials, table);
+ if (result)
+ audit(credentials, "split tablet on table %s allowed", table);
+ else
+ audit(credentials, "split tablet on table %s denied", table);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, "split tablet on table %s denied", table);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canPerformSystemActions(TCredentials credentials) throws ThriftSecurityException {
+ try {
+ boolean result = super.canPerformSystemActions(credentials);
+ if (result)
+ audit(credentials, "system action allowed");
+ else
+ audit(credentials, "system action denied");
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, "system action denied");
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canFlush(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canFlush(c, tableId);
+ if (result)
+ audit(c, "flush on tableId %s allowed ", tableId);
+ else
+ audit(c, "flush on tableId %s denied ", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "flush on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canAlterTable(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canAlterTable(c, tableId);
+ if (result)
+ audit(c, "alter table on tableId %s allowed", tableId);
+ else
+ audit(c, "alter table on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "alter table on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canCloneTable(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canCloneTable(c, tableId);
+ if (result)
+ audit(c, "clone table on tableId %s allowed", tableId);
+ else
+ audit(c, "clone table on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "clone table on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canDeleteTable(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canDeleteTable(c, tableId);
+ if (result)
+ audit(c, "delete table on tableId %s allowed", tableId);
+ else
+ audit(c, "delete table on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "delete table on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canOnlineOfflineTable(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canOnlineOfflineTable(c, tableId);
+ if (result)
+ audit(c, "offline table on tableId %s allowed", tableId);
+ else
+ audit(c, "offline table on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "offline table on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canMerge(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canMerge(c, tableId);
+ if (result)
+ audit(c, "merge table on tableId %s allowed", tableId);
+ else
+ audit(c, "merge table on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "merge table on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canDeleteRange(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canDeleteRange(c, tableId);
+ if (result)
+ audit(c, "delete range on tableId %s allowed", tableId);
+ else
+ audit(c, "delete range on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "delete range on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canBulkImport(TCredentials c, String tableId, String importDir) throws ThriftSecurityException {
+ try {
+ boolean result = super.canBulkImport(c, tableId, importDir);
+ if (result)
+ audit(c, "bulk import on tableId %s from directory %s allowed", tableId, importDir);
+ else
+ audit(c, "bulk import on tableId %s from directory %s denied", tableId, importDir);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "bulk import on tableId %s from directory %s denied", tableId, importDir);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canCompact(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canCompact(c, tableId);
+ if (result)
+ audit(c, "compact on tableId %s allowed", tableId);
+ else
+ audit(c, "compact on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "compact on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canChangeAuthorizations(TCredentials c, String user) throws ThriftSecurityException {
+ try {
+ boolean result = super.canChangeAuthorizations(c, user);
+ if (result)
+ audit(c, "change authorizations on user %s allowed", user);
+ else
+ audit(c, "change authorizations on user %s denied", user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "change authorizations on user %s denied", user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canChangePassword(TCredentials c, String user) throws ThriftSecurityException {
+ try {
+ boolean result = super.canChangePassword(c, user);
+ if (result)
+ audit(c, "change password on user %s allowed", user);
+ else
+ audit(c, "change password on user %s denied", user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "change password on user %s denied", user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canCreateUser(TCredentials c, String user) throws ThriftSecurityException {
+ try {
+ boolean result = super.canCreateUser(c, user);
+ if (result)
+ audit(c, "create user on user %s allowed", user);
+ else
+ audit(c, "create user on user %s denied", user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "create user on user %s denied", user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canDropUser(TCredentials c, String user) throws ThriftSecurityException {
+ try {
+ boolean result = super.canDropUser(c, user);
+ if (result)
+ audit(c, "drop user on user %s allowed", user);
+ else
+ audit(c, "drop user on user %s denied", user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "drop user on user %s denied", user);
+
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canGrantSystem(TCredentials c, String user, SystemPermission sysPerm) throws ThriftSecurityException {
+ try {
+ boolean result = super.canGrantSystem(c, user, sysPerm);
+ if (result)
+ audit(c, "grant system permission %s for user %s allowed", sysPerm, user);
+ else
+ audit(c, "grant system permission %s for user %s denied", sysPerm, user);
+ return result;
+
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "grant system permission %s for user %s denied", sysPerm, user);
+
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canGrantTable(TCredentials c, String user, String table) throws ThriftSecurityException {
+ try {
+ boolean result = super.canGrantTable(c, user, table);
+ if (result)
+ audit(c, "grant table on table %s for user %s allowed", table, user);
+ else
+ audit(c, "grant table on table %s for user %s denied", table, user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "grant table on table %s for user %s denied", table, user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canRevokeSystem(TCredentials c, String user, SystemPermission sysPerm) throws ThriftSecurityException {
+ try {
+ boolean result = super.canRevokeSystem(c, user, sysPerm);
+ if (result)
+ audit(c, "revoke system permission %s for user %s allowed", sysPerm, user);
+ else
+ audit(c, "revoke system permission %s for user %s denied", sysPerm, user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "revoke system permission %s for user %s denied", sysPerm, user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canRevokeTable(TCredentials c, String user, String table) throws ThriftSecurityException {
+ try {
+ boolean result = super.canRevokeTable(c, user, table);
+ if (result)
+ audit(c, "revoke table on table %s for user %s allowed", table, user);
+ else
+ audit(c, "revoke table on table %s for user %s denied", table, user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "revoke table on table %s for user %s denied", table, user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canExport(TCredentials credentials, String tableId, String exportDir) throws ThriftSecurityException {
+ try {
+ boolean result = super.canExport(credentials, tableId, exportDir);
+ if (result)
+ audit(credentials, "export table on tableId %s to directory %s allowed", tableId, exportDir);
+ else
+ audit(credentials, "export table on tableId %s to directory %s denied", tableId, exportDir);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, "export table on tableId %s to directory %s denied", tableId, exportDir);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canImport(TCredentials credentials, String tableName, String importDir) throws ThriftSecurityException {
+ try {
+ boolean result = super.canImport(credentials, tableName, importDir);
+ if (result)
+ audit(credentials, "import table %s from directory %s allowed", tableName, importDir);
+ else
+ audit(credentials, "import table %s from directory %s denied", tableName, importDir);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, "import table %s from directory %s denied", tableName, importDir);
+ throw ex;
+ }
+ }
+
+ @Override
public void initializeSecurity(TCredentials credentials, String principal, byte[] token) throws AccumuloSecurityException, ThriftSecurityException {
super.initializeSecurity(credentials, principal, token);
log.info("Initialized root user with username: " + principal + " at the request of user " + credentials.getPrincipal());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/dad7c7c9/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java b/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
index 13d1c32..6a817f2 100644
--- a/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
+++ b/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
@@ -314,12 +314,12 @@ public class SecurityOperation {
|| hasSystemPermission(c.getPrincipal(), SystemPermission.ALTER_TABLE, false);
}
- public boolean canCreateTable(TCredentials c) throws ThriftSecurityException {
+ public boolean canCreateTable(TCredentials c, String tablename) throws ThriftSecurityException {
authenticate(c);
return hasSystemPermission(c.getPrincipal(), SystemPermission.CREATE_TABLE, false);
}
- public boolean canRenameTable(TCredentials c, String tableId) throws ThriftSecurityException {
+ public boolean canRenameTable(TCredentials c, String tableId, String newTableName, String oldTableName) throws ThriftSecurityException {
authenticate(c);
return hasSystemPermission(c.getPrincipal(), SystemPermission.ALTER_TABLE, false)
|| hasTablePermission(c.getPrincipal(), tableId, TablePermission.ALTER_TABLE, false);
@@ -354,7 +354,7 @@ public class SecurityOperation {
return hasSystemPermission(c.getPrincipal(), SystemPermission.SYSTEM, false) || hasTablePermission(c.getPrincipal(), tableId, TablePermission.WRITE, false);
}
- public boolean canBulkImport(TCredentials c, String tableId) throws ThriftSecurityException {
+ public boolean canBulkImport(TCredentials c, String tableId, String importDir) throws ThriftSecurityException {
authenticate(c);
return hasTablePermission(c.getPrincipal(), tableId, TablePermission.BULK_IMPORT, false);
}
@@ -601,12 +601,12 @@ public class SecurityOperation {
}
}
- public boolean canExport(TCredentials credentials, String tableId) throws ThriftSecurityException {
+ public boolean canExport(TCredentials credentials, String tableId, String exportDir) throws ThriftSecurityException {
authenticate(credentials);
return hasTablePermission(credentials.getPrincipal(), tableId, TablePermission.READ, false);
}
- public boolean canImport(TCredentials credentials) throws ThriftSecurityException {
+ public boolean canImport(TCredentials credentials, String tableName, String importDir) throws ThriftSecurityException {
authenticate(credentials);
return hasSystemPermission(credentials.getPrincipal(), SystemPermission.CREATE_TABLE, false);
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/dad7c7c9/test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java b/test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java
index 61b146a..318c2a6 100644
--- a/test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java
+++ b/test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java
@@ -36,7 +36,7 @@ public class CreateTable extends Test {
String tableName = WalkingSecurity.get(state).getTableName();
boolean exists = WalkingSecurity.get(state).getTableExists();
- boolean hasPermission = WalkingSecurity.get(state).canCreateTable(WalkingSecurity.get(state).getSysCredentials());
+ boolean hasPermission = WalkingSecurity.get(state).canCreateTable(WalkingSecurity.get(state).getSysCredentials(), tableName);
try {
conn.tableOperations().create(tableName);
http://git-wip-us.apache.org/repos/asf/accumulo/blob/dad7c7c9/test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java b/test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java
index 6db56b2..dfe9c15 100644
--- a/test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java
+++ b/test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java
@@ -216,7 +216,7 @@ public class TableOp extends Test {
return;
} catch (AccumuloSecurityException ae) {
if (ae.getSecurityErrorCode().equals(SecurityErrorCode.PERMISSION_DENIED)) {
- if (WalkingSecurity.get(state).canBulkImport(WalkingSecurity.get(state).getTabCredentials(), tableName))
+ if (WalkingSecurity.get(state).canBulkImport(WalkingSecurity.get(state).getTabCredentials(), tableName, dir.getName()))
throw new AccumuloException("Bulk Import failed when it should have worked: " + tableName);
return;
} else if (ae.getSecurityErrorCode().equals(SecurityErrorCode.BAD_CREDENTIALS)) {
@@ -230,7 +230,7 @@ public class TableOp extends Test {
fs.delete(dir, true);
fs.delete(fail, true);
- if (!WalkingSecurity.get(state).canBulkImport(WalkingSecurity.get(state).getTabCredentials(), tableName))
+ if (!WalkingSecurity.get(state).canBulkImport(WalkingSecurity.get(state).getTabCredentials(), tableName, dir.getName()))
throw new AccumuloException("Bulk Import succeeded when it should have failed: " + dir + " table " + tableName);
break;
case ALTER_TABLE:
[08/10] accumulo git commit: Merge branch '1.6' into 1.7
Posted by el...@apache.org.
Merge branch '1.6' into 1.7
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/d5d883cb
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/d5d883cb
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/d5d883cb
Branch: refs/heads/1.7
Commit: d5d883cbbdc1341b07e1e6ec72631ad66fbcdd49
Parents: e4f1df3 00c275b
Author: Josh Elser <el...@apache.org>
Authored: Wed Aug 19 23:36:49 2015 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Wed Aug 19 23:36:49 2015 -0400
----------------------------------------------------------------------
.../security/AuditedSecurityOperation.java | 213 +++++++++++++++++++
1 file changed, 213 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/d5d883cb/server/base/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
----------------------------------------------------------------------
[03/10] accumulo git commit: ACCUMULO-3946 Added missing audits on
security operations.
Posted by el...@apache.org.
ACCUMULO-3946 Added missing audits on security operations.
Signed-off-by: Josh Elser <el...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/dad7c7c9
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/dad7c7c9
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/dad7c7c9
Branch: refs/heads/1.7
Commit: dad7c7c93a7825dd967d42a99380ccd8beb06e24
Parents: 262decd
Author: jamesmello <ja...@atsid.com>
Authored: Tue Aug 11 13:21:04 2015 -0700
Committer: Josh Elser <el...@apache.org>
Committed: Wed Aug 19 21:47:44 2015 -0400
----------------------------------------------------------------------
.../apache/accumulo/server/master/Master.java | 21 +-
.../security/AuditedSecurityOperation.java | 355 ++++++++++++++++++-
.../server/security/SecurityOperation.java | 10 +-
.../test/randomwalk/security/CreateTable.java | 2 +-
.../test/randomwalk/security/TableOp.java | 4 +-
5 files changed, 370 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/dad7c7c9/server/src/main/java/org/apache/accumulo/server/master/Master.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/master/Master.java b/server/src/main/java/org/apache/accumulo/server/master/Master.java
index dd94683..924e120 100644
--- a/server/src/main/java/org/apache/accumulo/server/master/Master.java
+++ b/server/src/main/java/org/apache/accumulo/server/master/Master.java
@@ -857,15 +857,16 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
switch (op) {
case CREATE: {
String tableName = ByteBufferUtil.toString(arguments.get(0));
- if (!security.canCreateTable(c))
+ if (!security.canCreateTable(c, tableName))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
+
checkNotMetadataTable(tableName, TableOperation.CREATE);
checkTableName(tableName, TableOperation.CREATE);
org.apache.accumulo.core.client.admin.TimeType timeType = org.apache.accumulo.core.client.admin.TimeType.valueOf(ByteBufferUtil.toString(arguments
.get(1)));
- fate.seedTransaction(opid, new TraceRepo<Master>(new CreateTable(c.getPrincipal(), tableName, timeType, options)), autoCleanup);
+ fate.seedTransaction(opid, new TraceRepo<Master>(new CreateTable(c.getPrincipal(), tableName, timeType, options)), autoCleanup);
break;
}
case RENAME: {
@@ -879,7 +880,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
final boolean canRename;
try {
- canRename = security.canRenameTable(c, tableId);
+ canRename = security.canRenameTable(c, tableId, newTableName, oldTableName);
} catch (ThriftSecurityException e) {
throwIfTableMissingSecurityException(e, tableId, oldTableName, TableOperation.RENAME);
throw e;
@@ -926,7 +927,6 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
propertiesToSet.put(entry.getKey(), entry.getValue());
}
-
fate.seedTransaction(opid, new TraceRepo<Master>(new CloneTable(c.getPrincipal(), srcTableId, tableName, propertiesToSet, propertiesToExclude)),
autoCleanup);
@@ -1051,7 +1051,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
final boolean canBulkImport;
try {
- canBulkImport = security.canBulkImport(c, tableId);
+ canBulkImport = security.canBulkImport(c, tableId, dir);
} catch (ThriftSecurityException e) {
throwIfTableMissingSecurityException(e, tableId, tableName, TableOperation.BULK_IMPORT);
throw e;
@@ -1104,7 +1104,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
String tableName = ByteBufferUtil.toString(arguments.get(0));
String exportDir = ByteBufferUtil.toString(arguments.get(1));
- if (!security.canImport(c))
+ if (!security.canImport(c, tableName, exportDir))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
checkNotMetadataTable(tableName, TableOperation.CREATE);
@@ -1121,7 +1121,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
final boolean canExport;
try {
- canExport = security.canExport(c, tableId);
+ canExport = security.canExport(c, tableId, exportDir);
} catch (ThriftSecurityException e) {
throwIfTableMissingSecurityException(e, tableId, tableName, TableOperation.EXPORT);
throw e;
@@ -2308,12 +2308,9 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
});
TCredentials systemAuths = SecurityConstants.getSystemCredentials();
- final TabletStateStore stores[] = {
- new ZooTabletStateStore(new ZooStore(zroot)),
+ final TabletStateStore stores[] = {new ZooTabletStateStore(new ZooStore(zroot)),
// ACCUMULO-3580 ACCUMULO-3618 disable metadata table scanning optimizations
- new RootTabletStateStore(instance, systemAuths, null),
- new MetaDataStateStore(instance, systemAuths, null)
- };
+ new RootTabletStateStore(instance, systemAuths, null), new MetaDataStateStore(instance, systemAuths, null)};
watchers.add(new TabletGroupWatcher(stores[2], null));
watchers.add(new TabletGroupWatcher(stores[1], watchers.get(0)));
watchers.add(new TabletGroupWatcher(stores[0], watchers.get(1)));
http://git-wip-us.apache.org/repos/asf/accumulo/blob/dad7c7c9/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java b/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
index b2e810d..68dcb27 100644
--- a/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
+++ b/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
@@ -201,10 +201,13 @@ public class AuditedSecurityOperation extends SecurityOperation {
public boolean hasSystemPermission(TCredentials credentials, String user, SystemPermission permission) throws ThriftSecurityException {
try {
boolean result = super.hasSystemPermission(credentials, user, permission);
- audit(credentials, "checked permission %s on %s", permission, user);
+ if (result)
+ audit(credentials, "checked permission %s on %s", permission, user);
+ else
+ audit(credentials, "checked permission %s on %s denied", permission, user);
return result;
} catch (ThriftSecurityException ex) {
- audit(credentials, ex, "checking permission %s on %s", permission, user);
+ audit(credentials, ex, "checking permission %s on %s denied", permission, user);
log.debug(ex);
throw ex;
}
@@ -249,6 +252,354 @@ public class AuditedSecurityOperation extends SecurityOperation {
}
@Override
+ public boolean canCreateTable(TCredentials c, String tablename) throws ThriftSecurityException {
+ try {
+ boolean result = super.canCreateTable(c, tablename);
+ if (result)
+ audit(c, "create table %s allowed", tablename);
+ else
+ audit(c, "create table %s denied", tablename);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "create table %s denied", tablename);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canRenameTable(TCredentials c, String tableId, String newTableName, String oldTableName) throws ThriftSecurityException {
+ try {
+ boolean result = super.canRenameTable(c, tableId, newTableName, oldTableName);
+ if (result)
+ audit(c, "rename table on tableId %s from %s to %s allowed", tableId, oldTableName, newTableName);
+ else
+ audit(c, "rename table on tableId %s from %s to %s denied", tableId, oldTableName, newTableName);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "rename table on tableId %s from %s to %s denied", tableId, oldTableName, newTableName);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canSplitTablet(TCredentials credentials, String table) throws ThriftSecurityException {
+ try {
+ boolean result = super.canSplitTablet(credentials, table);
+ if (result)
+ audit(credentials, "split tablet on table %s allowed", table);
+ else
+ audit(credentials, "split tablet on table %s denied", table);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, "split tablet on table %s denied", table);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canPerformSystemActions(TCredentials credentials) throws ThriftSecurityException {
+ try {
+ boolean result = super.canPerformSystemActions(credentials);
+ if (result)
+ audit(credentials, "system action allowed");
+ else
+ audit(credentials, "system action denied");
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, "system action denied");
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canFlush(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canFlush(c, tableId);
+ if (result)
+ audit(c, "flush on tableId %s allowed ", tableId);
+ else
+ audit(c, "flush on tableId %s denied ", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "flush on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canAlterTable(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canAlterTable(c, tableId);
+ if (result)
+ audit(c, "alter table on tableId %s allowed", tableId);
+ else
+ audit(c, "alter table on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "alter table on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canCloneTable(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canCloneTable(c, tableId);
+ if (result)
+ audit(c, "clone table on tableId %s allowed", tableId);
+ else
+ audit(c, "clone table on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "clone table on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canDeleteTable(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canDeleteTable(c, tableId);
+ if (result)
+ audit(c, "delete table on tableId %s allowed", tableId);
+ else
+ audit(c, "delete table on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "delete table on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canOnlineOfflineTable(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canOnlineOfflineTable(c, tableId);
+ if (result)
+ audit(c, "offline table on tableId %s allowed", tableId);
+ else
+ audit(c, "offline table on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "offline table on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canMerge(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canMerge(c, tableId);
+ if (result)
+ audit(c, "merge table on tableId %s allowed", tableId);
+ else
+ audit(c, "merge table on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "merge table on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canDeleteRange(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canDeleteRange(c, tableId);
+ if (result)
+ audit(c, "delete range on tableId %s allowed", tableId);
+ else
+ audit(c, "delete range on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "delete range on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canBulkImport(TCredentials c, String tableId, String importDir) throws ThriftSecurityException {
+ try {
+ boolean result = super.canBulkImport(c, tableId, importDir);
+ if (result)
+ audit(c, "bulk import on tableId %s from directory %s allowed", tableId, importDir);
+ else
+ audit(c, "bulk import on tableId %s from directory %s denied", tableId, importDir);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "bulk import on tableId %s from directory %s denied", tableId, importDir);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canCompact(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canCompact(c, tableId);
+ if (result)
+ audit(c, "compact on tableId %s allowed", tableId);
+ else
+ audit(c, "compact on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "compact on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canChangeAuthorizations(TCredentials c, String user) throws ThriftSecurityException {
+ try {
+ boolean result = super.canChangeAuthorizations(c, user);
+ if (result)
+ audit(c, "change authorizations on user %s allowed", user);
+ else
+ audit(c, "change authorizations on user %s denied", user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "change authorizations on user %s denied", user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canChangePassword(TCredentials c, String user) throws ThriftSecurityException {
+ try {
+ boolean result = super.canChangePassword(c, user);
+ if (result)
+ audit(c, "change password on user %s allowed", user);
+ else
+ audit(c, "change password on user %s denied", user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "change password on user %s denied", user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canCreateUser(TCredentials c, String user) throws ThriftSecurityException {
+ try {
+ boolean result = super.canCreateUser(c, user);
+ if (result)
+ audit(c, "create user on user %s allowed", user);
+ else
+ audit(c, "create user on user %s denied", user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "create user on user %s denied", user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canDropUser(TCredentials c, String user) throws ThriftSecurityException {
+ try {
+ boolean result = super.canDropUser(c, user);
+ if (result)
+ audit(c, "drop user on user %s allowed", user);
+ else
+ audit(c, "drop user on user %s denied", user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "drop user on user %s denied", user);
+
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canGrantSystem(TCredentials c, String user, SystemPermission sysPerm) throws ThriftSecurityException {
+ try {
+ boolean result = super.canGrantSystem(c, user, sysPerm);
+ if (result)
+ audit(c, "grant system permission %s for user %s allowed", sysPerm, user);
+ else
+ audit(c, "grant system permission %s for user %s denied", sysPerm, user);
+ return result;
+
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "grant system permission %s for user %s denied", sysPerm, user);
+
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canGrantTable(TCredentials c, String user, String table) throws ThriftSecurityException {
+ try {
+ boolean result = super.canGrantTable(c, user, table);
+ if (result)
+ audit(c, "grant table on table %s for user %s allowed", table, user);
+ else
+ audit(c, "grant table on table %s for user %s denied", table, user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "grant table on table %s for user %s denied", table, user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canRevokeSystem(TCredentials c, String user, SystemPermission sysPerm) throws ThriftSecurityException {
+ try {
+ boolean result = super.canRevokeSystem(c, user, sysPerm);
+ if (result)
+ audit(c, "revoke system permission %s for user %s allowed", sysPerm, user);
+ else
+ audit(c, "revoke system permission %s for user %s denied", sysPerm, user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "revoke system permission %s for user %s denied", sysPerm, user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canRevokeTable(TCredentials c, String user, String table) throws ThriftSecurityException {
+ try {
+ boolean result = super.canRevokeTable(c, user, table);
+ if (result)
+ audit(c, "revoke table on table %s for user %s allowed", table, user);
+ else
+ audit(c, "revoke table on table %s for user %s denied", table, user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "revoke table on table %s for user %s denied", table, user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canExport(TCredentials credentials, String tableId, String exportDir) throws ThriftSecurityException {
+ try {
+ boolean result = super.canExport(credentials, tableId, exportDir);
+ if (result)
+ audit(credentials, "export table on tableId %s to directory %s allowed", tableId, exportDir);
+ else
+ audit(credentials, "export table on tableId %s to directory %s denied", tableId, exportDir);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, "export table on tableId %s to directory %s denied", tableId, exportDir);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canImport(TCredentials credentials, String tableName, String importDir) throws ThriftSecurityException {
+ try {
+ boolean result = super.canImport(credentials, tableName, importDir);
+ if (result)
+ audit(credentials, "import table %s from directory %s allowed", tableName, importDir);
+ else
+ audit(credentials, "import table %s from directory %s denied", tableName, importDir);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, "import table %s from directory %s denied", tableName, importDir);
+ throw ex;
+ }
+ }
+
+ @Override
public void initializeSecurity(TCredentials credentials, String principal, byte[] token) throws AccumuloSecurityException, ThriftSecurityException {
super.initializeSecurity(credentials, principal, token);
log.info("Initialized root user with username: " + principal + " at the request of user " + credentials.getPrincipal());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/dad7c7c9/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java b/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
index 13d1c32..6a817f2 100644
--- a/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
+++ b/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
@@ -314,12 +314,12 @@ public class SecurityOperation {
|| hasSystemPermission(c.getPrincipal(), SystemPermission.ALTER_TABLE, false);
}
- public boolean canCreateTable(TCredentials c) throws ThriftSecurityException {
+ public boolean canCreateTable(TCredentials c, String tablename) throws ThriftSecurityException {
authenticate(c);
return hasSystemPermission(c.getPrincipal(), SystemPermission.CREATE_TABLE, false);
}
- public boolean canRenameTable(TCredentials c, String tableId) throws ThriftSecurityException {
+ public boolean canRenameTable(TCredentials c, String tableId, String newTableName, String oldTableName) throws ThriftSecurityException {
authenticate(c);
return hasSystemPermission(c.getPrincipal(), SystemPermission.ALTER_TABLE, false)
|| hasTablePermission(c.getPrincipal(), tableId, TablePermission.ALTER_TABLE, false);
@@ -354,7 +354,7 @@ public class SecurityOperation {
return hasSystemPermission(c.getPrincipal(), SystemPermission.SYSTEM, false) || hasTablePermission(c.getPrincipal(), tableId, TablePermission.WRITE, false);
}
- public boolean canBulkImport(TCredentials c, String tableId) throws ThriftSecurityException {
+ public boolean canBulkImport(TCredentials c, String tableId, String importDir) throws ThriftSecurityException {
authenticate(c);
return hasTablePermission(c.getPrincipal(), tableId, TablePermission.BULK_IMPORT, false);
}
@@ -601,12 +601,12 @@ public class SecurityOperation {
}
}
- public boolean canExport(TCredentials credentials, String tableId) throws ThriftSecurityException {
+ public boolean canExport(TCredentials credentials, String tableId, String exportDir) throws ThriftSecurityException {
authenticate(credentials);
return hasTablePermission(credentials.getPrincipal(), tableId, TablePermission.READ, false);
}
- public boolean canImport(TCredentials credentials) throws ThriftSecurityException {
+ public boolean canImport(TCredentials credentials, String tableName, String importDir) throws ThriftSecurityException {
authenticate(credentials);
return hasSystemPermission(credentials.getPrincipal(), SystemPermission.CREATE_TABLE, false);
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/dad7c7c9/test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java b/test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java
index 61b146a..318c2a6 100644
--- a/test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java
+++ b/test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java
@@ -36,7 +36,7 @@ public class CreateTable extends Test {
String tableName = WalkingSecurity.get(state).getTableName();
boolean exists = WalkingSecurity.get(state).getTableExists();
- boolean hasPermission = WalkingSecurity.get(state).canCreateTable(WalkingSecurity.get(state).getSysCredentials());
+ boolean hasPermission = WalkingSecurity.get(state).canCreateTable(WalkingSecurity.get(state).getSysCredentials(), tableName);
try {
conn.tableOperations().create(tableName);
http://git-wip-us.apache.org/repos/asf/accumulo/blob/dad7c7c9/test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java b/test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java
index 6db56b2..dfe9c15 100644
--- a/test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java
+++ b/test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java
@@ -216,7 +216,7 @@ public class TableOp extends Test {
return;
} catch (AccumuloSecurityException ae) {
if (ae.getSecurityErrorCode().equals(SecurityErrorCode.PERMISSION_DENIED)) {
- if (WalkingSecurity.get(state).canBulkImport(WalkingSecurity.get(state).getTabCredentials(), tableName))
+ if (WalkingSecurity.get(state).canBulkImport(WalkingSecurity.get(state).getTabCredentials(), tableName, dir.getName()))
throw new AccumuloException("Bulk Import failed when it should have worked: " + tableName);
return;
} else if (ae.getSecurityErrorCode().equals(SecurityErrorCode.BAD_CREDENTIALS)) {
@@ -230,7 +230,7 @@ public class TableOp extends Test {
fs.delete(dir, true);
fs.delete(fail, true);
- if (!WalkingSecurity.get(state).canBulkImport(WalkingSecurity.get(state).getTabCredentials(), tableName))
+ if (!WalkingSecurity.get(state).canBulkImport(WalkingSecurity.get(state).getTabCredentials(), tableName, dir.getName()))
throw new AccumuloException("Bulk Import succeeded when it should have failed: " + dir + " table " + tableName);
break;
case ALTER_TABLE:
[02/10] accumulo git commit: ACCUMULO-3946 Added missing audits on
security operations.
Posted by el...@apache.org.
ACCUMULO-3946 Added missing audits on security operations.
Signed-off-by: Josh Elser <el...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/dad7c7c9
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/dad7c7c9
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/dad7c7c9
Branch: refs/heads/1.6
Commit: dad7c7c93a7825dd967d42a99380ccd8beb06e24
Parents: 262decd
Author: jamesmello <ja...@atsid.com>
Authored: Tue Aug 11 13:21:04 2015 -0700
Committer: Josh Elser <el...@apache.org>
Committed: Wed Aug 19 21:47:44 2015 -0400
----------------------------------------------------------------------
.../apache/accumulo/server/master/Master.java | 21 +-
.../security/AuditedSecurityOperation.java | 355 ++++++++++++++++++-
.../server/security/SecurityOperation.java | 10 +-
.../test/randomwalk/security/CreateTable.java | 2 +-
.../test/randomwalk/security/TableOp.java | 4 +-
5 files changed, 370 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/dad7c7c9/server/src/main/java/org/apache/accumulo/server/master/Master.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/master/Master.java b/server/src/main/java/org/apache/accumulo/server/master/Master.java
index dd94683..924e120 100644
--- a/server/src/main/java/org/apache/accumulo/server/master/Master.java
+++ b/server/src/main/java/org/apache/accumulo/server/master/Master.java
@@ -857,15 +857,16 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
switch (op) {
case CREATE: {
String tableName = ByteBufferUtil.toString(arguments.get(0));
- if (!security.canCreateTable(c))
+ if (!security.canCreateTable(c, tableName))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
+
checkNotMetadataTable(tableName, TableOperation.CREATE);
checkTableName(tableName, TableOperation.CREATE);
org.apache.accumulo.core.client.admin.TimeType timeType = org.apache.accumulo.core.client.admin.TimeType.valueOf(ByteBufferUtil.toString(arguments
.get(1)));
- fate.seedTransaction(opid, new TraceRepo<Master>(new CreateTable(c.getPrincipal(), tableName, timeType, options)), autoCleanup);
+ fate.seedTransaction(opid, new TraceRepo<Master>(new CreateTable(c.getPrincipal(), tableName, timeType, options)), autoCleanup);
break;
}
case RENAME: {
@@ -879,7 +880,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
final boolean canRename;
try {
- canRename = security.canRenameTable(c, tableId);
+ canRename = security.canRenameTable(c, tableId, newTableName, oldTableName);
} catch (ThriftSecurityException e) {
throwIfTableMissingSecurityException(e, tableId, oldTableName, TableOperation.RENAME);
throw e;
@@ -926,7 +927,6 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
propertiesToSet.put(entry.getKey(), entry.getValue());
}
-
fate.seedTransaction(opid, new TraceRepo<Master>(new CloneTable(c.getPrincipal(), srcTableId, tableName, propertiesToSet, propertiesToExclude)),
autoCleanup);
@@ -1051,7 +1051,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
final boolean canBulkImport;
try {
- canBulkImport = security.canBulkImport(c, tableId);
+ canBulkImport = security.canBulkImport(c, tableId, dir);
} catch (ThriftSecurityException e) {
throwIfTableMissingSecurityException(e, tableId, tableName, TableOperation.BULK_IMPORT);
throw e;
@@ -1104,7 +1104,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
String tableName = ByteBufferUtil.toString(arguments.get(0));
String exportDir = ByteBufferUtil.toString(arguments.get(1));
- if (!security.canImport(c))
+ if (!security.canImport(c, tableName, exportDir))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
checkNotMetadataTable(tableName, TableOperation.CREATE);
@@ -1121,7 +1121,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
final boolean canExport;
try {
- canExport = security.canExport(c, tableId);
+ canExport = security.canExport(c, tableId, exportDir);
} catch (ThriftSecurityException e) {
throwIfTableMissingSecurityException(e, tableId, tableName, TableOperation.EXPORT);
throw e;
@@ -2308,12 +2308,9 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
});
TCredentials systemAuths = SecurityConstants.getSystemCredentials();
- final TabletStateStore stores[] = {
- new ZooTabletStateStore(new ZooStore(zroot)),
+ final TabletStateStore stores[] = {new ZooTabletStateStore(new ZooStore(zroot)),
// ACCUMULO-3580 ACCUMULO-3618 disable metadata table scanning optimizations
- new RootTabletStateStore(instance, systemAuths, null),
- new MetaDataStateStore(instance, systemAuths, null)
- };
+ new RootTabletStateStore(instance, systemAuths, null), new MetaDataStateStore(instance, systemAuths, null)};
watchers.add(new TabletGroupWatcher(stores[2], null));
watchers.add(new TabletGroupWatcher(stores[1], watchers.get(0)));
watchers.add(new TabletGroupWatcher(stores[0], watchers.get(1)));
http://git-wip-us.apache.org/repos/asf/accumulo/blob/dad7c7c9/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java b/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
index b2e810d..68dcb27 100644
--- a/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
+++ b/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
@@ -201,10 +201,13 @@ public class AuditedSecurityOperation extends SecurityOperation {
public boolean hasSystemPermission(TCredentials credentials, String user, SystemPermission permission) throws ThriftSecurityException {
try {
boolean result = super.hasSystemPermission(credentials, user, permission);
- audit(credentials, "checked permission %s on %s", permission, user);
+ if (result)
+ audit(credentials, "checked permission %s on %s", permission, user);
+ else
+ audit(credentials, "checked permission %s on %s denied", permission, user);
return result;
} catch (ThriftSecurityException ex) {
- audit(credentials, ex, "checking permission %s on %s", permission, user);
+ audit(credentials, ex, "checking permission %s on %s denied", permission, user);
log.debug(ex);
throw ex;
}
@@ -249,6 +252,354 @@ public class AuditedSecurityOperation extends SecurityOperation {
}
@Override
+ public boolean canCreateTable(TCredentials c, String tablename) throws ThriftSecurityException {
+ try {
+ boolean result = super.canCreateTable(c, tablename);
+ if (result)
+ audit(c, "create table %s allowed", tablename);
+ else
+ audit(c, "create table %s denied", tablename);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "create table %s denied", tablename);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canRenameTable(TCredentials c, String tableId, String newTableName, String oldTableName) throws ThriftSecurityException {
+ try {
+ boolean result = super.canRenameTable(c, tableId, newTableName, oldTableName);
+ if (result)
+ audit(c, "rename table on tableId %s from %s to %s allowed", tableId, oldTableName, newTableName);
+ else
+ audit(c, "rename table on tableId %s from %s to %s denied", tableId, oldTableName, newTableName);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "rename table on tableId %s from %s to %s denied", tableId, oldTableName, newTableName);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canSplitTablet(TCredentials credentials, String table) throws ThriftSecurityException {
+ try {
+ boolean result = super.canSplitTablet(credentials, table);
+ if (result)
+ audit(credentials, "split tablet on table %s allowed", table);
+ else
+ audit(credentials, "split tablet on table %s denied", table);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, "split tablet on table %s denied", table);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canPerformSystemActions(TCredentials credentials) throws ThriftSecurityException {
+ try {
+ boolean result = super.canPerformSystemActions(credentials);
+ if (result)
+ audit(credentials, "system action allowed");
+ else
+ audit(credentials, "system action denied");
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, "system action denied");
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canFlush(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canFlush(c, tableId);
+ if (result)
+ audit(c, "flush on tableId %s allowed ", tableId);
+ else
+ audit(c, "flush on tableId %s denied ", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "flush on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canAlterTable(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canAlterTable(c, tableId);
+ if (result)
+ audit(c, "alter table on tableId %s allowed", tableId);
+ else
+ audit(c, "alter table on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "alter table on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canCloneTable(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canCloneTable(c, tableId);
+ if (result)
+ audit(c, "clone table on tableId %s allowed", tableId);
+ else
+ audit(c, "clone table on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "clone table on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canDeleteTable(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canDeleteTable(c, tableId);
+ if (result)
+ audit(c, "delete table on tableId %s allowed", tableId);
+ else
+ audit(c, "delete table on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "delete table on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canOnlineOfflineTable(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canOnlineOfflineTable(c, tableId);
+ if (result)
+ audit(c, "offline table on tableId %s allowed", tableId);
+ else
+ audit(c, "offline table on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "offline table on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canMerge(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canMerge(c, tableId);
+ if (result)
+ audit(c, "merge table on tableId %s allowed", tableId);
+ else
+ audit(c, "merge table on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "merge table on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canDeleteRange(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canDeleteRange(c, tableId);
+ if (result)
+ audit(c, "delete range on tableId %s allowed", tableId);
+ else
+ audit(c, "delete range on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "delete range on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canBulkImport(TCredentials c, String tableId, String importDir) throws ThriftSecurityException {
+ try {
+ boolean result = super.canBulkImport(c, tableId, importDir);
+ if (result)
+ audit(c, "bulk import on tableId %s from directory %s allowed", tableId, importDir);
+ else
+ audit(c, "bulk import on tableId %s from directory %s denied", tableId, importDir);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "bulk import on tableId %s from directory %s denied", tableId, importDir);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canCompact(TCredentials c, String tableId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canCompact(c, tableId);
+ if (result)
+ audit(c, "compact on tableId %s allowed", tableId);
+ else
+ audit(c, "compact on tableId %s denied", tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "compact on tableId %s denied", tableId);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canChangeAuthorizations(TCredentials c, String user) throws ThriftSecurityException {
+ try {
+ boolean result = super.canChangeAuthorizations(c, user);
+ if (result)
+ audit(c, "change authorizations on user %s allowed", user);
+ else
+ audit(c, "change authorizations on user %s denied", user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "change authorizations on user %s denied", user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canChangePassword(TCredentials c, String user) throws ThriftSecurityException {
+ try {
+ boolean result = super.canChangePassword(c, user);
+ if (result)
+ audit(c, "change password on user %s allowed", user);
+ else
+ audit(c, "change password on user %s denied", user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "change password on user %s denied", user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canCreateUser(TCredentials c, String user) throws ThriftSecurityException {
+ try {
+ boolean result = super.canCreateUser(c, user);
+ if (result)
+ audit(c, "create user on user %s allowed", user);
+ else
+ audit(c, "create user on user %s denied", user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "create user on user %s denied", user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canDropUser(TCredentials c, String user) throws ThriftSecurityException {
+ try {
+ boolean result = super.canDropUser(c, user);
+ if (result)
+ audit(c, "drop user on user %s allowed", user);
+ else
+ audit(c, "drop user on user %s denied", user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "drop user on user %s denied", user);
+
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canGrantSystem(TCredentials c, String user, SystemPermission sysPerm) throws ThriftSecurityException {
+ try {
+ boolean result = super.canGrantSystem(c, user, sysPerm);
+ if (result)
+ audit(c, "grant system permission %s for user %s allowed", sysPerm, user);
+ else
+ audit(c, "grant system permission %s for user %s denied", sysPerm, user);
+ return result;
+
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "grant system permission %s for user %s denied", sysPerm, user);
+
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canGrantTable(TCredentials c, String user, String table) throws ThriftSecurityException {
+ try {
+ boolean result = super.canGrantTable(c, user, table);
+ if (result)
+ audit(c, "grant table on table %s for user %s allowed", table, user);
+ else
+ audit(c, "grant table on table %s for user %s denied", table, user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "grant table on table %s for user %s denied", table, user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canRevokeSystem(TCredentials c, String user, SystemPermission sysPerm) throws ThriftSecurityException {
+ try {
+ boolean result = super.canRevokeSystem(c, user, sysPerm);
+ if (result)
+ audit(c, "revoke system permission %s for user %s allowed", sysPerm, user);
+ else
+ audit(c, "revoke system permission %s for user %s denied", sysPerm, user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "revoke system permission %s for user %s denied", sysPerm, user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canRevokeTable(TCredentials c, String user, String table) throws ThriftSecurityException {
+ try {
+ boolean result = super.canRevokeTable(c, user, table);
+ if (result)
+ audit(c, "revoke table on table %s for user %s allowed", table, user);
+ else
+ audit(c, "revoke table on table %s for user %s denied", table, user);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, "revoke table on table %s for user %s denied", table, user);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canExport(TCredentials credentials, String tableId, String exportDir) throws ThriftSecurityException {
+ try {
+ boolean result = super.canExport(credentials, tableId, exportDir);
+ if (result)
+ audit(credentials, "export table on tableId %s to directory %s allowed", tableId, exportDir);
+ else
+ audit(credentials, "export table on tableId %s to directory %s denied", tableId, exportDir);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, "export table on tableId %s to directory %s denied", tableId, exportDir);
+ throw ex;
+ }
+ }
+
+ @Override
+ public boolean canImport(TCredentials credentials, String tableName, String importDir) throws ThriftSecurityException {
+ try {
+ boolean result = super.canImport(credentials, tableName, importDir);
+ if (result)
+ audit(credentials, "import table %s from directory %s allowed", tableName, importDir);
+ else
+ audit(credentials, "import table %s from directory %s denied", tableName, importDir);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, "import table %s from directory %s denied", tableName, importDir);
+ throw ex;
+ }
+ }
+
+ @Override
public void initializeSecurity(TCredentials credentials, String principal, byte[] token) throws AccumuloSecurityException, ThriftSecurityException {
super.initializeSecurity(credentials, principal, token);
log.info("Initialized root user with username: " + principal + " at the request of user " + credentials.getPrincipal());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/dad7c7c9/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java b/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
index 13d1c32..6a817f2 100644
--- a/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
+++ b/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
@@ -314,12 +314,12 @@ public class SecurityOperation {
|| hasSystemPermission(c.getPrincipal(), SystemPermission.ALTER_TABLE, false);
}
- public boolean canCreateTable(TCredentials c) throws ThriftSecurityException {
+ public boolean canCreateTable(TCredentials c, String tablename) throws ThriftSecurityException {
authenticate(c);
return hasSystemPermission(c.getPrincipal(), SystemPermission.CREATE_TABLE, false);
}
- public boolean canRenameTable(TCredentials c, String tableId) throws ThriftSecurityException {
+ public boolean canRenameTable(TCredentials c, String tableId, String newTableName, String oldTableName) throws ThriftSecurityException {
authenticate(c);
return hasSystemPermission(c.getPrincipal(), SystemPermission.ALTER_TABLE, false)
|| hasTablePermission(c.getPrincipal(), tableId, TablePermission.ALTER_TABLE, false);
@@ -354,7 +354,7 @@ public class SecurityOperation {
return hasSystemPermission(c.getPrincipal(), SystemPermission.SYSTEM, false) || hasTablePermission(c.getPrincipal(), tableId, TablePermission.WRITE, false);
}
- public boolean canBulkImport(TCredentials c, String tableId) throws ThriftSecurityException {
+ public boolean canBulkImport(TCredentials c, String tableId, String importDir) throws ThriftSecurityException {
authenticate(c);
return hasTablePermission(c.getPrincipal(), tableId, TablePermission.BULK_IMPORT, false);
}
@@ -601,12 +601,12 @@ public class SecurityOperation {
}
}
- public boolean canExport(TCredentials credentials, String tableId) throws ThriftSecurityException {
+ public boolean canExport(TCredentials credentials, String tableId, String exportDir) throws ThriftSecurityException {
authenticate(credentials);
return hasTablePermission(credentials.getPrincipal(), tableId, TablePermission.READ, false);
}
- public boolean canImport(TCredentials credentials) throws ThriftSecurityException {
+ public boolean canImport(TCredentials credentials, String tableName, String importDir) throws ThriftSecurityException {
authenticate(credentials);
return hasSystemPermission(credentials.getPrincipal(), SystemPermission.CREATE_TABLE, false);
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/dad7c7c9/test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java b/test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java
index 61b146a..318c2a6 100644
--- a/test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java
+++ b/test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java
@@ -36,7 +36,7 @@ public class CreateTable extends Test {
String tableName = WalkingSecurity.get(state).getTableName();
boolean exists = WalkingSecurity.get(state).getTableExists();
- boolean hasPermission = WalkingSecurity.get(state).canCreateTable(WalkingSecurity.get(state).getSysCredentials());
+ boolean hasPermission = WalkingSecurity.get(state).canCreateTable(WalkingSecurity.get(state).getSysCredentials(), tableName);
try {
conn.tableOperations().create(tableName);
http://git-wip-us.apache.org/repos/asf/accumulo/blob/dad7c7c9/test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java b/test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java
index 6db56b2..dfe9c15 100644
--- a/test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java
+++ b/test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java
@@ -216,7 +216,7 @@ public class TableOp extends Test {
return;
} catch (AccumuloSecurityException ae) {
if (ae.getSecurityErrorCode().equals(SecurityErrorCode.PERMISSION_DENIED)) {
- if (WalkingSecurity.get(state).canBulkImport(WalkingSecurity.get(state).getTabCredentials(), tableName))
+ if (WalkingSecurity.get(state).canBulkImport(WalkingSecurity.get(state).getTabCredentials(), tableName, dir.getName()))
throw new AccumuloException("Bulk Import failed when it should have worked: " + tableName);
return;
} else if (ae.getSecurityErrorCode().equals(SecurityErrorCode.BAD_CREDENTIALS)) {
@@ -230,7 +230,7 @@ public class TableOp extends Test {
fs.delete(dir, true);
fs.delete(fail, true);
- if (!WalkingSecurity.get(state).canBulkImport(WalkingSecurity.get(state).getTabCredentials(), tableName))
+ if (!WalkingSecurity.get(state).canBulkImport(WalkingSecurity.get(state).getTabCredentials(), tableName, dir.getName()))
throw new AccumuloException("Bulk Import succeeded when it should have failed: " + dir + " table " + tableName);
break;
case ALTER_TABLE:
[06/10] accumulo git commit: Merge branch '1.5' into 1.6
Posted by el...@apache.org.
Merge branch '1.5' into 1.6
Conflicts:
server/src/main/java/org/apache/accumulo/server/master/Master.java
server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java
test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/00c275b1
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/00c275b1
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/00c275b1
Branch: refs/heads/1.6
Commit: 00c275b1f655e91a8a79bb24aab0e57eaf75d096
Parents: 6425c37 dad7c7c
Author: Josh Elser <el...@apache.org>
Authored: Wed Aug 19 23:13:23 2015 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Wed Aug 19 23:34:24 2015 -0400
----------------------------------------------------------------------
.../security/AuditedSecurityOperation.java | 213 +++++++++++++++++++
1 file changed, 213 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/00c275b1/server/base/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
----------------------------------------------------------------------
diff --cc server/base/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
index 50f258e,0000000..5aea5a2
mode 100644,000000..100644
--- a/server/base/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
@@@ -1,457 -1,0 +1,670 @@@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.server.security;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.client.impl.Tables;
+import org.apache.accumulo.core.client.impl.Translator;
+import org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException;
+import org.apache.accumulo.core.data.Column;
+import org.apache.accumulo.core.data.KeyExtent;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.thrift.IterInfo;
+import org.apache.accumulo.core.data.thrift.TColumn;
+import org.apache.accumulo.core.data.thrift.TKeyExtent;
+import org.apache.accumulo.core.data.thrift.TRange;
+import org.apache.accumulo.core.master.thrift.FateOperation;
+import org.apache.accumulo.core.metadata.MetadataTable;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.security.Credentials;
+import org.apache.accumulo.core.security.SystemPermission;
+import org.apache.accumulo.core.security.TablePermission;
+import org.apache.accumulo.core.security.thrift.TCredentials;
+import org.apache.accumulo.core.util.ByteBufferUtil;
+import org.apache.accumulo.server.client.HdfsZooInstance;
+import org.apache.accumulo.server.security.handler.Authenticator;
+import org.apache.accumulo.server.security.handler.Authorizor;
+import org.apache.accumulo.server.security.handler.PermissionHandler;
+import org.apache.accumulo.server.util.TServerUtils;
+import org.apache.hadoop.io.Text;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+
+/**
+ *
+ */
+public class AuditedSecurityOperation extends SecurityOperation {
+
+ public static final String AUDITLOG = "Audit";
+ public static final Logger audit = Logger.getLogger(AUDITLOG);
+
+ public AuditedSecurityOperation(Authorizor author, Authenticator authent, PermissionHandler pm, String instanceId) {
+ super(author, authent, pm, instanceId);
+ }
+
+ public static synchronized SecurityOperation getInstance() {
+ String instanceId = HdfsZooInstance.getInstance().getInstanceID();
+ return getInstance(instanceId, false);
+ }
+
+ public static synchronized SecurityOperation getInstance(String instanceId, boolean initialize) {
+ if (instance == null) {
+ instance = new AuditedSecurityOperation(getAuthorizor(instanceId, initialize), getAuthenticator(instanceId, initialize), getPermHandler(instanceId,
+ initialize), instanceId);
+ }
+ return instance;
+ }
+
+ private static String getTableName(String tableId) {
+ try {
+ return Tables.getTableName(HdfsZooInstance.getInstance(), tableId);
+ } catch (TableNotFoundException e) {
+ return "Unknown Table with ID " + tableId;
+ }
+ }
+
+ public static StringBuilder getAuthString(List<ByteBuffer> authorizations) {
+ StringBuilder auths = new StringBuilder();
+ for (ByteBuffer bb : authorizations) {
+ auths.append(ByteBufferUtil.toString(bb)).append(",");
+ }
+ return auths;
+ }
+
+ private static boolean shouldAudit(TCredentials credentials, String tableId) {
+ return (audit.isInfoEnabled() || audit.isEnabledFor(Level.WARN)) && !tableId.equals(MetadataTable.ID) && shouldAudit(credentials);
+ }
+
+ // Is INFO the right level to check? Do we even need that check?
+ private static boolean shouldAudit(TCredentials credentials) {
+ return !SystemCredentials.get().getToken().getClass().getName().equals(credentials.getTokenClassName());
+ }
+
+ /*
+ * Three auditing methods try to capture the 4 states we might have here. audit is in response to a thrown exception, the operation failed (perhaps due to
+ * insufficient privs, or some other reason) audit(credentials, template, args) is a successful operation audit(credentials, permitted, template, args) is a
+ * privileges check that is either permitted or denied. We don't know if the operation went on to be successful or not at this point, we would have to go
+ * digging through loads of other code to find it.
+ */
+ private void audit(TCredentials credentials, ThriftSecurityException ex, String template, Object... args) {
+ audit.warn("operation: failed; user: " + credentials.getPrincipal() + "; " + String.format(template, args) + "; exception: " + ex.toString());
+ }
+
+ private void audit(TCredentials credentials, String template, Object... args) {
+ if (shouldAudit(credentials)) {
+ audit.info("operation: success; user: " + credentials.getPrincipal() + ": " + String.format(template, args));
+ }
+ }
+
+ private void audit(TCredentials credentials, boolean permitted, String template, Object... args) {
+ if (shouldAudit(credentials)) {
+ String prefix = permitted ? "permitted" : "denied";
+ audit.info("operation: " + prefix + "; user: " + credentials.getPrincipal() + "; client: " + TServerUtils.clientAddress.get() + "; "
+ + String.format(template, args));
+ }
+ }
+
+ public static final String CAN_SCAN_AUDIT_TEMPLATE = "action: scan; targetTable: %s; authorizations: %s; range: %s; columns: %s; iterators: %s; iteratorOptions: %s;";
+ private static final int MAX_ELEMENTS_TO_LOG = 10;
+
+ private static List<String> truncate(Collection<?> list) {
+ List<String> result = new ArrayList<String>();
+ int i = 0;
+ for (Object obj : list) {
+ if (i++ > MAX_ELEMENTS_TO_LOG) {
+ result.add(" and " + (list.size() - MAX_ELEMENTS_TO_LOG) + " more ");
+ break;
+ }
+ result.add(obj.toString());
+ }
+ return result;
+ }
+
+ @Override
+ public boolean canScan(TCredentials credentials, String tableId, String namespaceId, TRange range, List<TColumn> columns, List<IterInfo> ssiList,
+ Map<String,Map<String,String>> ssio, List<ByteBuffer> authorizations) throws ThriftSecurityException {
+ if (shouldAudit(credentials, tableId)) {
+ Range convertedRange = new Range(range);
+ List<String> convertedColumns = truncate(Translator.translate(columns, new Translator.TColumnTranslator()));
+ String tableName = getTableName(tableId);
+
+ try {
+ boolean canScan = super.canScan(credentials, tableId, namespaceId);
+ audit(credentials, canScan, CAN_SCAN_AUDIT_TEMPLATE, tableName, getAuthString(authorizations), convertedRange, convertedColumns, ssiList, ssio);
+
+ return canScan;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CAN_SCAN_AUDIT_TEMPLATE, getAuthString(authorizations), tableId, convertedRange, convertedColumns, ssiList, ssio);
+ throw ex;
+ }
+ } else {
+ return super.canScan(credentials, tableId, namespaceId);
+ }
+ }
+
+ public static final String CAN_SCAN_BATCH_AUDIT_TEMPLATE = "action: scan; targetTable: %s; authorizations: %s; range: %s; columns: %s; iterators: %s; iteratorOptions: %s;";
+
+ @Override
+ public boolean canScan(TCredentials credentials, String tableId, String namespaceId, Map<TKeyExtent,List<TRange>> tbatch, List<TColumn> tcolumns,
+ List<IterInfo> ssiList, Map<String,Map<String,String>> ssio, List<ByteBuffer> authorizations) throws ThriftSecurityException {
+ if (shouldAudit(credentials, tableId)) {
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ Map<KeyExtent,List<Range>> convertedBatch = Translator.translate(tbatch, new Translator.TKeyExtentTranslator(), new Translator.ListTranslator(
+ new Translator.TRangeTranslator()));
+ Map<KeyExtent,List<String>> truncated = new HashMap<KeyExtent,List<String>>();
+ for (Entry<KeyExtent,List<Range>> entry : convertedBatch.entrySet()) {
+ truncated.put(entry.getKey(), truncate(entry.getValue()));
+ }
+ List<Column> convertedColumns = Translator.translate(tcolumns, new Translator.TColumnTranslator());
+ String tableName = getTableName(tableId);
+
+ try {
+ boolean canScan = super.canScan(credentials, tableId, namespaceId);
+ audit(credentials, canScan, CAN_SCAN_BATCH_AUDIT_TEMPLATE, tableName, getAuthString(authorizations), truncated, convertedColumns, ssiList, ssio);
+
+ return canScan;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CAN_SCAN_BATCH_AUDIT_TEMPLATE, getAuthString(authorizations), tableId, truncated, convertedColumns, ssiList, ssio);
+ throw ex;
+ }
+ } else {
+ return super.canScan(credentials, tableId, namespaceId);
+ }
+ }
+
+ public static final String CHANGE_AUTHORIZATIONS_AUDIT_TEMPLATE = "action: changeAuthorizations; targetUser: %s; authorizations: %s";
+
+ @Override
+ public void changeAuthorizations(TCredentials credentials, String user, Authorizations authorizations) throws ThriftSecurityException {
+ try {
+ super.changeAuthorizations(credentials, user, authorizations);
+ audit(credentials, CHANGE_AUTHORIZATIONS_AUDIT_TEMPLATE, user, authorizations);
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CHANGE_AUTHORIZATIONS_AUDIT_TEMPLATE, user, authorizations);
+ throw ex;
+ }
+ }
+
+ public static final String CHANGE_PASSWORD_AUDIT_TEMPLATE = "action: changePassword; targetUser: %s;";
+
+ @Override
+ public void changePassword(TCredentials credentials, Credentials newInfo) throws ThriftSecurityException {
+ try {
+ super.changePassword(credentials, newInfo);
+ audit(credentials, CHANGE_PASSWORD_AUDIT_TEMPLATE, newInfo.getPrincipal());
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CHANGE_PASSWORD_AUDIT_TEMPLATE, newInfo.getPrincipal());
+ throw ex;
+ }
+ }
+
+ public static final String CREATE_USER_AUDIT_TEMPLATE = "action: createUser; targetUser: %s; Authorizations: %s;";
+
+ @Override
+ public void createUser(TCredentials credentials, Credentials newUser, Authorizations authorizations) throws ThriftSecurityException {
+ try {
+ super.createUser(credentials, newUser, authorizations);
+ audit(credentials, CREATE_USER_AUDIT_TEMPLATE, newUser.getPrincipal(), authorizations);
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CREATE_USER_AUDIT_TEMPLATE, newUser.getPrincipal(), authorizations);
+ throw ex;
+ }
+ }
+
+ public static final String CAN_CREATE_TABLE_AUDIT_TEMPLATE = "action: createTable; targetTable: %s;";
+
+ @Override
+ public boolean canCreateTable(TCredentials c, String tableName, String namespaceId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canCreateTable(c, tableName, namespaceId);
+ audit(c, result, CAN_CREATE_TABLE_AUDIT_TEMPLATE, tableName);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, CAN_CREATE_TABLE_AUDIT_TEMPLATE, tableName);
+ throw ex;
+ }
+ }
+
+ public static final String CAN_DELETE_TABLE_AUDIT_TEMPLATE = "action: deleteTable; targetTable: %s;";
+
+ @Override
+ public boolean canDeleteTable(TCredentials c, String tableId, String namespaceId) throws ThriftSecurityException {
+ String tableName = getTableName(tableId);
+ try {
+ boolean result = super.canDeleteTable(c, tableId, namespaceId);
+ audit(c, result, CAN_DELETE_TABLE_AUDIT_TEMPLATE, tableName, tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, CAN_DELETE_TABLE_AUDIT_TEMPLATE, tableName, tableId);
+ throw ex;
+ }
+ }
+
+ public static final String CAN_RENAME_TABLE_AUDIT_TEMPLATE = "action: renameTable; targetTable: %s; newTableName: %s;";
+
+ @Override
+ public boolean canRenameTable(TCredentials c, String tableId, String oldTableName, String newTableName, String namespaceId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canRenameTable(c, tableId, oldTableName, newTableName, namespaceId);
+ audit(c, result, CAN_RENAME_TABLE_AUDIT_TEMPLATE, oldTableName, newTableName);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, CAN_RENAME_TABLE_AUDIT_TEMPLATE, oldTableName, newTableName);
+ throw ex;
+ }
+ }
+
++ public static final String CAN_SPLIT_TABLE_AUDIT_TEMPLATE = "action: splitTable; targetTable: %s; targetNamespace: %s;";
++
++ @Override
++ public boolean canSplitTablet(TCredentials credentials, String table, String namespaceId) throws ThriftSecurityException {
++ try {
++ boolean result = super.canSplitTablet(credentials, table, namespaceId);
++ audit(credentials, result, CAN_SPLIT_TABLE_AUDIT_TEMPLATE, table, namespaceId);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(credentials, ex, "split tablet on table %s denied", table);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_PERFORM_SYSTEM_ACTION_AUDIT_TEMPLATE = "action: performSystemAction; principal: %s;";
++
++ @Override
++ public boolean canPerformSystemActions(TCredentials credentials) throws ThriftSecurityException {
++ try {
++ boolean result = super.canPerformSystemActions(credentials);
++ audit(credentials, result, CAN_PERFORM_SYSTEM_ACTION_AUDIT_TEMPLATE, credentials.getPrincipal());
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(credentials, ex, "system action denied");
++ throw ex;
++ }
++ }
++
++ public static final String CAN_FLUSH_TABLE_AUDIT_TEMPLATE = "action: flushTable; targetTable: %s; targetNamespace: %s;";
++
++ @Override
++ public boolean canFlush(TCredentials c, String tableId, String namespaceId) throws ThriftSecurityException {
++ try {
++ boolean result = super.canFlush(c, tableId, namespaceId);
++ audit(c, result, CAN_FLUSH_TABLE_AUDIT_TEMPLATE, tableId, namespaceId);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "flush on tableId %s denied", tableId);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_ALTER_TABLE_AUDIT_TEMPLATE = "action: alterTable; targetTable: %s; targetNamespace: %s;";
++
++ @Override
++ public boolean canAlterTable(TCredentials c, String tableId, String namespaceId) throws ThriftSecurityException {
++ try {
++ boolean result = super.canAlterTable(c, tableId, namespaceId);
++ audit(c, result, CAN_ALTER_TABLE_AUDIT_TEMPLATE, tableId, namespaceId);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "alter table on tableId %s denied", tableId);
++ throw ex;
++ }
++ }
++
+ public static final String CAN_CLONE_TABLE_AUDIT_TEMPLATE = "action: cloneTable; targetTable: %s; newTableName: %s";
+
+ @Override
+ public boolean canCloneTable(TCredentials c, String tableId, String tableName, String destinationNamespaceId, String sourceNamespaceId)
+ throws ThriftSecurityException {
+ String oldTableName = getTableName(tableId);
+ try {
+ boolean result = super.canCloneTable(c, tableId, tableName, destinationNamespaceId, sourceNamespaceId);
+ audit(c, result, CAN_CLONE_TABLE_AUDIT_TEMPLATE, oldTableName, tableName);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, CAN_CLONE_TABLE_AUDIT_TEMPLATE, oldTableName, tableName);
+ throw ex;
+ }
+ }
+
+ public static final String CAN_DELETE_RANGE_AUDIT_TEMPLATE = "action: deleteData; targetTable: %s; startRange: %s; endRange: %s;";
+
+ @Override
+ public boolean canDeleteRange(TCredentials c, String tableId, String tableName, Text startRow, Text endRow, String namespaceId)
+ throws ThriftSecurityException {
+ try {
+ boolean result = super.canDeleteRange(c, tableId, tableName, startRow, endRow, namespaceId);
+ audit(c, result, CAN_DELETE_RANGE_AUDIT_TEMPLATE, tableName, startRow.toString(), endRow.toString());
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, CAN_DELETE_RANGE_AUDIT_TEMPLATE, tableName, startRow.toString(), endRow.toString());
+ throw ex;
+ }
+ }
+
+ public static final String CAN_BULK_IMPORT_AUDIT_TEMPLATE = "action: bulkImport; targetTable: %s; dataDir: %s; failDir: %s;";
+
+ @Override
+ public boolean canBulkImport(TCredentials c, String tableId, String tableName, String dir, String failDir, String namespaceId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canBulkImport(c, tableId, namespaceId);
+ audit(c, result, CAN_BULK_IMPORT_AUDIT_TEMPLATE, tableName, dir, failDir);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, CAN_BULK_IMPORT_AUDIT_TEMPLATE, tableName, dir, failDir);
+ throw ex;
+ }
+ }
+
++ public static final String CAN_COMPACT_TABLE_AUDIT_TEMPLATE = "action: compactTable; targetTable: %s; targetNamespace: %s;";
++
++ @Override
++ public boolean canCompact(TCredentials c, String tableId, String namespaceId) throws ThriftSecurityException {
++ try {
++ boolean result = super.canCompact(c, tableId, namespaceId);
++ audit(c, result, CAN_COMPACT_TABLE_AUDIT_TEMPLATE, tableId, namespaceId);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "compact on tableId %s denied", tableId);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_CHANGE_AUTHORIZATIONS_AUDIT_TEMPLATE = "action: changeAuthorizations; targetUser: %s;";
++
++ @Override
++ public boolean canChangeAuthorizations(TCredentials c, String user) throws ThriftSecurityException {
++ try {
++ boolean result = super.canChangeAuthorizations(c, user);
++ audit(c, result, CAN_CHANGE_AUTHORIZATIONS_AUDIT_TEMPLATE, user);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "change authorizations on user %s denied", user);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_CHANGE_PASSWORD_AUDIT_TEMPLATE = "action: changePassword; targetUser: %s;";
++
++ @Override
++ public boolean canChangePassword(TCredentials c, String user) throws ThriftSecurityException {
++ try {
++ boolean result = super.canChangePassword(c, user);
++ audit(c, result, CAN_CHANGE_PASSWORD_AUDIT_TEMPLATE, user);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "change password on user %s denied", user);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_CREATE_USER_AUDIT_TEMPLATE = "action: createUser; targetUser: %s;";
++
++ @Override
++ public boolean canCreateUser(TCredentials c, String user) throws ThriftSecurityException {
++ try {
++ boolean result = super.canCreateUser(c, user);
++ audit(c, result, CAN_CREATE_USER_AUDIT_TEMPLATE, user);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "create user on user %s denied", user);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_DROP_USER_AUDIT_TEMPLATE = "action: dropUser; targetUser: %s;";
++
++ @Override
++ public boolean canDropUser(TCredentials c, String user) throws ThriftSecurityException {
++ try {
++ boolean result = super.canDropUser(c, user);
++ audit(c, result, CAN_DROP_USER_AUDIT_TEMPLATE, user);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "drop user on user %s denied", user);
++
++ throw ex;
++ }
++ }
++
++ public static final String CAN_GRANT_SYSTEM_AUDIT_TEMPLATE = "action: grantSystem; targetUser: %s; targetPermission: %s;";
++
++ @Override
++ public boolean canGrantSystem(TCredentials c, String user, SystemPermission sysPerm) throws ThriftSecurityException {
++ try {
++ boolean result = super.canGrantSystem(c, user, sysPerm);
++ audit(c, result, CAN_GRANT_SYSTEM_AUDIT_TEMPLATE, user, sysPerm);
++ return result;
++
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "grant system permission %s for user %s denied", sysPerm, user);
++
++ throw ex;
++ }
++ }
++
++ public static final String CAN_GRANT_TABLE_AUDIT_TEMPLATE = "action: grantTable; targetUser: %s; targetTable: %s; targetNamespace: %s;";
++
++ @Override
++ public boolean canGrantTable(TCredentials c, String user, String table, String namespaceId) throws ThriftSecurityException {
++ try {
++ boolean result = super.canGrantTable(c, user, table, namespaceId);
++ audit(c, result, CAN_GRANT_TABLE_AUDIT_TEMPLATE, user, table, namespaceId);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "grant table on table %s for user %s denied", table, user);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_REVOKE_SYSTEM_AUDIT_TEMPLATE = "action: revokeSystem; targetUser: %s;, targetPermission: %s;";
++
++ @Override
++ public boolean canRevokeSystem(TCredentials c, String user, SystemPermission sysPerm) throws ThriftSecurityException {
++ try {
++ boolean result = super.canRevokeSystem(c, user, sysPerm);
++ audit(c, result, CAN_REVOKE_SYSTEM_AUDIT_TEMPLATE, user, sysPerm);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "revoke system permission %s for user %s denied", sysPerm, user);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_REVOKE_TABLE_AUDIT_TEMPLATE = "action: revokeTable; targetUser: %s; targetTable %s; targetNamespace: %s;";
++
++ @Override
++ public boolean canRevokeTable(TCredentials c, String user, String table, String namespaceId) throws ThriftSecurityException {
++ try {
++ boolean result = super.canRevokeTable(c, user, table, namespaceId);
++ audit(c, result, CAN_REVOKE_TABLE_AUDIT_TEMPLATE, user, table, namespaceId);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "revoke table on table %s for user %s denied", table, user);
++ throw ex;
++ }
++ }
++
+ public static final String CAN_IMPORT_AUDIT_TEMPLATE = "action: import; targetTable: %s; dataDir: %s;";
+
+ @Override
+ public boolean canImport(TCredentials credentials, String tableName, String importDir, String namespaceId) throws ThriftSecurityException {
+
+ try {
+ boolean result = super.canImport(credentials, tableName, importDir, namespaceId);
+ audit(credentials, result, CAN_IMPORT_AUDIT_TEMPLATE, tableName, importDir);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CAN_IMPORT_AUDIT_TEMPLATE, tableName, importDir);
+ throw ex;
+ }
+ }
+
+ public static final String CAN_EXPORT_AUDIT_TEMPLATE = "action: export; targetTable: %s; dataDir: %s;";
+
+ @Override
+ public boolean canExport(TCredentials credentials, String tableId, String tableName, String exportDir, String namespaceId) throws ThriftSecurityException {
+
+ try {
+ boolean result = super.canExport(credentials, tableId, tableName, exportDir, namespaceId);
+ audit(credentials, result, CAN_EXPORT_AUDIT_TEMPLATE, tableName, exportDir);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CAN_EXPORT_AUDIT_TEMPLATE, tableName, exportDir);
+ throw ex;
+ }
+ }
+
+ public static final String DROP_USER_AUDIT_TEMPLATE = "action: dropUser; targetUser: %s;";
+
+ @Override
+ public void dropUser(TCredentials credentials, String user) throws ThriftSecurityException {
+ try {
+ super.dropUser(credentials, user);
+ audit(credentials, DROP_USER_AUDIT_TEMPLATE, user);
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, DROP_USER_AUDIT_TEMPLATE, user);
+ throw ex;
+ }
+ }
+
+ public static final String GRANT_SYSTEM_PERMISSION_AUDIT_TEMPLATE = "action: grantSystemPermission; permission: %s; targetUser: %s;";
+
+ @Override
+ public void grantSystemPermission(TCredentials credentials, String user, SystemPermission permission) throws ThriftSecurityException {
+ try {
+ super.grantSystemPermission(credentials, user, permission);
+ audit(credentials, GRANT_SYSTEM_PERMISSION_AUDIT_TEMPLATE, permission, user);
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, GRANT_SYSTEM_PERMISSION_AUDIT_TEMPLATE, permission, user);
+ throw ex;
+ }
+ }
+
+ public static final String GRANT_TABLE_PERMISSION_AUDIT_TEMPLATE = "action: grantTablePermission; permission: %s; targetTable: %s; targetUser: %s;";
+
+ @Override
+ public void grantTablePermission(TCredentials credentials, String user, String tableId, TablePermission permission, String namespaceId)
+ throws ThriftSecurityException {
+ String tableName = getTableName(tableId);
+ try {
+ super.grantTablePermission(credentials, user, tableId, permission, namespaceId);
+ audit(credentials, GRANT_TABLE_PERMISSION_AUDIT_TEMPLATE, permission, tableName, user);
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, GRANT_TABLE_PERMISSION_AUDIT_TEMPLATE, permission, tableName, user);
+ throw ex;
+ }
+ }
+
+ public static final String REVOKE_SYSTEM_PERMISSION_AUDIT_TEMPLATE = "action: revokeSystemPermission; permission: %s; targetUser: %s;";
+
+ @Override
+ public void revokeSystemPermission(TCredentials credentials, String user, SystemPermission permission) throws ThriftSecurityException {
+
+ try {
+ super.revokeSystemPermission(credentials, user, permission);
+ audit(credentials, REVOKE_SYSTEM_PERMISSION_AUDIT_TEMPLATE, permission, user);
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, REVOKE_SYSTEM_PERMISSION_AUDIT_TEMPLATE, permission, user);
+ throw ex;
+ }
+ }
+
+ public static final String REVOKE_TABLE_PERMISSION_AUDIT_TEMPLATE = "action: revokeTablePermission; permission: %s; targetTable: %s; targetUser: %s;";
+
+ @Override
+ public void revokeTablePermission(TCredentials credentials, String user, String tableId, TablePermission permission, String namespaceId)
+ throws ThriftSecurityException {
+ String tableName = getTableName(tableId);
+ try {
+ super.revokeTablePermission(credentials, user, tableId, permission, namespaceId);
+ audit(credentials, REVOKE_TABLE_PERMISSION_AUDIT_TEMPLATE, permission, tableName, user);
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, REVOKE_TABLE_PERMISSION_AUDIT_TEMPLATE, permission, tableName, user);
+ throw ex;
+ }
+ }
+
++ public static final String HAS_SYSTEM_PERMISSION_AUDIT_TEMPLATE = "action: hasSystemPermission; permission: %s; targetUser: %s;";
++
++ @Override
++ public boolean hasSystemPermission(TCredentials credentials, String user, SystemPermission permission) throws ThriftSecurityException {
++ try {
++ boolean result = super.hasSystemPermission(credentials, user, permission);
++ audit(credentials, result, HAS_SYSTEM_PERMISSION_AUDIT_TEMPLATE, permission, user);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(credentials, ex, "checking permission %s on %s denied", permission, user);
++ throw ex;
++ }
++ }
++
+ public static final String CAN_ONLINE_OFFLINE_TABLE_AUDIT_TEMPLATE = "action: %s; targetTable: %s;";
+
+ @Override
+ public boolean canOnlineOfflineTable(TCredentials credentials, String tableId, FateOperation op, String namespaceId) throws ThriftSecurityException {
+ String tableName = getTableName(tableId);
+ String operation = null;
+ if (op == FateOperation.TABLE_ONLINE)
+ operation = "onlineTable";
+ if (op == FateOperation.TABLE_OFFLINE)
+ operation = "offlineTable";
+ try {
+ boolean result = super.canOnlineOfflineTable(credentials, tableId, op, namespaceId);
+ audit(credentials, result, CAN_ONLINE_OFFLINE_TABLE_AUDIT_TEMPLATE, operation, tableName, tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CAN_ONLINE_OFFLINE_TABLE_AUDIT_TEMPLATE, operation, tableName, tableId);
+ throw ex;
+ }
+ }
+
++ public static final String CAN_MERGE_TABLE_AUDIT_TEMPLATE = "action: mergeTable; targetTable: %s; targetNamespace: %s;";
++
++ @Override
++ public boolean canMerge(TCredentials c, String tableId, String namespaceId) throws ThriftSecurityException {
++ try {
++ boolean result = super.canMerge(c, tableId, namespaceId);
++ audit(c, result, CAN_MERGE_TABLE_AUDIT_TEMPLATE, tableId, namespaceId);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "merge table on tableId %s denied", tableId);
++ throw ex;
++ }
++ }
++
+ // The audit log is already logging the principal, so we don't have anything else to audit
+ public static final String AUTHENICATE_AUDIT_TEMPLATE = "";
+
+ @Override
+ protected void authenticate(TCredentials credentials) throws ThriftSecurityException {
+ try {
+ super.authenticate(credentials);
+ audit(credentials, true, AUTHENICATE_AUDIT_TEMPLATE);
+ } catch (ThriftSecurityException e) {
+ audit(credentials, false, AUTHENICATE_AUDIT_TEMPLATE);
+ throw e;
+ }
+ }
+}
[09/10] accumulo git commit: Merge branch '1.6' into 1.7
Posted by el...@apache.org.
Merge branch '1.6' into 1.7
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/d5d883cb
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/d5d883cb
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/d5d883cb
Branch: refs/heads/master
Commit: d5d883cbbdc1341b07e1e6ec72631ad66fbcdd49
Parents: e4f1df3 00c275b
Author: Josh Elser <el...@apache.org>
Authored: Wed Aug 19 23:36:49 2015 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Wed Aug 19 23:36:49 2015 -0400
----------------------------------------------------------------------
.../security/AuditedSecurityOperation.java | 213 +++++++++++++++++++
1 file changed, 213 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/d5d883cb/server/base/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
----------------------------------------------------------------------
[07/10] accumulo git commit: Merge branch '1.5' into 1.6
Posted by el...@apache.org.
Merge branch '1.5' into 1.6
Conflicts:
server/src/main/java/org/apache/accumulo/server/master/Master.java
server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java
test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/00c275b1
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/00c275b1
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/00c275b1
Branch: refs/heads/master
Commit: 00c275b1f655e91a8a79bb24aab0e57eaf75d096
Parents: 6425c37 dad7c7c
Author: Josh Elser <el...@apache.org>
Authored: Wed Aug 19 23:13:23 2015 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Wed Aug 19 23:34:24 2015 -0400
----------------------------------------------------------------------
.../security/AuditedSecurityOperation.java | 213 +++++++++++++++++++
1 file changed, 213 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/00c275b1/server/base/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
----------------------------------------------------------------------
diff --cc server/base/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
index 50f258e,0000000..5aea5a2
mode 100644,000000..100644
--- a/server/base/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
@@@ -1,457 -1,0 +1,670 @@@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.server.security;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.client.impl.Tables;
+import org.apache.accumulo.core.client.impl.Translator;
+import org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException;
+import org.apache.accumulo.core.data.Column;
+import org.apache.accumulo.core.data.KeyExtent;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.thrift.IterInfo;
+import org.apache.accumulo.core.data.thrift.TColumn;
+import org.apache.accumulo.core.data.thrift.TKeyExtent;
+import org.apache.accumulo.core.data.thrift.TRange;
+import org.apache.accumulo.core.master.thrift.FateOperation;
+import org.apache.accumulo.core.metadata.MetadataTable;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.security.Credentials;
+import org.apache.accumulo.core.security.SystemPermission;
+import org.apache.accumulo.core.security.TablePermission;
+import org.apache.accumulo.core.security.thrift.TCredentials;
+import org.apache.accumulo.core.util.ByteBufferUtil;
+import org.apache.accumulo.server.client.HdfsZooInstance;
+import org.apache.accumulo.server.security.handler.Authenticator;
+import org.apache.accumulo.server.security.handler.Authorizor;
+import org.apache.accumulo.server.security.handler.PermissionHandler;
+import org.apache.accumulo.server.util.TServerUtils;
+import org.apache.hadoop.io.Text;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+
+/**
+ *
+ */
+public class AuditedSecurityOperation extends SecurityOperation {
+
+ public static final String AUDITLOG = "Audit";
+ public static final Logger audit = Logger.getLogger(AUDITLOG);
+
+ public AuditedSecurityOperation(Authorizor author, Authenticator authent, PermissionHandler pm, String instanceId) {
+ super(author, authent, pm, instanceId);
+ }
+
+ public static synchronized SecurityOperation getInstance() {
+ String instanceId = HdfsZooInstance.getInstance().getInstanceID();
+ return getInstance(instanceId, false);
+ }
+
+ public static synchronized SecurityOperation getInstance(String instanceId, boolean initialize) {
+ if (instance == null) {
+ instance = new AuditedSecurityOperation(getAuthorizor(instanceId, initialize), getAuthenticator(instanceId, initialize), getPermHandler(instanceId,
+ initialize), instanceId);
+ }
+ return instance;
+ }
+
+ private static String getTableName(String tableId) {
+ try {
+ return Tables.getTableName(HdfsZooInstance.getInstance(), tableId);
+ } catch (TableNotFoundException e) {
+ return "Unknown Table with ID " + tableId;
+ }
+ }
+
+ public static StringBuilder getAuthString(List<ByteBuffer> authorizations) {
+ StringBuilder auths = new StringBuilder();
+ for (ByteBuffer bb : authorizations) {
+ auths.append(ByteBufferUtil.toString(bb)).append(",");
+ }
+ return auths;
+ }
+
+ private static boolean shouldAudit(TCredentials credentials, String tableId) {
+ return (audit.isInfoEnabled() || audit.isEnabledFor(Level.WARN)) && !tableId.equals(MetadataTable.ID) && shouldAudit(credentials);
+ }
+
+ // Is INFO the right level to check? Do we even need that check?
+ private static boolean shouldAudit(TCredentials credentials) {
+ return !SystemCredentials.get().getToken().getClass().getName().equals(credentials.getTokenClassName());
+ }
+
+ /*
+ * Three auditing methods try to capture the 4 states we might have here. audit is in response to a thrown exception, the operation failed (perhaps due to
+ * insufficient privs, or some other reason) audit(credentials, template, args) is a successful operation audit(credentials, permitted, template, args) is a
+ * privileges check that is either permitted or denied. We don't know if the operation went on to be successful or not at this point, we would have to go
+ * digging through loads of other code to find it.
+ */
+ private void audit(TCredentials credentials, ThriftSecurityException ex, String template, Object... args) {
+ audit.warn("operation: failed; user: " + credentials.getPrincipal() + "; " + String.format(template, args) + "; exception: " + ex.toString());
+ }
+
+ private void audit(TCredentials credentials, String template, Object... args) {
+ if (shouldAudit(credentials)) {
+ audit.info("operation: success; user: " + credentials.getPrincipal() + ": " + String.format(template, args));
+ }
+ }
+
+ private void audit(TCredentials credentials, boolean permitted, String template, Object... args) {
+ if (shouldAudit(credentials)) {
+ String prefix = permitted ? "permitted" : "denied";
+ audit.info("operation: " + prefix + "; user: " + credentials.getPrincipal() + "; client: " + TServerUtils.clientAddress.get() + "; "
+ + String.format(template, args));
+ }
+ }
+
+ public static final String CAN_SCAN_AUDIT_TEMPLATE = "action: scan; targetTable: %s; authorizations: %s; range: %s; columns: %s; iterators: %s; iteratorOptions: %s;";
+ private static final int MAX_ELEMENTS_TO_LOG = 10;
+
+ private static List<String> truncate(Collection<?> list) {
+ List<String> result = new ArrayList<String>();
+ int i = 0;
+ for (Object obj : list) {
+ if (i++ > MAX_ELEMENTS_TO_LOG) {
+ result.add(" and " + (list.size() - MAX_ELEMENTS_TO_LOG) + " more ");
+ break;
+ }
+ result.add(obj.toString());
+ }
+ return result;
+ }
+
+ @Override
+ public boolean canScan(TCredentials credentials, String tableId, String namespaceId, TRange range, List<TColumn> columns, List<IterInfo> ssiList,
+ Map<String,Map<String,String>> ssio, List<ByteBuffer> authorizations) throws ThriftSecurityException {
+ if (shouldAudit(credentials, tableId)) {
+ Range convertedRange = new Range(range);
+ List<String> convertedColumns = truncate(Translator.translate(columns, new Translator.TColumnTranslator()));
+ String tableName = getTableName(tableId);
+
+ try {
+ boolean canScan = super.canScan(credentials, tableId, namespaceId);
+ audit(credentials, canScan, CAN_SCAN_AUDIT_TEMPLATE, tableName, getAuthString(authorizations), convertedRange, convertedColumns, ssiList, ssio);
+
+ return canScan;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CAN_SCAN_AUDIT_TEMPLATE, getAuthString(authorizations), tableId, convertedRange, convertedColumns, ssiList, ssio);
+ throw ex;
+ }
+ } else {
+ return super.canScan(credentials, tableId, namespaceId);
+ }
+ }
+
+ public static final String CAN_SCAN_BATCH_AUDIT_TEMPLATE = "action: scan; targetTable: %s; authorizations: %s; range: %s; columns: %s; iterators: %s; iteratorOptions: %s;";
+
+ @Override
+ public boolean canScan(TCredentials credentials, String tableId, String namespaceId, Map<TKeyExtent,List<TRange>> tbatch, List<TColumn> tcolumns,
+ List<IterInfo> ssiList, Map<String,Map<String,String>> ssio, List<ByteBuffer> authorizations) throws ThriftSecurityException {
+ if (shouldAudit(credentials, tableId)) {
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ Map<KeyExtent,List<Range>> convertedBatch = Translator.translate(tbatch, new Translator.TKeyExtentTranslator(), new Translator.ListTranslator(
+ new Translator.TRangeTranslator()));
+ Map<KeyExtent,List<String>> truncated = new HashMap<KeyExtent,List<String>>();
+ for (Entry<KeyExtent,List<Range>> entry : convertedBatch.entrySet()) {
+ truncated.put(entry.getKey(), truncate(entry.getValue()));
+ }
+ List<Column> convertedColumns = Translator.translate(tcolumns, new Translator.TColumnTranslator());
+ String tableName = getTableName(tableId);
+
+ try {
+ boolean canScan = super.canScan(credentials, tableId, namespaceId);
+ audit(credentials, canScan, CAN_SCAN_BATCH_AUDIT_TEMPLATE, tableName, getAuthString(authorizations), truncated, convertedColumns, ssiList, ssio);
+
+ return canScan;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CAN_SCAN_BATCH_AUDIT_TEMPLATE, getAuthString(authorizations), tableId, truncated, convertedColumns, ssiList, ssio);
+ throw ex;
+ }
+ } else {
+ return super.canScan(credentials, tableId, namespaceId);
+ }
+ }
+
+ public static final String CHANGE_AUTHORIZATIONS_AUDIT_TEMPLATE = "action: changeAuthorizations; targetUser: %s; authorizations: %s";
+
+ @Override
+ public void changeAuthorizations(TCredentials credentials, String user, Authorizations authorizations) throws ThriftSecurityException {
+ try {
+ super.changeAuthorizations(credentials, user, authorizations);
+ audit(credentials, CHANGE_AUTHORIZATIONS_AUDIT_TEMPLATE, user, authorizations);
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CHANGE_AUTHORIZATIONS_AUDIT_TEMPLATE, user, authorizations);
+ throw ex;
+ }
+ }
+
+ public static final String CHANGE_PASSWORD_AUDIT_TEMPLATE = "action: changePassword; targetUser: %s;";
+
+ @Override
+ public void changePassword(TCredentials credentials, Credentials newInfo) throws ThriftSecurityException {
+ try {
+ super.changePassword(credentials, newInfo);
+ audit(credentials, CHANGE_PASSWORD_AUDIT_TEMPLATE, newInfo.getPrincipal());
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CHANGE_PASSWORD_AUDIT_TEMPLATE, newInfo.getPrincipal());
+ throw ex;
+ }
+ }
+
+ public static final String CREATE_USER_AUDIT_TEMPLATE = "action: createUser; targetUser: %s; Authorizations: %s;";
+
+ @Override
+ public void createUser(TCredentials credentials, Credentials newUser, Authorizations authorizations) throws ThriftSecurityException {
+ try {
+ super.createUser(credentials, newUser, authorizations);
+ audit(credentials, CREATE_USER_AUDIT_TEMPLATE, newUser.getPrincipal(), authorizations);
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CREATE_USER_AUDIT_TEMPLATE, newUser.getPrincipal(), authorizations);
+ throw ex;
+ }
+ }
+
+ public static final String CAN_CREATE_TABLE_AUDIT_TEMPLATE = "action: createTable; targetTable: %s;";
+
+ @Override
+ public boolean canCreateTable(TCredentials c, String tableName, String namespaceId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canCreateTable(c, tableName, namespaceId);
+ audit(c, result, CAN_CREATE_TABLE_AUDIT_TEMPLATE, tableName);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, CAN_CREATE_TABLE_AUDIT_TEMPLATE, tableName);
+ throw ex;
+ }
+ }
+
+ public static final String CAN_DELETE_TABLE_AUDIT_TEMPLATE = "action: deleteTable; targetTable: %s;";
+
+ @Override
+ public boolean canDeleteTable(TCredentials c, String tableId, String namespaceId) throws ThriftSecurityException {
+ String tableName = getTableName(tableId);
+ try {
+ boolean result = super.canDeleteTable(c, tableId, namespaceId);
+ audit(c, result, CAN_DELETE_TABLE_AUDIT_TEMPLATE, tableName, tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, CAN_DELETE_TABLE_AUDIT_TEMPLATE, tableName, tableId);
+ throw ex;
+ }
+ }
+
+ public static final String CAN_RENAME_TABLE_AUDIT_TEMPLATE = "action: renameTable; targetTable: %s; newTableName: %s;";
+
+ @Override
+ public boolean canRenameTable(TCredentials c, String tableId, String oldTableName, String newTableName, String namespaceId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canRenameTable(c, tableId, oldTableName, newTableName, namespaceId);
+ audit(c, result, CAN_RENAME_TABLE_AUDIT_TEMPLATE, oldTableName, newTableName);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, CAN_RENAME_TABLE_AUDIT_TEMPLATE, oldTableName, newTableName);
+ throw ex;
+ }
+ }
+
++ public static final String CAN_SPLIT_TABLE_AUDIT_TEMPLATE = "action: splitTable; targetTable: %s; targetNamespace: %s;";
++
++ @Override
++ public boolean canSplitTablet(TCredentials credentials, String table, String namespaceId) throws ThriftSecurityException {
++ try {
++ boolean result = super.canSplitTablet(credentials, table, namespaceId);
++ audit(credentials, result, CAN_SPLIT_TABLE_AUDIT_TEMPLATE, table, namespaceId);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(credentials, ex, "split tablet on table %s denied", table);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_PERFORM_SYSTEM_ACTION_AUDIT_TEMPLATE = "action: performSystemAction; principal: %s;";
++
++ @Override
++ public boolean canPerformSystemActions(TCredentials credentials) throws ThriftSecurityException {
++ try {
++ boolean result = super.canPerformSystemActions(credentials);
++ audit(credentials, result, CAN_PERFORM_SYSTEM_ACTION_AUDIT_TEMPLATE, credentials.getPrincipal());
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(credentials, ex, "system action denied");
++ throw ex;
++ }
++ }
++
++ public static final String CAN_FLUSH_TABLE_AUDIT_TEMPLATE = "action: flushTable; targetTable: %s; targetNamespace: %s;";
++
++ @Override
++ public boolean canFlush(TCredentials c, String tableId, String namespaceId) throws ThriftSecurityException {
++ try {
++ boolean result = super.canFlush(c, tableId, namespaceId);
++ audit(c, result, CAN_FLUSH_TABLE_AUDIT_TEMPLATE, tableId, namespaceId);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "flush on tableId %s denied", tableId);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_ALTER_TABLE_AUDIT_TEMPLATE = "action: alterTable; targetTable: %s; targetNamespace: %s;";
++
++ @Override
++ public boolean canAlterTable(TCredentials c, String tableId, String namespaceId) throws ThriftSecurityException {
++ try {
++ boolean result = super.canAlterTable(c, tableId, namespaceId);
++ audit(c, result, CAN_ALTER_TABLE_AUDIT_TEMPLATE, tableId, namespaceId);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "alter table on tableId %s denied", tableId);
++ throw ex;
++ }
++ }
++
+ public static final String CAN_CLONE_TABLE_AUDIT_TEMPLATE = "action: cloneTable; targetTable: %s; newTableName: %s";
+
+ @Override
+ public boolean canCloneTable(TCredentials c, String tableId, String tableName, String destinationNamespaceId, String sourceNamespaceId)
+ throws ThriftSecurityException {
+ String oldTableName = getTableName(tableId);
+ try {
+ boolean result = super.canCloneTable(c, tableId, tableName, destinationNamespaceId, sourceNamespaceId);
+ audit(c, result, CAN_CLONE_TABLE_AUDIT_TEMPLATE, oldTableName, tableName);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, CAN_CLONE_TABLE_AUDIT_TEMPLATE, oldTableName, tableName);
+ throw ex;
+ }
+ }
+
+ public static final String CAN_DELETE_RANGE_AUDIT_TEMPLATE = "action: deleteData; targetTable: %s; startRange: %s; endRange: %s;";
+
+ @Override
+ public boolean canDeleteRange(TCredentials c, String tableId, String tableName, Text startRow, Text endRow, String namespaceId)
+ throws ThriftSecurityException {
+ try {
+ boolean result = super.canDeleteRange(c, tableId, tableName, startRow, endRow, namespaceId);
+ audit(c, result, CAN_DELETE_RANGE_AUDIT_TEMPLATE, tableName, startRow.toString(), endRow.toString());
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, CAN_DELETE_RANGE_AUDIT_TEMPLATE, tableName, startRow.toString(), endRow.toString());
+ throw ex;
+ }
+ }
+
+ public static final String CAN_BULK_IMPORT_AUDIT_TEMPLATE = "action: bulkImport; targetTable: %s; dataDir: %s; failDir: %s;";
+
+ @Override
+ public boolean canBulkImport(TCredentials c, String tableId, String tableName, String dir, String failDir, String namespaceId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canBulkImport(c, tableId, namespaceId);
+ audit(c, result, CAN_BULK_IMPORT_AUDIT_TEMPLATE, tableName, dir, failDir);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, CAN_BULK_IMPORT_AUDIT_TEMPLATE, tableName, dir, failDir);
+ throw ex;
+ }
+ }
+
++ public static final String CAN_COMPACT_TABLE_AUDIT_TEMPLATE = "action: compactTable; targetTable: %s; targetNamespace: %s;";
++
++ @Override
++ public boolean canCompact(TCredentials c, String tableId, String namespaceId) throws ThriftSecurityException {
++ try {
++ boolean result = super.canCompact(c, tableId, namespaceId);
++ audit(c, result, CAN_COMPACT_TABLE_AUDIT_TEMPLATE, tableId, namespaceId);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "compact on tableId %s denied", tableId);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_CHANGE_AUTHORIZATIONS_AUDIT_TEMPLATE = "action: changeAuthorizations; targetUser: %s;";
++
++ @Override
++ public boolean canChangeAuthorizations(TCredentials c, String user) throws ThriftSecurityException {
++ try {
++ boolean result = super.canChangeAuthorizations(c, user);
++ audit(c, result, CAN_CHANGE_AUTHORIZATIONS_AUDIT_TEMPLATE, user);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "change authorizations on user %s denied", user);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_CHANGE_PASSWORD_AUDIT_TEMPLATE = "action: changePassword; targetUser: %s;";
++
++ @Override
++ public boolean canChangePassword(TCredentials c, String user) throws ThriftSecurityException {
++ try {
++ boolean result = super.canChangePassword(c, user);
++ audit(c, result, CAN_CHANGE_PASSWORD_AUDIT_TEMPLATE, user);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "change password on user %s denied", user);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_CREATE_USER_AUDIT_TEMPLATE = "action: createUser; targetUser: %s;";
++
++ @Override
++ public boolean canCreateUser(TCredentials c, String user) throws ThriftSecurityException {
++ try {
++ boolean result = super.canCreateUser(c, user);
++ audit(c, result, CAN_CREATE_USER_AUDIT_TEMPLATE, user);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "create user on user %s denied", user);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_DROP_USER_AUDIT_TEMPLATE = "action: dropUser; targetUser: %s;";
++
++ @Override
++ public boolean canDropUser(TCredentials c, String user) throws ThriftSecurityException {
++ try {
++ boolean result = super.canDropUser(c, user);
++ audit(c, result, CAN_DROP_USER_AUDIT_TEMPLATE, user);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "drop user on user %s denied", user);
++
++ throw ex;
++ }
++ }
++
++ public static final String CAN_GRANT_SYSTEM_AUDIT_TEMPLATE = "action: grantSystem; targetUser: %s; targetPermission: %s;";
++
++ @Override
++ public boolean canGrantSystem(TCredentials c, String user, SystemPermission sysPerm) throws ThriftSecurityException {
++ try {
++ boolean result = super.canGrantSystem(c, user, sysPerm);
++ audit(c, result, CAN_GRANT_SYSTEM_AUDIT_TEMPLATE, user, sysPerm);
++ return result;
++
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "grant system permission %s for user %s denied", sysPerm, user);
++
++ throw ex;
++ }
++ }
++
++ public static final String CAN_GRANT_TABLE_AUDIT_TEMPLATE = "action: grantTable; targetUser: %s; targetTable: %s; targetNamespace: %s;";
++
++ @Override
++ public boolean canGrantTable(TCredentials c, String user, String table, String namespaceId) throws ThriftSecurityException {
++ try {
++ boolean result = super.canGrantTable(c, user, table, namespaceId);
++ audit(c, result, CAN_GRANT_TABLE_AUDIT_TEMPLATE, user, table, namespaceId);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "grant table on table %s for user %s denied", table, user);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_REVOKE_SYSTEM_AUDIT_TEMPLATE = "action: revokeSystem; targetUser: %s;, targetPermission: %s;";
++
++ @Override
++ public boolean canRevokeSystem(TCredentials c, String user, SystemPermission sysPerm) throws ThriftSecurityException {
++ try {
++ boolean result = super.canRevokeSystem(c, user, sysPerm);
++ audit(c, result, CAN_REVOKE_SYSTEM_AUDIT_TEMPLATE, user, sysPerm);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "revoke system permission %s for user %s denied", sysPerm, user);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_REVOKE_TABLE_AUDIT_TEMPLATE = "action: revokeTable; targetUser: %s; targetTable %s; targetNamespace: %s;";
++
++ @Override
++ public boolean canRevokeTable(TCredentials c, String user, String table, String namespaceId) throws ThriftSecurityException {
++ try {
++ boolean result = super.canRevokeTable(c, user, table, namespaceId);
++ audit(c, result, CAN_REVOKE_TABLE_AUDIT_TEMPLATE, user, table, namespaceId);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "revoke table on table %s for user %s denied", table, user);
++ throw ex;
++ }
++ }
++
+ public static final String CAN_IMPORT_AUDIT_TEMPLATE = "action: import; targetTable: %s; dataDir: %s;";
+
+ @Override
+ public boolean canImport(TCredentials credentials, String tableName, String importDir, String namespaceId) throws ThriftSecurityException {
+
+ try {
+ boolean result = super.canImport(credentials, tableName, importDir, namespaceId);
+ audit(credentials, result, CAN_IMPORT_AUDIT_TEMPLATE, tableName, importDir);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CAN_IMPORT_AUDIT_TEMPLATE, tableName, importDir);
+ throw ex;
+ }
+ }
+
+ public static final String CAN_EXPORT_AUDIT_TEMPLATE = "action: export; targetTable: %s; dataDir: %s;";
+
+ @Override
+ public boolean canExport(TCredentials credentials, String tableId, String tableName, String exportDir, String namespaceId) throws ThriftSecurityException {
+
+ try {
+ boolean result = super.canExport(credentials, tableId, tableName, exportDir, namespaceId);
+ audit(credentials, result, CAN_EXPORT_AUDIT_TEMPLATE, tableName, exportDir);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CAN_EXPORT_AUDIT_TEMPLATE, tableName, exportDir);
+ throw ex;
+ }
+ }
+
+ public static final String DROP_USER_AUDIT_TEMPLATE = "action: dropUser; targetUser: %s;";
+
+ @Override
+ public void dropUser(TCredentials credentials, String user) throws ThriftSecurityException {
+ try {
+ super.dropUser(credentials, user);
+ audit(credentials, DROP_USER_AUDIT_TEMPLATE, user);
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, DROP_USER_AUDIT_TEMPLATE, user);
+ throw ex;
+ }
+ }
+
+ public static final String GRANT_SYSTEM_PERMISSION_AUDIT_TEMPLATE = "action: grantSystemPermission; permission: %s; targetUser: %s;";
+
+ @Override
+ public void grantSystemPermission(TCredentials credentials, String user, SystemPermission permission) throws ThriftSecurityException {
+ try {
+ super.grantSystemPermission(credentials, user, permission);
+ audit(credentials, GRANT_SYSTEM_PERMISSION_AUDIT_TEMPLATE, permission, user);
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, GRANT_SYSTEM_PERMISSION_AUDIT_TEMPLATE, permission, user);
+ throw ex;
+ }
+ }
+
+ public static final String GRANT_TABLE_PERMISSION_AUDIT_TEMPLATE = "action: grantTablePermission; permission: %s; targetTable: %s; targetUser: %s;";
+
+ @Override
+ public void grantTablePermission(TCredentials credentials, String user, String tableId, TablePermission permission, String namespaceId)
+ throws ThriftSecurityException {
+ String tableName = getTableName(tableId);
+ try {
+ super.grantTablePermission(credentials, user, tableId, permission, namespaceId);
+ audit(credentials, GRANT_TABLE_PERMISSION_AUDIT_TEMPLATE, permission, tableName, user);
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, GRANT_TABLE_PERMISSION_AUDIT_TEMPLATE, permission, tableName, user);
+ throw ex;
+ }
+ }
+
+ public static final String REVOKE_SYSTEM_PERMISSION_AUDIT_TEMPLATE = "action: revokeSystemPermission; permission: %s; targetUser: %s;";
+
+ @Override
+ public void revokeSystemPermission(TCredentials credentials, String user, SystemPermission permission) throws ThriftSecurityException {
+
+ try {
+ super.revokeSystemPermission(credentials, user, permission);
+ audit(credentials, REVOKE_SYSTEM_PERMISSION_AUDIT_TEMPLATE, permission, user);
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, REVOKE_SYSTEM_PERMISSION_AUDIT_TEMPLATE, permission, user);
+ throw ex;
+ }
+ }
+
+ public static final String REVOKE_TABLE_PERMISSION_AUDIT_TEMPLATE = "action: revokeTablePermission; permission: %s; targetTable: %s; targetUser: %s;";
+
+ @Override
+ public void revokeTablePermission(TCredentials credentials, String user, String tableId, TablePermission permission, String namespaceId)
+ throws ThriftSecurityException {
+ String tableName = getTableName(tableId);
+ try {
+ super.revokeTablePermission(credentials, user, tableId, permission, namespaceId);
+ audit(credentials, REVOKE_TABLE_PERMISSION_AUDIT_TEMPLATE, permission, tableName, user);
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, REVOKE_TABLE_PERMISSION_AUDIT_TEMPLATE, permission, tableName, user);
+ throw ex;
+ }
+ }
+
++ public static final String HAS_SYSTEM_PERMISSION_AUDIT_TEMPLATE = "action: hasSystemPermission; permission: %s; targetUser: %s;";
++
++ @Override
++ public boolean hasSystemPermission(TCredentials credentials, String user, SystemPermission permission) throws ThriftSecurityException {
++ try {
++ boolean result = super.hasSystemPermission(credentials, user, permission);
++ audit(credentials, result, HAS_SYSTEM_PERMISSION_AUDIT_TEMPLATE, permission, user);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(credentials, ex, "checking permission %s on %s denied", permission, user);
++ throw ex;
++ }
++ }
++
+ public static final String CAN_ONLINE_OFFLINE_TABLE_AUDIT_TEMPLATE = "action: %s; targetTable: %s;";
+
+ @Override
+ public boolean canOnlineOfflineTable(TCredentials credentials, String tableId, FateOperation op, String namespaceId) throws ThriftSecurityException {
+ String tableName = getTableName(tableId);
+ String operation = null;
+ if (op == FateOperation.TABLE_ONLINE)
+ operation = "onlineTable";
+ if (op == FateOperation.TABLE_OFFLINE)
+ operation = "offlineTable";
+ try {
+ boolean result = super.canOnlineOfflineTable(credentials, tableId, op, namespaceId);
+ audit(credentials, result, CAN_ONLINE_OFFLINE_TABLE_AUDIT_TEMPLATE, operation, tableName, tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CAN_ONLINE_OFFLINE_TABLE_AUDIT_TEMPLATE, operation, tableName, tableId);
+ throw ex;
+ }
+ }
+
++ public static final String CAN_MERGE_TABLE_AUDIT_TEMPLATE = "action: mergeTable; targetTable: %s; targetNamespace: %s;";
++
++ @Override
++ public boolean canMerge(TCredentials c, String tableId, String namespaceId) throws ThriftSecurityException {
++ try {
++ boolean result = super.canMerge(c, tableId, namespaceId);
++ audit(c, result, CAN_MERGE_TABLE_AUDIT_TEMPLATE, tableId, namespaceId);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "merge table on tableId %s denied", tableId);
++ throw ex;
++ }
++ }
++
+ // The audit log is already logging the principal, so we don't have anything else to audit
+ public static final String AUTHENICATE_AUDIT_TEMPLATE = "";
+
+ @Override
+ protected void authenticate(TCredentials credentials) throws ThriftSecurityException {
+ try {
+ super.authenticate(credentials);
+ audit(credentials, true, AUTHENICATE_AUDIT_TEMPLATE);
+ } catch (ThriftSecurityException e) {
+ audit(credentials, false, AUTHENICATE_AUDIT_TEMPLATE);
+ throw e;
+ }
+ }
+}
[05/10] accumulo git commit: Merge branch '1.5' into 1.6
Posted by el...@apache.org.
Merge branch '1.5' into 1.6
Conflicts:
server/src/main/java/org/apache/accumulo/server/master/Master.java
server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
test/src/main/java/org/apache/accumulo/test/randomwalk/security/CreateTable.java
test/src/main/java/org/apache/accumulo/test/randomwalk/security/TableOp.java
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/00c275b1
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/00c275b1
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/00c275b1
Branch: refs/heads/1.7
Commit: 00c275b1f655e91a8a79bb24aab0e57eaf75d096
Parents: 6425c37 dad7c7c
Author: Josh Elser <el...@apache.org>
Authored: Wed Aug 19 23:13:23 2015 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Wed Aug 19 23:34:24 2015 -0400
----------------------------------------------------------------------
.../security/AuditedSecurityOperation.java | 213 +++++++++++++++++++
1 file changed, 213 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/00c275b1/server/base/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
----------------------------------------------------------------------
diff --cc server/base/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
index 50f258e,0000000..5aea5a2
mode 100644,000000..100644
--- a/server/base/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
@@@ -1,457 -1,0 +1,670 @@@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.server.security;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.client.impl.Tables;
+import org.apache.accumulo.core.client.impl.Translator;
+import org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException;
+import org.apache.accumulo.core.data.Column;
+import org.apache.accumulo.core.data.KeyExtent;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.thrift.IterInfo;
+import org.apache.accumulo.core.data.thrift.TColumn;
+import org.apache.accumulo.core.data.thrift.TKeyExtent;
+import org.apache.accumulo.core.data.thrift.TRange;
+import org.apache.accumulo.core.master.thrift.FateOperation;
+import org.apache.accumulo.core.metadata.MetadataTable;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.security.Credentials;
+import org.apache.accumulo.core.security.SystemPermission;
+import org.apache.accumulo.core.security.TablePermission;
+import org.apache.accumulo.core.security.thrift.TCredentials;
+import org.apache.accumulo.core.util.ByteBufferUtil;
+import org.apache.accumulo.server.client.HdfsZooInstance;
+import org.apache.accumulo.server.security.handler.Authenticator;
+import org.apache.accumulo.server.security.handler.Authorizor;
+import org.apache.accumulo.server.security.handler.PermissionHandler;
+import org.apache.accumulo.server.util.TServerUtils;
+import org.apache.hadoop.io.Text;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+
+/**
+ *
+ */
+public class AuditedSecurityOperation extends SecurityOperation {
+
+ public static final String AUDITLOG = "Audit";
+ public static final Logger audit = Logger.getLogger(AUDITLOG);
+
+ public AuditedSecurityOperation(Authorizor author, Authenticator authent, PermissionHandler pm, String instanceId) {
+ super(author, authent, pm, instanceId);
+ }
+
+ public static synchronized SecurityOperation getInstance() {
+ String instanceId = HdfsZooInstance.getInstance().getInstanceID();
+ return getInstance(instanceId, false);
+ }
+
+ public static synchronized SecurityOperation getInstance(String instanceId, boolean initialize) {
+ if (instance == null) {
+ instance = new AuditedSecurityOperation(getAuthorizor(instanceId, initialize), getAuthenticator(instanceId, initialize), getPermHandler(instanceId,
+ initialize), instanceId);
+ }
+ return instance;
+ }
+
+ private static String getTableName(String tableId) {
+ try {
+ return Tables.getTableName(HdfsZooInstance.getInstance(), tableId);
+ } catch (TableNotFoundException e) {
+ return "Unknown Table with ID " + tableId;
+ }
+ }
+
+ public static StringBuilder getAuthString(List<ByteBuffer> authorizations) {
+ StringBuilder auths = new StringBuilder();
+ for (ByteBuffer bb : authorizations) {
+ auths.append(ByteBufferUtil.toString(bb)).append(",");
+ }
+ return auths;
+ }
+
+ private static boolean shouldAudit(TCredentials credentials, String tableId) {
+ return (audit.isInfoEnabled() || audit.isEnabledFor(Level.WARN)) && !tableId.equals(MetadataTable.ID) && shouldAudit(credentials);
+ }
+
+ // Is INFO the right level to check? Do we even need that check?
+ private static boolean shouldAudit(TCredentials credentials) {
+ return !SystemCredentials.get().getToken().getClass().getName().equals(credentials.getTokenClassName());
+ }
+
+ /*
+ * Three auditing methods try to capture the 4 states we might have here. audit is in response to a thrown exception, the operation failed (perhaps due to
+ * insufficient privs, or some other reason) audit(credentials, template, args) is a successful operation audit(credentials, permitted, template, args) is a
+ * privileges check that is either permitted or denied. We don't know if the operation went on to be successful or not at this point, we would have to go
+ * digging through loads of other code to find it.
+ */
+ private void audit(TCredentials credentials, ThriftSecurityException ex, String template, Object... args) {
+ audit.warn("operation: failed; user: " + credentials.getPrincipal() + "; " + String.format(template, args) + "; exception: " + ex.toString());
+ }
+
+ private void audit(TCredentials credentials, String template, Object... args) {
+ if (shouldAudit(credentials)) {
+ audit.info("operation: success; user: " + credentials.getPrincipal() + ": " + String.format(template, args));
+ }
+ }
+
+ private void audit(TCredentials credentials, boolean permitted, String template, Object... args) {
+ if (shouldAudit(credentials)) {
+ String prefix = permitted ? "permitted" : "denied";
+ audit.info("operation: " + prefix + "; user: " + credentials.getPrincipal() + "; client: " + TServerUtils.clientAddress.get() + "; "
+ + String.format(template, args));
+ }
+ }
+
+ public static final String CAN_SCAN_AUDIT_TEMPLATE = "action: scan; targetTable: %s; authorizations: %s; range: %s; columns: %s; iterators: %s; iteratorOptions: %s;";
+ private static final int MAX_ELEMENTS_TO_LOG = 10;
+
+ private static List<String> truncate(Collection<?> list) {
+ List<String> result = new ArrayList<String>();
+ int i = 0;
+ for (Object obj : list) {
+ if (i++ > MAX_ELEMENTS_TO_LOG) {
+ result.add(" and " + (list.size() - MAX_ELEMENTS_TO_LOG) + " more ");
+ break;
+ }
+ result.add(obj.toString());
+ }
+ return result;
+ }
+
+ @Override
+ public boolean canScan(TCredentials credentials, String tableId, String namespaceId, TRange range, List<TColumn> columns, List<IterInfo> ssiList,
+ Map<String,Map<String,String>> ssio, List<ByteBuffer> authorizations) throws ThriftSecurityException {
+ if (shouldAudit(credentials, tableId)) {
+ Range convertedRange = new Range(range);
+ List<String> convertedColumns = truncate(Translator.translate(columns, new Translator.TColumnTranslator()));
+ String tableName = getTableName(tableId);
+
+ try {
+ boolean canScan = super.canScan(credentials, tableId, namespaceId);
+ audit(credentials, canScan, CAN_SCAN_AUDIT_TEMPLATE, tableName, getAuthString(authorizations), convertedRange, convertedColumns, ssiList, ssio);
+
+ return canScan;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CAN_SCAN_AUDIT_TEMPLATE, getAuthString(authorizations), tableId, convertedRange, convertedColumns, ssiList, ssio);
+ throw ex;
+ }
+ } else {
+ return super.canScan(credentials, tableId, namespaceId);
+ }
+ }
+
+ public static final String CAN_SCAN_BATCH_AUDIT_TEMPLATE = "action: scan; targetTable: %s; authorizations: %s; range: %s; columns: %s; iterators: %s; iteratorOptions: %s;";
+
+ @Override
+ public boolean canScan(TCredentials credentials, String tableId, String namespaceId, Map<TKeyExtent,List<TRange>> tbatch, List<TColumn> tcolumns,
+ List<IterInfo> ssiList, Map<String,Map<String,String>> ssio, List<ByteBuffer> authorizations) throws ThriftSecurityException {
+ if (shouldAudit(credentials, tableId)) {
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ Map<KeyExtent,List<Range>> convertedBatch = Translator.translate(tbatch, new Translator.TKeyExtentTranslator(), new Translator.ListTranslator(
+ new Translator.TRangeTranslator()));
+ Map<KeyExtent,List<String>> truncated = new HashMap<KeyExtent,List<String>>();
+ for (Entry<KeyExtent,List<Range>> entry : convertedBatch.entrySet()) {
+ truncated.put(entry.getKey(), truncate(entry.getValue()));
+ }
+ List<Column> convertedColumns = Translator.translate(tcolumns, new Translator.TColumnTranslator());
+ String tableName = getTableName(tableId);
+
+ try {
+ boolean canScan = super.canScan(credentials, tableId, namespaceId);
+ audit(credentials, canScan, CAN_SCAN_BATCH_AUDIT_TEMPLATE, tableName, getAuthString(authorizations), truncated, convertedColumns, ssiList, ssio);
+
+ return canScan;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CAN_SCAN_BATCH_AUDIT_TEMPLATE, getAuthString(authorizations), tableId, truncated, convertedColumns, ssiList, ssio);
+ throw ex;
+ }
+ } else {
+ return super.canScan(credentials, tableId, namespaceId);
+ }
+ }
+
+ public static final String CHANGE_AUTHORIZATIONS_AUDIT_TEMPLATE = "action: changeAuthorizations; targetUser: %s; authorizations: %s";
+
+ @Override
+ public void changeAuthorizations(TCredentials credentials, String user, Authorizations authorizations) throws ThriftSecurityException {
+ try {
+ super.changeAuthorizations(credentials, user, authorizations);
+ audit(credentials, CHANGE_AUTHORIZATIONS_AUDIT_TEMPLATE, user, authorizations);
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CHANGE_AUTHORIZATIONS_AUDIT_TEMPLATE, user, authorizations);
+ throw ex;
+ }
+ }
+
+ public static final String CHANGE_PASSWORD_AUDIT_TEMPLATE = "action: changePassword; targetUser: %s;";
+
+ @Override
+ public void changePassword(TCredentials credentials, Credentials newInfo) throws ThriftSecurityException {
+ try {
+ super.changePassword(credentials, newInfo);
+ audit(credentials, CHANGE_PASSWORD_AUDIT_TEMPLATE, newInfo.getPrincipal());
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CHANGE_PASSWORD_AUDIT_TEMPLATE, newInfo.getPrincipal());
+ throw ex;
+ }
+ }
+
+ public static final String CREATE_USER_AUDIT_TEMPLATE = "action: createUser; targetUser: %s; Authorizations: %s;";
+
+ @Override
+ public void createUser(TCredentials credentials, Credentials newUser, Authorizations authorizations) throws ThriftSecurityException {
+ try {
+ super.createUser(credentials, newUser, authorizations);
+ audit(credentials, CREATE_USER_AUDIT_TEMPLATE, newUser.getPrincipal(), authorizations);
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CREATE_USER_AUDIT_TEMPLATE, newUser.getPrincipal(), authorizations);
+ throw ex;
+ }
+ }
+
+ public static final String CAN_CREATE_TABLE_AUDIT_TEMPLATE = "action: createTable; targetTable: %s;";
+
+ @Override
+ public boolean canCreateTable(TCredentials c, String tableName, String namespaceId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canCreateTable(c, tableName, namespaceId);
+ audit(c, result, CAN_CREATE_TABLE_AUDIT_TEMPLATE, tableName);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, CAN_CREATE_TABLE_AUDIT_TEMPLATE, tableName);
+ throw ex;
+ }
+ }
+
+ public static final String CAN_DELETE_TABLE_AUDIT_TEMPLATE = "action: deleteTable; targetTable: %s;";
+
+ @Override
+ public boolean canDeleteTable(TCredentials c, String tableId, String namespaceId) throws ThriftSecurityException {
+ String tableName = getTableName(tableId);
+ try {
+ boolean result = super.canDeleteTable(c, tableId, namespaceId);
+ audit(c, result, CAN_DELETE_TABLE_AUDIT_TEMPLATE, tableName, tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, CAN_DELETE_TABLE_AUDIT_TEMPLATE, tableName, tableId);
+ throw ex;
+ }
+ }
+
+ public static final String CAN_RENAME_TABLE_AUDIT_TEMPLATE = "action: renameTable; targetTable: %s; newTableName: %s;";
+
+ @Override
+ public boolean canRenameTable(TCredentials c, String tableId, String oldTableName, String newTableName, String namespaceId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canRenameTable(c, tableId, oldTableName, newTableName, namespaceId);
+ audit(c, result, CAN_RENAME_TABLE_AUDIT_TEMPLATE, oldTableName, newTableName);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, CAN_RENAME_TABLE_AUDIT_TEMPLATE, oldTableName, newTableName);
+ throw ex;
+ }
+ }
+
++ public static final String CAN_SPLIT_TABLE_AUDIT_TEMPLATE = "action: splitTable; targetTable: %s; targetNamespace: %s;";
++
++ @Override
++ public boolean canSplitTablet(TCredentials credentials, String table, String namespaceId) throws ThriftSecurityException {
++ try {
++ boolean result = super.canSplitTablet(credentials, table, namespaceId);
++ audit(credentials, result, CAN_SPLIT_TABLE_AUDIT_TEMPLATE, table, namespaceId);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(credentials, ex, "split tablet on table %s denied", table);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_PERFORM_SYSTEM_ACTION_AUDIT_TEMPLATE = "action: performSystemAction; principal: %s;";
++
++ @Override
++ public boolean canPerformSystemActions(TCredentials credentials) throws ThriftSecurityException {
++ try {
++ boolean result = super.canPerformSystemActions(credentials);
++ audit(credentials, result, CAN_PERFORM_SYSTEM_ACTION_AUDIT_TEMPLATE, credentials.getPrincipal());
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(credentials, ex, "system action denied");
++ throw ex;
++ }
++ }
++
++ public static final String CAN_FLUSH_TABLE_AUDIT_TEMPLATE = "action: flushTable; targetTable: %s; targetNamespace: %s;";
++
++ @Override
++ public boolean canFlush(TCredentials c, String tableId, String namespaceId) throws ThriftSecurityException {
++ try {
++ boolean result = super.canFlush(c, tableId, namespaceId);
++ audit(c, result, CAN_FLUSH_TABLE_AUDIT_TEMPLATE, tableId, namespaceId);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "flush on tableId %s denied", tableId);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_ALTER_TABLE_AUDIT_TEMPLATE = "action: alterTable; targetTable: %s; targetNamespace: %s;";
++
++ @Override
++ public boolean canAlterTable(TCredentials c, String tableId, String namespaceId) throws ThriftSecurityException {
++ try {
++ boolean result = super.canAlterTable(c, tableId, namespaceId);
++ audit(c, result, CAN_ALTER_TABLE_AUDIT_TEMPLATE, tableId, namespaceId);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "alter table on tableId %s denied", tableId);
++ throw ex;
++ }
++ }
++
+ public static final String CAN_CLONE_TABLE_AUDIT_TEMPLATE = "action: cloneTable; targetTable: %s; newTableName: %s";
+
+ @Override
+ public boolean canCloneTable(TCredentials c, String tableId, String tableName, String destinationNamespaceId, String sourceNamespaceId)
+ throws ThriftSecurityException {
+ String oldTableName = getTableName(tableId);
+ try {
+ boolean result = super.canCloneTable(c, tableId, tableName, destinationNamespaceId, sourceNamespaceId);
+ audit(c, result, CAN_CLONE_TABLE_AUDIT_TEMPLATE, oldTableName, tableName);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, CAN_CLONE_TABLE_AUDIT_TEMPLATE, oldTableName, tableName);
+ throw ex;
+ }
+ }
+
+ public static final String CAN_DELETE_RANGE_AUDIT_TEMPLATE = "action: deleteData; targetTable: %s; startRange: %s; endRange: %s;";
+
+ @Override
+ public boolean canDeleteRange(TCredentials c, String tableId, String tableName, Text startRow, Text endRow, String namespaceId)
+ throws ThriftSecurityException {
+ try {
+ boolean result = super.canDeleteRange(c, tableId, tableName, startRow, endRow, namespaceId);
+ audit(c, result, CAN_DELETE_RANGE_AUDIT_TEMPLATE, tableName, startRow.toString(), endRow.toString());
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, CAN_DELETE_RANGE_AUDIT_TEMPLATE, tableName, startRow.toString(), endRow.toString());
+ throw ex;
+ }
+ }
+
+ public static final String CAN_BULK_IMPORT_AUDIT_TEMPLATE = "action: bulkImport; targetTable: %s; dataDir: %s; failDir: %s;";
+
+ @Override
+ public boolean canBulkImport(TCredentials c, String tableId, String tableName, String dir, String failDir, String namespaceId) throws ThriftSecurityException {
+ try {
+ boolean result = super.canBulkImport(c, tableId, namespaceId);
+ audit(c, result, CAN_BULK_IMPORT_AUDIT_TEMPLATE, tableName, dir, failDir);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(c, ex, CAN_BULK_IMPORT_AUDIT_TEMPLATE, tableName, dir, failDir);
+ throw ex;
+ }
+ }
+
++ public static final String CAN_COMPACT_TABLE_AUDIT_TEMPLATE = "action: compactTable; targetTable: %s; targetNamespace: %s;";
++
++ @Override
++ public boolean canCompact(TCredentials c, String tableId, String namespaceId) throws ThriftSecurityException {
++ try {
++ boolean result = super.canCompact(c, tableId, namespaceId);
++ audit(c, result, CAN_COMPACT_TABLE_AUDIT_TEMPLATE, tableId, namespaceId);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "compact on tableId %s denied", tableId);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_CHANGE_AUTHORIZATIONS_AUDIT_TEMPLATE = "action: changeAuthorizations; targetUser: %s;";
++
++ @Override
++ public boolean canChangeAuthorizations(TCredentials c, String user) throws ThriftSecurityException {
++ try {
++ boolean result = super.canChangeAuthorizations(c, user);
++ audit(c, result, CAN_CHANGE_AUTHORIZATIONS_AUDIT_TEMPLATE, user);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "change authorizations on user %s denied", user);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_CHANGE_PASSWORD_AUDIT_TEMPLATE = "action: changePassword; targetUser: %s;";
++
++ @Override
++ public boolean canChangePassword(TCredentials c, String user) throws ThriftSecurityException {
++ try {
++ boolean result = super.canChangePassword(c, user);
++ audit(c, result, CAN_CHANGE_PASSWORD_AUDIT_TEMPLATE, user);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "change password on user %s denied", user);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_CREATE_USER_AUDIT_TEMPLATE = "action: createUser; targetUser: %s;";
++
++ @Override
++ public boolean canCreateUser(TCredentials c, String user) throws ThriftSecurityException {
++ try {
++ boolean result = super.canCreateUser(c, user);
++ audit(c, result, CAN_CREATE_USER_AUDIT_TEMPLATE, user);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "create user on user %s denied", user);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_DROP_USER_AUDIT_TEMPLATE = "action: dropUser; targetUser: %s;";
++
++ @Override
++ public boolean canDropUser(TCredentials c, String user) throws ThriftSecurityException {
++ try {
++ boolean result = super.canDropUser(c, user);
++ audit(c, result, CAN_DROP_USER_AUDIT_TEMPLATE, user);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "drop user on user %s denied", user);
++
++ throw ex;
++ }
++ }
++
++ public static final String CAN_GRANT_SYSTEM_AUDIT_TEMPLATE = "action: grantSystem; targetUser: %s; targetPermission: %s;";
++
++ @Override
++ public boolean canGrantSystem(TCredentials c, String user, SystemPermission sysPerm) throws ThriftSecurityException {
++ try {
++ boolean result = super.canGrantSystem(c, user, sysPerm);
++ audit(c, result, CAN_GRANT_SYSTEM_AUDIT_TEMPLATE, user, sysPerm);
++ return result;
++
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "grant system permission %s for user %s denied", sysPerm, user);
++
++ throw ex;
++ }
++ }
++
++ public static final String CAN_GRANT_TABLE_AUDIT_TEMPLATE = "action: grantTable; targetUser: %s; targetTable: %s; targetNamespace: %s;";
++
++ @Override
++ public boolean canGrantTable(TCredentials c, String user, String table, String namespaceId) throws ThriftSecurityException {
++ try {
++ boolean result = super.canGrantTable(c, user, table, namespaceId);
++ audit(c, result, CAN_GRANT_TABLE_AUDIT_TEMPLATE, user, table, namespaceId);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "grant table on table %s for user %s denied", table, user);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_REVOKE_SYSTEM_AUDIT_TEMPLATE = "action: revokeSystem; targetUser: %s;, targetPermission: %s;";
++
++ @Override
++ public boolean canRevokeSystem(TCredentials c, String user, SystemPermission sysPerm) throws ThriftSecurityException {
++ try {
++ boolean result = super.canRevokeSystem(c, user, sysPerm);
++ audit(c, result, CAN_REVOKE_SYSTEM_AUDIT_TEMPLATE, user, sysPerm);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "revoke system permission %s for user %s denied", sysPerm, user);
++ throw ex;
++ }
++ }
++
++ public static final String CAN_REVOKE_TABLE_AUDIT_TEMPLATE = "action: revokeTable; targetUser: %s; targetTable %s; targetNamespace: %s;";
++
++ @Override
++ public boolean canRevokeTable(TCredentials c, String user, String table, String namespaceId) throws ThriftSecurityException {
++ try {
++ boolean result = super.canRevokeTable(c, user, table, namespaceId);
++ audit(c, result, CAN_REVOKE_TABLE_AUDIT_TEMPLATE, user, table, namespaceId);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "revoke table on table %s for user %s denied", table, user);
++ throw ex;
++ }
++ }
++
+ public static final String CAN_IMPORT_AUDIT_TEMPLATE = "action: import; targetTable: %s; dataDir: %s;";
+
+ @Override
+ public boolean canImport(TCredentials credentials, String tableName, String importDir, String namespaceId) throws ThriftSecurityException {
+
+ try {
+ boolean result = super.canImport(credentials, tableName, importDir, namespaceId);
+ audit(credentials, result, CAN_IMPORT_AUDIT_TEMPLATE, tableName, importDir);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CAN_IMPORT_AUDIT_TEMPLATE, tableName, importDir);
+ throw ex;
+ }
+ }
+
+ public static final String CAN_EXPORT_AUDIT_TEMPLATE = "action: export; targetTable: %s; dataDir: %s;";
+
+ @Override
+ public boolean canExport(TCredentials credentials, String tableId, String tableName, String exportDir, String namespaceId) throws ThriftSecurityException {
+
+ try {
+ boolean result = super.canExport(credentials, tableId, tableName, exportDir, namespaceId);
+ audit(credentials, result, CAN_EXPORT_AUDIT_TEMPLATE, tableName, exportDir);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CAN_EXPORT_AUDIT_TEMPLATE, tableName, exportDir);
+ throw ex;
+ }
+ }
+
+ public static final String DROP_USER_AUDIT_TEMPLATE = "action: dropUser; targetUser: %s;";
+
+ @Override
+ public void dropUser(TCredentials credentials, String user) throws ThriftSecurityException {
+ try {
+ super.dropUser(credentials, user);
+ audit(credentials, DROP_USER_AUDIT_TEMPLATE, user);
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, DROP_USER_AUDIT_TEMPLATE, user);
+ throw ex;
+ }
+ }
+
+ public static final String GRANT_SYSTEM_PERMISSION_AUDIT_TEMPLATE = "action: grantSystemPermission; permission: %s; targetUser: %s;";
+
+ @Override
+ public void grantSystemPermission(TCredentials credentials, String user, SystemPermission permission) throws ThriftSecurityException {
+ try {
+ super.grantSystemPermission(credentials, user, permission);
+ audit(credentials, GRANT_SYSTEM_PERMISSION_AUDIT_TEMPLATE, permission, user);
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, GRANT_SYSTEM_PERMISSION_AUDIT_TEMPLATE, permission, user);
+ throw ex;
+ }
+ }
+
+ public static final String GRANT_TABLE_PERMISSION_AUDIT_TEMPLATE = "action: grantTablePermission; permission: %s; targetTable: %s; targetUser: %s;";
+
+ @Override
+ public void grantTablePermission(TCredentials credentials, String user, String tableId, TablePermission permission, String namespaceId)
+ throws ThriftSecurityException {
+ String tableName = getTableName(tableId);
+ try {
+ super.grantTablePermission(credentials, user, tableId, permission, namespaceId);
+ audit(credentials, GRANT_TABLE_PERMISSION_AUDIT_TEMPLATE, permission, tableName, user);
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, GRANT_TABLE_PERMISSION_AUDIT_TEMPLATE, permission, tableName, user);
+ throw ex;
+ }
+ }
+
+ public static final String REVOKE_SYSTEM_PERMISSION_AUDIT_TEMPLATE = "action: revokeSystemPermission; permission: %s; targetUser: %s;";
+
+ @Override
+ public void revokeSystemPermission(TCredentials credentials, String user, SystemPermission permission) throws ThriftSecurityException {
+
+ try {
+ super.revokeSystemPermission(credentials, user, permission);
+ audit(credentials, REVOKE_SYSTEM_PERMISSION_AUDIT_TEMPLATE, permission, user);
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, REVOKE_SYSTEM_PERMISSION_AUDIT_TEMPLATE, permission, user);
+ throw ex;
+ }
+ }
+
+ public static final String REVOKE_TABLE_PERMISSION_AUDIT_TEMPLATE = "action: revokeTablePermission; permission: %s; targetTable: %s; targetUser: %s;";
+
+ @Override
+ public void revokeTablePermission(TCredentials credentials, String user, String tableId, TablePermission permission, String namespaceId)
+ throws ThriftSecurityException {
+ String tableName = getTableName(tableId);
+ try {
+ super.revokeTablePermission(credentials, user, tableId, permission, namespaceId);
+ audit(credentials, REVOKE_TABLE_PERMISSION_AUDIT_TEMPLATE, permission, tableName, user);
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, REVOKE_TABLE_PERMISSION_AUDIT_TEMPLATE, permission, tableName, user);
+ throw ex;
+ }
+ }
+
++ public static final String HAS_SYSTEM_PERMISSION_AUDIT_TEMPLATE = "action: hasSystemPermission; permission: %s; targetUser: %s;";
++
++ @Override
++ public boolean hasSystemPermission(TCredentials credentials, String user, SystemPermission permission) throws ThriftSecurityException {
++ try {
++ boolean result = super.hasSystemPermission(credentials, user, permission);
++ audit(credentials, result, HAS_SYSTEM_PERMISSION_AUDIT_TEMPLATE, permission, user);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(credentials, ex, "checking permission %s on %s denied", permission, user);
++ throw ex;
++ }
++ }
++
+ public static final String CAN_ONLINE_OFFLINE_TABLE_AUDIT_TEMPLATE = "action: %s; targetTable: %s;";
+
+ @Override
+ public boolean canOnlineOfflineTable(TCredentials credentials, String tableId, FateOperation op, String namespaceId) throws ThriftSecurityException {
+ String tableName = getTableName(tableId);
+ String operation = null;
+ if (op == FateOperation.TABLE_ONLINE)
+ operation = "onlineTable";
+ if (op == FateOperation.TABLE_OFFLINE)
+ operation = "offlineTable";
+ try {
+ boolean result = super.canOnlineOfflineTable(credentials, tableId, op, namespaceId);
+ audit(credentials, result, CAN_ONLINE_OFFLINE_TABLE_AUDIT_TEMPLATE, operation, tableName, tableId);
+ return result;
+ } catch (ThriftSecurityException ex) {
+ audit(credentials, ex, CAN_ONLINE_OFFLINE_TABLE_AUDIT_TEMPLATE, operation, tableName, tableId);
+ throw ex;
+ }
+ }
+
++ public static final String CAN_MERGE_TABLE_AUDIT_TEMPLATE = "action: mergeTable; targetTable: %s; targetNamespace: %s;";
++
++ @Override
++ public boolean canMerge(TCredentials c, String tableId, String namespaceId) throws ThriftSecurityException {
++ try {
++ boolean result = super.canMerge(c, tableId, namespaceId);
++ audit(c, result, CAN_MERGE_TABLE_AUDIT_TEMPLATE, tableId, namespaceId);
++ return result;
++ } catch (ThriftSecurityException ex) {
++ audit(c, ex, "merge table on tableId %s denied", tableId);
++ throw ex;
++ }
++ }
++
+ // The audit log is already logging the principal, so we don't have anything else to audit
+ public static final String AUTHENICATE_AUDIT_TEMPLATE = "";
+
+ @Override
+ protected void authenticate(TCredentials credentials) throws ThriftSecurityException {
+ try {
+ super.authenticate(credentials);
+ audit(credentials, true, AUTHENICATE_AUDIT_TEMPLATE);
+ } catch (ThriftSecurityException e) {
+ audit(credentials, false, AUTHENICATE_AUDIT_TEMPLATE);
+ throw e;
+ }
+ }
+}