【问题标题】:Reverse Proxy to VPC-Based AWS Elasticsearch Domain Without Bypassing AWS Cognito在不绕过 AWS Cognito 的情况下反向代理到基于 VPC 的 AWS Elasticsearch 域
【发布时间】:2019-04-17 15:58:44
【问题描述】:

我提前道歉 - 我对 Nginx 非常陌生。

我有两个基于 VPC 的 AWS Elasticsearch 域,我们称之为 dev 和 prod。我希望这两个域都无法访问开放的 Internet,但在 VPC 之外的某些网络中可用。为此,我将它们设置为基于 VPC 的 Elasticsearch 域,并计划使用只能从我希望的网络访问的反向代理。我已经使用具有以下配置的 NGINX 反向代理设置了没有身份验证的开发集群:

events{

}

http{
  server {
    listen       80;
    server_name kibana-dev.[domain name];

    location / {

      proxy_http_version 1.1;
      proxy_set_header Connection "Keep-Alive";
      proxy_set_header Proxy-Connection "Keep-Alive";

      proxy_pass https://[vpc id].[vpc region].es.amazonaws.com/_plugin/kibana/;
      proxy_redirect https://[vpc id].[vpc region].es.amazonaws.com/_plugin/kibana/ https://kibana-dev.[domain name]/;
    }

      location ~ (/app/kibana|/app/timelion|/bundles|/es_admin|/plugins|/api|/ui|/elasticsearch|/app/opendistro-alerting) {
         proxy_pass          https://[vpc id].[vpc region].es.amazonaws.com;
         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-Proto $scheme;
         proxy_set_header    X-Forwarded-Host $http_host;
    }

  }
}

这很好用。

但是,对于 prod 域,我遇到了问题。我希望所有用户,即使是那些使用代理的用户,都必须使用 AWS Cognito 进行身份验证(所以我不只是想,例如,为代理的 IP 地址创建一个带有 IP 例外的访问策略,因为它绕过了 Cognito )。

我为我的“prod”Elasticsearch 实例使用了类似的 NGINX 配置,但没有运气。 Cognito 登录页面在身份验证后重定向到基于 VPC 的 URL。我尝试手动将代理的 URL 添加到 Cognito 应用程序的回调 URL,但默认情况下它仍重定向到基于 VPC 的 URL。我还尝试手动更改 Cognito URL 中的重定向 URI 以引用我的代理,但我发现在身份验证后我再次被重定向到 Cognito 登录页面 - 可能是标题或其他内容没有通过?

我如何(或可以)让它在 Nginx 中运行,以便用户可以访问“prod”Elasticsearch 域,同时仍需要通过 AWS Cognito 进行身份验证?

谢谢!

【问题讨论】:

    标签: nginx amazon-cognito nginx-reverse-proxy aws-elasticsearch


    【解决方案1】:

    哇!我应该更仔细地阅读文档。 AWS 为带有 Cognito 的 Kibana 代理提供 an example Nginx conf file

    {
    server {
        listen 443;
        server_name $host;
        rewrite ^/$ https://$host/_plugin/kibana redirect;
    
        ssl_certificate           /etc/nginx/cert.crt;
        ssl_certificate_key       /etc/nginx/cert.key;
    
        ssl on;
        ssl_session_cache  builtin:1000  shared:SSL:10m;
        ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
        ssl_prefer_server_ciphers on;
    
        location /_plugin/kibana {
            # Forward requests to Kibana
            proxy_pass https://$kibana_host/_plugin/kibana;
    
            # Handle redirects to Cognito
            proxy_redirect https://$cognito_host https://$host;
    
            # Update cookie domain and path
            proxy_cookie_domain $kibana_host $host;
            proxy_cookie_path / /_plugin/kibana/;
    
            # Response buffer settings
            proxy_buffer_size 128k;
            proxy_buffers 4 256k;
            proxy_busy_buffers_size 256k;
        }
    
        location ~ \/(log|sign|fav|forgot|change|saml|oauth2) {
            # Forward requests to Cognito
            proxy_pass https://$cognito_host;
    
            # Handle redirects to Kibana
            proxy_redirect https://$kibana_host https://$host;
    
            # Update cookie domain
            proxy_cookie_domain $cognito_host $host;
        }
    }
    

    【讨论】:

    • 你的 cognito 用户池和 cognito 的 ES 域配置是什么?我尝试设置相同并具有上述 nginx 配置,但当我的域在 VPC 中时没有运气。当我尝试在 cognito 中使用代理域作为回调 url 时出现 redirect_mismatch 错误
    • @TamasSzasz 我遇到了同样的问题。你有没有设法把它修好?
    • 您会收到 redirect_mismatch 错误,因为您登录后 redirect_uri 查询参数与 Cognito 中允许的 redirect_uri 不匹配。查询参数很可能是私有 URL (vpc-xxx.region.es.amazonaws.com),而不是您设置 Cognito 应用程序客户端回调 URL 的公共 URL。就我而言,我必须重写位置标头才能替换 URL。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-04
    • 2018-04-12
    • 1970-01-01
    • 1970-01-01
    • 2018-02-23
    • 2016-09-26
    相关资源
    最近更新 更多