最近安全事故濒发啊,前段时间发生了《顺丰高级运维工程师的删库事件》,今天又看到了 PHP 工程师在线执行了 Redis 危险命令致使某公司损失 400 万。。
java
什么样的 Redis 命令会有如此威力,形成如此大的损失?面试
具体消息以下:redis
据云头条报道,某公司技术部发生 2 起本年度 PO 级特大事故,形成公司资金损失 400 万,缘由以下:数据库
因为 PHP 工程师直接操做上线 redis,执行 keys * wxdb(此处省略)cf8* 这样的命令,致使redis锁住,致使 CPU 飙升,引发全部支付链路卡住,等十几秒结束后,全部的请求流量所有挤压到了 rds 数据库中,使数据库产生了雪崩效应,发生了数据库宕机事件。安全
该公司表示,如再犯相似事故,将直接开除,并表示以后会逐步收回运维部各项权限。bash
看完这个消息后,我心又一惊,为何这么低级的问题还在犯?为何线上的危险命令没有被禁用?这事件报道出来真是以为很低级。。。架构
且不说是哪家公司,发生这样的事故,无论是大公司仍是小公司,我以为都不该该,相关负责人应该引咎辞职!!!运维
对 Redis 稍微有点使用经验的人都知道线上是不能执行 keys *
相关命令的,虽然其模糊匹配功能使用很是方便也很强大,在小数据量状况下使用没什么问题,数据量大会致使 Redis 锁住及 CPU 飙升,在生产环境建议禁用或者重命名!ide
小编分类整理了许多java进阶学习材料和BAT面试题,须要资料的请加JAVA高阶学习Q群:8515318105;就能领取2019年java架构师进阶学习资料和BAT面试题。
学习
Redis 的危险命令主要有如下几个:
keys
客户端可查询出全部存在的键。
flushdb
Delete all the keys of the currently selected DB. This command never fails.
删除 Redis 中当前所在数据库中的全部记录,而且此命令从不会执行失败。
flushall
Delete all the keys of all the existing databases, not just the currently selected one. This command never fails.
删除 Redis 中全部数据库中的全部记录,不仅是当前所在数据库,而且此命令从不会执行失败。
config
客户端可修改 Redis 配置。
看下 redis.conf
默认配置文件,找到 SECURITY
区域,如如下所示。
################################## SECURITY ###################################
# Require clients to issue AUTH <PASSWORD> before processing any other
# commands. This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
# requirepass foobared
# Command renaming.
#
# It is possible to change the name of dangerous commands in a shared
# environment. For instance the CONFIG command may be renamed into something
# hard to guess so that it will still be available for internal-use tools
# but not available for general clients.
#
# Example:
#
# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
#
# It is also possible to completely kill a command by renaming it into
# an empty string:
#
# rename-command CONFIG ""
#
# Please note that changing the name of commands that are logged into the
# AOF file or transmitted to slaves may cause problems.
复制代码
看说明,添加 rename-command
配置便可达到安全目的。
小编分类整理了许多java进阶学习材料和BAT面试题,须要资料的请加JAVA高阶学习Q群:8515318105;就能领取2019年java架构师进阶学习资料和BAT面试题。
1)禁用命令
rename-command KEYS ""
rename-command FLUSHALL ""
rename-command FLUSHDB ""
rename-command CONFIG ""
复制代码
2)重命名命令
rename-command KEYS "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
rename-command FLUSHALL "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
rename-command FLUSHDB "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
rename-command CONFIG "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
复制代码
上面的 XX 能够定义新命令名称,或者用随机字符代替。
通过以上的设置以后,危险命令就不会被客户端执行了。
小编分类整理了许多java进阶学习材料和BAT面试题,须要资料的请加JAVA高阶学习Q群:8515318105;就能领取2019年java架构师进阶学习资料和BAT面试题。