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”}