Git Product home page Git Product logo

cloudera-scripts-for-log4j's Introduction

cloudera-scripts-for-log4j

This repo contains scripts and helper tools to mitigate the critical log4j vulnerability CVE-2021-44228 for Cloudera products affecting all versions of log4j between 2.0 and 2.14.1.

Please read the technical service bulletin found here for an analysis of which products have been affected, and find the mitigations in the actions required section for the TSB.

If you are using “CDH, HDP, and HDF” or “CDP Private Cloud”, refer to Resolution for TSB-545 - Private Cloud Version

If you are using “CDP Public Cloud”, refer to Resolution for TSB-545 - Public Cloud Version

Running the script

run_log4j_patcher.sh scans a directory for jar files and removes JndiLookup.class from the ones it finds. Do not run any other scripts in this directory--they will be called by run_log4j_patcher.sh automatically.

  1. Run the script as root on ALL nodes of your cluster.
    • Script will take 1 mandatory argument (cdh|cdp|hdp)
    • (For CDH and CDP only) The script takes 2 optional arguments: a base directory to scan in, and a backup directory. The default for both are /opt/cloudera and /opt/cloudera/log4shell-backup, respectively. These defaults work for CM/CDH 6 and CDP 7. A different set of directories will be used for HDP.
  2. Ensure that the last line of the script output indicates ‘Finished’ to verify that the job has completed successfully. The script will fail if a command exits unsuccessfully.
  3. Restart Cloudera Manager Server or Ambari, all clusters, and all running jobs and queries.
    Usage: run_log4j_patcher.sh (subcommand) [options]
    Subcommands:
        help              Prints this message
        cdh               Scan a CDH cluster node
        cdp               Scan a CDP cluster node
        hdp               Scan a HDP cluster node
        hdf               Scan a HDF cluster node

    Options:
        -t <targetdir>          Override target directory (default: distro-specific)
        -b <backupdir>          Override backup directory (default: /opt/cloudera/log4shell-backup)
        -p <dell|ibm|common>    Override platform type (default: common)

    Environment Variables:
        SKIP_JAR          If non-empty, skips scanning and patching .jar files
        SKIP_TGZ          If non-empty, skips scanning and patching .tar.gz files (cdh and cdp only)
        SKIP_HDFS         If non-empty, skips scanning and patching .tar.gz files in HDFS
        RUN_SCAN          If non-empty, runs a final scan for missed vulnerable files. This can take several hours.
        TMPDIR            If non-empty, uses /tmp as the temporary directory. Set a different temporary directory using this.
        LOG4J_VERSION     If non-empty, runs scan or removal of vulnerable classes from specific log4j version. For eg: "LOG4J_VERSION=1.x"
        EXIT_ON_FAIL      If non-empty, exit with non-zero error code if any vulnerabilities were found. Script will return zero, if there are no vulnerabilities.

Example :

  1. Run scan without patching jar, tar, and HDFS.
SKIP_JAR=1 SKIP_TGZ=1 SKIP_HDFS=1 RUN_SCAN=1 ./run_log4j_patcher.sh [cdp|cdh|hdp|hdf]
  1. Run scan after patching jar, tar, and HDFS.
RUN_SCAN=1 ./run_log4j_patcher.sh [cdp|cdh|hdp|hdf]
  1. Run script on an IBM SpectrumScale
./run_log4j_patcher.sh [cdp|cdh|hdp|hdf] -p ibm
NOTE: For IBM Power PC with HDFS clusters, '-p ibm' option is NOT required. Default platform will be picked for such deployments.
  1. Run script on an DELL PowerScale/ISILON
./run_log4j_patcher.sh [cdp|cdh|hdp|hdf] -p dell
NOTE: HDFS keytab is mandatory to run the script for DELL Secure clusters. Script expects HDFS headless keytab in '/etc/security/keytabs/hdfs.headless.keytab' path.
  1. Run scan without patching jar, tar, and HDFS for log4j1.
LOG4J_VERSION=1.x SKIP_JAR=1 SKIP_TGZ=1 SKIP_HDFS=1 RUN_SCAN=1 ./run_log4j_patcher.sh [cdp|cdh|hdp|hdf]
  1. Run lo4j vulnarable class removal script for log4j1
LOG4J_VERSION=1.x ./run_log4j_patcher.sh [cdp|cdh|hdp|hdf]

HDP Notes : Currently the HDP removal scrips works on folder /user/ on HDFS. Please modify/extent in The hdp_log4j_jndi_removal.sh around line 57.

cloudera-scripts-for-log4j's People

Contributors

abjain123 avatar jtran-cloudera avatar shardy-cloudera avatar sunilgovind avatar tarunparimi avatar zvaradi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cloudera-scripts-for-log4j's Issues

Not working for HDFS file system for non-secure HDFS Cluster

Hi Team,

Thanks for great work, this is not working for HDFS file system for non-secure HDFS Cluster. Below is an error:

Running on '/usr/lib'
Backing up files to '/opt/cloudera/log4shell-backup'
Running on '/var/lib'
Backing up files to '/opt/cloudera/log4shell-backup'
Run successful
Found an HDFS namenode on this host, removing JNDI from HDFS tar.gz files
Using /etc/security/keytabs/hdfs.headless.keytab to access HDFS
./hdp_support_scripts/patch_hdfs_tgz.sh: line 43: klist: command not found
Using /etc/security/keytabs/hdfs.headless.keytab to access HDFS
./hdp_support_scripts/patch_hdfs_tgz.sh: line 43: klist: command not found

Script Scans all Parcels

Hello,

The script (by default) scan /opt/cloudera for jar/tar/war files. This has the affect of also modifying files which are not part of Cloudera's stack e.g. StreamSets managed by CM. Is there a way the script can check the top-level directories to ensure that they are Cloudera products before scanning?

Thanks.

Use git best-practices: do NOT force-push into the main branch

IMO force-push into the main branch should not be allowed at all, for many reasons:

  • for one the community/contributors here need to all the time rebase their forks, PRs, patches
  • and it seems PRs got auto-closed because of this, including mine #2 :(
    (Of course in feature branches it's OK to force-push , if it helps to keep the history cleaner etc)

Also in general would be nice if Cloudera does changes via feature branches , as does the community

  • and we would almost need some CI/CD incl. basic integration tests for this (with the many changes and contributions)

No validation on backup files - roll back not possible

There is no validation on backup files.
I have a case where the backup path filled up from the script and a number of jar files didn't get backed up, but did get modified.
This means there is no rollback - very bad

if [ ! -f "$targetbackup" ]; then
  echo "Backing up to '$targetbackup'"
  cp -f "$jarfile" "$targetbackup"
fi

Can this script work on CDH5

Hi Team,

Thanks for the great work. The readme said These defaults work for CM/CDH 6 and CDP 7. A different set of directories will be used for HDP. I'm wondering to ask does this script work on CDH5. Thanks.

Script hangs/asks for user input if a war file has duplicate file

If a war file contains the same file twice the script will hang when it asks for a response from the user. This becomes an issue especially when running via Ansible or other automation.

This file has this issue: /opt/cloudera/parcels/CDH-5.16.1-1.cdh5.16.1.p3368.3632/lib/hbase-solr/lib/solr-4.10.3-cdh5.16.1.war

To see the issue, run these commands:

rm -r -f /tmp/unzip_target
mkdir /tmp/unzip_target
unzip -qq /opt/cloudera/parcels/CDH-5.16.1-1.cdh5.16.1.p3368.3632/lib/hbase-solr/lib/solr-4.10.3-cdh5.16.1.war -d /tmp/unzip_target
replace /tmp/unzip_target/WEB-INF/lib/jackson-core-asl-1.8.10.jar? [y]es, [n]o, [A]ll, [N]one, [r]ename:

A proposed fix for this is to add the overwrite option -o to the unzip command. I can create a PR for this.

Create Summary Report After Completion

Please create some sort of summary.date.log file in each CDH/CDP /opt/cloudera/ scanned directory which records all of the original SHA fingerprints of the affected JAR/TAR/WAR files and the SHA fingerprints of their modified versions. This information may be helpful, but most importantly, can be used as a maker to indicate that a particular node has been secured.

Sanity Check for Affected Class File

Not an issue per se, just a quick sanity check if anyone would like.

[root@host]# find / -type f -name '*.jar' -exec unzip -l {} \; | grep JndiLookup.class

Backup of tar.gz files is not occurring at the correct path with '-b' option

Issue is in cloudera-scripts-for-log4j/hdp_support_scripts/delete_jndi.sh file, where we are not passing backupdir while patching tar.gz file.

Actual code snippet with the issue:
for tarfile in $(find -L $targetdir -name "*.tar.gz" -o -name "*.tgz"); do if [ -L "$tarfile" ]; then continue fi if zgrep -q JndiLookup.class $tarfile; then $patch_tgz $tarfile fi done

Correct will be:
for tarfile in $(find -L $targetdir -name "*.tar.gz" -o -name "*.tgz"); do if [ -L "$tarfile" ]; then continue fi if zgrep -q JndiLookup.class $tarfile; then $patch_tgz $tarfile $backupdir fi done

PS: Fix of this issue was identified by my fellow colleague Davinder Singh.

Iterator File List for JAR Files When Looking for Class

if grep -q JndiLookup.class $jarfile; then

I think it's more safe and proper to actually iterate the files in the JAR files instead of scanning through their binary contents:

 if unzip -l $jarfile | grep -q JndiLookup.class; then 

Should also be faster than the current implementation because the unzip utility knows how to quickly find the class names within the ZIP file dictionary without having to scan/read the entire file.

Files Can´t updated (cloudera-manager-daemons)

I need you help because after apply patches only 2 files from Cloudera Manager can´t updated, so is necessary restores
both files (from backup"/opt/cloudera/log4shell-backup") because cloudera manager dont start again after "applied patches", restore both files then Cloudera manager start without problem.

:::Files Can´t updated (cloudera-manager-daemons):::
[0]
/opt/cloudera/cm/common_jars/log4j-1.2.17-cloudera1.9b958f437c18806864374725d91ab8b7.jar
[1]
/opt/cloudera/cm/common_jars/log4j-core-2.8.2.f3f743bada8d698e2d116e5c9951fe2f.jar

Background
Versions: CDP Private Cloud Base= 7.1.5
Cloudera Manager version= 7.2.4


output_run_log4j_patcher .log

/tmp as backup dir is hardcoded

Hi,

backups go the /tmp hardcoded.
On our systems /tmp is not big enough., so we change it to an other directory.

Question: can you make the “/tmp” backup dir an option or variable?

export TMPDIR=/opt/cloudera/tmp

changes we need to make:
local_path=“/opt/cloudera/tmp/hdfs_tar_files.${current_time}”
hdfs_bc_path=“/opt/cloudera/tmp/backup.${current_time}"

Regards, Hans

Parametrize targetdir and backupdir for HDP/HDF

Options (cdh and cdp subcommands only):
    -t <targetdir>    Override target directory (default: distro-specific)
    -b <backupdir>    Override backup directory (default: /opt/cloudera/log4shell-backup)

HDP: Symlinks to jars not getting followed and scanned for JndiLookup.class files

Observation from a test run of log4j patch script on HDP:

Looks like if a OS directory has symlinks to jars, its not getting followed and scanned for JndiLookup.class files.

grep: /usr/hdp/current/phoenix-server/lib/hbase-testing-util.jar: No such file or directory

Test run Log:

[root@server]# ./run_log4j_patcher.sh hdp
INFO : Running HDP/HDF patcher script: ./hdp_log4j_jndi_removal.sh '/usr/hdp/current /usr/hdf/current /usr/lib /var/lib' /opt/cloudera/log4shell-backup
INFO : Log file: output_run_log4j_patcher.hjH6lO
.
Removing JNDI from jar files
Running on '/usr/hdp/current'
Backing up files to '/opt/cloudera/log4shell-backup'
grep: /usr/hdp/current/hadoop-client/lib/ojdbc6.jar: No such file or directory
grep: /usr/hdp/current/hbase-client/lib/ojdbc6.jar: No such file or directory
grep: /usr/hdp/current/hbase-master/lib/ojdbc6.jar: No such file or directory
grep: /usr/hdp/current/hbase-regionserver/lib/ojdbc6.jar: No such file or directory
grep: /usr/hdp/current/phoenix-client/lib/hbase-testing-util.jar: No such file or directory
grep: /usr/hdp/current/phoenix-server/lib/hbase-testing-util.jar: No such file or directory
Running on '/usr/hdf/current'
Backing up files to '/opt/cloudera/log4shell-backup'
Running on '/usr/lib'
Backing up files to '/opt/cloudera/log4shell-backup'
Running on '/var/lib'
Backing up files to '/opt/cloudera/log4shell-backup'
Run successful
INFO : Finished
[root@server]#

Symlink:
[user@server]$ ll /usr/hdp/current/phoenix-client/lib/hbase-testing-util.jar
lrwxrwxrwx 1 root root 52 May 22 2018 /usr/hdp/current/phoenix-client/lib/hbase-testing-util.jar -> /usr/hdp/2.6.4.0-91/hbase/lib/hbase-testing-util.jar

Any fix for this? Or am I missing something?

Symlinks are being followed and thus backing up the wrong jar

There is a number of bit of code like

for jarfile in $targetdir/**/*.jar; do

Thus symlinks are being followed and bad things happen, espically with backup of the link name and not the actual file

consider using
for jarfile in $(find ${targetdir} -type f -name "*.jar") ; do

code to backup for tar.gz is invalid

The code here is not working (cm_cdp_cdh_log4j_jndi_removal.sh line 139)

  local backupdir=${2:-/opt/cloudera/log4shell-backup}
  mkdir -p "$backupdir/$(dirname $tarfile)"
  targetbackup="$backupdir/$tarfile.backup"
  if [ ! -f "$targetbackup" ]; then
    echo "Backing up to '$targetbackup'"
    cp -f "$tarfile" "$targetbackup"
  fi

You do a mkdir for a path and then don't use it.

I can't see any backups for the *.tar.gz in the location of the backupdir

There is something wrong with this block of code

Also the function is always creating a new tar.gz, even if there is nothing to "patch" thus touching files which don't need to be altered - this is bad.....

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.