Skip to content

Commit ad8f28e

Browse files
HBASE-27493: Allow namespace admins to clone snapshots created by them (#4885)
Signed-off-by: Duo Zhang <[email protected]> Signed-off-by: Peter Somogyi <[email protected]>
1 parent d799c3c commit ad8f28e

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,9 @@ public void preCloneSnapshot(final ObserverContext<MasterCoprocessorEnvironment>
10721072
AuthResult result = AuthResult.allow("cloneSnapshot " + snapshot.getName(),
10731073
"Snapshot owner check allowed", user, null, hTableDescriptor.getTableName(), null);
10741074
AccessChecker.logResult(result);
1075+
} else if (SnapshotDescriptionUtils.isSnapshotOwner(snapshot, user)) {
1076+
requireNamespacePermission(ctx, "cloneSnapshot",
1077+
hTableDescriptor.getTableName().getNamespaceAsString(), Action.ADMIN);
10751078
} else {
10761079
accessChecker.requirePermission(user, "cloneSnapshot " + snapshot.getName(), null,
10771080
Action.ADMIN);

hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController.java

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,16 +2074,16 @@ public Object run() throws Exception {
20742074
USER_GROUP_WRITE, USER_GROUP_CREATE);
20752075

20762076
verifyAllowed(cloneAction, SUPERUSER, USER_ADMIN, USER_GROUP_ADMIN);
2077-
verifyDenied(deleteAction, USER_CREATE, USER_RW, USER_RO, USER_NONE, USER_OWNER,
2078-
USER_GROUP_READ, USER_GROUP_WRITE, USER_GROUP_CREATE);
2077+
verifyDenied(cloneAction, USER_CREATE, USER_RW, USER_RO, USER_NONE, USER_OWNER, USER_GROUP_READ,
2078+
USER_GROUP_WRITE, USER_GROUP_CREATE);
20792079

20802080
verifyAllowed(restoreAction, SUPERUSER, USER_ADMIN, USER_GROUP_ADMIN);
20812081
verifyDenied(restoreAction, USER_CREATE, USER_RW, USER_RO, USER_NONE, USER_OWNER,
20822082
USER_GROUP_READ, USER_GROUP_WRITE, USER_GROUP_CREATE);
20832083

20842084
verifyAllowed(deleteAction, SUPERUSER, USER_ADMIN, USER_GROUP_ADMIN);
2085-
verifyDenied(cloneAction, USER_CREATE, USER_RW, USER_RO, USER_NONE, USER_OWNER, USER_GROUP_READ,
2086-
USER_GROUP_WRITE, USER_GROUP_CREATE);
2085+
verifyDenied(deleteAction, USER_CREATE, USER_RW, USER_RO, USER_NONE, USER_OWNER,
2086+
USER_GROUP_READ, USER_GROUP_WRITE, USER_GROUP_CREATE);
20872087
}
20882088

20892089
@Test
@@ -2126,18 +2126,65 @@ public Object run() throws Exception {
21262126
verifyAllowed(restoreAction, SUPERUSER, USER_ADMIN, USER_OWNER, USER_GROUP_ADMIN);
21272127
verifyDenied(restoreAction, USER_CREATE, USER_RW, USER_RO, USER_NONE, USER_GROUP_READ,
21282128
USER_GROUP_WRITE, USER_GROUP_CREATE);
2129+
}
21292130

2130-
AccessTestAction cloneAction = new AccessTestAction() {
2131+
@Test
2132+
public void testCloneSnapshotWithOwner() throws Exception {
2133+
Admin admin = TEST_UTIL.getAdmin();
2134+
final TableDescriptor originalTd = admin.getDescriptor(TEST_TABLE);
2135+
final SnapshotDescription snapshot = new SnapshotDescription(
2136+
TEST_TABLE.getNameAsString() + "-snapshot", TEST_TABLE, null, USER_OWNER.getName());
2137+
String namespace = "testCloneSnapshot";
2138+
NamespaceDescriptor desc = NamespaceDescriptor.create(namespace).build();
2139+
createNamespace(TEST_UTIL, desc);
2140+
2141+
String differentTableString = "testtable2";
2142+
TableName differentTable = TableName.valueOf(namespace, differentTableString);
2143+
TableDescriptor diffrentTd = TableDescriptorBuilder.newBuilder(differentTable)
2144+
.setColumnFamily(ColumnFamilyDescriptorBuilder.of(TEST_FAMILY)).build();
2145+
2146+
// recreating the original table
2147+
AccessTestAction cloneOriginalAction = new AccessTestAction() {
21312148
@Override
21322149
public Object run() throws Exception {
21332150
ACCESS_CONTROLLER.preCloneSnapshot(ObserverContextImpl.createAndPrepare(CP_ENV), snapshot,
2134-
htd);
2151+
originalTd);
21352152
return null;
21362153
}
21372154
};
2138-
verifyAllowed(cloneAction, SUPERUSER, USER_ADMIN, USER_GROUP_ADMIN, USER_OWNER);
2139-
verifyDenied(cloneAction, USER_CREATE, USER_RW, USER_RO, USER_NONE, USER_GROUP_READ,
2155+
verifyAllowed(cloneOriginalAction, SUPERUSER, USER_ADMIN, USER_GROUP_ADMIN, USER_OWNER);
2156+
verifyDenied(cloneOriginalAction, USER_CREATE, USER_RW, USER_RO, USER_NONE, USER_GROUP_READ,
21402157
USER_GROUP_WRITE, USER_GROUP_CREATE);
2158+
2159+
// cloning to a different table
2160+
AccessTestAction cloneDifferentAction = new AccessTestAction() {
2161+
@Override
2162+
public Object run() throws Exception {
2163+
ACCESS_CONTROLLER.preCloneSnapshot(ObserverContextImpl.createAndPrepare(CP_ENV), snapshot,
2164+
diffrentTd);
2165+
return null;
2166+
}
2167+
};
2168+
verifyAllowed(cloneDifferentAction, SUPERUSER, USER_ADMIN, USER_GROUP_ADMIN);
2169+
verifyDenied(cloneDifferentAction, USER_CREATE, USER_RW, USER_RO, USER_NONE, USER_GROUP_READ,
2170+
USER_GROUP_WRITE, USER_GROUP_CREATE, USER_OWNER);
2171+
2172+
// cloning to a different table where user is namespace admin
2173+
grantOnNamespace(TEST_UTIL, USER_OWNER.getShortName(), namespace, Action.ADMIN);
2174+
2175+
AccessTestAction cloneNamespaceAdminAction = new AccessTestAction() {
2176+
@Override
2177+
public Object run() throws Exception {
2178+
ACCESS_CONTROLLER.preCloneSnapshot(ObserverContextImpl.createAndPrepare(CP_ENV), snapshot,
2179+
diffrentTd);
2180+
return null;
2181+
}
2182+
};
2183+
verifyAllowed(cloneNamespaceAdminAction, SUPERUSER, USER_ADMIN, USER_GROUP_ADMIN, USER_OWNER);
2184+
verifyDenied(cloneNamespaceAdminAction, USER_CREATE, USER_RW, USER_RO, USER_NONE,
2185+
USER_GROUP_READ, USER_GROUP_WRITE, USER_GROUP_CREATE);
2186+
2187+
deleteNamespace(TEST_UTIL, namespace);
21412188
}
21422189

21432190
@Test

0 commit comments

Comments
 (0)