lua-resty-aws-signature
AWS 签名 V4 头部生成器
$ opm get jobteaser/lua-resty-aws-signature
lua-resty-aws-signature
该库基于 Alan Grosskurth 在 https://github.com/grosskur/lua-resty-aws 上的工作。它基本上是从他的仓库中分叉出来的,我们更改了使用的 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
依赖项
版本
-
AWS 签名 V4 头部生成器 2018-09-20 13:12:26
-
AWS 签名 V4 头部生成器 2018-09-20 12:40:45
-
AWS 签名 V4 头部生成器 2018-09-20 12:19:09