|
@@ -1850,11 +1850,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
final String operationName = "setPermission";
|
|
|
FileStatus auditStat;
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot set permission for " + src);
|
|
|
- auditStat = FSDirAttrOp.setPermission(dir, src, permission);
|
|
|
+ auditStat = FSDirAttrOp.setPermission(dir, pc, src, permission);
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, operationName, src);
|
|
|
throw e;
|
|
@@ -1874,11 +1875,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
final String operationName = "setOwner";
|
|
|
FileStatus auditStat;
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot set owner for " + src);
|
|
|
- auditStat = FSDirAttrOp.setOwner(dir, src, username, group);
|
|
|
+ auditStat = FSDirAttrOp.setOwner(dir, pc, src, username, group);
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, operationName, src);
|
|
|
throw e;
|
|
@@ -1898,7 +1900,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
final String operationName = "open";
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
GetBlockLocationsResult res = null;
|
|
|
- FSPermissionChecker pc = getPermissionChecker();
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
readLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.READ);
|
|
@@ -2011,11 +2013,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
final String operationName = "concat";
|
|
|
FileStatus stat = null;
|
|
|
boolean success = false;
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot concat " + target);
|
|
|
- stat = FSDirConcatOp.concat(dir, target, srcs, logRetryCache);
|
|
|
+ stat = FSDirConcatOp.concat(dir, pc, target, srcs, logRetryCache);
|
|
|
success = true;
|
|
|
} catch (AccessControlException ace) {
|
|
|
logAuditEvent(success, operationName, Arrays.toString(srcs),
|
|
@@ -2039,11 +2042,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
final String operationName = "setTimes";
|
|
|
FileStatus auditStat;
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot set times " + src);
|
|
|
- auditStat = FSDirAttrOp.setTimes(dir, src, mtime, atime);
|
|
|
+ auditStat = FSDirAttrOp.setTimes(dir, pc, src, mtime, atime);
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, operationName, src);
|
|
|
throw e;
|
|
@@ -2077,8 +2081,8 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
throw new HadoopIllegalArgumentException(
|
|
|
"Cannot truncate to a negative file size: " + newLength + ".");
|
|
|
}
|
|
|
- final FSPermissionChecker pc = getPermissionChecker();
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
BlocksMapUpdateInfo toRemoveBlocks = new BlocksMapUpdateInfo();
|
|
|
try {
|
|
@@ -2147,11 +2151,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
final String operationName = "setReplication";
|
|
|
boolean success = false;
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot set replication for " + src);
|
|
|
- success = FSDirAttrOp.setReplication(dir, blockManager, src, replication);
|
|
|
+ success = FSDirAttrOp.setReplication(dir, pc, blockManager, src,
|
|
|
+ replication);
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, operationName, src);
|
|
|
throw e;
|
|
@@ -2175,11 +2181,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
final String operationName = "setStoragePolicy";
|
|
|
FileStatus auditStat;
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot set storage policy for " + src);
|
|
|
- auditStat = FSDirAttrOp.setStoragePolicy(dir, blockManager, src,
|
|
|
+ auditStat = FSDirAttrOp.setStoragePolicy(dir, pc, blockManager, src,
|
|
|
policyName);
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, operationName, src);
|
|
@@ -2200,11 +2207,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
final String operationName = "unsetStoragePolicy";
|
|
|
FileStatus auditStat;
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot unset storage policy for " + src);
|
|
|
- auditStat = FSDirAttrOp.unsetStoragePolicy(dir, blockManager, src);
|
|
|
+ auditStat = FSDirAttrOp.unsetStoragePolicy(dir, pc, blockManager, src);
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, operationName, src);
|
|
|
throw e;
|
|
@@ -2223,10 +2231,11 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
*/
|
|
|
BlockStoragePolicy getStoragePolicy(String src) throws IOException {
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
readLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
- return FSDirAttrOp.getStoragePolicy(dir, blockManager, src);
|
|
|
+ return FSDirAttrOp.getStoragePolicy(dir, pc, blockManager, src);
|
|
|
} finally {
|
|
|
readUnlock("getStoragePolicy");
|
|
|
}
|
|
@@ -2248,10 +2257,11 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
|
|
|
long getPreferredBlockSize(String src) throws IOException {
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
readLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
- return FSDirAttrOp.getPreferredBlockSize(dir, src);
|
|
|
+ return FSDirAttrOp.getPreferredBlockSize(dir, pc, src);
|
|
|
} finally {
|
|
|
readUnlock("getPreferredBlockSize");
|
|
|
}
|
|
@@ -2355,13 +2365,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
"ecPolicyName are exclusive parameters. Set both is not allowed!");
|
|
|
}
|
|
|
|
|
|
- FSPermissionChecker pc = getPermissionChecker();
|
|
|
INodesInPath iip = null;
|
|
|
boolean skipSync = true; // until we do something that might create edits
|
|
|
HdfsFileStatus stat = null;
|
|
|
BlocksMapUpdateInfo toRemoveBlocks = null;
|
|
|
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
@@ -2402,7 +2412,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
toRemoveBlocks = new BlocksMapUpdateInfo();
|
|
|
dir.writeLock();
|
|
|
try {
|
|
|
- stat = FSDirWriteFileOp.startFile(this, iip, permissions, holder,
|
|
|
+ stat = FSDirWriteFileOp.startFile(this, pc, iip, permissions, holder,
|
|
|
clientMachine, flag, createParent, replication, blockSize, feInfo,
|
|
|
toRemoveBlocks, shouldReplicate, ecPolicyName, logRetryCache);
|
|
|
} catch (IOException e) {
|
|
@@ -2442,8 +2452,8 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
boolean recoverLease(String src, String holder, String clientMachine)
|
|
|
throws IOException {
|
|
|
boolean skipSync = false;
|
|
|
- FSPermissionChecker pc = getPermissionChecker();
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
@@ -2582,8 +2592,8 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
try {
|
|
|
boolean skipSync = false;
|
|
|
LastBlockWithStatus lbs = null;
|
|
|
- final FSPermissionChecker pc = getPermissionChecker();
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
@@ -2638,8 +2648,8 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
|
|
|
LocatedBlock[] onRetryBlock = new LocatedBlock[1];
|
|
|
FSDirWriteFileOp.ValidateAddBlockResult r;
|
|
|
- FSPermissionChecker pc = getPermissionChecker();
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
readLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.READ);
|
|
@@ -2689,7 +2699,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
final List<DatanodeStorageInfo> chosen;
|
|
|
final BlockType blockType;
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
- FSPermissionChecker pc = getPermissionChecker();
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
readLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.READ);
|
|
@@ -2737,7 +2747,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
NameNode.stateChangeLog.debug(
|
|
|
"BLOCK* NameSystem.abandonBlock: {} of file {}", b, src);
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
- FSPermissionChecker pc = getPermissionChecker();
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
@@ -2802,7 +2812,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
throws IOException {
|
|
|
boolean success = false;
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
- FSPermissionChecker pc = getPermissionChecker();
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
@@ -2880,11 +2890,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
throws IOException {
|
|
|
final String operationName = "rename";
|
|
|
FSDirRenameOp.RenameResult ret = null;
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot rename " + src);
|
|
|
- ret = FSDirRenameOp.renameToInt(dir, src, dst, logRetryCache);
|
|
|
+ ret = FSDirRenameOp.renameToInt(dir, pc, src, dst, logRetryCache);
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, operationName, src, dst, null);
|
|
|
throw e;
|
|
@@ -2904,11 +2916,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
throws IOException {
|
|
|
final String operationName = "rename";
|
|
|
FSDirRenameOp.RenameResult res = null;
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot rename " + src);
|
|
|
- res = FSDirRenameOp.renameToInt(dir, src, dst, logRetryCache, options);
|
|
|
+ res = FSDirRenameOp.renameToInt(dir, pc, src, dst, logRetryCache,
|
|
|
+ options);
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, operationName + " (options=" +
|
|
|
Arrays.toString(options) + ")", src, dst, null);
|
|
@@ -2939,13 +2954,15 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
throws IOException {
|
|
|
final String operationName = "delete";
|
|
|
BlocksMapUpdateInfo toRemovedBlocks = null;
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
boolean ret = false;
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot delete " + src);
|
|
|
toRemovedBlocks = FSDirDeleteOp.delete(
|
|
|
- this, src, recursive, logRetryCache);
|
|
|
+ this, pc, src, recursive, logRetryCache);
|
|
|
ret = toRemovedBlocks != null;
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, operationName, src);
|
|
@@ -3039,10 +3056,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
final String operationName = "getfileinfo";
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
HdfsFileStatus stat = null;
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
readLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
- stat = FSDirStatAndListingOp.getFileInfo(dir, src, resolveLink);
|
|
|
+ stat = FSDirStatAndListingOp.getFileInfo(
|
|
|
+ dir, pc, src, resolveLink);
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, operationName, src);
|
|
|
throw e;
|
|
@@ -3059,10 +3078,11 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
boolean isFileClosed(final String src) throws IOException {
|
|
|
final String operationName = "isFileClosed";
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
readLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
- return FSDirStatAndListingOp.isFileClosed(dir, src);
|
|
|
+ return FSDirStatAndListingOp.isFileClosed(dir, pc, src);
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, operationName, src);
|
|
|
throw e;
|
|
@@ -3079,11 +3099,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
final String operationName = "mkdirs";
|
|
|
FileStatus auditStat = null;
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot create directory " + src);
|
|
|
- auditStat = FSDirMkdirOp.mkdirs(this, src, permissions, createParent);
|
|
|
+ auditStat = FSDirMkdirOp.mkdirs(this, pc, src, permissions,
|
|
|
+ createParent);
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, operationName, src);
|
|
|
throw e;
|
|
@@ -3112,12 +3134,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
ContentSummary getContentSummary(final String src) throws IOException {
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
final String operationName = "contentSummary";
|
|
|
- readLock();
|
|
|
boolean success = true;
|
|
|
ContentSummary cs;
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
+ readLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
- cs = FSDirStatAndListingOp.getContentSummary(dir, src);
|
|
|
+ cs = FSDirStatAndListingOp.getContentSummary(dir, pc, src);
|
|
|
} catch (AccessControlException ace) {
|
|
|
success = false;
|
|
|
logAuditEvent(success, operationName, src);
|
|
@@ -3147,11 +3170,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
final String operationName = "quotaUsage";
|
|
|
QuotaUsage quotaUsage;
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
readLock();
|
|
|
boolean success = true;
|
|
|
try {
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
- quotaUsage = FSDirStatAndListingOp.getQuotaUsage(dir, src);
|
|
|
+ quotaUsage = FSDirStatAndListingOp.getQuotaUsage(dir, pc, src);
|
|
|
} catch (AccessControlException ace) {
|
|
|
success = false;
|
|
|
logAuditEvent(success, operationName, src);
|
|
@@ -3177,12 +3201,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
}
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
final String operationName = "setQuota";
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
boolean success = false;
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot set quota on " + src);
|
|
|
- FSDirAttrOp.setQuota(dir, src, nsQuota, ssQuota, type);
|
|
|
+ FSDirAttrOp.setQuota(dir, pc, src, nsQuota, ssQuota, type);
|
|
|
success = true;
|
|
|
} catch (AccessControlException ace) {
|
|
|
logAuditEvent(success, operationName, src);
|
|
@@ -3209,8 +3234,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
throws IOException {
|
|
|
NameNode.stateChangeLog.info("BLOCK* fsync: " + src + " for " + clientName);
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
-
|
|
|
- FSPermissionChecker pc = getPermissionChecker();
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
@@ -3714,10 +3738,11 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
final String operationName = "listStatus";
|
|
|
DirectoryListing dl = null;
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
readLock();
|
|
|
try {
|
|
|
checkOperation(NameNode.OperationCategory.READ);
|
|
|
- dl = getListingInt(dir, src, startAfter, needLocation);
|
|
|
+ dl = getListingInt(dir, pc, src, startAfter, needLocation);
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, operationName, src);
|
|
|
throw e;
|
|
@@ -4621,6 +4646,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ void checkSuperuserPrivilege(FSPermissionChecker pc)
|
|
|
+ throws AccessControlException {
|
|
|
+ if (isPermissionEnabled) {
|
|
|
+ pc.checkSuperuserPrivilege();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Check to see if we have exceeded the limit on the number
|
|
|
* of inodes.
|
|
@@ -6303,14 +6335,16 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
*/
|
|
|
String createSnapshot(String snapshotRoot, String snapshotName,
|
|
|
boolean logRetryCache) throws IOException {
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
|
final String operationName = "createSnapshot";
|
|
|
String snapshotPath = null;
|
|
|
boolean success = false;
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot create snapshot for " + snapshotRoot);
|
|
|
- snapshotPath = FSDirSnapshotOp.createSnapshot(dir,
|
|
|
+ snapshotPath = FSDirSnapshotOp.createSnapshot(dir, pc,
|
|
|
snapshotManager, snapshotRoot, snapshotName, logRetryCache);
|
|
|
success = true;
|
|
|
} catch (AccessControlException ace) {
|
|
@@ -6337,15 +6371,17 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
void renameSnapshot(
|
|
|
String path, String snapshotOldName, String snapshotNewName,
|
|
|
boolean logRetryCache) throws IOException {
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
|
final String operationName = "renameSnapshot";
|
|
|
boolean success = false;
|
|
|
String oldSnapshotRoot = Snapshot.getSnapshotPath(path, snapshotOldName);
|
|
|
String newSnapshotRoot = Snapshot.getSnapshotPath(path, snapshotNewName);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot rename snapshot for " + path);
|
|
|
- FSDirSnapshotOp.renameSnapshot(dir, snapshotManager, path,
|
|
|
+ FSDirSnapshotOp.renameSnapshot(dir, pc, snapshotManager, path,
|
|
|
snapshotOldName, snapshotNewName, logRetryCache);
|
|
|
success = true;
|
|
|
} catch (AccessControlException ace) {
|
|
@@ -6373,10 +6409,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
SnapshottableDirectoryStatus[] status = null;
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
boolean success = false;
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
readLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
- status = FSDirSnapshotOp.getSnapshottableDirListing(dir, snapshotManager);
|
|
|
+ status = FSDirSnapshotOp.getSnapshottableDirListing(dir, pc,
|
|
|
+ snapshotManager);
|
|
|
success = true;
|
|
|
} catch (AccessControlException ace) {
|
|
|
logAuditEvent(success, operationName, null, null, null);
|
|
@@ -6413,10 +6451,11 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
path : Snapshot.getSnapshotPath(path, fromSnapshot);
|
|
|
String toSnapshotRoot = (toSnapshot == null || toSnapshot.isEmpty()) ?
|
|
|
path : Snapshot.getSnapshotPath(path, toSnapshot);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
readLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
- diffs = FSDirSnapshotOp.getSnapshotDiffReport(dir, snapshotManager,
|
|
|
+ diffs = FSDirSnapshotOp.getSnapshotDiffReport(dir, pc, snapshotManager,
|
|
|
path, fromSnapshot, toSnapshot);
|
|
|
success = true;
|
|
|
} catch (AccessControlException ace) {
|
|
@@ -6430,7 +6469,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
toSnapshotRoot, null);
|
|
|
return diffs;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Delete a snapshot of a snapshottable directory
|
|
|
* @param snapshotRoot The snapshottable directory
|
|
@@ -6443,14 +6482,15 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
final String operationName = "deleteSnapshot";
|
|
|
boolean success = false;
|
|
|
String rootPath = null;
|
|
|
- writeLock();
|
|
|
BlocksMapUpdateInfo blocksToBeDeleted = null;
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
+ writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot delete snapshot for " + snapshotRoot);
|
|
|
rootPath = Snapshot.getSnapshotPath(snapshotRoot, snapshotName);
|
|
|
- blocksToBeDeleted = FSDirSnapshotOp.deleteSnapshot(dir, snapshotManager,
|
|
|
- snapshotRoot, snapshotName, logRetryCache);
|
|
|
+ blocksToBeDeleted = FSDirSnapshotOp.deleteSnapshot(dir, pc,
|
|
|
+ snapshotManager, snapshotRoot, snapshotName, logRetryCache);
|
|
|
success = true;
|
|
|
} catch (AccessControlException ace) {
|
|
|
logAuditEvent(success, operationName, rootPath, null, null);
|
|
@@ -6930,11 +6970,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
final String operationName = "modifyAclEntries";
|
|
|
FileStatus auditStat = null;
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot modify ACL entries on " + src);
|
|
|
- auditStat = FSDirAclOp.modifyAclEntries(dir, src, aclSpec);
|
|
|
+ auditStat = FSDirAclOp.modifyAclEntries(dir, pc, src, aclSpec);
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, operationName, src);
|
|
|
throw e;
|
|
@@ -6950,11 +6991,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
final String operationName = "removeAclEntries";
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
FileStatus auditStat = null;
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot remove ACL entries on " + src);
|
|
|
- auditStat = FSDirAclOp.removeAclEntries(dir, src, aclSpec);
|
|
|
+ auditStat = FSDirAclOp.removeAclEntries(dir, pc, src, aclSpec);
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, operationName, src);
|
|
|
throw e;
|
|
@@ -6969,11 +7011,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
final String operationName = "removeDefaultAcl";
|
|
|
FileStatus auditStat = null;
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot remove default ACL entries on " + src);
|
|
|
- auditStat = FSDirAclOp.removeDefaultAcl(dir, src);
|
|
|
+ auditStat = FSDirAclOp.removeDefaultAcl(dir, pc, src);
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, operationName, src);
|
|
|
throw e;
|
|
@@ -6988,11 +7031,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
final String operationName = "removeAcl";
|
|
|
FileStatus auditStat = null;
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot remove ACL on " + src);
|
|
|
- auditStat = FSDirAclOp.removeAcl(dir, src);
|
|
|
+ auditStat = FSDirAclOp.removeAcl(dir, pc, src);
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, operationName, src);
|
|
|
throw e;
|
|
@@ -7007,11 +7051,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
final String operationName = "setAcl";
|
|
|
FileStatus auditStat = null;
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot set ACL on " + src);
|
|
|
- auditStat = FSDirAclOp.setAcl(dir, src, aclSpec);
|
|
|
+ auditStat = FSDirAclOp.setAcl(dir, pc, src, aclSpec);
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, operationName, src);
|
|
|
throw e;
|
|
@@ -7026,10 +7071,11 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
final String operationName = "getAclStatus";
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
final AclStatus ret;
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
readLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
- ret = FSDirAclOp.getAclStatus(dir, src);
|
|
|
+ ret = FSDirAclOp.getAclStatus(dir, pc, src);
|
|
|
} catch(AccessControlException ace) {
|
|
|
logAuditEvent(false, operationName, src);
|
|
|
throw ace;
|
|
@@ -7058,13 +7104,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
try {
|
|
|
Metadata metadata = FSDirEncryptionZoneOp.ensureKeyIsInitialized(dir,
|
|
|
keyName, src);
|
|
|
- checkSuperuserPrivilege();
|
|
|
- FSPermissionChecker pc = getPermissionChecker();
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
+ checkSuperuserPrivilege(pc);
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
final FileStatus resultingStat;
|
|
|
writeLock();
|
|
|
try {
|
|
|
- checkSuperuserPrivilege();
|
|
|
+ checkSuperuserPrivilege(pc);
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot create encryption zone on " + src);
|
|
|
resultingStat = FSDirEncryptionZoneOp.createEncryptionZone(dir, src,
|
|
@@ -7119,12 +7165,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
throws IOException {
|
|
|
final String operationName = "listEncryptionZones";
|
|
|
boolean success = false;
|
|
|
- checkSuperuserPrivilege();
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
+ checkSuperuserPrivilege(pc);
|
|
|
readLock();
|
|
|
try {
|
|
|
- checkSuperuserPrivilege();
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
+ checkSuperuserPrivilege(pc);
|
|
|
final BatchedListEntries<EncryptionZone> ret =
|
|
|
FSDirEncryptionZoneOp.listEncryptionZones(dir, prevId);
|
|
|
success = true;
|
|
@@ -7140,11 +7187,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
boolean success = false;
|
|
|
try {
|
|
|
Preconditions.checkNotNull(zone, "zone is null.");
|
|
|
- checkSuperuserPrivilege();
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
+ final FSPermissionChecker pc = dir.getPermissionChecker();
|
|
|
+ checkSuperuserPrivilege(pc);
|
|
|
checkNameNodeSafeMode("NameNode in safemode, cannot " + action
|
|
|
+ " re-encryption on zone " + zone);
|
|
|
- reencryptEncryptionZoneInt(zone, action, logRetryCache);
|
|
|
+ reencryptEncryptionZoneInt(pc, zone, action, logRetryCache);
|
|
|
success = true;
|
|
|
} finally {
|
|
|
logAuditEvent(success, action + "reencryption", zone, null, null);
|
|
@@ -7155,12 +7203,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
final long prevId) throws IOException {
|
|
|
final String operationName = "listReencryptionStatus";
|
|
|
boolean success = false;
|
|
|
- checkSuperuserPrivilege();
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
+ checkSuperuserPrivilege(pc);
|
|
|
readLock();
|
|
|
try {
|
|
|
- checkSuperuserPrivilege();
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
+ checkSuperuserPrivilege(pc);
|
|
|
final BatchedListEntries<ZoneReencryptionStatus> ret =
|
|
|
FSDirEncryptionZoneOp.listReencryptionStatus(dir, prevId);
|
|
|
success = true;
|
|
@@ -7171,9 +7220,9 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void reencryptEncryptionZoneInt(final String zone,
|
|
|
- final ReencryptAction action, final boolean logRetryCache)
|
|
|
- throws IOException {
|
|
|
+ private void reencryptEncryptionZoneInt(final FSPermissionChecker pc,
|
|
|
+ final String zone, final ReencryptAction action,
|
|
|
+ final boolean logRetryCache) throws IOException {
|
|
|
if (getProvider() == null) {
|
|
|
throw new IOException("No key provider configured, re-encryption "
|
|
|
+ "operation is rejected");
|
|
@@ -7181,7 +7230,8 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
String keyVersionName = null;
|
|
|
if (action == ReencryptAction.START) {
|
|
|
// get zone's latest key version name out of the lock.
|
|
|
- keyVersionName = FSDirEncryptionZoneOp.getCurrentKeyVersion(dir, zone);
|
|
|
+ keyVersionName =
|
|
|
+ FSDirEncryptionZoneOp.getCurrentKeyVersion(dir, pc, zone);
|
|
|
if (keyVersionName == null) {
|
|
|
throw new IOException("Failed to get key version name for " + zone);
|
|
|
}
|
|
@@ -7190,11 +7240,10 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
}
|
|
|
writeLock();
|
|
|
try {
|
|
|
- checkSuperuserPrivilege();
|
|
|
+ checkSuperuserPrivilege(pc);
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("NameNode in safemode, cannot " + action
|
|
|
+ " re-encryption on zone " + zone);
|
|
|
- final FSPermissionChecker pc = dir.getPermissionChecker();
|
|
|
List<XAttr> xattrs;
|
|
|
dir.writeLock();
|
|
|
try {
|
|
@@ -7429,7 +7478,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
final String operationName = "getErasureCodingPolicy";
|
|
|
boolean success = false;
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
- FSPermissionChecker pc = getPermissionChecker();
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
readLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.READ);
|
|
@@ -7488,11 +7537,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
throws IOException {
|
|
|
final String operationName = "setXAttr";
|
|
|
FileStatus auditStat = null;
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot set XAttr on " + src);
|
|
|
- auditStat = FSDirXAttrOp.setXAttr(dir, src, xAttr, flag, logRetryCache);
|
|
|
+ auditStat = FSDirXAttrOp.setXAttr(dir, pc, src, xAttr, flag,
|
|
|
+ logRetryCache);
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, operationName, src);
|
|
|
throw e;
|
|
@@ -7508,10 +7560,11 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
final String operationName = "getXAttrs";
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
List<XAttr> fsXattrs;
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
readLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
- fsXattrs = FSDirXAttrOp.getXAttrs(dir, src, xAttrs);
|
|
|
+ fsXattrs = FSDirXAttrOp.getXAttrs(dir, pc, src, xAttrs);
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, operationName, src);
|
|
|
throw e;
|
|
@@ -7526,10 +7579,11 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
final String operationName = "listXAttrs";
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
List<XAttr> fsXattrs;
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
readLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
- fsXattrs = FSDirXAttrOp.listXAttrs(dir, src);
|
|
|
+ fsXattrs = FSDirXAttrOp.listXAttrs(dir, pc, src);
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, operationName, src);
|
|
|
throw e;
|
|
@@ -7544,11 +7598,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
throws IOException {
|
|
|
final String operationName = "removeXAttr";
|
|
|
FileStatus auditStat = null;
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
checkNameNodeSafeMode("Cannot remove XAttr entry on " + src);
|
|
|
- auditStat = FSDirXAttrOp.removeXAttr(dir, src, xAttr, logRetryCache);
|
|
|
+ auditStat = FSDirXAttrOp.removeXAttr(dir, pc, src, xAttr, logRetryCache);
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, operationName, src);
|
|
|
throw e;
|
|
@@ -7562,7 +7618,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
void checkAccess(String src, FsAction mode) throws IOException {
|
|
|
final String operationName = "checkAccess";
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
- FSPermissionChecker pc = getPermissionChecker();
|
|
|
+ final FSPermissionChecker pc = getPermissionChecker();
|
|
|
readLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.READ);
|
|
@@ -7813,5 +7869,16 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
.size();
|
|
|
}
|
|
|
|
|
|
+ // This method logs operatoinName without super user privilege.
|
|
|
+ // It should be called without holding FSN lock.
|
|
|
+ void checkSuperuserPrivilege(String operationName)
|
|
|
+ throws IOException {
|
|
|
+ try {
|
|
|
+ checkSuperuserPrivilege();
|
|
|
+ } catch (AccessControlException ace) {
|
|
|
+ logAuditEvent(false, operationName, null);
|
|
|
+ throw ace;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|