Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mitigate: RCE 0-day exploit found in log4j, a popular Java logging package https://github.com/elastic/elasticsearch/issues/81618 #2992

Closed
wants to merge 1 commit into from

Conversation

PrajaktaPurohit
Copy link
Contributor

Signed-off-by: Prajakta Purohit prajakta@chef.io

@PrajaktaPurohit PrajaktaPurohit requested review from a team as code owners December 10, 2021 21:19
@netlify
Copy link

netlify bot commented Dec 10, 2021

👷 Deploy Preview for chef-server processing.

🔨 Explore the source changes: 768f12d

🔍 Inspect the deploy log: https://app.netlify.com/sites/chef-server/deploys/61b3c447fd637100074bdecf

Copy link
Contributor

@lbakerchef lbakerchef left a comment

Choose a reason for hiding this comment

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

Looks good. Is there anything showing this working?

@jasonwbarnett
Copy link
Contributor

jasonwbarnett commented Dec 10, 2021

I'm using chef-server-core v14.9.23 on RHEL 7.

I manually added this into the Chef Infra Server (/var/opt/opscode/elasticsearch/config/jvm.options) and after restarting elastic search, it fails to start.

‐Dlog4j2.formatMsgNoLookups=true

You see it try to start with this:

/opt/opscode/embedded/open-jre//bin/java -cp /opt/opscode/embedded/elasticsearch/lib/* org.elasticsearch.tools.launchers.JvmOptionsParser /var/opt/opscode/elasticsearch/config/jvm.options

and after that it doesn't actually successfully start the service. It ends up executing the above over and over and over.

How to reproduce

  1. Switch to root user on chef infra server

    sudo su -
    
  2. Stop elasticsearch

    chef-server-ctl stop elasticsearch
    
  3. Add config to /var/opt/opscode/elasticsearch/config/jvm.options

  4. Impersonate startup process

    Do the following as root user:

    ulimit -n 65536
    
    export ES_HOME=/var/opt/opscode/elasticsearch            #/var/opt/opscode/elasticsearch
    export ES_DATA=/var/opt/opscode/elasticsearch/data       #/var/opt/opscode/elasticsearch/data
    
    export JAVA_HOME=/opt/opscode/embedded/open-jre/
    export ES_PATH_CONF=/var/opt/opscode/elasticsearch/config
    export PATH=/opt/opscode/embedded/bin:$JAVA_HOME/bin:$ES_HOME:$PATH #/opt/opscode/embedded/bin
    
    export TMPDIR=/var/opt/opscode/elasticsearch/tmp
    export ES_TMPDIR=/var/opt/opscode/elasticsearch/tmp
    
    cd $ES_HOME
    
    exec /opt/opscode/embedded/bin/chpst -P -u opscode -U opscode /opt/opscode/embedded/elasticsearch/bin/elasticsearch
    encountered [1] error parsing [/var/opt/opscode/elasticsearch/config/jvm.options]
    [1]: encountered improperly formatted JVM option line [‐Dlog4j2.formatMsgNoLookups=true] on line number [51]
    

p.s. I used viddy at 200ms to capture the following command retrying:

/opt/opscode/embedded/open-jre//bin/java -cp /opt/opscode/embedded/elasticsearch/lib/* org.elasticsearch.tools.launchers.JvmOptionsParser /var/opt/opscode/elasticsearch/config/jvm.options

@PrajaktaPurohit
Copy link
Contributor Author

PrajaktaPurohit commented Dec 11, 2021

I am currently testing the build off of this PR and it elasticsearch service comes up ok. I will try the manual steps by editing the config after testing the upgrades.

@jasonwbarnett
Copy link
Contributor

jasonwbarnett commented Dec 11, 2021

I am currently testing the build off of this PR and it elasticsearch service comes up ok. I will try the manual steps but editing the config after testing the upgrades.

@PrajaktaPurohit What version of elastic is used in the latest version of Chef Infra Server? I'm obviously running on a bit older version of Chef Infra Server so maybe that's why I'm getting different results.

@jasonwbarnett
Copy link
Contributor

@PrajaktaPurohit in parallel I'm going to try to edit /opt/opscode/embedded/cookbooks/private-chef/templates/default/elasticsearch_jvm.opts.erb and then run chef-server-ctl reconfigure followed by chef-server-ctl restart to see if that yields success.

@jasonwbarnett
Copy link
Contributor

jasonwbarnett commented Dec 11, 2021

@PrajaktaPurohit it worked! No idea why that's different, but it works!

/opt/opscode/embedded/open-jre//bin/java -Xmx3467m -Xms3467m -XX:NewSize=216M -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.io.tmpdir=/var/opt/opscode/elasticsearch/tmp -XX:+HeapDumpOnOutOfMemoryError -Dlog4j2.formatMsgNoLookups=true -Des.path.home=/opt/opscode/embedded/elasticsearch -Des.path.conf=/var/opt/opscode/elasticsearch/config -Des.distribution.flavor=oss -Des.distribution.type=tar -cp /opt/opscode/embedded/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch

@PrajaktaPurohit
Copy link
Contributor Author

14.9.23 and the latest 14.15.11 on chef-server uses elasticsearch 6.8.18 (internally)

@PrajaktaPurohit
Copy link
Contributor Author

PrajaktaPurohit commented Dec 11, 2021

@PrajaktaPurohit in parallel I'm going to try to edit /opt/opscode/embedded/cookbooks/private-chef/templates/default/elasticsearch_jvm.opts.erb and then run chef-server-ctl reconfigure followed by chef-server-ctl restart to see if that yields success.

yep - that would be the path I would test out to see if the config works! Glad to hear that is working! Thank you for checking!

@tas50 tas50 closed this Dec 19, 2021
@tas50
Copy link
Contributor

tas50 commented Dec 19, 2021

Closing this out since we went to Elasticsearch 6.8.21 which does the same thing out of the box

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

Successfully merging this pull request may close these issues.

None yet

4 participants