Apache Log4j 2 is an open source logging tool, which is widely used in various frameworks. Recently, a vulnerability in Apache Log4j 2 has been revealed, and the vulnerability has now been disclosed. This article provides recommended fixes for KubeSphere users.

This vulnerability is caused by the lookup function provided by Log4j 2, which allows developers to read the configuration in the corresponding environment through some protocols. However, in the process of implementation, no strict judgment was made on the input, which caused loopholes. As a large number of software uses the Log4j 2 plug-in, a large number of Java products have been affected, including but not limited to Apache Solr, srping-boot-strater-log4j2, Apache Struts2, ElasticSearch, Dubbo, Redis, Logstash, Kafka... For more components, please refer to Log4j 2 related documents .

The affected Log4j version is Apache Log4j 2.x <2.15.0-rc2. At present, the official release of Apache 2.15.0-rc2 version fixes the vulnerability, but this version is not an informal release, so there are unstable factors. If you want to upgrade, it is recommended to back up the relevant data.

At the same time, three methods are also provided to remedy the vulnerability.

  • Set the system environment variable FORMAT_MESSAGES_PATTERN_DISABLE_LOOKUPS to true
  • Modify configuration log4j2.formatMsgNoLookups=True
  • Modify JVM parameters -Dlog4j2.formatMsgNoLookups=true

You can choose one of the following three solutions for reference.

Method 1: Modify system environment variables

Since KubeSphere uses ElasticSearch to collect logs by default, the corresponding configuration should also be modified in KubeSphere to fix the vulnerabilities. The following explains how to perform corresponding operations in KubeSphere to repair ElasticSearch.

Set the system environment variable FORMAT_MESSAGES_PATTERN_DISABLE_LOOKUPS to True. For this, we need to modify the ElasticSearch Yaml file, because it is a StatefulSet file, so we need to make the following modifications:

kubectl edit  statefulset  elasticsearch-logging-data -n kubesphere-logging-system
kubectl edit  statefulset  elasticsearch-logging-discovery  -n kubesphere-logging-system

Insert environment variable settings in these two Yaml files:

env:
- name: FORMAT_MESSAGES_PATTERN_DISABLE_LOOKUPS
  value: "true"

Method 2: Modify Log4j 2 configuration

In addition, you can also modify the configuration log4j2.formatMsgNoLookups=True , you can execute the following command:

kubectl edit configmaps elasticsearch-logging  -n kubesphere-logging-system

Then insert the configuration mentioned above:

log4j2.properties: |-
    status=error
    appender.console.type=Console
    appender.console.name=console
    appender.console.layout.type=PatternLayout
    appender.console.layout.pattern=[%d{ISO8601}][%-5p][%-25c{1.}] %marker%m%n
    rootLogger.level=info
    rootLogger.appenderRef.console.ref=console
    logger.searchguard.name=com.floragunn
    logger.searchguard.level=info
    # 插入此行
    log4j2.formatMsgNoLookups=true

Notice:

  1. After modification, please pay attention to whether the relevant configuration is mounted. If it is not mounted, please restart the Pod.
  2. If you reinstall the KubeSphere Logging component, ks-installer may cause the configuration of the ConfigMap to be reset. You need to configure it again by referring to method two, or use method one to set the system environment variable 161c2f72a6c29a FORMAT_MESSAGES_PATTERN_DISABLE_LOOKUPS to true.

Method 3: Modify the JVM parameters of ElasticSearch

In addition to the above two methods, you can also choose to add configuration files to ElasticSearch in the KubeSphere cluster and configure JVM parameters separately. For details, see ElasticSearch announcement statement .

Related references

This article is published by the blog one article multi-posting OpenWrite

KubeSphere
127 声望61 粉丝

KubeSphere 是一个开源的以应用为中心的容器管理平台,支持部署在任何基础设施之上,并提供简单易用的 UI,极大减轻日常开发、测试、运维的复杂度,旨在解决 Kubernetes 本身存在的存储、网络、安全和易用性等痛...