Redis RU330课程 Redis Security 第1周学习笔记

Overview of RU330

  • https://github.com/redislabs-training/ru330

3个部分:

  1. 基础
  2. 认证与授权
  3. TLS

Introduction

  • CIA Triad (Confidentiality, Integrity, Availability)
    - confidentiality is a set of rules that limits access to information
    - integrity is the assurance that the information is trustworthy and accurate
    - availability is a guarantee of reliable access to the information by authorized people.
  • RIsk Assessment
    Risk assessment is a term used to describe the overall process or method where you:
    - Identify hazards and risk factors that have the potential to cause harm (hazard identification).
    - Analyze and evaluate the risk associated with that hazard (risk analysis, and risk evaluation).
    - Determine appropriate ways to eliminate the hazard, or control the risk when the hazard cannot be eliminated (risk control).
  • Defense in Depth

Redis Horror Story #1

这个故事时关于Redis Wannamine的,就是一种malware或破解口令的恶意攻击。
strong password
monera coin:门罗币
lurk - 潜伏
mishap:不幸的事

Introduction to Information Security Concepts

CIA Triad

confidentiality指只有授权的人可看到信息;integrity指信息在传输过程中未篡改;availability指随时可获取信息。

RIsk Assessment

为什么要做Risk Assessment,因为安全并非保护所有信息,信息也是分级的。Risk Assessment分为5步:

  1. establist context
  2. analyze the situation 评估风险发生带来的影响,如法规遵从,社会声誉,服务不可用等。
  3. evaluate the risk 量化损失,例如IBM的报告表明一个健康记录泄露会导致429美元损失。但声誉,顾客流失等其实是不太好估计的。
  4. risk decision 面对风险,可能有4种抉择。接受/缓解(mitigating)/转移(如保险公司)/避免(如解散项目或完全解决问题)
  5. monitor and review 本身是循环往复的过程。

a risk assessment is “an assessment of the possible mishaps, their likelihood and consequences and your tolerances for such events.”

Defense in Depth

“Attackers only have to be right once, but we have to be right every time.”

Defense in Depth指数据保护的层级结构,类似于洋葱,数据库保护是最后一层。从外到里为防火墙,应用层防护(如补丁),数据库。

一些保护措施包括:

  • 保证软件是最新的,没有漏洞,不要用老版本软件
  • 强认证和细粒度授权
  • 加密
  • Data Loss Prevention,发现数据泄露,监控数据破坏事件

Deploying Redis Securely

3个安装最佳实践:

  1. 使用非root用户安装,例如redis
  2. 限制安装路径访问 (只允许redis访问)
  3. 限制日志,配置和数据文件访问 (只允许redis访问)

这一节演示了一步一步的基于源代码的安装。

Redis Security and Authentication

  • firewall
  • protected mode
  • bind interface

New research shows 75% of ‘open’ Redis servers infected

redis是数据库,因此如果放在公有云上,应放在公有云的内网(如VCN,VPC),并以防火墙保护。

https://www.shodan.io/ 上搜索redis,可发现暴露在公网上的redis。一些可以看到版本等信息,而那些看不到的是因为处于protection mode。

redis默认启动时即为protection mode,即只能为本机上的客户端访问。关闭protection mode,可以修改配置文件:

  1. protected-mode no
  2. bind改为允许外部主机访问

redis 6以前,没有用户的概念,只有一个single global password(require-pass)。

$ grep ^requirepass redis.conf
requirepass foobared

$ redis-server ./redis.conf &

$ redis-cli
127.0.0.1:6379> info
NOAUTH Authentication required.
127.0.0.1:6379> auth foobared
OK

redis 6以后,require-pass还可以用,但应该用ACL替代,默认用户为default。

$ grep ^user redis.conf
user default on >foobared allcommands allkeys

$ redis-cli
127.0.0.1:6379> info
NOAUTH Authentication required.
127.0.0.1:6379> auth default foobared
OK

应使用强口令,不要明码存放口令。产生强口令的一种方法:

$ echo "i like sharing" |sha1sum
dfb485877510659ff25f7d64a43a03fb2cbd84fb  -

Securing Redis Client Code

redis不支持SQL,因此不担心SQL injection。但需要关注key name和Lua script。

key name的惯例为用冒号分开,如session:user:123。对于动态生成的key,需要验证其输入,如digest,以防止敏感数据泄露。

不要基于用户的输入生成Lua script,防止lua script injection。Lua script可以调用外部API,但不应由用户上载和执行。

Security Tip #1: Disaster Recovery and Availability

CIA中的A。手段有:

  • persistence 服务器或进程重启不会丢数据。手段有RDB(快照)或AOF(Append Only File)。
  • replication 一个站点毁坏,数据仍可用。(Sentinal提供HA,企业版支持复制)
  • backup 通常为远程的冷数据副本

来看一些关于RDB和AOF的默认配置:

## RDB的
127.0.0.1:6379> config get dbfilename
1) "dbfilename"
2) "dump.rdb"
127.0.0.1:6379> config get dir
1) "dir"
2) "/home/vagrant/redis-stable"
127.0.0.1:6379> config get save
1) "save"
2) "900 1 300 10 60 10000"

## AOF的
127.0.0.1:6379> config get appendonly
1) "appendonly"
2) "no"
127.0.0.1:6379> config get appendfsync
1) "appendfsync"
2) "everysec"
127.0.0.1:6379> config get auto-aof-rewrite-percentage
1) "auto-aof-rewrite-percentage"
2) "100"
127.0.0.1:6379> config get auto-aof-rewrite-min-size
1) "auto-aof-rewrite-min-size"
2) "67108864"

RDB和AOF都是存于同一目录的,RDB和AOF同时使用可以加快恢复速度,都是在config.conf中设置。

AOF实际使用了fsync函数,appendfsync 参数按性能从低到高,持久化从高到低依次为always,everysec,no。

/etc/logrotate.conf 可设置log rotation,保证空间不被日志撑满。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值