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

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
Vercel News
Vercel News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
J
Java Code Geeks
M
MIT News - Artificial intelligence
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog RSS Feed
MongoDB | Blog
MongoDB | Blog
G
Google Developers Blog
Engineering at Meta
Engineering at Meta
量子位
S
SegmentFault 最新的问题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
A
About on SuperTechFans
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
Recent Announcements
Recent Announcements
腾讯CDC
I
InfoQ
F
Fortinet All Blogs
Hugging Face - Blog
Hugging Face - Blog
Blog — PlanetScale
Blog — PlanetScale
H
Help Net Security
爱范儿
爱范儿

杂烩饭

使用RetroArch玩步步高电子词典游戏 彻底删除CCLibrary 在 Nginx 中禁止 IP 直连与域名暴露 使用 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字符集转换导致的故障
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 许可协议。转载请注明来源 杂烩饭