Skip to content
This repository has been archived by the owner on Aug 6, 2022. It is now read-only.

Reduce the number of high-priority CVEs in scans #405

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

acdha
Copy link
Contributor

@acdha acdha commented Dec 22, 2021

This has two of the changes discussed in https://issues.apache.org/jira/browse/SOLR-15855 which will reduce the number of CVEs reported in a container scan somewhat dramatically (~50 critical, 120 high in a recent scan). I put those in as separate RUN commands for clarity but there is a potential argument to combining them into the previous layer if you're trying to optimize for layer count.

@acdha acdha force-pushed the patch-1 branch 2 times, most recently from 0fc1734 to 64a9067 Compare December 22, 2021 22:18
Copy link
Contributor

@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.

Removing htrace will lead to ClassNotFoundException for anyone using Hdfs stuff. Moving Hadoop stuff to a module (aka "contrib") is happening in 9.x and that will help somewhat. We can't remove that in 8x's Docker image (sorry). I could see replacing the JAR if there is something suitable.

Modifying the Dockerfile directly is not how this project works. See Dockerfile-varsolr.template and we run scripts to regenerate. Also, removing stuff in the big "RUN" command would be superior as it saves space and a layer.

@acdha acdha mentioned this pull request Dec 27, 2021
acdha and others added 2 commits December 27, 2021 17:47
This updates the work @janhoy did in
0b13c14 by adjusting to a change in
shell behaviour: now that dash is the default shell, the brace expansion
does not work as expected but the `-f` flag passed to `rm` meant that
the build continued without deleting the intended files.

This partially addresses
https://issues.apache.org/jira/browse/SOLR-15855 because the removed
files have a number of open CVEs, several of which are serious and may
block deployments if used in a CI/CD pipeline which has a scanner.

Because dash does not support brace expansion and find’s `-delete`
action does not support deleting directories, this commit splits the
work into two commands: `rm -R` for the directories and `find … -delete`
for the files.
@acdha
Copy link
Contributor Author

acdha commented Dec 27, 2021

This turned out to be more interesting than I expected: I noticed that my removal of the test-framework appeared to be completely unnecessary because @janhoy already did this 2 years ago in 0b13c14:

0b13c14#diff-8d7a21b017921bb88eaf71656b7b5767203db16e8126fc1e5ad2a9ba0bc542f5

Unfortunately, that no longer works as intended because the default shell is currently dash, which doesn't support bash's non-POSIX brace expansion extension so /opt/solr/dist/{solr-core-$SOLR_VERSION.jar,solr-solrj-$SOLR_VERSION.jar,solrj-lib,solr-test-framework-$SOLR_VERSION.jar,test-framework} is treated as a single string literal. The use of -f causes that error to silently be ignored and since that forces rc=0 it does not force an exit due to the earlier set -e. Removing -f makes the problem clear:

rm: cannot remove '/opt/solr/dist/{solr-core-8.11.1.jar,solr-solrj-8.11.1.jar,solrj-lib,solr-test-framework-8.11.1.jar,test-framework}': No such file or directory

I'm guessing that when @janhoy made that change originally the default shell was bash and since everything targeted was by definition not a dependency it wasn't obvious that this no longer worked when the default shell changed.

I removed the -f option to avoid future errors of this class.

To work around the lack of brace expansion, I split that into two parts: removing the directories with rm -R and using find … -delete with a list of the target JAR files. There are only 3 so there would be an argument from simplicity for simply breaking that into three rm commands but I used an OR-block on the assumption that future changes would likely grow that list.

-  rm -Rf /opt/solr/docs/ /opt/solr/dist/{solr-core-$SOLR_VERSION.jar,solr-solrj-$SOLR_VERSION.jar,solrj-lib,solr-test-framework-$SOLR_VERSION.jar,test-framework}; \
+  rm -R /opt/solr/docs/ /opt/solr/dist/solrj-lib /opt/solr/dist/test-framework; \
+  find /opt/solr/dist/ \( -name "solr-core-$SOLR_VERSION.jar" -o -name "solr-solrj-$SOLR_VERSION.jar" -o -name "solr-test-framework-$SOLR_VERSION.jar" \) -delete; \

@acdha
Copy link
Contributor Author

acdha commented Dec 27, 2021

The HTrace issue has a potential fix thanks to https://issues.apache.org/jira/browse/HBASE-24802 but I wanted to check your course on this. The HBase project produced hbase-noop-htrace, which appears to be a drop-in replacement.

Would it be considered cleaner to drop that in in the Docker build process or try to get that merged into the upstream Solr builds?

@dsmiley
Copy link
Contributor

dsmiley commented Dec 28, 2021

Awesome investigation Chris!

RE htrace: this should be done upstream (in Solr proper). Forewarning: Solr 9 (not yet released) has a very different build/dependency management than Solr 8 so sadly the work on each branch there is different but not hard in any case. You don't "have" to do it on both but if you do it on 8, it's kinda necessary to do so in 9 as well. I can help. There are tests for Hadoop related functionality, and so replacing it there gives some comfort we didn't break something.

p.s. I'm on vacation this week in DC (I see you work there) so I'm not particularly responsive.

@dsmiley
Copy link
Contributor

dsmiley commented Dec 28, 2021

Oh another thing: In 9x there's big effort to put hadoop stuff into another module so I suggest you not bother with the 9x side, leaving that side to me and/or the person doing that as a minor change.

@acdha
Copy link
Contributor Author

acdha commented Dec 28, 2021

p.s. I'm on vacation this week in DC (I see you work there) so I'm not particularly responsive.

Please do not feel any pressure from me to do anything otherwise — I have deep sympathy for other maintainers.

Oh another thing: In 9x there's big effort to put hadoop stuff into another module so I suggest you not bother with the 9x side, leaving that side to me and/or the person doing that as a minor change.

That's good to know, thanks. I was wondering how big a project that was going to be since I think continuous security monitoring is going to increase the overhead of public services like this and was wondering whether it might make sense to have something like separate container tags for major features like Hadoop, but that's hardly free.

@dsmiley
Copy link
Contributor

dsmiley commented Dec 28, 2021

I'd definitely be in favor of splitting the docker distro into two -- one is just "core" (+ prometheus exporter perhaps) and the other has all the so-called "contribs" in it (or perhaps drop that entirely). This is the kind of thing we can do at a 9.0 release.

@janhoy
Copy link
Contributor

janhoy commented Jan 4, 2022

This may be an issue also for the 9.0 dockerfile template at https://github.com/apache/solr/blob/main/solr/docker/templates/Dockerfile.body.template - have not tested, but it likely has dash as default shell too...

@janhoy
Copy link
Contributor

janhoy commented Jan 4, 2022

Note that once solr-core.jar is successfully deleted, the bin/post tool will stop working. See fix in apache/solr#494

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants