修补 log4j 删除 JndiLookup 类:
三个文件变更:
1、distribution/build.gradle
distribution/build.gradle
@@ -276,6 +276,10 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {
}
}
}
all {
resolutionStrategy.dependencySubstitution {
substitute module("org.apache.logging.log4j:log4j-core") using project(":libs:elasticsearch-log4j") because "patched to remove JndiLookup clas"}
}
}
dependencies {
2、libs/build.gradle
@@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
subprojects {
configure(subprojects - project('elasticsearch-log4j')) {
/*
* All subprojects are java projects using Elasticsearch's standard build
* tools.
3、libs/log4j/build.gradle
@@ -0,0 +1,28 @@
plugins {
id 'base'
id 'elasticsearch.repositories'
}
configurations {
log4j {
transitive = false
}
}
dependencies {
log4j "org.apache.logging.log4j:log4j-core:${versions.log4j}"
}
// Strip out JndiLookup class to avoid any possibility of exploitation of CVE-2021-44228
// See: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-44228
// See: https://issues.apache.org/jira/browse/LOG4J2-3201
def patchLog4j = tasks.register('patchLog4j', Zip) {
archiveExtension = 'jar'
from({ zipTree(configurations.log4j.singleFile) }) {
exclude '**/JndiLookup.class'
}
}
artifacts {
'default'(patchLog4j)
}
总体来讲:
1、替代模块org.apache.logging.log4j:log4j的核心,使用es自己的库:elasticsearch-log4j;因为删除JndiLookup CLAS
2、es升级到7.16.1版本启动后会发现有以下新参数:
-Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j2.formatMsgNoLookups=true