Skip to content

Refactor: move isFileForbiddenInConfigSets #4193

Open
dsmiley wants to merge 5 commits intoapache:mainfrom
dsmiley:copilot/move-configset-methods
Open

Refactor: move isFileForbiddenInConfigSets #4193
dsmiley wants to merge 5 commits intoapache:mainfrom
dsmiley:copilot/move-configset-methods

Conversation

@dsmiley
Copy link
Contributor

@dsmiley dsmiley commented Mar 7, 2026

The issue https://issues.apache.org/jira/browse/SOLR-16480 introduced ZkMaintenanceUtils.isFileForbiddenInConfigSets. It's location poor as this is not a ZK specific matter, it's a ConfigSet matter. Moved to ConfigSetService.

Copilot AI and others added 3 commits March 6, 2026 20:41
…anceUtils to ConfigSetService

Co-authored-by: dsmiley <377295+dsmiley@users.noreply.github.com>
…c block

Co-authored-by: dsmiley <377295+dsmiley@users.noreply.github.com>
Copy link
Contributor Author

@dsmiley dsmiley left a comment

Choose a reason for hiding this comment

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

Needs review from a security standpoint, at least. Look at the original JIRA.

Comment on lines +56 to +64
private static final Set<String> USE_FORBIDDEN_FILE_TYPES;

static {
String userForbiddenFileTypes = EnvUtils.getProperty(FORBIDDEN_FILE_TYPES_PROP);
USE_FORBIDDEN_FILE_TYPES =
StrUtils.isNullOrEmpty(userForbiddenFileTypes)
? DEFAULT_FORBIDDEN_FILE_TYPES
: Set.of(userForbiddenFileTypes.split(","));
}
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 is now much simpler -- no lazy initialization with double-checked locking. Wasn't necessary!

public void uploadFileToConfig(
String configName, String fileName, byte[] data, boolean overwriteOnExists)
throws IOException {
if (ZkMaintenanceUtils.isFileForbiddenInConfigSets(fileName)) {
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 line (and really the very definition of that method in a ZK specific class) irritated the hell out of me, prompting me to do this PR

if (children.size() == 0) {
// If we didn't copy data down, then we also didn't create the file. But we still need a
// marker on the local disk so create an empty file.
if (isFileForbiddenInConfigSets(zkPath)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see why this was here. This method doesn't even say "configSet" in it, but lets pretend it did. So nonetheless, what risk does this stop? I think it's sufficient to prevent ConfigSetService from adding "forbidden" files to its storage (usually ZK). If such a file got there already, then it's either by design (sys-admin knows what they are doing) or if bad actors can get stuff into ZK then you've already lost.

+ " to ZooKeeper at "
+ zkHost);
FileTypeMagicUtil.assertConfigSetFolderLegal(confPath);
Files.walkFileTree(
Copy link
Contributor

Choose a reason for hiding this comment

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

I like adding the validation earlier in the process!

Is there an opportunity to DRY up this block of code in this plus ZkConfigSetService?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Come to think of it, I disagree with limiting what the CLI tool can upload on principle. This is a false protection -- if you can use the CLI tool (to touch zookeeper, then you already have permission to do so by your ability to do that very thing.

Copy link
Contributor

@epugh epugh left a comment

Choose a reason for hiding this comment

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

Nice!

@github-actions github-actions bot removed the cat:cli label Mar 8, 2026
New behavior:  uploading configs with forbidden files will now stop the configset from being created!  Yay
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test was oddly asserting an additional configSet being there. It turns out, this was the "_testconf" that was poisoned with the forbidden file. The previous behavior would leave a partial configset in place despite throwing an error but now the logic is pre-validation, thus we don't create the configset if it has forbidden stuff. An improvement!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants