如何将内容安全策略(CSP)添加到 nginxinc 入口控制器或入口规则

问题描述 投票:0回答:3

如何将内容安全策略(CSP)添加到nginxinc入口控制器或入口规则。

我尝试了以下两种入口规则注释,但都不起作用。

annotations:
  nginx.ingress.kubernetes.io/configuration-snippet: |
      more_set_headers "Content-Security-Policy-Report-Only: Content-Security-Policy: script-src 'self' 'none' ;";
      add_header Content-Security-Policy: default-src 'self' 'none' ;
kubernetes content-security-policy nginx-ingress ingress-controller
3个回答
1
投票

这有效:

annotations:
  nginx.ingress.kubernetes.io/configuration-snippet: |
    more_set_headers "Content-Security-Policy-Report-Only: your-policy";

记得将

your-policy
修改为真实的东西;-)


0
投票

fandasson 的解决方案有效,但自 Ingress-NGINX 版本 1.9.0 起默认禁用“configuration-snippet”注释。

如果您使用 nginx-ingress Helm 图表,这意味着设置:

controller:
  allowSnippetAnnotations: true

启用它会对多租户集群产生安全影响,请参阅:

https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#configuration-snippet


0
投票

NGINX Ingress Controller 的注释以

nginx.org
nginx.com
开头。您使用的代码片段注释前缀属于社区入口控制器,但是您提到您正在使用 NGINX Inc 的入口控制器,即 NGINX 入口控制器。

要将您的代码片段添加到入口的服务器块级别,您可以使用此注释。

nginx.org/server-snippets: |
  more_set_headers "Content-Security-Policy-Report-Only: Content-Security-Policy: script-src 'self' 'none' ;";
  add_header Content-Security-Policy: default-src 'self' 'none' ;

您可以在此处

查看片段上的文档
© www.soinside.com 2019 - 2024. All rights reserved.