Ubuntu 22.04
Sponsored Link

Redis 6 : SSL/TLS の設定2022/09/09

 
Redis で SSL/TLS による暗号化通信の設定を有効にします。
[1] 自己署名の証明書を作成します。Let's Encrypt 等の正規の証明書を使用する場合は当作業は不要です。
root@dlp:~#
cd /etc/ssl/private

root@dlp:/etc/ssl/private#
openssl req -x509 -nodes -newkey rsa:2048 -keyout redis.pem -out redis.pem -days 3650

Generating a RSA private key
.................+++++
........+++++
writing new private key to 'vsftpd.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:JP                            # 国コード
State or Province Name (full name) [Some-State]:Hiroshima       # 地域(県)
Locality Name (eg, city) []:Hiroshima                           # 都市
Organization Name (eg, company) [Internet Widgits Pty Ltd]:GTS  # 組織名
Organizational Unit Name (eg, section) []:Server World          # 組織の部門名
Common Name (e.g. server FQDN or YOUR name) []:dlp.srv.world    # サーバーの FQDN
Email Address []:root@srv.world                                 # 管理者アドレス

root@dlp:/etc/ssl/private#
chmod 600 redis.pem

[2] Redis の SSL/TLS の設定です。
root@dlp:~#
cp /etc/ssl/private/redis.pem /etc/redis/

root@dlp:~#
chown redis. /etc/redis/redis.pem

root@dlp:~#
vi /etc/redis/redis.conf
# 91行目 : 変更 : [0] 指定でリスン無効化

port
0
# 138行目 : コメント解除

tls-port 6379
# 144,145行目 : コメント解除して証明書を指定

tls-cert-file
/etc/redis/redis.pem

tls-key-file
/etc/redis/redis.pem
# 156行目 : コメント解除

tls-ca-cert-dir /etc/ssl/certs
# 165行目 : コメント解除

tls-auth-clients no
root@dlp:~#
systemctl restart redis

[3] クライアントからの接続です。他ホストから接続する場合は、事前に証明書をクライアントへ転送しておく必要があります。
root@node01:~#
ll /etc/redis

total 96
-rw-r-----   1 redis redis 85844 Mar  4  2022 redis.conf
-rw-------   1 redis redis  3160 Sep  9 02:01 redis.pem

# [tls] オプションと証明書を指定して接続する
root@node01:~# redis-cli -h dlp.srv.world --tls \
--cert /etc/redis/redis.pem \
--key /etc/redis/redis.pem \
--cacert /etc/redis/redis.pem

dlp.srv.world:6379> auth password 
OK
dlp.srv.world:6379> info
# Server
redis_version:6.0.16
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:a3fdef44459b3ad6
redis_mode:standalone
os:Linux 5.15.0-25-generic x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:11.2.0
process_id:12733
run_id:af822cba1ec1b6d60211ecb26d6877c9292cb364
tcp_port:6379
uptime_in_seconds:18
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:1744616
executable:/usr/bin/redis-server
config_file:/etc/redis/redis.conf
io_threads_active:0
.....
.....
関連コンテンツ