Skip to content

Commit a10b081

Browse files
guangxuChengtamaashu
authored andcommitted
HBASE-23896 Snapshot owner cannot delete snapshot when ACL is enabled and Kerberos is not enabled (apache#1211)
Signed-off-by: binlijin <[email protected]> (cherry picked from commit 5f7e55b) Change-Id: Ib229a5878ee67d7c587d10942ed2359026a9a6c1
1 parent 7d55e98 commit a10b081

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ private void takeSnapshotInternal(SnapshotDescription snapshot) throws IOExcepti
633633
builder.setVersion(SnapshotDescriptionUtils.SNAPSHOT_LAYOUT_VERSION);
634634
}
635635
RpcServer.getRequestUser().ifPresent(user -> {
636-
if (User.isHBaseSecurityEnabled(master.getConfiguration())) {
636+
if (AccessChecker.isAuthorizationSupported(master.getConfiguration())) {
637637
builder.setOwner(user.getShortName());
638638
}
639639
});

hbase-server/src/test/java/org/apache/hadoop/hbase/client/SnapshotWithAclTestBase.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
package org.apache.hadoop.hbase.client;
1919

2020
import java.io.IOException;
21+
import java.util.List;
22+
import java.util.regex.Pattern;
2123
import org.apache.hadoop.conf.Configuration;
2224
import org.apache.hadoop.hbase.Coprocessor;
25+
import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
2326
import org.apache.hadoop.hbase.HBaseTestingUtility;
2427
import org.apache.hadoop.hbase.TableName;
2528
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
@@ -228,4 +231,45 @@ public void testRestoreSnapshot() throws Exception {
228231
verifyAllowed(new AccessWriteAction(TEST_TABLE), USER_OWNER, USER_RW);
229232
verifyDenied(new AccessWriteAction(TEST_TABLE), USER_RO, USER_NONE);
230233
}
234+
235+
236+
final class AccessSnapshotAction implements AccessTestAction {
237+
private String snapshotName;
238+
private AccessSnapshotAction(String snapshotName) {
239+
this.snapshotName = snapshotName;
240+
}
241+
@Override
242+
public Object run() throws Exception {
243+
try (Connection conn = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration());
244+
Admin admin = conn.getAdmin()) {
245+
admin.snapshot(this.snapshotName, TEST_TABLE);
246+
}
247+
return null;
248+
}
249+
}
250+
251+
@Test
252+
public void testDeleteSnapshot() throws Exception {
253+
String testSnapshotName = HBaseCommonTestingUtility.getRandomUUID().toString();
254+
verifyAllowed(new AccessSnapshotAction(testSnapshotName), USER_OWNER);
255+
verifyDenied(new AccessSnapshotAction(HBaseCommonTestingUtility.getRandomUUID().toString()),
256+
USER_RO, USER_RW, USER_NONE);
257+
List<SnapshotDescription> snapshotDescriptions = TEST_UTIL.getAdmin().listSnapshots(
258+
Pattern.compile(testSnapshotName));
259+
Assert.assertEquals(1, snapshotDescriptions.size());
260+
Assert.assertEquals(USER_OWNER.getShortName(), snapshotDescriptions.get(0).getOwner());
261+
AccessTestAction deleteSnapshotAction = () -> {
262+
try (Connection conn = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration());
263+
Admin admin = conn.getAdmin()) {
264+
admin.deleteSnapshot(testSnapshotName);
265+
}
266+
return null;
267+
};
268+
verifyDenied(deleteSnapshotAction, USER_RO, USER_RW, USER_NONE);
269+
verifyAllowed(deleteSnapshotAction, USER_OWNER);
270+
271+
List<SnapshotDescription> snapshotsAfterDelete = TEST_UTIL.getAdmin().listSnapshots(
272+
Pattern.compile(testSnapshotName));
273+
Assert.assertEquals(0, snapshotsAfterDelete.size());
274+
}
231275
}

0 commit comments

Comments
 (0)