Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation in broker container configure updating command #7587

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -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
Loading