繁体   English   中英

混合内容错误nginx入侵kubernetes for rails app

[英]Mixed Content error nginx ingress in kubernetes for rails app

使用Nginx Ingress负载均衡器在GCP中部署Portus Portus加载得很好,但在尝试使用应用程序并填写一些表单时,我收到以下错误:

VM798:1混合内容:“ https://staging.foo.bar/admin/registries/new ”页面通过HTTPS加载,但请求了一个不安全的XMLHttpRequest端点“ http://staging.foo.bar//api / v1 / registries / validate?name = devreg&hostname = staging-foo-barregistry%3A5000&external_hostname =&use_ssl = false&force = false&only%5B%5D = hostname '。 此请求已被阻止; 内容必须通过HTTPS提供。

Nginx配置: https//github.com/kubic-project/caasp-services/blob/master/contrib/helm-charts/portus/templates/nginx-configmap.yaml

环境:

  • GCP中的Kubernetes
  • 通过helm部署的所有资源
  • ssl由kube-lego提供
  • 带有Grape API gem的Rails应用程序
  • Grape按如下方式挂载api: mount API::RootAPI => "/"

所以我确保检查手动http调用的代码并没有看到任何内容。 我花了一天时间试图挖掘rails docs和nginx docs,看看是什么导致某些应用程序正确加载ssl和API不遵循相同的规则

-----更新1 ------经过进一步调查,看起来它与Vue验证器有关。 检查开发人员工具显示以下内容:

卷曲' http://staging.foo.bar//api/v1/registries/validate?name=devreg&hostname=st&external_hostname=&use_ssl=false&force=false&only%5B%5D=name'-X选项-H'访问控制请求-Method:获取'-H'来源: https ://staging.foo.bar'-H'Access-Control-Request-Headers:x-csrf-token' - 压缩

它看起来像是在这里调用根URL:

javascript:
      window.API_ROOT_URL = '#{root_url}';

如上所述,root_url设置为/。

然而,分析Vue代码更接近狂欢:

Vue.http.options.root = window.API_ROOT_URL;

Vue.http.interceptors.push((_request, next) => {
  window.$.active = window.$.active || 0;
  window.$.active += 1;

  next(() => {
    window.$.active -= 1;
  });
});

Vue.http.interceptors.push((request, next) => {
  if ($.rails) {
    // eslint-disable-next-line no-param-reassign
    request.headers.set('X-CSRF-Token', $.rails.csrfToken());
  }
  next();
});

// we are not a SPA and when user clicks on back/forward
// we want the page to be fully reloaded to take advantage of
// the url query params state
window.onpopstate = function (e) {
  // phantomjs seems to trigger an oppopstate event
  // when visiting pages, e.state is always null and
  // in our component we set an empty string
  if (e.state !== null) {
    window.location.reload();
  }
};

Vue.config.productionTip = process.env.NODE_ENV !== 'production';

参数设置为在查询中使用SSL

params do
          requires :name,
                   using: API::Entities::Registries.documentation.slice(:name)
          requires :hostname,
                   using: API::Entities::Registries.documentation.slice(:hostname)
          optional :external_hostname,
                   using: API::Entities::Registries.documentation.slice(:external_hostname)
          requires :use_ssl,
                   using: API::Entities::Registries.documentation.slice(:use_ssl)
          optional :only, type: Array[String]
        end

我不确定您的应用程序是如何工作的,以及在哪里传递数据的机制,但我怀疑您可能需要将querystring参数中的use_ssl=true传递给/validate端点。

目前,正在传递use_ssl=false ,这可能会返回非SSL响应。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM