与Elastic Beanstalk的Api网关连接(客户端SSL证书)

时间:2017-02-01 13:48:14

标签: amazon-web-services ssl nginx elastic-beanstalk aws-api-gateway

我试图在Alastic Beanstalk中将Api Gateway连接到我的api。我希望我的api只能通过Api Gateway访问,为此我在后端使用客户端SSL证书授权(就像这个aws发布链接:http://docs.aws.amazon.com/es_es/apigateway/latest/developerguide/getting-started-client-side-ssl-authentication.html)。所以我的建筑是这样的:

API GATEWAY-> ELASTIC LOAD BALANCER-> EC2(ELASTIC BEANSTALK)

我的EC2机器有NGINX和Ruby。

连接的工作方式如下:

API GATEWAY - > (80 PORT) - > ELASTIC LOAD BALANCER - > (443 PORT) - > NGINX - > RUBY

我在NGINX中进行客户端身份验证。 当我使用浏览器访问Elastic Load Balancer时,它显示400 Bad Request - NGINX错误:没有发送所需的SSL证书(这是正确的,因为我没有发送证书)。但是当我使用Api Gateway访问并发送客户端证书时,我得到了同样的错误(我不明白为什么)。

当我在NGINX中配置SSL连接时,我使用了我签名的SSL证书(可能这是问题吗?)

我的问题的其他可能原因是Elastic Load Balancer中的端口配置(在图片中)。我有后端身份验证:已禁用。这是一个问题吗? Pictura Port Config ELB

我的nginx配置是:

upstream my_app {
  server unix:///var/run/puma/my_app.sock;
}

log_format healthd '$msec"$uri"'
                '$status"$request_time"$upstream_response_time"'
                '$http_x_forwarded_for';

server {
listen       443 ssl;
listen       [::]:443 ssl;
server_name  localhost;
root         /usr/share/nginx/html;

ssl on;
ssl_certificate /etc/nginx/ssl/dev.crt;
ssl_certificate_key /etc/nginx/ssl/dev.key;
ssl_trusted_certificate /etc/nginx/ssl/api-gateway.pem;
ssl_client_certificate /etc/nginx/ssl/api-gateway.pem;
ssl_verify_client on;

ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
ssl_prefer_server_ciphers on;
if ($ssl_client_verify = FAILED) {
        return 495;
}
if ($ssl_client_verify = NONE) {
    return 402;
}
if ($ssl_client_verify != SUCCESS) {
    return 403;
}
try_files $uri/index.html $uri @my_app;
  location @my_app {
    proxy_set_header  Host $host;
    proxy_set_header  X-Real-IP $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header  X-Forwarded-Host $server_name;
    proxy_set_header  Client-IP $remote_addr;
            proxy_pass        http://my_app;
    proxy_set_header X-Client-Verify $ssl_client_verify;
  }
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
    proxy_pass http://my_app; # match the name of upstream directive which is defined above
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header gonzalo1 $ssl_client_verify;
}
error_page 404 /404.html;
    location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
    location = /50x.html {
}

}

1 个答案:

答案 0 :(得分:2)

Amazon API Gateway不支持集成端点的自签名证书。您是否尝试过使用Amazon Certificate Manager或Let's Encrypt的证书?