<p>I am using nginx-ingress in my cluster to expose certain services. I have an &quot;auth&quot; service that handles authentication, which I am trying to setup through nginx. Currently the service has a very simple GET endpoint, that always responds with a <code>UserId</code> header and tries to set two cookies:</p>
<pre class="lang-js prettyprint-override"><code>// This is implemented on Nest.js which uses express.js

@Get('*')
auth(@Res() res: Response): void {
  res.header('UserId', '1')

  res.cookie('key', 'value')
  res.cookie('x', 'y')

  res.status(200).send('hello')
}
</code></pre>
<p>I can confirm that both cookies are being set when I manually send a request to that endpoint, but when I set it as an annotation to the ingress:</p>
<pre><code>nginx.ingress.kubernetes.io/auth-url: http://auth.dev.svc.cluster.local
</code></pre>
<p>and send a request through the ingress, only one of the cookies is forwarded to the Response (the first one <code>key=value</code>). I am not familiar with the nginx configuration, is there something I am supposed to change to make this work, so that both cookies are set?</p>
<p>I found <a href="https://github.com/kubernetes/ingress-nginx/issues/8183" rel="nofollow noreferrer">this issue</a> on GitHub, but it seems to be about OAuth2  there is no clear explanation on what I am supposed to change.</p>

yisog
<p>I couldn't find a way to make this work with the <code>Set-Cookie</code> header. Not sure if there is a better way, but here is a workaround:</p>
<p>I added a snippet for the <code>location</code> block that converts two headers to cookies:</p>
<pre><code>nginx.ingress.kubernetes.io/configuration-snippet: |
  auth_request_set    $auth_cookie1 $upstream_http_x_header1;
  auth_request_set    $auth_cookie2 $upstream_http_x_header2;
  add_header          Set-Cookie $auth_cookie1;
  add_header          Set-Cookie $auth_cookie2;
</code></pre>
<p>And the <code>auth()</code> endpoint now responds with the <code>X-Header1</code> and <code>X-Header2</code> headers:</p>
<pre class="lang-js prettyprint-override"><code>import { serialize } from 'cookie'

@Get('*')
auth(@Res() res: Response): void {
  res.header('UserId', '1')

  res.header('X-Header1', serialize('key', 'value'))
  res.header('X-Header2', serialize('x', 'y'))

  res.status(200).send('hello')
}
</code></pre>
<p>Everything seems to be working well and this solution is similar to how nginx is adding the Set-Cookie header which doesn't support multiple cookies. The code below is copied from the <code>nginx.conf</code> file in the <code>nginx-controller</code> pod that <code>nginx-ingress</code> creates.</p>
<pre><code>auth_request_set    $auth_cookie $upstream_http_set_cookie;
add_header          Set-Cookie $auth_cookie;
</code></pre>
