Giter Club home page Giter Club logo

ngx_aws_auth's Introduction

AWS proxy module

Build Status Gitter chat

This nginx module can proxy requests to authenticated S3 backends using Amazon's V4 authentication API. The first version of this module was written for the V2 authentication protocol and can be found in the AuthV2 branch.

License

This project uses the same license as ngnix does i.e. the 2 clause BSD / simplified BSD / FreeBSD license

Usage example

Implements proxying of authenticated requests to S3.

  server {
    listen     8000;

    aws_access_key your_aws_access_key; # Example AKIDEXAMPLE
    aws_key_scope scope_of_generated_signing_key; #Example 20150830/us-east-1/service/aws4_request
    aws_signing_key signing_key_generated_using_script; #Example L4vRLWAO92X5L3Sqk5QydUSdB0nC9+1wfqLMOKLbRp4=
    aws_s3_bucket your_s3_bucket;

    location / {
      aws_sign;
      proxy_pass http://your_s3_bucket.s3.amazonaws.com;
    }

    # This is an example that does not use the server root for the proxy root
    location /myfiles {

      rewrite /myfiles/(.*) /$1 break;
      proxy_pass http://your_s3_bucket.s3.amazonaws.com/$1;

      aws_access_key your_aws_access_key;
      aws_key_scope scope_of_generated_signing_key;
      aws_signing_key signing_key_generated_using_script;
    }

    # This is an example that use specific s3 endpoint, default endpoint is s3.amazonaws.com
    location /s3_beijing {

      rewrite /s3_beijing/(.*) /$1 break;
      proxy_pass http://your_s3_bucket.s3.cn-north-1.amazonaws.com.cn/$1;

      aws_sign;
      aws_endpoint "s3.cn-north-1.amazonaws.com.cn";
      aws_access_key your_aws_access_key;
      aws_key_scope scope_of_generated_signing_key;
      aws_signing_key signing_key_generated_using_script;
    }
  }

Security considerations

The V4 protocol does not need access to the actual secret keys that one obtains from the IAM service. The correct way to use the IAM key is to actually generate a scoped signing key and use this signing key to access S3. This nginx module requires the signing key and not the actual secret key. It is an insecure practise to let the secret key reside on your nginx server.

Note that signing keys have a validity of just one week. Hence, they need to be refreshed constantly. Please useyour favourite configuration management system such as saltstack, puppet, chef, etc. etc. to distribute the signing keys to your nginx clusters. Do not forget to HUP the server after placing the new signing key as nginx reads the configuration only at startup time.

A standalone python script has been provided to generate the signing key

./generate_signing_key -h
usage: generate_signing_key [-h] -k SECRET_KEY -r REGION [-s SERVICE]
                            [-d DATE] [--no-base64] [-v]

Generate AWS S3 signing key in it's base64 encoded form

optional arguments:
  -h, --help            show this help message and exit
  -k SECRET_KEY, --secret-key SECRET_KEY
                        The secret key generated using AWS IAM. Do not confuse
                        this with the access key id
  -r REGION, --region REGION
                        The AWS region where this key would be used. Example:
                        us-east-1
  -s SERVICE, --service SERVICE
                        The AWS service for which this key would be used.
                        Example: s3
  -d DATE, --date DATE  The date on which this key is generated in yyyymmdd
                        format
  --no-base64           Disable output as a base64 encoded string. This NOT
                        recommended
  -v, --verbose         Produce verbose output on stderr


./generate_signing_key -k wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY -r us-east-1
L4vRLWAO92X5L3Sqk5QydUSdB0nC9+1wfqLMOKLbRp4=
20160902/us-east-1/s3/aws4_request

Supported environments

This plugin is tested against a variety of nginx versions, compilers, OS versions and hardware architectures. Take a look at the .travis.yml file or the latest travis build status to see the versions that the plugin has been tested against

Known limitations

The 2.x version of the module currently only has support for GET and HEAD calls. This is because signing request body is complex and has not yet been implemented.

Credits

Original idea based on http://nginx.org/pipermail/nginx/2010-February/018583.html and suggestion of moving to variables rather than patching the proxy module.

Subsequent contributions can be found in the commit logs of the project.

ngx_aws_auth's People

Contributors

andrea-spoldi avatar anomalizer avatar aosaginohi avatar asottile avatar billatq avatar dbezemer avatar doubleshot avatar gauravko avatar grzegorzlyczba avatar hasnat avatar ichaozai avatar npahucki avatar roylee17 avatar tarfik avatar vickybiswas avatar wk8 avatar yteraoka avatar zkolb-cldr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ngx_aws_auth's Issues

Couldn't signin buckets with name included double dash.

When i try to use buckets with name included double dash, i am getting 403 forbidden.
e.g.: my-test-bucket getting 403 but my-testbucket works well with same configuration.
I am sure about given access to buckets for my secret.

my configuration like this;

aws_access_key *****;
aws_key_scope ****;
aws_signing_key ****;
aws_s3_bucket my-test-bucket;

location ~ ^/images {
	aws_sign;
	proxy_pass http://my-test-bucket.s3.amazonaws.com;
}

Is there a restriction for bucket naming or is this a bug ?

SignatureDoesNotMatch on filename with space

Receiving a SignatureDoesNotMatch when proxy_pass to a file with a space. Seems like it is signing the canonical decoded uri instead of the encoded request uri. Log file shows:


2016-11-01T14:13:38.19+0000 [App/1] ERR 2016/11/01 14:13:38 [error] 60#0: *8 canonical url extracted is /images/global standalone2.gif, client: 127.0.0.1, server: localhost, request: "GET /images/global%20standalone2.gif HTTP/1.0", host: "127.0.0.1:8000"
2016-11-01T14:13:38.19+0000 [App/1] ERR 2016/11/01 14:13:38 [error] 60#0: *8 canonical req is GET
2016-11-01T14:13:38.19+0000 [App/1] ERR /images/global standalone2.gif
2016-11-01T14:13:38.19+0000 [App/1] ERR host:cg-0127f0fb-962c-496e-a286-67cd2a75760f.s3.amazonaws.com
2016-11-01T14:13:38.19+0000 [App/1] ERR x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
2016-11-01T14:13:38.19+0000 [App/1] ERR x-amz-date:20161101T141338Z
2016-11-01T14:13:38.19+0000 [App/1] ERR host;x-amz-content-sha256;x-amz-date
2016-11-01T14:13:38.19+0000 [App/1] ERR e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855, client: 127.0.0.1, server: localhost, request: "GET /images/global%20standalone2.gif HTTP/1.0", host: "127.0.0.1:8000"


AWS error contains:


&tlCanonicalRequest&gtGET
/images/global%20standalone2.gif

host:cg-0127f0fb-962c-496e-a286-67cd2a75760f.s3.amazonaws.com
x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
x-amz-date:20161101T141338Z

host;x-amz-content-sha256;x-amz-date
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855&lt/CanonicalRequest&gt


Causes a seg fault if an init_worker_by_lua block is present

If any init_worker_by_lua block is present at all in my config, my worker processes core dump immediately. Below is the gdb trace of my core dump, version of resty and an example of the code triggering the problem. I have not been able to reproduce this problem in any other *_by_lua block.

dockerd[1968]: 2017/11/12 23:08:10 [alert] 1#1: worker process 29 exited on signal 11 (core dumped)

init_worker_by_lua '
  local function hi(premature)
    ngx.log(ngx.ERR, "hi")
  end   ngx.timer.at(0, hi)
';

/usr/local/openresty/bin/openresty -V
nginx version: openresty/1.11.2.5
built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5)
built with OpenSSL 1.0.2k  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.0 --add-module=../echo-nginx-module-0.61 --add-module=../xss-nginx-module-0.05 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.31 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.06 --add-module=../srcache-nginx-module-0.31--add-module=../ngx_lua-0.10.10 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.32 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.18 --add-module=../redis2-nginx-module-0.14 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.14 --add-module=../rds-csv-nginx-module-0.07 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --with-openssl=/tmp/openssl-1.0.2k --with-pcre=/tmp/pcre-8.40 --add-module=/tmp/openresty-1.11.2.5/ngx_aws_auth --with-file-aio --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_xslt_module=dynamic --with-ipv6 --with-mail --with-mail_ssl_module --with-md5-asm --with-pcre-jit --with-sha1-asm --with-stream --with-stream_ssl_module --with-threads

dockerd[1968]: 2017/11/12 23:08:10 [alert] 1#1: worker process 29 exited on signal 11 (core dumped)

GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/local/openresty/bin/openresty...done.


warning: core file may not match specified executable file.
[New LWP 78]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `nginx: master process /usr/local/openresty/bin/openresty -c /ngin'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  ngx_http_add_variable (cf=cf@entry=0x7ffe5328a9a0,
    name=name@entry=0x9ec160 <ngx_http_aws_auth_vars>, flags=1)
    at src/http/ngx_http_variables.c:387
387 src/http/ngx_http_variables.c: No such file or directory.
(gdb)

Signing key validity in README is overestimated

In https://github.com/anomalizer/ngx_aws_auth#security-considerations

Note that signing keys have a validity of just one week.

In my experience, they are valid for the date of signing key generation only, as they are date specific.

If you attempt to use a signing key generated on the day before, you will get a 400 Bad Request from S3 due to:

<Error><Code>AuthorizationHeaderMalformed</Code><Message>The authorization header is malformed; Invalid credential date. Date is not the same as X-Amz-Date.</Message>...

Verified over 2 days, in a container with a UTC timezone. Making requests against nginx right after midnight UTC fail, re-running generate_signing_key (well, my ported variant of it, identical in nature with test coverage) and reloading nginx allows successful requests to occur again.

Should the README be adjusted...?

Minio compatibility

Hi,
I use Minio (min.io) for my object storage which has AWS compatible API.
Is it possible to use this mobile with Minio ?
Thanks

Possible Error in Readme Examples

Hi there!! Thank you for writing this module, it has really saved me a ton of time!!

I just wanted to point out a possible issue with two of the examples in the README.

I'm no expert with Nginx, but it appears that the proxy_pass directive for the non-root locations is incorrect.

Instead of...

proxy_pass http://your_s3_bucket.s3.amazonaws.com/$1;

I believe the path specification is not needed.

I based this on the following Nginx documentation.

http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass_header

When the URI is changed inside a proxied location using the rewrite directive, and this same configuration will be used to process a request (break):

location /name/ {
    rewrite    /name/([^/]+) /users?name=$1 break;
    proxy_pass http://127.0.0.1;
}

In this case, the URI specified in the directive is ignored and the full changed request URI is passed to the server.

So your example only requires the server name.

proxy_pass http://your_s3_bucket.s3.amazonaws.com;

I believe there is also another example with the same issue.

My Nginx knowledge is pretty noobish so this could be something I've overlooked. But, if there is an issue, I will gladly create a PR to update the README docs... I love doing all the heavy-lifting ya know ๐Ÿ’ช ๐Ÿ˜‰

Oh, and I'm talking about the AuthV2 examples, which may be the issue... Not sure if these are being maintained still.

With nginx -t command error

After the module installation:
With nginx -t command prompt
[Emerg] SSL_CTX_new () failed (SSL: error: 140A90A1: SSL routines: SSL_CTX_new: library has no ciphers)

Documentation

Can we get some documentation on how to build this and use it?

Non-subresource query params generate SignatureDoesNotMatch errors

We're using this to serve a small JS webapp from S3. Its Javascript code uses a few query parameters, but when we append those to our requests, it results in SignatureDoesNotMatch errors.

An example query param that it has failed on is foo.html?polling-location. A request to just foo.html succeeds.

This is with the latest master HEAD code of this module running in nginx 1.9.3.

Let me know if you need more info to reproduce or diagnose.

Need more info on how to use this

Hi, I am having trouble getting this to work.

My proxy_pass works correctly if my s3 files are marked as public (grant Everybody read) and I set the Authorization header to "".

When I set it to $s3_auth_token to access the ones that are not public, I get the following response from s3:

SignatureDoesNotMatch The request signature we calculated does not match the signature you provided. Check your key and signing method. < /Message> 47 45 54 0a 0a 0a 0a 78 2d 61 6d 7a 2d 64 61 74 65 3a 46 72 69 2c 20 31 31 20 46 65 62 20 32 30 31 31 20 30 32 3a 35 35 3a 33 30 20 47 4d 54 0a 2f 61 76 61 6e 74 76 69 64 65 6f 2f 50 49 43 54 30 30 30 32 5f 74 68 75 6d 62 2e 6a 70 67 C25896F6962FDBBB kYC4uobCU4qqUp1Q3TQ7UyhFMK8t4bBCdXpUpJhWuxa1SX/OgFse+/LHlo7uGr2t rIdXUJystqzERO1FbGjsS4t20Y8= GET x-amz-date:Fri, 11 Feb 2011 02:55:30 GMT /avantvideo/PICT0002_thumb.jpg AKIAJW4F7BXSTS5RCQLQ

My setup is the following:

    aws_access_key ***********;
    aws_secret_key ************************;
    s3_bucket avantvideo;

    proxy_set_header Authorization $s3_auth_token;
    proxy_set_header x-amz-date $aws_date;
    proxy_pass $download_url;

where download_url is something like: https://s3.amazonaws.com/avantvideo/PICT0002_thumb.jpg

I replaced my access keys with ****.

What permissions should I set in my files? What else could be wrong?

Thanks.
Daniel.

other services than s3

Why is this project is limited to S3. It'll be nice if it'll be configurable also for other services such as ElasticSearch

enabled variable is not merged in location configuration

I configured 'aws_sign' in my server block and I'm getting a 403 error since the ngx_http_aws_proxy_sign function is returning NGX_DECLINED since conf->enabled is 0.

When I move the 'aws_sign' configuration to the location block, the request is being sent sucessfully.

Upon further debugging, I found that the enabled variable from server block is not being merged to the location configuration.

The directive declaration has 'NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF'.
Can anyone help me understand why the ngx_http_aws_auth_merge_loc_conf() function is not merging conf->enabled ?

Compability problem with ngx_aws_auth and nginx-vod-module

Hi

Here's some background about our situation: We're running a VOD streaming service. We've been successfully using the ngx_aws_auth module (https://github.com/anomalizer/ngx_aws_auth/) to authenticate proxy_passed requests to S3 API end points with parts of our video platform.

Now, we decided to try using Nginx and the Kaltura nginx-vod-module (https://github.com/kaltura/nginx-vod-module) as our streamers. The idea was to proxy_pass the S3 requests like we've been doing. Note that we're not using the S3 "static website hosting" feature, but instead the S3 API end points. This is so that we can use signed requests for authentication(which is what ngx_aws_auth is for).

After installing both modules, we quickly discovered that we're getting nothing but 403s from S3. Further digging revealed that the AWS signature headers were missing from the requests sent to S3, even though the Nginx configuration had the "aws_sign" command in the appropriate location.

After debugging for a while, we found the problem at ngx_aws_auth/ngx_http_aws_auth.c:150 . The line in question calls "ngx_http_get_module_loc_conf", which, according to documentation, "..gets the moduleโ€™s http location block configuration object from the request object". The returned conf object is then checked with "if(!conf->enabled) {". For requests that have been processed by the nginx-vod-module, this check returns true. In other words:

When a request has been processed with "vod hls;", the conf object returned for the request doesn't have the "module enabled" flag set for ngx_aws_auth. Since that's the case, ngx_aws_auth thinks it's not enabled, and won't sign the request.

Now I don't know anything about how Nginx modules work, so I don't know if this is a bug in ngx_aws_auth or nginx-vod-module. As such, this bug report has been added to both projects' issue queues. Please let me know your thoughts about which module is the cause of the problem, so we can continue the discussion in the appropriate ticket.

Relevant parts of the Nginx configuration follow. The "test" location is to confirm that the authentication works without nginx-vod-module.

server {
  listen     80;

  vod_mode remote;
  vod_upstream_location /s3;

  location /s3/ {
    aws_access_key "REDACTED";
    aws_key_scope "20171005/eu-west-1/s3/aws4_request";
    aws_signing_key "REDACTED";
    aws_s3_bucket my-example-video-bucket;
    aws_sign;

    rewrite ^/s3/hls/(.*) /$1 break;
    
    proxy_pass http://my-example-video-bucket.s3.amazonaws.com;    
  }

  location /hls/ {
    vod hls;
  }

  location /test/ {
    aws_sign;
    rewrite ^/test/(.*) /$1 break;
    proxy_pass http://my-example-video-bucket.s3.amazonaws.com;
  }
}

nginx worker process getting killed when request has query string parameters

Nginx worker process is getting killed, on every request with query string parameters

request: "GET /s3proxy/test.html?dc=apples HTTP/1.1"
[error] 332#332: *15 canonical qs constructed is dc=apples

*15 canonical req is GET
/s3proxy/test.html
dc=apples

Error backtrace:
[alert] 326#326: worker process 331 exited on signal 11 (core dumped)

*** glibc detected *** nginx: worker process: corrupted double-linked list: 0x0000560500c0e790 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x75e5e)[0x7fcadad5ce5e]
/lib64/libc.so.6(+0x7a614)[0x7fcadad61614]
/lib64/libc.so.6(__libc_malloc+0x5c)[0x7fcadad61b1c]
/usr/lib64/libcrypto.so.10(CRYPTO_malloc+0x5e)[0x7fcadb2fbcee]
/usr/lib64/libcrypto.so.10(sk_new+0x3d)[0x7fcadb37704d]
/usr/lib64/libcrypto.so.10(+0x103b00)[0x7fcadb394b00]
/usr/lib64/libcrypto.so.10(+0x1084ce)[0x7fcadb3994ce]
/usr/lib64/libcrypto.so.10(+0x1083fa)[0x7fcadb3993fa]
/usr/lib64/libcrypto.so.10(+0x1083fa)[0x7fcadb3993fa]
/usr/lib64/libcrypto.so.10(ASN1_item_ex_d2i+0xc37)[0x7fcadb39c5a7]
/usr/lib64/libcrypto.so.10(ASN1_item_d2i+0x44)[0x7fcadb39cc64]
/usr/lib64/libssl.so.10(ssl3_get_server_certificate+0x251)[0x7fcadb69b621]
/usr/lib64/libssl.so.10(ssl3_connect+0x892)[0x7fcadb69dd62]
nginx: worker process(ngx_ssl_handshake+0x1f)[0x5604ff06f95f]
nginx: worker process(+0x59b32)[0x5604ff06fb32]
nginx: worker process(+0x548d3)[0x5604ff06a8d3]
nginx: worker process(ngx_process_events_and_timers+0x7f)[0x5604ff06033f]
nginx: worker process(+0x525d0)[0x5604ff0685d0]
nginx: worker process(ngx_spawn_process+0x195)[0x5604ff0667e5]
nginx: worker process(ngx_master_process_cycle+0x804)[0x5604ff0692b4]
nginx: worker process(main+0xb4a)[0x5604ff04172a]
/lib64/libc.so.6(__libc_start_main+0x100)[0x7fcadad05d20]
nginx: worker process(+0x29769)[0x5604ff03f769]

nginx version: nginx/1.15.7
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled

OS: centos6

AuthV2 - signed key cached

Hello,

Please check this log file https://paste.ubuntu.com/p/J23S8jgtWP/, then search for string "3RXW5M4E5GEZAS34UC6E"

The module use the same signed key for different paths: bcn_720p.mp4 and bcn_1080p.mp4

curl http://api.dev.xxxx.com:8001/hls/bcn_,1080p,1080p,1080p,.mp4.urlset/master.m3u8 -I 2>/dev/null | grep HTTP
HTTP/1.1 200 OK
d4jk4@Konoha ~
curl http://api.dev.xxxx.com:8001/hls/bcn_,360p,720p,1080p,.mp4.urlset/master.m3u8 -I 2>/dev/null | grep HTTP
HTTP/1.1 502 Bad Gateway

Can you check this case?

Thanks,

Is there a way to abstract `index.html`

Hello,
I use this package to serve my S3 buckets as an https server, however, I cannot abstract the index.html

I cannot use the https S3 feature direclty because I need it to be served behing a VPN, which is not possible through s3 direclty.

Is their a way to abstract the index.html in the url as it wil always be called ?

For example let's way my url is
https://behind_vpn.com/index.html
I would like to do
https://behind_vpn.com who will access to index.html without having to add it on the url.
Thanks

โ€˜SHA256_Initโ€™ is deprecated, can't compile on ubuntu 22.04, nginx 1.19.7

compile error

cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -O3  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules \
        -o objs/addon/ngx_aws_auth-2.1.1/crypto_helper_openssl.o \
        ../ngx_aws_auth-2.1.1/crypto_helper_openssl.c
../ngx_aws_auth-2.1.1/crypto_helper_openssl.c: In function โ€˜ngx_aws_auth__hash_sha256โ€™:
../ngx_aws_auth-2.1.1/crypto_helper_openssl.c:43:5: error: โ€˜SHA256_Initโ€™ is deprecated: Since OpenSSL 3.0 [-Werror=deprecated-declarations]
   43 |     SHA256_Init(&sha256);
      |     ^~~~~~~~~~~
In file included from ../ngx_aws_auth-2.1.1/crypto_helper_openssl.c:14:
/usr/include/openssl/sha.h:73:27: note: declared here
   73 | OSSL_DEPRECATEDIN_3_0 int SHA256_Init(SHA256_CTX *c);
      |                           ^~~~~~~~~~~
../ngx_aws_auth-2.1.1/crypto_helper_openssl.c:44:5: error: โ€˜SHA256_Updateโ€™ is deprecated: Since OpenSSL 3.0 [-Werror=deprecated-declarations]
   44 |     SHA256_Update(&sha256, blob->data, blob->len);
      |     ^~~~~~~~~~~~~
In file included from ../ngx_aws_auth-2.1.1/crypto_helper_openssl.c:14:
/usr/include/openssl/sha.h:74:27: note: declared here
   74 | OSSL_DEPRECATEDIN_3_0 int SHA256_Update(SHA256_CTX *c,
      |                           ^~~~~~~~~~~~~
../ngx_aws_auth-2.1.1/crypto_helper_openssl.c:45:5: error: โ€˜SHA256_Finalโ€™ is deprecated: Since OpenSSL 3.0 [-Werror=deprecated-declarations]
   45 |     SHA256_Final(hash, &sha256);
      |     ^~~~~~~~~~~~
In file included from ../ngx_aws_auth-2.1.1/crypto_helper_openssl.c:14:
/usr/include/openssl/sha.h:76:27: note: declared here
   76 | OSSL_DEPRECATEDIN_3_0 int SHA256_Final(unsigned char *md, SHA256_CTX *c);
      |                           ^~~~~~~~~~~~
cc1: all warnings being treated as errors

Any Ideas how to get around this?

SignatureDoesNotMatch

Hello,

I am facing SignatureDoesNotMatch error although I have followed same configurations suggested in this plugin manual.

nginx.conf

server {
listen 80;
aws_access_key XXXX;
aws_key_scope 20181116/us-east-1/s3/aws4_request;
aws_signing_key XXXX;
aws_s3_bucket example-nginx;

location / {
aws_sign;
proxy_pass http://example-nginx.s3.amazonaws.com;
}
}

Please advise if I am making anything wrong.

PS: I am using aws secret key for signing key generation and aws access key for aws_access_key

Regards,
Karthik

The plugin support china region?

server {
listen 8000;
aws_access_key ***************;
aws_key_scope 20170920/cn-north-1/s3/aws4_request;
aws_signing_key WFsSMzFYjgpJowdl+x5lMGHE6dcqAguAk+VxB0ATGx8=;
aws_s3_bucket *********;

   location / {
      aws_sign;
      proxy_pass http://s3.cn-north-1.amazonaws.com.cn;
   }
}

I set my nginx like this.But like this

UnauthorizedAccessYou are not authorized to perform this operationCDBF7F9E48FA6F90GlqLofDFEbC66G99POZqUJbNTefhW87REIh009owtp1vVQAoRE11xltzW1wFqRWMt56S5mZiyOQ=

SignatureDoesNotMatch

following your example to the letter and providing my key, secret, and bucket information i get the following error

The request signature we calculated does not match the signature you provided. Check your key and signing method.

any ideas?

It's not compatible with S3 Beijing region because endpoint is hardcoding.

The endpoint of Beijing S3 endpoint is s3.cn-north-1.amazonaws.com.cn.
However, s3.amazonaws.com is hardcoding and affects the canonical headers:

header_ptr = ngx_array_push(settable_header_array);
header_ptr->key = HOST_HEADER;
header_ptr->value.len = s3_bucket->len + 40;
header_ptr->value.data = ngx_palloc(pool, header_ptr->value.len);
header_ptr->value.len = ngx_snprintf(header_ptr->value.data, header_ptr->value.len, "%V.s3.amazonaws.com", s3_bucket) - header_ptr->value.data;

It will never compute the correct signature for Beijing S3 region.
Make endpoint configurable can help to solve this problem.

SignatureDoesNotMatch for encoded URI with special character '+'

Details

Good day.

Noticing the SignatureDoesNotMatch issue when accessing a S3 key with special character '+' in it. Able to repro the issue consistently. S3 keys that do not have '+' special character work fine.

Steps to Repro:

  • Build nginx from source with ngx_aws_auth module.
  • update nginx.conf with ngx_aws_auth configuration.
  • create s3 files named: libstdc++-docs.x86_64.rpm
  • Accessing above s3 file results in error below:
<Code>SignatureDoesNotMatch</Code>
<Message>
The request signature we calculated does not match the signature you provided. Check your key and signing method.
</Message>
...
<CanonicalRequest>
GET /libstdc%20%20-docs.x86_64.rpm host:XXXXX-test-bucket01.s3.amazonaws.com x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 x-amz-date:20231004T172751Z host;x-amz-content-sha256;x-amz-date e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
</CanonicalRequest>

nginx.conf

server {
        listen       8082;
        server_name  localhost;

        aws_access_key XXXXXXXXX; # Example AKIDEXAMPLE
        aws_key_scope 20231004/us-west-2/s3/aws4_request; #Example 20150830/us-east-1/service/aws4_request
        aws_signing_key XXXXXXXXXXXXXXXXXXX; 
        aws_s3_bucket XXXXXXXX-test-bucket01;

        location / {
            root   html;
            index  index.html index.htm;
            aws_sign;
            proxy_pass http://XXXXXXXX-test-bucket01.s3.amazonaws.com;
        }

Versions

$ sudo /usr/local/nginx-from-src/nginx -V
nginx version: nginx/1.24.0
built by gcc 7.3.1 20180712 (Red Hat 7.3.1-17) (GCC)
built with OpenSSL 1.1.1v  1 Aug 2023
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx-from-src --sbin-path=/usr/local/nginx-from-src/nginx --conf-path=/usr/local/nginx-from-src/nginx.conf --pid-path=/usr/local/nginx-from-src/nginx.pid --with-pcre=../pcre2-10.40 --with-zlib=../zlib-1.3 --with-http_ssl_module --with-stream --with-mail=dynamic --add-module=../ngx_aws_auth --with-debug

Nginx Logs

# Request
2023/10/04 17:27:51 [error] 30944#0: *1 canonical url extracted before URI encoding is /libstdc++-docs.x86_64.rpm, c
lient: 10.187.171.30, server: localhost, request: "GET /libstdc++-docs.x86_64.rpm HTTP/1.1", host: "172.19.24.58:808
2"
2023/10/04 17:27:51 [error] 30944#0: *1 canonical url extracted after URI encoding is /libstdc%2B%2B-docs.x86_64.rpm
, client: 10.187.171.30, server: localhost, request: "GET /libstdc++-docs.x86_64.rpm HTTP/1.1", host: "172.19.24.58:
8082"
2023/10/04 17:27:51 [debug] 30944#0: *1 malloc: 0000000000FA8160:10000
2023/10/04 17:27:51 [error] 30944#0: *1 canonical req is GET
/libstdc%2B%2B-docs.x86_64.rpm

host:XXXXXXX-test-bucket01.s3.amazonaws.com
x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
x-amz-date:20231004T172751Z

host;x-amz-content-sha256;x-amz-date
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855, client: 10.187.171.30, server: localhost, request:
 "GET /libstdc++-docs.x86_64.rpm HTTP/1.1", host: "172.19.24.58:8082"
 2023/10/04 17:27:51 [debug] 30944#0: *1 posix_memalign: 0000000000FAA880:4096 @16
2023/10/04 17:27:51 [debug] 30944#0: *1 header name host, value XXXXXXX-test-bucket01.s3.amazonaws.com4<9F>
2023/10/04 17:27:51 [debug] 30944#0: *1 header name x-amz-content-sha256, value e3b0c44298fc1c149afbf4c8996fb92427ae
41e4649b934ca495991b7852b855
2023/10/04 17:27:51 [debug] 30944#0: *1 header name x-amz-date, value 20231004T172751Z
2023/10/04 17:27:51 [debug] 30944#0: *1 header name authorization, value AWS4-HMAC-SHA256 Credential=AKIAXCGE7VOLQ7W
JG4Z6/20231004/us-west-2/s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date,Signature=73286ab0026b5f
17749ba6720f748a069085380883bb077571996265838d8fa42a8a9b8dfd65cf2^D

2023/10/04 17:27:51 [debug] 30944#0: *1 http proxy header: "authorization: AWS4-HMAC-SHA256 Credential=AKIAXCGE7VOLQ
7WJG4Z6/20231004/us-west-2/s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date,Signature=73286ab0026b
5f17749ba6720f748a069085380883bb077571996265838d8fa4"
2023/10/04 17:27:51 [debug] 30944#0: *1 http proxy header:
"GET /libstdc++-docs.x86_64.rpm HTTP/1.0
Host: XXXXXXX.s3.amazonaws.com
Connection: close
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/115.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Upgrade-Insecure-Requests: 1
x-amz-content-sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
x-amz-date: 20231004T172751Z
authorization: AWS4-HMAC-SHA256 Credential=AKIAXCGE7VOLQ7WJG4Z6/20231004/us-west-2/s3/aws4_request,SignedHeaders=hos
t;x-amz-content-sha256;x-amz-date,Signature=73286ab0026b5f17749ba6720f748a069085380883bb077571996265838d8fa4

"
# Response

2023/10/04 17:27:51 [debug] 30944#0: *1 http upstream request: "/libstdc++-docs.x86_64.rpm?"
2023/10/04 17:27:51 [debug] 30944#0: *1 http upstream process header
2023/10/04 17:27:51 [debug] 30944#0: *1 malloc: 0000000001003A90:4096
2023/10/04 17:27:51 [debug] 30944#0: *1 recv: eof:0, avail:-1
2023/10/04 17:27:51 [debug] 30944#0: *1 recv: fd:10 257 of 4096
2023/10/04 17:27:51 [debug] 30944#0: *1 http proxy status 403 "403 Forbidden"
2023/10/04 17:27:51 [debug] 30944#0: *1 http proxy header: "x-amz-request-id: N8BNZZ83W06NCYW8"
2023/10/04 17:27:51 [debug] 30944#0: *1 http proxy header: "x-amz-id-2: iuwOkkVNCq7wrW/xUBGtJTa644jGBG5uba1QDi1Nz343
7jbXFiKIfvjQXzSvbf0YSOE0GSEq808="
2023/10/04 17:27:51 [debug] 30944#0: *1 http proxy header: "Content-Type: application/xml"
2023/10/04 17:27:51 [debug] 30944#0: *1 http proxy header: "Date: Wed, 04 Oct 2023 17:27:51 GMT"
2023/10/04 17:27:51 [debug] 30944#0: *1 http proxy header: "Server: AmazonS3"
2023/10/04 17:27:51 [debug] 30944#0: *1 posix_memalign: 0000000001004AA0:4096 @16
2023/10/04 17:27:51 [debug] 30944#0: *1 http proxy header: "Connection: close"
2023/10/04 17:27:51 [debug] 30944#0: *1 http proxy header done
2023/10/04 17:27:51 [debug] 30944#0: *1 HTTP/1.1 403 Forbidden
Server: nginx/1.24.0
Date: Wed, 04 Oct 2023 17:27:51 GMT
Content-Type: application/xml
Transfer-Encoding: chunked
Connection: keep-alive
x-amz-request-id: N8BNZZ83W06NCYW8
x-amz-id-2: iuwOkkVNCq7wrW/xUBGtJTa644jGBG5uba1QDi1Nz3437jbXFiKIfvjQXzSvbf0YSOE0GSEq808=

Help much appreciated. Thanks in advance.

create release for 2.0.0

Hi, I see that you have incremented the version 2.0.0 with the latest auth_v4 rewrite, but there is no release created. Can you please create one? Thanks

Something is wrong with dynamic module compilation

When trying to build with --add-module everything builds fine and I can see in logs:

configuring additional modules
adding module in /usr/src/nginx-modules/ngx_aws_auth-2.1.1

But when I am building with --with-compat --add-dynamic-module building fails with:

make[1]: Entering directory '/usr/src/nginx/nginx-1.17.9'
cc -c -fPIC -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules \
	-o objs/addon/ngx_aws_auth-2.1.1/ngx_http_aws_auth.o \
	/usr/src/nginx-modules/ngx_aws_auth-2.1.1/ngx_http_aws_auth.c
cc -c -fPIC -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules \
	-o objs/addon/ngx_aws_auth-2.1.1/crypto_helper_openssl.o \
	/usr/src/nginx-modules/ngx_aws_auth-2.1.1/crypto_helper_openssl.c
In file included from src/os/unix/ngx_process.h:12,
                 from src/core/ngx_core.h:55,
                 from /usr/src/nginx-modules/ngx_aws_auth-2.1.1/crypto_helper.h:5,
                 from /usr/src/nginx-modules/ngx_aws_auth-2.1.1/crypto_helper_openssl.c:16:
src/os/unix/ngx_setaffinity.h:16:9: error: unknown type name 'cpu_set_t'
 typedef cpu_set_t  ngx_cpuset_t;

The best way to install this module into nginx?

Hi, can someone provide some insight regarding how to load this module into NGINX? I do some search and find two ways:
(1) Build a customized NGINX with source code from scratch: https://github.com/ajdruff/nginx-naxsi-rpm/blob/master/how-to-build-your-own-nginx-rpm.md
(2) Install NGINX directly "yum install nginx", then load this module into nginx in the runtime
like "./configure --with-compat --add-dynamic-module=../ngx_aws_auth"
https://www.nginx.com/blog/compiling-dynamic-modules-nginx-plus/

Can anyone provide some insight regarding the pros and cons of these two? Thanks

Support for Roles

Hi

I'd like to make a feature request for this product (assuming it isn't already possible and I'm just missing something). I'm running nginx with ngx_aws_auth on an EC2 instance running under an IAM Role which has the correct permissions to access the S3 bucket I'm interested in.

Would it be possible to include an option to sign requests based on the credentials of the Role under which the EC2 instance is running under?

Thanks
Andy

Unexpected debug output?

Hello,

I recently built this using the nginx docker image, and when testing a proxy to my S3 bucket, it appears to work, but includes some extra output. Not sure what's happening here, but here's my curl example:

# curl -s http://127.0.0.1:8000/foo/version.json
2017/11/21 21:47:04 [error] 13287#13287: *7 canonical url extracted before URI encoding is /foo/version.json, client: 127.0.0.1, server: , request: "GET /foo/version.json HTTP/1.1", host: "127.0.0.1:8000"
2017/11/21 21:47:04 [error] 13287#13287: *7 canonical url extracted after URI encoding is /foo/version.json, client: 127.0.0.1, server: , request: "GET /foo/version.json HTTP/1.1", host: "127.0.0.1:8000"
2017/11/21 21:47:04 [error] 13287#13287: *7 canonical req is GET
/foo/version.json

host:<my_redacted_bucket>.s3.amazonaws.com
x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
x-amz-date:20171121T214704Z

host;x-amz-content-sha256;x-amz-date
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855, client: 127.0.0.1, server: , request: "GET /foo/version.json HTTP/1.1", host: "127.0.0.1:8000"
127.0.0.1 - - [21/Nov/2017:21:47:04 +0000] "GET /foo/version.json HTTP/1.1" 200 26 "-" "curl/7.52.1" "-"
{"version":"1.0-bea7e8b"}

Expected:

# curl -s http://127.0.0.1:8000/foo/version.json
{"version":"1.0-bea7e8b"}

I built from master @ f1bcf3b on nginx 1.13.7 on debian (nginx docker image).

Signature Error when not using server's root location

Hi,

I don't understand why I always get "SignatureDoesNotMatch" error from aws when trying to get object with specified location for example:

   location /storage {
        s3_bucket my_bucket;
        chop_prefix /storage;
        proxy_pass http://my_bucket.s3.amazonaws.com;

        aws_access_key my_access_key;
        aws_secret_key my_secret_key;

        proxy_set_header Authorization $s3_auth_token;
        proxy_set_header x-amz-date $aws_date;
    }

If I use / location and comment out the chop_prefix variable it's working good.
Can you help here?

Module breaks core nginx functionality

Compiling nginx with latest ngx_aws_auth module breaks core nginx functionality.

Given test vhost below (example straight from nginx documentation), expectation is that nginx will
respond with authorization request. With module compiled in, access is allowed unconditionally.

Tests with module version 1.1.1 work as expected. Examples below use module from master branch.

Test vhost

server {
        listen *:80;
        server_name example.com;

        root /var/www/;

        location / {
                satisfy any;

                allow 1.2.3.4;
                deny all;

                auth_basic "Zone";
                auth_basic_user_file /var/www/.htpasswd;
        }
}

nginx 1.10.3 without ngx_aws_auth

Nginx version

# ./nginx-1.10.3 -V
nginx version: nginx/1.10.3
built by gcc 4.9.2 (Debian 4.9.2-10) 
configure arguments:

Example request

# curl -ILH "Host: example.com" localhost
HTTP/1.1 401 Unauthorized
Server: nginx/1.10.3
Date: Thu, 02 Feb 2017 10:09:31 GMT
Content-Type: text/html
Content-Length: 195
Connection: keep-alive
WWW-Authenticate: Basic realm="Zone"

nginx 1.10.3 with ngx_aws_auth

Nginx version

# ./nginx-1.10.3-aws -V
nginx version: nginx/1.10.3
built by gcc 4.9.2 (Debian 4.9.2-10) 
configure arguments: --add-module=../ngx_aws_auth/

Example request

# curl -ILH "Host: example.com" localhost
HTTP/1.1 200 OK
Server: nginx/1.10.3
Date: Thu, 02 Feb 2017 10:10:53 GMT
Content-Type: text/html
Content-Length: 0
Last-Modified: Thu, 02 Feb 2017 09:29:56 GMT
Connection: keep-alive
ETag: "5892fc14-0"
Accept-Ranges: bytes

The request signature we calculated does not match the signature you provided

I am have a problem using this module. My config is:

worker_processes 1;

events {
  worker_connections 1024;
}

http {
  server {
    listen 80;
    client_max_body_size 100G;
    aws_access_key 'xxx';
    aws_signing_key 'yyy';
    aws_key_scope '20190130/eu-west-1/s3/aws4_request';
    aws_s3_bucket 'bucket_name';

    location /s3 {
      rewrite /s3/(.*) /$1 break;
      resolver 8.8.8.8 valid=300s;
      resolver_timeout 10s;
      proxy_pass http://bucket_name.s3-eu-west-1.amazonaws.com/$1;
      aws_access_key 'xxx';
      aws_signing_key 'yyy';
      aws_key_scope '20190130/eu-west-1/s3/aws4_request';
      aws_sign;
    }
  }
}

Each time when I am calling http://x.y.z/s3/
I am getting following error:

The request signature we calculated does not match the signature you provided. Check your key and signing method.

Variables?

Hi.

We'd like to set key_scope, signing_key and access_key with a variable. Based on our tests this doesn't work, one prood is :

<Error><Code>InvalidAccessKeyId</Code><Message>The AWS Access Key Id you provided does not exist in our records.</Message><AWSAccessKeyId>$aws_access_key</AWSAccessKeyId><RequestId>

Config is:

set $aws_access_key_dynamic "XXXXXXXXXXX";
aws_access_key aws_access_key_dynamic;

Are these variables supported or are we doing something wrong?

Scope or Signature not working

Hey guys,

I've generated the scope and the signature using the python script and hardcoded into my NGINX to test, but AWS response says that the signature expected doesn't match
The request signature we calculated does not match the signature you provided. Check your key and signing method

I'm stucked into this somedays and I really don't know what more I can do.

I'm using ./script -k my-aws-secret-key -r my-aws-region -s my-aws-service, it returns the right scope and the signature and the I'm copying and pasting into nginx to use it.

location /test {
aws_access_key AKIAEXAMPLETEST;
        aws_s3_bucket my-test-bucket;
        aws_key_scope 20230630/us-east-1/s3/aws4_request;
        aws_signing_key SOMERANDOMVALUE=;
        aws_sign;

        proxy_pass http://my-test-bucket/my-test-file.mp4
}

Any ideas?

ngx_aws_auth do not support s3 compatible protocol

Some compatible s3 service need more conditions parameters, such as Ceph s3.

s3fs-fuse example : s3fs-fuse/s3fs-fuse#305. Need sigv2 for compatible .

Otherwise, you will auth fail and receive '403 Forbidden'.

HTTP/1.1 403 Forbidden
Server: Tengine
Date: Fri, 19 Feb 2016 03:21:18 GMT
Content-Type: application/xml
Content-Length: 158
Connection: keep-alive
x-amz-request-id: tx000000000000000108025-0056c68a2e-c7142-default
Accept-Ranges: bytes
<?xml version="1.0" encoding="UTF-8"?><Error><Code>SignatureDoesNotMatch</Code><RequestId>tx000000000000000108025-0056c68a2e-c7142-default</RequestId></Error>

image

Signing Key Expire within a day

i encountered the error
AuthorizationHeaderMalformedThe authorization header is malformed; Invalid credential date. Date is not the same as X-Amz-Date.... after a day.

I thought the signing key was suppose to last for a week. can anyone help? How do i set the X-Amz-Date? Or do i need to set the amz-expire field??

What values need to go in aws_key_scope?

I'm trying to figure out what value needs to go in:
aws_key_scope scope_of_generated_signing_key;

is it only the region name?

I'm getting the following "Malformed entry" error. Any help on this would be GREATLY appreciated.

ERROR:

<Error>
<Code>AuthorizationHeaderMalformed</Code>
<Message>
The authorization header is malformed; the Credential is mal-formed; expecting "<YOUR-AKID>/YYYYMMDD/REGION/SERVICE/aws4_request".
</Message>
<RequestId>59D3A159DA4C78A6</RequestId>
<HostId>
/+Ern48H+67YCS+dSvGkXUtxnUUndZNAojMAnfUdgpVI0zaodKOvNe/Aut93+bltXetXPVXKzDU=
</HostId>
</Error>

NGINX CONF:

    location /saspub/ {
    aws_sign;
        proxy_pass http://MYBUCKET.s3.amazonaws.com/$1;

        aws_access_key MYACCESSKEY;
        #aws_key_scope scope_of_generated_signing_key;
        aws_signing_key MYGENERATED_KEY_WITH_SCRIPT;

    resolver        MYDNSIP;
    resolver_timeout    10s;
    }

First request after nginx restart is not served

It seems that the first nginx request after nginx initialization or restart is not served by S3 due to signature mismatch. The problem is probably caused by missing timestamp in string_to_sign even though x-amz-date header is present.
Debug log for the very first request after start or restart

2014/03/28 20:02:20 [debug] 31823#0: *1 start normalize headers
2014/03/28 20:02:20 [debug] 31823#0: *1 normalized: 
2014/03/28 20:02:20 [debug] 31823#0: *1 bucket: mybucket
2014/03/28 20:02:20 [debug] 31823#0: *1 uri:    /backup/amazon/review01.txt
2014/03/28 20:02:20 [debug] 31823#0: *1 normalized resources: /mybucket/backup/amazon/review01.txt
2014/03/28 20:02:20 [debug] 31823#0: *1 String to sign:GET



/mybucket/backup/amazon/review01.txt
2014/03/28 20:02:20 [debug] 31823#0: *1 aws string being signed BEGIN:
GET



/mybucket/backup/amazon/review01.txt
aws string being signed END
2014/03/28 20:02:20 [debug] 31823#0: *1 Signature: AWS AKIAICP2LJG6EZD7V62Q:hZlFkPilKWyG023B0WctzIB1Q38=
2014/03/28 20:02:20 [debug] 31823#0: *1 posix_memalign: 09CB86E0:4096 @16
2014/03/28 20:02:20 [debug] 31823#0: *1 http script copy: "Authorization: "
2014/03/28 20:02:20 [debug] 31823#0: *1 http script var: "AWS AKIAICP2LJG6EZD7V62Q:hZlFkPilKWyG023B0WctzIB1Q38="
2014/03/28 20:02:20 [debug] 31823#0: *1 http script copy: "
"
2014/03/28 20:02:20 [debug] 31823#0: *1 http script copy: "x-amz-date: "
2014/03/28 20:02:20 [debug] 31823#0: *1 http script var: "Fri, 28 Mar 2014 18:02:20 GMT"
2014/03/28 20:02:20 [debug] 31823#0: *1 http script copy: "
"
2014/03/28 20:02:20 [debug] 31823#0: *1 http script copy: "Host: "
2014/03/28 20:02:20 [debug] 31823#0: *1 http script var: "mybucket.s3.amazonaws.com"
2014/03/28 20:02:20 [debug] 31823#0: *1 http script copy: "
"
2014/03/28 20:02:20 [debug] 31823#0: *1 http script copy: "Connection: close
"

Each subsequent request includes the correct timestamp from x-amz-date header

2014/03/28 20:13:59 [debug] 31823#0: *17 start normalize headers
2014/03/28 20:13:59 [debug] 31823#0: *17 normalized: x-amz-date:Fri, 28 Mar 2014 18:13:59 GMT

2014/03/28 20:13:59 [debug] 31823#0: *17 bucket: mybucket
2014/03/28 20:13:59 [debug] 31823#0: *17 uri:    /backup/amazon/review01.txt
2014/03/28 20:13:59 [debug] 31823#0: *17 normalized resources: /mybucket/backup/amazon/review01.txt
2014/03/28 20:13:59 [debug] 31823#0: *17 String to sign:GET



x-amz-date:Fri, 28 Mar 2014 18:13:59 GMT
/mybucket/backup/amazon/review01.txt
2014/03/28 20:13:59 [debug] 31823#0: *17 aws string being signed BEGIN:
GET



x-amz-date:Fri, 28 Mar 2014 18:13:59 GMT
/mybucket/backup/amazon/review01.txt
aws string being signed END
2014/03/28 20:13:59 [debug] 31823#0: *17 Signature: AWS AKIAICP2LJG6EZD7V62Q:d/q/UjFsoSxNHtJhQCFUfGUFOwo=
2014/03/28 20:13:59 [debug] 31823#0: *17 posix_memalign: 09CB7FA0:4096 @16
2014/03/28 20:13:59 [debug] 31823#0: *17 http script copy: "Authorization: "
2014/03/28 20:13:59 [debug] 31823#0: *17 http script var: "AWS AKIAICP2LJG6EZD7V62Q:d/q/UjFsoSxNHtJhQCFUfGUFOwo="
2014/03/28 20:13:59 [debug] 31823#0: *17 http script copy: "
"
2014/03/28 20:13:59 [debug] 31823#0: *17 http script copy: "x-amz-date: "
2014/03/28 20:13:59 [debug] 31823#0: *17 http script var: "Fri, 28 Mar 2014 18:13:59 GMT"
2014/03/28 20:13:59 [debug] 31823#0: *17 http script copy: "
"
2014/03/28 20:13:59 [debug] 31823#0: *17 http script copy: "Host: "
2014/03/28 20:13:59 [debug] 31823#0: *17 http script var: "mybucket.s3.amazonaws.com"
2014/03/28 20:13:59 [debug] 31823#0: *17 http script copy: "
"
2014/03/28 20:13:59 [debug] 31823#0: *17 http script copy: "Connection: close
"

Every request generates several lines of error logs

cache_1  | 2019/10/30 21:26:30 [error] 7#7: *6 canonical url extracted before URI encoding is /video, client: 172.18.0.1, server: , request: "GET /video HTTP/1.1", host: "localhost:8080"
cache_1  | 2019/10/30 21:26:30 [error] 7#7: *6 canonical url extracted after URI encoding is /video, client: 172.18.0.1, server: , request: "GET /video HTTP/1.1", host: "localhost:8080"
cache_1  | 2019/10/30 21:26:30 [error] 7#7: *6 canonical req is GET
cache_1  | /video
cache_1  |
cache_1  | host:example.s3.amazonaws.com
cache_1  | x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
cache_1  | x-amz-date:20191030T212630Z
cache_1  |
cache_1  | host;x-amz-content-sha256;x-amz-date
cache_1  | e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855, client: 172.18.0.1, server: , request: "GET /video HTTP/1.1", host: "localhost:8080"

Is there a way to disable these or perhaps these should be at debug level?

When I configure nginx with signature calculation S3 cp fails with errors

I configured nginx with the following configuration S3 cp with KMS encryption fails

location / {
resolver 8.8.8.8;
proxy_pass https://s3.amazonaws.com;
proxy_ssl_name s3.amazonaws.com;
proxy_pass_request_headers on;
client_max_body_size 5G;
proxy_send_timeout 600;
proxy_read_timeout 600;
proxy_intercept_errors on;
proxy_next_upstream error timeout http_500 http_502 http_503 http_504;
aws_sign;
aws_signing_key
}
I get this error

ResponseParserError: Unable to parse response (mismatched tag: line 6, column 2), invalid XML received:

<title>405 Not Allowed</title>

405 Not Allowed


nginx/1.14.0

upload failed: ./test.txt to s3://..../test.txt An error occurred (405) when calling the PutObject operation: Method Not Allowed
Appreciate your advise on this

tag 2.1.0

@anomalizer This commit #33 was a good new feature, can you please create a new tag such as 2.1.0? Thanks!

Signing error if behind CloudFront

Hi,
it seems there is a problem with request signing if it comes from behind Amazon CloudFront service.

What I notice is the following :

HTTP_Request > Nginx with ngx_aws_auth > S3 bucket works OK

HTTP_Request > Amazon CF (distribution set to nginx) > Nginx with ngx_aws_auth > S3 bucket goes KO

here is the error from browser :

SignatureDoesNotMatch The request signature we calculated does not match the signature you provided. Check your key and signing method. omissis 127A95CC3037ABFF omissis omissis GET x-amz-cf-id:5ZxaxPOoKEPPe3gLsvAMMMdZzcl7GjVYrPFL2Yn88VWbwGLVtiTJFw== x-amz-date:Fri, 22 Nov 2013 16:48:18 GMT /mybucket/mypath/myfile.ext omissis

it seems that being behind CF adds x-amz-cf-id: header which I think S3 uses for signing when ngx_aws_auth doesn't, hence the error.

It works OK also behind ELB, which does not add any header.

Thanks.

A

critical error on a GET request and having to restart nginx

Occasionally, I'm getting this error and having to restart nginx to fix it:

2016/01/04 13:28:10 [crit] 7158#0: *25859 open() "/tmp/cache/temp/0000000312" failed (2: No such file or directory) while reading upstream, client: 127.0.0.1, server: , request: "GET /files/spark.tgz HTTP/1.1", upstream: "http://10.6.71.205:8080/files-bucket/spark.tgz", host: "localhost:8000"

getting 307 Temporary Redirect

Hi ,

I am using AuthV2 branch of this module

My nginx configuration

worker_processes 2;
pid /run/nginx.pid;
daemon off;

events {
    worker_connections 768;
}

http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    server_names_hash_bucket_size 64;

    include /usr/local/nginx/conf/mime.types;
    default_type application/octet-stream;

    access_log access.log;
    error_log  error.log;

    gzip on;
    gzip_disable "msie6";
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    proxy_cache_lock on;
    proxy_cache_lock_timeout 60s;
    proxy_cache_path /data/cache levels=1:2 keys_zone=s3cache:10m max_size=30g;

    server {
        listen     80;

        location / {
            proxy_pass https://foo.s3.amazonaws.com;

            aws_access_key ******************;
            aws_secret_key **********************;
            s3_bucket foo;

            proxy_set_header Authorization $s3_auth_token;
            proxy_set_header x-amz-date $aws_date;

            proxy_cache        s3cache;
            proxy_cache_valid  200 302  5m;
        }
    }
}

I am getting 307 Temporary Redirect

root@mesos-slaves5:~# curl -v  localhost:80
* Rebuilt URL to: localhost:21562/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 21562 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:21562
> Accept: */*
>
< HTTP/1.1 307 Temporary Redirect
* Server nginx/1.9.3 is not blacklisted
< Server: nginx/1.9.3
< Date: Wed, 22 Jun 2016 12:23:06 GMT
< Content-Type: application/xml
< Transfer-Encoding: chunked
< Connection: keep-alive
< x-amz-bucket-region: ap-southeast-1
< x-amz-request-id: 2F4E3E6C397522BF
< x-amz-id-2: /a20dStXAYIkRKIBm1VhcF1o1xN4qZ1vqJY7OlHZF/adsadasdasdhlKpvy
< Location: https://foo.s3-ap-southeast-1.amazonaws.com/
<
<?xml version="1.0" encoding="UTF-8"?>
* Connection #0 to host localhost left intact
<Error><Code>TemporaryRedirect</Code><Message>Please re-send this request to the specified temporary endpoint. Continue to use the original request endpoint for future requests.</Message><Bucket>foo</Bucket><Endpoint>foo.s3-ap-southeast-1.amazonaws.com</Endpoint><RequestId>2F4E3E6C397522BF</RequestId><HostId>/a20dStXAYIkRKIBm1VhcF1o1xN4qZ1vqJY7OlHZF/cPlPYKBXXrEAc4PnhlKpvy</HostId></Error>

Anything I am doing wrong ?

HEAD request does not work

hello,
I do a GET request on file without problem,
the same with HEAD request does not work, with 403 forbidden error , permission is good on this file, and with same key and standard s3 client, no problem.

127.0.0.1 - - [29/Jan/2015:21:09:46 +0000] "HEAD http://s3.amazonaws.com/nhc.c1/test HTTP/1.1" 403 394 (472) "-" "-" "-"[MISS] [0 / -] - AWS4-HMAC-SHA256 Credential=AKIAJG6NCXFPQGBUZ3YA/20150129/US/s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date,Signature=85369c88cbedbadcc5f8457b39b9683b69b861928c884b55e739a76d3905cca7

127.0.0.1 - - [29/Jan/2015:21:10:19 +0000] "GET http://s3.amazonaws.com/nhc.c1/test HTTP/1.1" 200 41799 (452) "-" "-" "-"[MISS] [41029 / -] - AWS4-HMAC-SHA256 Credential=AKIAJG6NCXFPQGBUZ3YA/20150129/US/s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date,Signature=34cbbfb2d48cb8ea516bd2bbb82bd894ee62ab854ceb448365ef4f1863513cde

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.