lua-resty-aws-signature

AWS 签名 V4 头部生成器

$ opm get GUI/lua-resty-aws-signature

lua-resty-aws-signature

该库基于 [Alan Grosskurth](https://github.com/grosskur) 在 [https://github.com/grosskur/lua-resty-aws](https://github.com/grosskur/lua-resty-aws) 上的工作。它基本上是从他的仓库中 fork 的,我们改变了使用的 HMAC 库。

概述

该库使用 [AWS 签名版本 4][aws4] 规范来实现请求签名。这种签名方案被几乎所有 AWS 服务使用。

AWS 文档

[aws4]: http://docs.aws.amazon.com/general/latest/gr/signature-version-4.html

使用

该库使用标准 AWS 环境变量作为凭据来生成 [AWS 签名版本 4][aws4]。

    export AWS_ACCESS_KEY_ID=AKIDEXAMPLE
    export AWS_SECRET_ACCESS_KEY=AKIDEXAMPLE

要使其在你的 nginx 配置中可用,这些变量应在 `nginx.conf` 文件中声明。

    #user  nobody;
    worker_processes  1;
    
    error_log  /dev/fd/1 debug;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    env AWS_ACCESS_KEY_ID;
    env AWS_SECRET_ACCESS_KEY;
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
        #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
        #                  '$status $body_bytes_sent "$http_referer" '
        #                  '"$http_user_agent" "$http_x_forwarded_for"';
    
        access_log  /dev/stdout;
    
        sendfile        on;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
    
        #gzip  on;
    
        include /etc/nginx/conf.d/*.conf;
    }

然后,你可以使用该库来添加 AWS 签名头并将 `proxy_pass` 到指定的 S3 存储桶。

    set $bucket 'example';
    set $s3_host $bucket.s3-eu-west-1.amazonaws.com;
    
    location / {
      access_by_lua_block {
        require("resty.aws-signature").s3_set_headers(ngx.var.s3_host, ngx.var.uri)
      }
    
      proxy_pass https://$s3_host;
    }

注意:你必须根据需要设置 `s3-<region>` 或 `s3` 作为 `amazonaws.com` 的子域。 `s3` 将使用 `us-east-1` 区域。

贡献

查看 CONTRIBUTING.md 以获取更多信息。

许可证

版权所有 2018 JobTeaser

根据 Apache 许可证 2.0 版(“许可证”)许可;除非符合许可证,否则你不得使用此文件。你可以在以下网址获得许可证副本:

https://apache.ac.cn/licenses/LICENSE-2.0

除非适用法律要求或以书面形式同意,否则根据许可证分发的软件按“原样”分发,不附带任何形式的明示或暗示的保证或条件。有关许可证管理的特定语言,请参阅许可证。

作者

Ludovic Vielle (lukkor)

许可证

apache2

依赖项

版本