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

推荐订阅源

A
Arctic Wolf
T
Tenable Blog
T
Troy Hunt's Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy & Cybersecurity Law Blog
NISL@THU
NISL@THU
Application and Cybersecurity Blog
Application and Cybersecurity Blog
H
Hacker News: Front Page
S
Secure Thoughts
AWS News Blog
AWS News Blog
L
LINUX DO - 最新话题
D
Darknet – Hacking Tools, Hacker News & Cyber Security
M
MIT News - Artificial intelligence
T
Tor Project blog
S
Schneier on Security
PCI Perspectives
PCI Perspectives
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
美团技术团队
Google DeepMind News
Google DeepMind News
V
Visual Studio Blog
爱范儿
爱范儿
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
T
The Exploit Database - CXSecurity.com
罗磊的独立博客
T
Threat Research - Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
V
V2EX
C
CXSECURITY Database RSS Feed - CXSecurity.com
Stack Overflow Blog
Stack Overflow Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
G
GRAHAM CLULEY
L
LINUX DO - 热门话题
D
Docker
J
Java Code Geeks
GbyAI
GbyAI
H
Heimdal Security Blog
The Hacker News
The Hacker News
MongoDB | Blog
MongoDB | Blog
V
Vulnerabilities – Threatpost
T
Tailwind CSS Blog
Cloudbric
Cloudbric
TaoSecurity Blog
TaoSecurity Blog
C
CERT Recently Published Vulnerability Notes
Y
Y Combinator Blog
Recorded Future
Recorded Future
Cisco Talos Blog
Cisco Talos Blog
T
Threatpost
The Register - Security
The Register - Security
Hacker News - Newest:
Hacker News - Newest: "LLM"

祈雨的笔记

安全多方计算MPC spark原理解析 kueue执行源码分析 spark on k8s执行源码分析 spark-operator源码解析 系统压测遇到的缓存击穿问题 我的世界PC与安卓联机 蚂蚁金服流量投放平台的AIG改造 G1大对象致Old区占用率高 日志打印导致接口响应率下跌分析 Groovy加载类导致OOM分析 ERROR日志打印导致CPU满载 记OceanBase死锁超时 应用发版期间服务响应超时 Ark Serverless初探 系统优化复盘一二三 The user specified as a definer does not exist Kong网关初探 API网关选型调研 CPU火焰图常用工具 配置中心选型调研 基于Proxifier使用代理 FastJSON字段智能匹配踩坑 Nacos初探 记一次Nginx服务器CPU满荷载故障 基于券系统分库分表的思考 limit不参与SQL成本计算致索引失效 Linux常用性能监控命令 golang低版本http2偶现400 hostname in certificate didn't match 常见对称加密原理以及应用 tcp_tw_recycle引起的TCP握手失败 记一次mysql执行DDL导致锁表 mysql磁盘占用查看 mysql对text字段update致磁盘增长 elasticsearch报错index read-only TIME_WAIT与Http的Keep-Alive 记一次TIME_WAIT导致连接数报警 记一次生产事故OOM问题排查 redis分布式锁RedissonLock的实现细节 webservice复杂加密签名(2)java调用 webservice复杂加密签名(1)SoapUI mysql延时关联 利用中间人拦截实现APP内H5窜改 MySQL表字符集不同导致关联查询索引失效 通过SSH隧道远程办公 数据落盘方案 BeanDefinitionRegistryPostProcessor扩展 mysql空间索引 HTTPS攻击 spring循环依赖过程解析 elasticsearch性能优化 mysql IS NULL 使用索引 mysql字符集utf8mb4失效踩坑 常用加密算法 xml与javaBean转换 初探InnoDB MVCC源码实现 mysql索引原理 redis之list源码分析 redis之key过期源码分析 redis之string源码分析 redis之hash源码分析 线程池之ThreadPoolExecutor mysql数据页结构 Using temporary与Using filesort mysql回表致索引失效 springboot(28)HTTP连接池 定时任务之ScheduledThreadPoolExecutor elasticsearch常用script聚合 elasticsearch实现like查询 elasticsearch实现乐观锁 elasticsearch准实时原理 springboot(27)自定义缓存读写机制CachingConfigurerSupport optimizer tracing arthas常用命令 HTTP和HTTPS详解 redis集群选举机制 kafka消息重试 一点压力测试的经验 kafka架构概念 explain分析sql语句字段的解释 JVM问题分析处理手册 logstash过滤器(2)date logstash过滤器(3)dissect logstash编码器(1)json logstash编码器(2)multiline logstash表达式 logstash输入(1)通用选项 logstash输入(3)file logstash过滤器(1)通用选项 logstash输入(2)stdin logstash安装 记一次前端vConsole导致JSON序列化错误排查 解决多个异步操作嵌套问题 fastjson反序列化失败autoType is not support RTMP串流服务 POI自动调整列宽错误 Nginx+Lua实现动态黑名单 使用curl命令模拟POST和GET请求 ResponseEntity下载文件
root操作Nginx导致用户组错误
祈雨的笔记 · 2021-02-03 · via 祈雨的笔记

问题

某年某月某日临近中午,用户突然反应系统出了问题,微信小程序的几个界面加载异常,不能正常访问。紧急排查发现,后端应用有大量的如下错误日志,错误信息SSL peer shut down incorrectly字面上看上去是HTTPS请求Nginx后SSL握手错误,于是再去查看Nginx的日志。

1
2
3
4
5
6
Error while extracting response for type [class java.lang.String] and content type [application/json;charset=utf-8]; nested exception is javax.net.ssl.SSLException: SSL peer shut down incorrectly
org.springframework.web.client.RestClientException: Error while extracting response for type [class java.lang.String] and content type [application/json;charset=utf-8]; nested exception is javax.net.ssl.SSLException: SSL peer shut down incorrectly
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:115)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:725)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:680)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:435)

查看Nginx日志后发现果然Nginx也有大量的报错,如下,字面意思就是Nginx自动生成的临时文件夹client_body_tempproxy_temp的读写权限错误。

1
2
3
4
5
6
7
2020/12/08 11:39:19 [crit] 3844#3844: *1686658178 open() "/opt/nginx/client_body_temp/0007652979" failed (13: Permission denied)
2020/12/08 11:39:19 [crit] 3844#3844: *1686658280 open() "/opt/nginx/client_body_temp/0007652980" failed (13: Permission denied)
2020/12/08 11:39:19 [crit] 3844#3844: *1686658233 open() "/opt/nginx/proxy_temp/1/98/0007652981" failed (13: Permission denied) while reading upstream
2020/12/08 11:39:21 [crit] 3842#3842: *1686658542 open() "/opt/nginx/client_body_temp/0007652982" failed (13: Permission denied)
2020/12/08 11:39:21 [crit] 3844#3844: *1686658318 open() "/opt/nginx/client_body_temp/0007652983" failed (13: Permission denied)
2020/12/08 11:39:23 [crit] 3844#3844: *1686651044 open() "/opt/nginx/client_body_temp/0007652984" failed (13: Permission denied)
2020/12/08 11:39:23 [crit] 3844#3844: *1686658745 open() "/opt/nginx/client_body_temp/0007652985" failed (13: Permission denied)

于是再转头查看文件夹的权限情况,输出如下,果然这两个文件夹本应该所属nginx用户,但现在却显示所属nobody用户。紧急修改文件夹权限组后,Nginx不再输出错误日志,后端服务也恢复正常。

1
2
3
4
5
6
7
8
9
drwx------  2 nobody nobody   6 Dec 10 11:26 client_body_temp
drwxr-xr-x 5 nginx nginx 4.0K Nov 13 01:48 conf
drwx------ 2 nobody nobody 6 Jul 12 2017 fastcgi_temp
drwxr-xr-x 2 nginx nginx 56 Apr 7 2020 html
drwxr-xr-x 3 nginx nginx 20K Dec 10 03:26 logs
drwx------ 12 nobody nobody 96 Dec 25 2017 proxy_temp
drwxr-xr-x 2 nginx nginx 19 Jul 12 2017 sbin
drwx------ 2 nobody nobody 6 Jul 12 2017 scgi_temp
drwx------ 2 nobody nobody 6 Jul 12 2017 uwsgi_temp

原因

如果Nginx非root用户启动后,再以root用户执行nginx -t命令,会修改client_body_tempproxy_temp等临时文件夹的权限,文件夹的用户组变为nobody,导致原Nginx进程用户没有权限读写受到影响的临时文件夹。

而这次导致事故的罪魁祸首是同事使用阿里云提供的安全扫描工具对系统进行扫描,但扫描工具本身的问题,以root用户对Nginx执行了操作导致了临时文件夹用户组被自动修改成了nobody

复现

1
2
3
4
5
6
7
8
9
10
11
[root@localhost nginx]# ll
total 4
drwx------. 2 webapp webapp 6 Jan 31 05:50 client_body_temp
drwxr-xr-x. 2 webapp webapp 4096 Jan 31 05:52 conf
drwx------. 2 webapp webapp 6 Jan 31 05:50 fastcgi_temp
drwxr-xr-x. 2 webapp webapp 40 Jan 31 05:50 html
drwxr-xr-x. 2 webapp webapp 58 Jan 31 05:50 logs
drwx------. 2 webapp webapp 6 Jan 31 05:50 proxy_temp
drwxr-xr-x. 2 webapp webapp 19 Jan 31 05:50 sbin
drwx------. 2 webapp webapp 6 Jan 31 05:50 scgi_temp
drwx------. 2 webapp webapp 6 Jan 31 05:50 uwsgi_temp
1
2
3
[root@localhost nginx]# ./sbin/nginx -t
nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/conf/nginx.conf test is successful
1
2
3
4
5
6
7
8
9
10
11
[root@localhost nginx]# ll
total 4
drwx------. 2 nobody webapp 6 Jan 31 05:50 client_body_temp
drwxr-xr-x. 2 webapp webapp 4096 Jan 31 05:52 conf
drwx------. 2 nobody webapp 6 Jan 31 05:50 fastcgi_temp
drwxr-xr-x. 2 webapp webapp 40 Jan 31 05:50 html
drwxr-xr-x. 2 webapp webapp 58 Jan 31 05:50 logs
drwx------. 2 nobody webapp 6 Jan 31 05:50 proxy_temp
drwxr-xr-x. 2 webapp webapp 19 Jan 31 05:50 sbin
drwx------. 2 nobody webapp 6 Jan 31 05:50 scgi_temp
drwx------. 2 nobody webapp 6 Jan 31 05:50 uwsgi_temp

如上,以root用户对Nginx执行nginx -t命令后,几个临时文件夹的用户组被修改成了nobody

总结

慎用root用户,不要以root用户对Nginx进行任何操作!