最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Google Engine instance HTTP 401 – Unauthorized when trying to test application with localhost - Stack Overflow

programmeradmin0浏览0评论

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 from my gcp vm:

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":"[email protected]","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":"[email protected]","salary":812780.00}'

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

Here is the output of docker ps from local machine:

CONTAINER ID   IMAGE                                        COMMAND                  CREATED          STATUS          PORTS                                                 NAMES
31a8ba030a98   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
3375321cc16e   bitnami/kafka:latest                         "/opt/bitnami/script…"   49 minutes ago   Up 49 minutes                                                         klt--tfpi

I even add the port 8098 to my firewall:

Link of my api to see the code

Tomcat config: .xml

Can you please help me with this ?

thank you

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 from my gcp vm:

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":"[email protected]","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":"[email protected]","salary":812780.00}'

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

Here is the output of docker ps from local machine:

CONTAINER ID   IMAGE                                        COMMAND                  CREATED          STATUS          PORTS                                                 NAMES
31a8ba030a98   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
3375321cc16e   bitnami/kafka:latest                         "/opt/bitnami/script…"   49 minutes ago   Up 49 minutes                                                         klt--tfpi

I even add the port 8098 to my firewall:

Link of my api to see the code

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

Tomcat config: https://github/DjarallahBrahim/jobOffer-producer-ws/blob/main/docker/config-files/tomcat/server.xml

Can you please help me with this ?

thank you

Share Improve this question edited Nov 20, 2024 at 9:34 Brahim Djarallah asked Nov 19, 2024 at 21:57 Brahim DjarallahBrahim Djarallah 1382 silver badges10 bronze badges 3
  • 1 Because you're using SSH to access the instance in order to invoke curl locally (on the VM), the Google Cloud firewall rules (beyond permitting 22 for SSH) are not relevant to your issue. It's challenging for others to diagnose even though your answer is comprehensive and you've included the repo. How confident are you that you're running the same container image locally and on the VM? The strongest evidence supporting this would be that both containers are using the same image digest. – DazWilkin Commented Nov 20, 2024 at 0:15
  • @DazWilkin thank you for your answer. I’m 100% sur that I use same image in vm (GCP) and on my local machine (with docker compose), I even checked my tomcat config and I did not find any problems (you can find it in my GitHub/docker/config-files)… any idea
发布评论

评论列表(0)

  1. 暂无评论