ElastiCache for Redis レプリケーショングループの保管時の暗号化設定の有効化手順

このブログシリーズ 「クラウドセキュリティ 実践集」 では、一般的なセキュリティ課題を取り上げ、「なぜ危険なのか?」 というリスクの解説から、「どうやって直すのか?」 という具体的な修復手順(コンソール、AWS CLI、Terraformなど)まで、分かりやすく解説します。
この記事では、Security Hubで検出された「[ElastiCache.4] ElastiCache レプリケーショングループは保管中に暗号化する必要があります」というセキュリティ課題の修正方法について解説します。

ポリシーの説明
[ElastiCache.4] ElastiCache レプリケーショングループは保管中に暗号化する必要があります
ElastiCache の Security Hub コントロール – AWS Security Hub
このコントロールは、ElastiCache レプリケーショングループが保管中に暗号化されているかどうかをチェックします。レプリケーショングループが保管時に暗号化されていない場合、コントロールは失敗します。
このコントロールは、ElastiCache レプリケーショングループが保管中に暗号化されているかどうかをチェックします。レプリケーショングループが保管時に暗号化されていない場合、コントロールは失敗します。
修復方法
AWSコンソールでの修正手順
既存のRedisレプリケーショングループで保管時の暗号化を後から有効にすることはできません。以下の手順で新しいレプリケーショングループを作成し、データを移行する必要があります。
- ElastiCache > Redis OSS キャッシュ に移動し、対象のキャッシュを選択
- 右上の「アクション」から「バックアップ」を選択し、バックアップを作成する
- バックアップを取得後、内容を確認し保管中の暗号化が「デフォルトの暗号化」となっていることを確認する

- 「アクション」から「復元」をクリックし、デフォルト設定>デフォルト設定をカスタマイズの順にクリックし、セキュリティの欄で「セキュリティ設定をカスタマイズ」を選択
- 暗号化キーを選択し、作成する

- バックアップから復元したキャッシュが暗号化されていることを確認する
Terraformでの修復手順
ElastiCache for Redisレプリケーショングループの保管時暗号化を有効にするためのTerraformコードと、重要な修正ポイントを説明します。
# KMS key for ElastiCache encryption
resource "aws_kms_key" "elasticache" {
description = "KMS key for ElastiCache encryption"
deletion_window_in_days = 7
enable_key_rotation = true
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Sid = "Enable IAM User Permissions"
Effect = "Allow"
Principal = {
AWS = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
}
Action = "kms:*"
Resource = "*"
},
{
Sid = "Allow ElastiCache to use the key"
Effect = "Allow"
Principal = {
Service = "elasticache.amazonaws.com"
}
Action = [
"kms:Decrypt",
"kms:GenerateDataKey",
"kms:CreateGrant"
]
Resource = "*"
}
]
})
tags = var.tags
}
# KMS alias
resource "aws_kms_alias" "elasticache" {
name = "alias/elasticache-${var.environment}"
target_key_id = aws_kms_key.elasticache.key_id
}
# Subnet group for Redis
resource "aws_elasticache_subnet_group" "redis" {
name = "redis-${var.environment}"
description = "Subnet group for Redis cluster"
subnet_ids = var.private_subnet_ids
tags = var.tags
}
# Parameter group for Redis
resource "aws_elasticache_parameter_group" "redis" {
family = "redis6.x"
name = "redis-params-${var.environment}"
# セキュリティ関連のパラメータ
parameter {
name = "maxmemory-policy"
value = "volatile-ttl"
}
tags = var.tags
}
# Security group for Redis
resource "aws_security_group" "redis" {
name = "redis-${var.environment}"
description = "Security group for Redis cluster"
vpc_id = var.vpc_id
ingress {
description = "Redis from application security groups"
from_port = 6379
to_port = 6379
protocol = "tcp"
security_groups = var.allowed_security_group_ids
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = merge(var.tags, {
Name = "redis-${var.environment}"
})
}
# ★重要: Redis replication group with encryption
resource "aws_elasticache_replication_group" "redis" {
replication_group_id = "redis-${var.environment}"
replication_group_description = "Redis cluster for ${var.environment}"
node_type = var.node_type
port = 6379
# ★重要: 保管時の暗号化設定
at_rest_encryption_enabled = true # 保管時の暗号化を有効化
kms_key_id = aws_kms_key.elasticache.arn
# ★重要: 転送時の暗号化も推奨
transit_encryption_enabled = true
auth_token = var.auth_token # 転送時暗号化が有効な場合は必須
# クラスター設定
engine = "redis"
engine_version = var.engine_version
parameter_group_name = aws_elasticache_parameter_group.redis.name
subnet_group_name = aws_elasticache_subnet_group.redis.name
security_group_ids = [aws_security_group.redis.id]
# 可用性設定
num_cache_clusters = var.number_of_nodes
automatic_failover_enabled = true
multi_az_enabled = true
# バックアップ設定
snapshot_retention_limit = var.backup_retention_days
snapshot_window = "03:00-04:00"
maintenance_window = "mon:04:00-mon:05:00"
tags = var.tags
}
# CloudWatch Alarms
resource "aws_cloudwatch_metric_alarm" "redis_cpu" {
alarm_name = "redis-cpu-${var.environment}"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = "3"
metric_name = "CPUUtilization"
namespace = "AWS/ElastiCache"
period = "300"
statistic = "Average"
threshold = "75"
alarm_description = "Redis cluster CPU utilization"
alarm_actions = var.alarm_sns_topic_arns
dimensions = {
CacheClusterId = aws_elasticache_replication_group.redis.id
}
tags = var.tags
}
# Variables
variable "environment" {
description = "Environment name"
type = string
}
variable "vpc_id" {
description = "VPC ID"
type = string
}
variable "private_subnet_ids" {
description = "List of private subnet IDs"
type = list(string)
}
variable "allowed_security_group_ids" {
description = "List of security group IDs allowed to access Redis"
type = list(string)
}
variable "node_type" {
description = "Cache node type"
type = string
default = "cache.t3.medium"
}
variable "engine_version" {
description = "Redis engine version"
type = string
default = "6.x"
}
variable "number_of_nodes" {
description = "Number of cache nodes"
type = number
default = 2
}
variable "auth_token" {
description = "Auth token for Redis authentication"
type = string
sensitive = true
}
variable "backup_retention_days" {
description = "Number of days to retain backups"
type = number
default = 7
}
variable "alarm_sns_topic_arns" {
description = "List of SNS topic ARNs for alarms"
type = list(string)
default = []
}
variable "tags" {
description = "Tags for resources"
type = map(string)
default = {}
}
# Data sources
data "aws_caller_identity" "current" {}
主要な修正ポイントは以下の通りです:
- 保管時暗号化の有効化(最重要):
resource "aws_elasticache_replication_group" "redis" {
# この設定が最も重要
at_rest_encryption_enabled = true
kms_key_id = aws_kms_key.elasticache.arn
}
カスタムKMSキーの設定:
resource "aws_kms_key" "elasticache" {
enable_key_rotation = true
policy = jsonencode({
Statement = [
{
Principal = {
Service = "elasticache.amazonaws.com"
}
Action = [
"kms:Decrypt",
"kms:GenerateDataKey"
]
}
]
})
}
総合的なセキュリティ設定:
resource "aws_elasticache_replication_group" "redis" {
# 転送時の暗号化
transit_encryption_enabled = true
auth_token = var.auth_token
# 高可用性設定
multi_az_enabled = true
automatic_failover_enabled = true
}
使用方法:
- 変数の設定:
# terraform.tfvars
environment = "production"
vpc_id = "vpc-xxxxx"
private_subnet_ids = ["subnet-xxxxx", "subnet-yyyyy"]
allowed_security_groups = ["sg-xxxxx"]
auth_token = "your-auth-token" # 16文字以上
セキュリティ設定:
# セキュリティグループの制限
security_group_ids = [aws_security_group.redis.id]
# プライベートサブネットでの配置
subnet_group_name = aws_elasticache_subnet_group.redis.name
監視とバックアップ:
# バックアップ設定
snapshot_retention_limit = 7
snapshot_window = "03:00-04:00"
# CloudWatch Alarms
resource "aws_cloudwatch_metric_alarm" "redis_cpu" {
# メトリクスの監視
}
この設定により:
- データの保管時暗号化
- 転送時の暗号化
- セキュアなネットワーク設定
- 監視とアラート
が実現されます。
注意:
- 既存の非暗号化クラスターは新規作成が必要
- 暗号化の変更には新しいクラスターの作成が必要
- KMS使用による追加コストの考慮が必要
最後に
今回は、ElastiCacheレプリケーショングループの保管時の暗号化を有効にする方法についてご紹介しました。保管時の暗号化は、保存されたデータを保護するための重要なセキュリティ対策です。
この問題の検出は弊社が提供するSecurifyのCSPM機能で簡単に検出及び管理する事が可能です。
運用が非常に楽に出来る製品になっていますので、ぜひ興味がある方はお問い合わせお待ちしております。
最後までお読みいただきありがとうございました。この記事が皆さんの役に立てば幸いです。