Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
import static org.apache.hadoop.hdds.scm.server.StorageContainerManager.startRpcServer;
import static org.apache.hadoop.hdds.server.ServerUtils.getRemoteUserName;
import static org.apache.hadoop.hdds.server.ServerUtils.updateRPCListenAddress;
import static org.apache.hadoop.hdds.utils.HddsServerUtil.getRemoteUser;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -177,6 +179,7 @@ public List<AllocatedBlock> allocateBlock(
ReplicationConfig replicationConfig,
String owner, ExcludeList excludeList
) throws IOException {
scm.checkAdminAccess(getRemoteUser(), false);
Map<String, String> auditMap = Maps.newHashMap();
auditMap.put("size", String.valueOf(size));
auditMap.put("num", String.valueOf(num));
Expand Down Expand Up @@ -229,6 +232,7 @@ public List<AllocatedBlock> allocateBlock(
@Override
public List<DeleteBlockGroupResult> deleteKeyBlocks(
List<BlockGroup> keyBlocksInfoList) throws IOException {
scm.checkAdminAccess(getRemoteUser(), false);
if (LOG.isDebugEnabled()) {
LOG.debug("SCM is informed by OM to delete {} blocks",
keyBlocksInfoList.size());
Expand Down Expand Up @@ -305,6 +309,7 @@ public ScmInfo getScmInfo() throws IOException {

@Override
public boolean addSCM(AddSCMRequest request) throws IOException {
scm.checkAdminAccess(getRemoteUser(), false);
LOG.debug("Adding SCM {} addr {} cluster id {}",
request.getScmId(), request.getRatisAddr(), request.getClusterId());

Expand Down Expand Up @@ -333,6 +338,7 @@ public boolean addSCM(AddSCMRequest request) throws IOException {
@Override
public List<DatanodeDetails> sortDatanodes(List<String> nodes,
String clientMachine) throws IOException {
scm.checkAdminAccess(getRemoteUser(), false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sortDatanodes is kind of a read operation, it doesn't change the in memory or persist state of pipeline.

Copy link
Contributor Author

@devmadhuu devmadhuu Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ChenSammi for review. I understood and handled the comment. Pls re-review.

boolean auditSuccess = true;
try {
NodeManager nodeManager = scm.getScmNodeManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ private ContainerWithPipeline getContainerWithPipelineCommon(
@Override
public ContainerWithPipeline getContainerWithPipeline(long containerID)
throws IOException {
getScm().checkAdminAccess(null, true);
getScm().checkAdminAccess(getRemoteUser(), true);

try {
ContainerWithPipeline cp = getContainerWithPipelineCommon(containerID);
Expand All @@ -321,6 +321,7 @@ public ContainerWithPipeline getContainerWithPipeline(long containerID)
@Override
public List<HddsProtos.SCMContainerReplicaProto> getContainerReplicas(
long containerId, int clientVersion) throws IOException {
getScm().checkAdminAccess(getRemoteUser(), true);
List<HddsProtos.SCMContainerReplicaProto> results = new ArrayList<>();

Set<ContainerReplica> replicas = getScm().getContainerManager()
Expand All @@ -344,7 +345,7 @@ public List<HddsProtos.SCMContainerReplicaProto> getContainerReplicas(
@Override
public List<ContainerWithPipeline> getContainerWithPipelineBatch(
Iterable<? extends Long> containerIDs) throws IOException {
getScm().checkAdminAccess(null, true);
getScm().checkAdminAccess(getRemoteUser(), true);

List<ContainerWithPipeline> cpList = new ArrayList<>();

Expand Down Expand Up @@ -378,10 +379,12 @@ public List<ContainerWithPipeline> getExistContainerWithPipelinesInBatch(
List<ContainerWithPipeline> cpList = new ArrayList<>();
for (Long containerID : containerIDs) {
try {
getScm().checkAdminAccess(getRemoteUser(), true);
ContainerWithPipeline cp = getContainerWithPipelineCommon(containerID);
cpList.add(cp);
} catch (IOException ex) {
//not found , just go ahead
LOG.error("IOException - Admin Access Failed: {}", ex);
}
}
return cpList;
Expand Down Expand Up @@ -449,6 +452,7 @@ public List<ContainerInfo> listContainer(long startContainerID,
public List<ContainerInfo> listContainer(long startContainerID,
int count, HddsProtos.LifeCycleState state,
HddsProtos.ReplicationFactor factor) throws IOException {
getScm().checkAdminAccess(getRemoteUser(), true);
boolean auditSuccess = true;
Map<String, String> auditMap = Maps.newHashMap();
auditMap.put("startContainerID", String.valueOf(startContainerID));
Expand Down Expand Up @@ -516,6 +520,7 @@ public List<ContainerInfo> listContainer(long startContainerID,
int count, HddsProtos.LifeCycleState state,
HddsProtos.ReplicationType replicationType,
ReplicationConfig repConfig) throws IOException {
getScm().checkAdminAccess(getRemoteUser(), true);
boolean auditSuccess = true;
Map<String, String> auditMap = Maps.newHashMap();
auditMap.put("startContainerID", String.valueOf(startContainerID));
Expand Down Expand Up @@ -595,7 +600,7 @@ public List<HddsProtos.Node> queryNode(
HddsProtos.NodeOperationalState opState, HddsProtos.NodeState state,
HddsProtos.QueryScope queryScope, String poolName, int clientVersion)
throws IOException {

getScm().checkAdminAccess(getRemoteUser(), true);
if (queryScope == HddsProtos.QueryScope.POOL) {
throw new IllegalArgumentException("Not Supported yet");
}
Expand Down Expand Up @@ -656,6 +661,7 @@ public List<DatanodeAdminError> startMaintenanceNodes(List<String> nodes,

@Override
public void closeContainer(long containerID) throws IOException {
getScm().checkAdminAccess(getRemoteUser(), false);
final UserGroupInformation remoteUser = getRemoteUser();
final Map<String, String> auditMap = Maps.newHashMap();
auditMap.put("containerID", String.valueOf(containerID));
Expand Down Expand Up @@ -684,6 +690,7 @@ public void closeContainer(long containerID) throws IOException {
public Pipeline createReplicationPipeline(HddsProtos.ReplicationType type,
HddsProtos.ReplicationFactor factor, HddsProtos.NodePool nodePool)
throws IOException {
getScm().checkAdminAccess(getRemoteUser(), false);
Map<String, String> auditMap = Maps.newHashMap();
if (type != null) {
auditMap.put("replicationType", type.toString());
Expand Down Expand Up @@ -721,6 +728,7 @@ public List<Pipeline> listPipelines() {
@Override
public Pipeline getPipeline(HddsProtos.PipelineID pipelineID)
throws IOException {
getScm().checkAdminAccess(getRemoteUser(), true);
return scm.getPipelineManager().getPipeline(
PipelineID.getFromProtobuf(pipelineID));
}
Expand All @@ -731,6 +739,7 @@ public void activatePipeline(HddsProtos.PipelineID pipelineID)
Map<String, String> auditMap = Maps.newHashMap();
auditMap.put("pipelineID", pipelineID.getId());
try {
getScm().checkAdminAccess(getRemoteUser(), false);
scm.getPipelineManager().activatePipeline(
PipelineID.getFromProtobuf(pipelineID));
AUDIT.logWriteSuccess(buildAuditMessageForSuccess(
Expand Down Expand Up @@ -865,6 +874,7 @@ public void transferLeadership(String newLeaderId)

public List<DeletedBlocksTransactionInfo> getFailedDeletedBlockTxn(int count,
long startTxId) throws IOException {
getScm().checkAdminAccess(getRemoteUser(), true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check can be removed too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check can be removed too.

Done.

List<DeletedBlocksTransactionInfo> result;
Map<String, String> auditMap = Maps.newHashMap();
auditMap.put("count", String.valueOf(count));
Expand Down Expand Up @@ -1221,19 +1231,22 @@ public Token<?> getContainerToken(ContainerID containerID)

@Override
public long getContainerCount() throws IOException {
getScm().checkAdminAccess(getRemoteUser(), true);
return scm.getContainerManager().getContainers().size();
}

@Override
public long getContainerCount(HddsProtos.LifeCycleState state)
throws IOException {
getScm().checkAdminAccess(getRemoteUser(), true);
return scm.getContainerManager().getContainers(state).size();
}

@Override
public List<ContainerInfo> getListOfContainers(
long startContainerID, int count, HddsProtos.LifeCycleState state)
throws IOException {
getScm().checkAdminAccess(getRemoteUser(), true);
return scm.getContainerManager().getContainers(
ContainerID.valueOf(startContainerID), count, state);
}
Expand Down Expand Up @@ -1328,6 +1341,7 @@ public DecommissionScmResponseProto decommissionScm(
DecommissionScmResponseProto.newBuilder();

try {
getScm().checkAdminAccess(getRemoteUser(), false);
decommissionScmResponseBuilder
.setSuccess(scm.removePeerFromHARing(scmId));
} catch (IOException ex) {
Expand Down