Skip to content

Commit

Permalink
Add validation in broker container configure updating command.
Browse files Browse the repository at this point in the history
  • Loading branch information
RongtongJin committed Nov 28, 2023
1 parent 9cfe724 commit 26d8e17
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ public class BrokerContainerConfig {
*/
private long updateNamesrvAddrInterval = 60 * 2 * 1000;


/**
* Config in this black list will be not allowed to update by command.
* Try to update this config black list by restart process.
* Try to update configures in black list by restart process.
*/
private String configBlackList = "configBlackList;brokerConfigPaths";

public String getRocketmqHome() {
return rocketmqHome;
}
Expand Down Expand Up @@ -108,4 +116,12 @@ public long getUpdateNamesrvAddrInterval() {
public void setUpdateNamesrvAddrInterval(long updateNamesrvAddrInterval) {
this.updateNamesrvAddrInterval = updateNamesrvAddrInterval;
}

public String getConfigBlackList() {
return configBlackList;
}

public void setConfigBlackList(String configBlackList) {
this.configBlackList = configBlackList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

import io.netty.channel.ChannelHandlerContext;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.List;
import java.util.Properties;
import org.apache.rocketmq.broker.BrokerController;
Expand All @@ -45,8 +48,19 @@ public class BrokerContainerProcessor implements NettyRequestProcessor {
private final BrokerContainer brokerContainer;
private List<BrokerBootHook> brokerBootHookList;

private final Set<String> configBlackList = new HashSet<>();

public BrokerContainerProcessor(BrokerContainer brokerContainer) {
this.brokerContainer = brokerContainer;
initConfigBlackList();
}

private void initConfigBlackList() {
configBlackList.add("brokerConfigPaths");
configBlackList.add("rocketmqHome");
configBlackList.add("configBlackList");
String[] configArray = brokerContainer.getBrokerContainerConfig().getConfigBlackList().split(";");
configBlackList.addAll(Arrays.asList(configArray));
}

@Override
Expand Down Expand Up @@ -232,15 +246,24 @@ private RemotingCommand updateBrokerConfig(ChannelHandlerContext ctx, RemotingCo
try {
String bodyStr = new String(body, MixAll.DEFAULT_CHARSET);
Properties properties = MixAll.string2Properties(bodyStr);
if (properties != null) {
LOGGER.info("updateSharedBrokerConfig, new config: [{}] client: {} ", properties, ctx.channel().remoteAddress());
this.brokerContainer.getConfiguration().update(properties);
} else {

if (properties == null) {
LOGGER.error("string2Properties error");
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setRemark("string2Properties error");
return response;
}

if (validateBlackListConfigExist(properties)) {
response.setCode(ResponseCode.NO_PERMISSION);
response.setRemark("Can not update config in black list.");
return response;
}


LOGGER.info("updateBrokerContainerConfig, new config: [{}] client: {} ", properties, ctx.channel().remoteAddress());
this.brokerContainer.getConfiguration().update(properties);

} catch (UnsupportedEncodingException e) {
LOGGER.error("", e);
response.setCode(ResponseCode.SYSTEM_ERROR);
Expand All @@ -254,6 +277,15 @@ private RemotingCommand updateBrokerConfig(ChannelHandlerContext ctx, RemotingCo
return response;
}

private boolean validateBlackListConfigExist(Properties properties) {
for (String blackConfig : configBlackList) {
if (properties.containsKey(blackConfig)) {
return true;
}
}
return false;
}

private RemotingCommand getBrokerConfig(ChannelHandlerContext ctx, RemotingCommand request) {

final RemotingCommand response = RemotingCommand.createResponseCommand(GetBrokerConfigResponseHeader.class);
Expand Down

0 comments on commit 26d8e17

Please sign in to comment.