Skip to content

Commit 56142a8

Browse files
authored
Throw sercurity exceptions when permissions checks fail. Backport to 1.10 (#1830)
* backport sercurity exceptions to 1.10 * fix AuditMessageIT
1 parent b8fd349 commit 56142a8

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

server/master/src/main/java/org/apache/accumulo/master/MasterClientServiceHandler.java

+14-7
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ protected MasterClientServiceHandler(Master master) {
118118
public long initiateFlush(TInfo tinfo, TCredentials c, String tableId)
119119
throws ThriftSecurityException, ThriftTableOperationException {
120120
String namespaceId = getNamespaceIdFromTableId(TableOperation.FLUSH, tableId);
121-
master.security.canFlush(c, tableId, namespaceId);
121+
if (!master.security.canFlush(c, tableId, namespaceId))
122+
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
122123

123124
String zTablePath = Constants.ZROOT + "/" + master.getInstance().getInstanceID()
124125
+ Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_FLUSH_ID;
@@ -150,7 +151,8 @@ public void waitForFlush(TInfo tinfo, TCredentials c, String tableId, ByteBuffer
150151
ByteBuffer endRow, long flushID, long maxLoops)
151152
throws ThriftSecurityException, ThriftTableOperationException {
152153
String namespaceId = getNamespaceIdFromTableId(TableOperation.FLUSH, tableId);
153-
master.security.canFlush(c, tableId, namespaceId);
154+
if (!master.security.canFlush(c, tableId, namespaceId))
155+
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
154156

155157
if (endRow != null && startRow != null
156158
&& ByteBufferUtil.toText(startRow).compareTo(ByteBufferUtil.toText(endRow)) >= 0)
@@ -305,7 +307,8 @@ public void setTableProperty(TInfo info, TCredentials credentials, String tableN
305307
@Override
306308
public void shutdown(TInfo info, TCredentials c, boolean stopTabletServers)
307309
throws ThriftSecurityException {
308-
master.security.canPerformSystemActions(c);
310+
if (!master.security.canPerformSystemActions(c))
311+
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
309312
if (stopTabletServers) {
310313
master.setMasterGoalState(MasterGoalState.CLEAN_STOP);
311314
EventCoordinator.Listener eventListener = master.nextEvent.getListener();
@@ -319,7 +322,8 @@ public void shutdown(TInfo info, TCredentials c, boolean stopTabletServers)
319322
@Override
320323
public void shutdownTabletServer(TInfo info, TCredentials c, String tabletServer, boolean force)
321324
throws ThriftSecurityException {
322-
master.security.canPerformSystemActions(c);
325+
if (!master.security.canPerformSystemActions(c))
326+
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
323327

324328
final TServerInstance doomed = master.tserverSet.find(tabletServer);
325329
if (!force) {
@@ -391,15 +395,17 @@ public void reportTabletStatus(TInfo info, TCredentials credentials, String serv
391395
@Override
392396
public void setMasterGoalState(TInfo info, TCredentials c, MasterGoalState state)
393397
throws ThriftSecurityException {
394-
master.security.canPerformSystemActions(c);
398+
if (!master.security.canPerformSystemActions(c))
399+
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
395400

396401
master.setMasterGoalState(state);
397402
}
398403

399404
@Override
400405
public void removeSystemProperty(TInfo info, TCredentials c, String property)
401406
throws ThriftSecurityException {
402-
master.security.canPerformSystemActions(c);
407+
if (!master.security.canPerformSystemActions(c))
408+
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
403409

404410
try {
405411
SystemPropUtil.removeSystemProperty(property);
@@ -413,7 +419,8 @@ public void removeSystemProperty(TInfo info, TCredentials c, String property)
413419
@Override
414420
public void setSystemProperty(TInfo info, TCredentials c, String property, String value)
415421
throws ThriftSecurityException, TException {
416-
master.security.canPerformSystemActions(c);
422+
if (!master.security.canPerformSystemActions(c))
423+
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
417424

418425
try {
419426
SystemPropUtil.setSystemProperty(property, value);

test/src/main/java/org/apache/accumulo/test/AuditMessageIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ public void testDeniedAudits() throws AccumuloSecurityException, AccumuloExcepti
465465
auditConnector.tableOperations().rename(OLD_TEST_TABLE_NAME, NEW_TEST_TABLE_NAME);
466466
} catch (AccumuloSecurityException ex) {}
467467
try {
468-
auditConnector.tableOperations().clone(OLD_TEST_TABLE_NAME, NEW_TEST_TABLE_NAME, true,
468+
auditConnector.tableOperations().clone(OLD_TEST_TABLE_NAME, NEW_TEST_TABLE_NAME, false,
469469
Collections.<String,String>emptyMap(), Collections.<String>emptySet());
470470
} catch (AccumuloSecurityException ex) {}
471471
try {

0 commit comments

Comments
 (0)