惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Register - Security
The Register - Security
P
Privacy International News Feed
月光博客
月光博客
博客园 - 聂微东
Blog — PlanetScale
Blog — PlanetScale
V
Visual Studio Blog
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Google DeepMind News
Google DeepMind News
罗磊的独立博客
Vercel News
Vercel News
Last Week in AI
Last Week in AI
A
About on SuperTechFans
P
Proofpoint News Feed
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园_首页
T
Tailwind CSS Blog
GbyAI
GbyAI
S
Schneier on Security
L
LINUX DO - 热门话题
C
CERT Recently Published Vulnerability Notes
AWS News Blog
AWS News Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Hacker News
The Hacker News
N
News and Events Feed by Topic
云风的 BLOG
云风的 BLOG
博客园 - 【当耐特】
C
Cybersecurity and Infrastructure Security Agency CISA
I
Intezer
V2EX - 技术
V2EX - 技术
The GitHub Blog
The GitHub Blog
Scott Helme
Scott Helme
V
V2EX
IT之家
IT之家
S
SegmentFault 最新的问题
爱范儿
爱范儿
L
LangChain Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MongoDB | Blog
MongoDB | Blog
S
Security Affairs
Security Latest
Security Latest
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
S
Secure Thoughts
MyScale Blog
MyScale Blog
F
Fortinet All Blogs
Hugging Face - Blog
Hugging Face - Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed

杂烩饭

使用 RustFS 自建对象存储 使用cURL命令管理对象存储(s3) AGENTS.md Prometheus使用kubeconfig做k8s的service 自动发现监控 定制Windows系统镜像iso 使用create-dmg工具制作dmg安装包 使用create-dmg工具制作dmg安装包 - 技术栈 superpowers Nexus仓库搭建记录 Git Merge代码冲突的解决方式 在 Linux 系统中安装与配置 OpenVPN:从入门到精通 使用 Easytier-web 管理 easytier 节点 ingress-nginx 去除指定context path 在macOS上使用MusicPlayer2听本地音乐 Kubernetes 1.34 + RHEL10 + Cilium + kube-vip 高可用集群部署 使用腾讯云CLS收集TKE(k8s)业务日志 容器调试工具之BusyBox 无Docker环境进行容器镜像操作 使用kubeadm部署一套高可用k8s集群1.34 for Ubuntu 正在运行的Docker容器增加端口映射 轻量级组网工具WireGuard 在Kubernetes中部署一个单节点Elasticsearch 使用openssl制作自签名双向认证(mTLS)证书 minio自建对象存储 P12格式证书与PEM格式转换 使用blackbox-exporter做域名监控 记一次MySQL字符集转换导致的故障 使用双向认证增加git仓库安全性 Prometheus自动监控K8S集群中的service Grafana 查询SQL 自定义变量 使用selenium来实现Grafana的自动截图
ingress-nginx 使用自定义的nginx配置
张理坤 · 2025-06-26 · via 杂烩饭

新版 ingress 增强了 安全性, 它认为用户自己写的 nginx 配置文件不安全,所以又加了限制。(允许自定义 nginx 配置有一定安全风险,酌情修改!)我的 ingress 版本是: 1.12.2

比如有个需求,Spring Boot 写的程序有个 /actuator 路径,安全审查不通过,如果是个 nginx 可以通过:

1
2
3
location /actuator {
return 404;
}

来直接让它返回 404

configmap

1
2
3
4
5
6
7
8
9
10
11
12
13
14
apiVersion: v1
data:
allow-snippet-annotations: "true"
annotations-risk-level: Critical
kind: ConfigMap
metadata:
labels:
app.kubernetes.io/component: controller
app.kubernetes.io/instance: public-ingress-nginx
app.kubernetes.io/name: public-ingress-nginx
app.kubernetes.io/part-of: public-ingress-nginx
app.kubernetes.io/version: 1.12.2
name: public-ingress-nginx-controller
namespace: public-ingress-nginx

加上这两个配置:
allow-snippet-annotations
annotations-risk-level

风险等级,在这里可以查到:
https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations-risk/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/cors-allow-headers: '*'
nginx.ingress.kubernetes.io/cors-allow-methods: '*'
nginx.ingress.kubernetes.io/cors-allow-origin: '*'
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/server-snippet: |
location /actuator {
return 404;
}
name: mtls
namespace: vos
spec:
ingressClassName: public-nginx
rules:
- host: a.com
http:
paths:
- backend:
service:
name: gateway
port:
number: 80
path: /
pathType: ImplementationSpecific
tls:
- hosts:
- a.com
secretName: a-com

server-snippet 作用于 server 块
configuration-snippet 作用于 location 块

注意:

1
nginx.ingress.kubernetes.io/use-regex: 'true'

当启用 use-regex 时,所有路径都会被当作正则表达式处理,会影响到匹配。

版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 杂烩饭