<p>I'm using kubernetes/ingress-nginx. 
Task is to extract CN field from client's certificate using nginx ingress. I was searching for a while and found a solution:</p>

<pre><code>   map  $ssl_client_s_dn  $ssl_client_s_dn_cn {
    default "";
    ~CN=(?&lt;CN&gt;[^/,\"]+) $CN;
  }
</code></pre>

<p>But I can't adapt this code for nginx ingress.That's what I currently have and it doesn't work.</p>

<pre><code>nginx.ingress.kubernetes.io/http-snippets: |
  map  $ssl_client_s_dn  $ssl_client_s_dn_cn {
    default "";
    ~CN=(?&lt;CN&gt;[^/,\"]+) $CN;
  }
nginx.ingress.kubernetes.io/configuration-snippet: |
  proxy_set_header Remote-User $ssl_client_s_dn_cn;
</code></pre>

<p>Probably someone faced with it and know how to adjust this properly, as I'm out of ideas.<br>
If you know more elegant way to do it please share you knowledge here.<br>
Thanks in advance.</p>

<p>I found a solution,hope it may help someone:</p>

<pre><code>    nginx.ingress.kubernetes.io/http-snippet: |
     map  $ssl_client_s_dn  $ssl_client_s_dn_cn {
       default "";
       ~CN=(?&lt;CN&gt;[^/,\"]+) $CN;
     };

    nginx.ingress.kubernetes.io/location-snippet: |
     proxy_set_header REMOTE-USER $ssl_client_s_dn_cn;
</code></pre>
