Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

401 unauthorized inside my instance engine

I have a Google Compute Engine instance, kafka-service, running a container (API REST, just for testing). No authentication is required, and my container is up and running.

Here is the output of docker ps:

CONTAINER ID   IMAGE                                        COMMAND                  CREATED          STATUS          PORTS                                                 NAMES
31a6ca030a71   djarallahbrahim/job-offer-producer-ws:main   "/entrypoint.sh $CAT…"   35 minutes ago   Up 35 minutes   8443/tcp, 0.0.0.0:8098->8080/tcp, :::8098->8080/tcp   producer-1
f372594cc16e   bitnami/kafka:latest                         "/opt/bitnami/script…"   49 minutes ago   Up 49 minutes                                                         klt--tfpi

I'm connecting to my instance via SSH through the browser. When I try using curl (with localhost, 127.0.0.1, etc.), I get the following response:

curl -X POST http://localhost:8098/job-offer-producer/job-offer/publish -H "Content-Type: application/json" -H "Access-Control-Allow-Origin: *" -d '{"name":"Software Backend Developer 2024","skills":"[\"JAVA\", \"Python\", \"SpringBoot\"]","description":"Design, develop, and maintain software applications using modern backend technologies.","email":"<PII removed by staff>","salary":812780.00}'

Result of curl:

<!doctype html><html lang="en"><head><title>HTTP Status 401 – Unauthorized</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 401 – Unauthorized</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> Unauthorized</p><p><b>Description</b> The request has not been applied because it lacks valid authentication credentials for the target resource.</p><hr class="line" /><h3>Apache Tomcat/11.0.0-M6</h3></body></html>

Inside my Continere, i see logs in localhost_access_log.2024-11-19.txt:

172.17.0.1 - - [19/Nov/2024:21:16:49 +0000] "GET / HTTP/1.1" 404 685
172.17.0.1 - - [19/Nov/2024:21:21:45 +0000] "GET /job-offer-producer/job-offer/publish HTTP/1.1" 401 706
172.17.0.1 - - [19/Nov/2024:21:26:46 +0000] "POST /job-offer-producer/job-offer/publish HTTP/1.1" 401 706
172.17.0.1 - - [19/Nov/2024:21:27:12 +0000] "GET /job-offer-producer/job-offer/publish HTTP/1.1" 401 706
172.17.0.1 - - [19/Nov/2024:21:27:23 +0000] "POST /job-offer-producer/job-offer/publish HTTP/1.1" 401 706
172.17.0.1 - - [19/Nov/2024:21:28:21 +0000] "POST /job-offer/publish HTTP/1.1" 404 685
172.17.0.1 - - [19/Nov/2024:21:29:57 +0000] "POST /job-offer-producer/job-offer/publish HTTP/1.1" 401 706
10.0.0.48 - - [19/Nov/2024:21:37:37 +0000] "POST /job-offer-producer/job-offer/publish HTTP/1.1" 401 706

When i run my container in local the same curl request works without any authentification, result in my local:

curl -X POST http://localhost:8098/job-offer-producer/job-offer/publish -H "Content-Type: application/json" -H "Access-Control-Allow-Origin: *" -d '{"name":"Software Backend Developer 2024","skills":"[\"JAVA\", \"Python\", \"SpringBoot\"]","description":"Design, develop, and maintain software applications using modern backend technologies.","email":"<PII removed by staff>","salary":812780.00}'

=> 39b96e79-d00f-4854-bc81-e141eb252b6b%

I even add the port 8098 to my firewall.

 

Link of my api to see the code

https://github.com/DjarallahBrahim/jobOffer-producer-ws/tree/main

Can you please help me with this ?

thank you

0 1 166
1 REPLY 1

Hi @djarallahbrahim, thanks for your question! This forum focuses on Apigee, Google Cloud’s API management solution. Your issue seems related to setting up a REST API in a Docker container on Google Compute Engine.

I recommend visiting this other forum for specific guidance. Let us know if you have any Apigee-related questions!