'AWS CodeArtifact behind nginx reverse proxy

Need some help on how to setup nginx as a proxy to AWS CodeArtifact. I have seen how ECR is being done with auto renewal token. I would like to know if anyone has successfully setup Nginx proxying to AWS CodeArtifact ? I don't need token auto renewal, i just want to know the nginx.conf configuration on how it is being setup.

I saw a python project that does this, but i'm more keen on doing it using nginx. Help is very much appreciated.

https://github.com/Polymathian/aws-codeartifact-python-proxy https://github.com/catalinpan/aws-ecr-proxy

The following is part of my nginx configuration. The redacted base64 authorization is aws:<codeartifact-token>

server {

    listen 443;
    listen [::]:443;
    server_name artifact.example.org;
    ssl on;
    ssl_certificate           /etc/nginx/ssl/default.crt;
    ssl_certificate_key       /etc/nginx/ssl/default.key;

    location /(.*) {
      set $upstream           https://<domain>-<accountid>.d.codeartifact.us-east-1.amazonaws.com/pypi/<repo-name>

      proxy_pass              $upstream/$1;
      proxy_redirect          $upstream https://$host;

      proxy_set_header        X-Real-IP            $remote_addr;
      proxy_set_header        X-Forwarded-For      $remote_addr;
      proxy_set_header        X-Forwarded-User     "Basic <redacted base64>"
      proxy_set_header        Authorization        "Basic <redacted base64>"
      proxy_pass_header       Server;
     
      client_max_body_size    0;
      proxy_connect_timeout   300s;
      proxy_read_timeout      300s;
      proxy_send_timeout      300s;
      send_timeout            300s;
    }
  }

pip.conf

[global]
timeout = 20
index-url = https://artifact.example.org
trusted-host = artifact.example.org

When i perform pip install my-package, i get the following error

172.17.0.1 - - [29/Mar/2022:01:58:59 +0000] "GET /my-package/ HTTP/1.1" 404 169 "-" "pip/21.1.1 {\x22ci\x22:null,\x22cpu\x22:\x22x86_64\x22,\x22distro\x22:{\x22name\x22:\x22macOS\x22,\x22version\x22:\x2212.2\x22},\x22implementation\x22:{\x22name\x22:\x22CPython\x22,\x22version\x22:\x223.8.12\x22},\x22installer\x22:{\x22name\x22:\x22pip\x22,\x22version\x22:\x2221.1.1\x22},\x22openssl_version\x22:\x22OpenSSL 1.1.1n  15 Mar 2022\x22,\x22python\x22:\x223.8.12\x22,\x22setuptools_version\x22:\x2256.0.0\x22,\x22system\x22:{\x22name\x22:\x22Darwin\x22,\x22release\x22:\x2221.3.0\x22}}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source