<p>I was trying to setup an elasticsearch cluster in AKS using helm chart but due to the log4j vulnerability, I wanted to set it up with option <code>-Dlog4j2.formatMsgNoLookups</code> set to <code>true</code>. I am getting unknown flag error when I pass the arguments in helm commands.
Ref: <a href="https://artifacthub.io/packages/helm/elastic/elasticsearch/6.8.16" rel="noreferrer">https://artifacthub.io/packages/helm/elastic/elasticsearch/6.8.16</a></p>
<pre><code>helm upgrade  elasticsearch elasticsearch --set imageTag=6.8.16 esJavaOpts &quot;-Dlog4j2.formatMsgNoLookups=true&quot;
Error: unknown shorthand flag: 'D' in -Dlog4j2.formatMsgNoLookups=true
</code></pre>
<p>I have also tried to add below in <code>values.yaml</code> file</p>
<pre><code>esConfig: {}
#  elasticsearch.yml: |
#    key:
#      nestedkey: value
log4j2.properties: |
  -Dlog4j2.formatMsgNoLookups = true
</code></pre>
<p>but the values are not adding to the <code>/usr/share/elasticsearch/config/jvm.options</code>, <code>/usr/share/elasticsearch/config/log4j2.properties</code> or in the environment variables.</p>

<p>First of all, here's a good source of knowledge about mitigating <a href="https://xeraa.net/blog/2021_mitigate-log4j2-log4shell-elasticsearch/" rel="nofollow noreferrer">Log4j2 security issue</a> if this is the reason you reached here.</p>
<p>Here's how you can write your <code>values.yaml</code> for the Elasticsearch chart:</p>
<pre><code>esConfig:
  log4j2.properties: |
    logger.discovery.name = org.elasticsearch.discovery
    logger.discovery.level = debug
</code></pre>
<p>A ConfigMap will be generated by Helm:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: elasticsearch-master-config
  ...
data:
  log4j2.properties: |
    logger.discovery.name = org.elasticsearch.discovery
    logger.discovery.level = debug
</code></pre>
<p>And the Log4j configuration will be mount to your Elasticsearch as:</p>
<pre><code>...
volumeMounts:
  ...
  - name: esconfig
    mountPath: /usr/share/elasticsearch/config/log4j2.properties
    subPath: log4j2.properties
</code></pre>
<p><strong>Update:</strong> How to set and add multiple configuration files.</p>
<p>You can setup other ES configuration files in your <code>values.yaml</code>, all the files that you specified here will be part of the ConfigMap, each of the files will be mounted at <code>/usr/share/elasticsearch/config/</code> in the Elasticsearch container. Example:</p>
<pre><code>esConfig:
  elasticsearch.yml: |
    node.master: true
    node.data: true

  log4j2.properties: |
    logger.discovery.name = org.elasticsearch.discovery
    logger.discovery.level = debug

  jvm.options: |
    # You can also place a comment here.
    -Xmx1g -Xms1g -Dlog4j2.formatMsgNoLookups=true

  roles.yml: |
    click_admins:
      run_as: [ 'clicks_watcher_1' ]
      cluster: [ 'monitor' ]
      indices:
      - names: [ 'events-*' ]
        privileges: [ 'read' ]
        field_security:
          grant: ['category', '@timestamp', 'message' ]
        query: '{&quot;match&quot;: {&quot;category&quot;: &quot;click&quot;}}'
</code></pre>
<p><strong>ALL of the configurations above are for illustration only to demonstrate how to add multiple configuration files in the values.yaml. Please substitute these configurations with your own settings.</strong></p>
