Nginx reverse proxy in Calponia

Hello Calponia community,

We have a requirement to use the calponia logged in user as a user to our application. To implement this feature we are planning to introduce a nginx proxy service as a upstream to our service which will read the calponia-user cookie extract the user id and set it as a header to the downstream request on our app.
we have implemented this using a sample app in node js - to test in the local docker environment we have set a cookie value to a variable and extracting the id and setting to header field.

Its working locally, but when we push the code to use the actual cookie value in Calponia its not recognizing the downstream hostname or service.

nginx.conf file

events {

}

http {

# Commented code which should run in the Calponia environment where it reads the actual http cookie value

# map $http_cookie $auth_header {

# default "";

# '~*calponia-user=%257B%2522id%2522%253A%2522(?<id>[^%]+)' "$id";

# }

## Create a test variable as my_cookie with the extract from calponia_user cookie"

map $host $my_cookie {

default '_ga=GA1.2.1273877671.1626243700;%20calponia-user=%257B%2522id%2522%253A%2522a0fdab44-f42b-11eb-95e5-ef37eff558e9%2522%252C%2522email%2522%253A%2522vasanthkumar.srinivasamurthy%2540in.bosch.com%2522%252C%2522firstName%2522%253Anull%252C%2522lastName%2522%253Anull%257D;%20calponia-instance=%257B%2522id%2522%253A%2522a6e99f82-889b-11eb-8790-f3804e212fc1%2522%252C%2522projectId%2522%253A%2522820e889e-889b-11eb-b626-cfedd53eb1f4%2522%252C%2522appId%2522%253A%2522a6e99f82-889b-11eb-8790-f3804e212fc1%2522%252C%2522versionId%2522%253A%25224af08c54-97eb-4c0f-aeae-350723acf9ab%2522%252C%2522name%2522%253A%2522EATB%2520PoC%2520Application%2522%252C%2522publisher%2522%253A%2522ETAS%252FENA1%2522%252C%2522description%2522%253A%2522Second%2520version%2520of%2520EATB%2520PoC%2520Application.%2520Goals%253A%255Cn*%2520use%2520CI%252FCD%2520builds%2522%252C%2522image%2522%253A%257B%2522_relType%2522%253A%2522files%2522%252C%2522id%2522%253A%2522d4456816-4845-473c-8f02-4cde96392be0%2522%257D%252C%2522version%2522%253A%25220.1.1%2522%257D';

}

## Extract the id from the cookie

map $my_cookie $auth_header {

default "";

'~*calponia-user=%257B%2522id%2522%253A%2522(?<id>[^%]+)' "$id";

}

server {

location / {

proxy_pass http://test_app:3000;

# Pass the id as a new header to test_app

add_header Calponia-auth-id "$auth_header";

}

listen 8080;

}

}

Error in Calponia dashboard

host not found in upstream “test_app” in /etc/nginx/nginx.conf:35

Error in browser console:
{“message”:“getaddrinfo ENOTFOUND a292fb290cb747e9cf73a5579f4f5f83_appmaster”}

Some quick thoughts I’ve got are that either there is no service named test_app in your docker-compose or your service is starting slower than Nginx. Then you’d have to make sure that the service is up before Nginx is trying to forward requests.

Hello matthias.koehler,

Thanks for your quick response!!

docker-compose.yml file

version: ‘3.4’

services:

nginx_rp:

build: ./nginx_rp

ports:

  - 8080:8080

  - 443:443

depends_on:

  - test_app

test_app:

build: ./test_app

ports:

  - 3000:3000

  - 3001:3001

labels:

  - "calponia.publish=3000"

i have named a service by name “test_app” in docker-compose and nginx_app has depends_on property set. Could you please check if i am missing something

Here the solution to the problem (Calponia Beta):
The proxy was blocking REST calls between the services. Unsetting the environment variable solved the issue, e.g. in Dockerfile “RUN unset http_proxy”.