ElastiCache for Redis クラスターの自動マイナーバージョンアップグレード設定有効化の手順

このブログシリーズ 「クラウドセキュリティ 実践集」 では、一般的なセキュリティ課題を取り上げ、「なぜ危険なのか?」 というリスクの解説から、「どうやって直すのか?」 という具体的な修復手順(コンソール、AWS CLI、Terraformなど)まで、分かりやすく解説します。

この記事では、Security Hubで検出された「[ElastiCache.2] ElastiCache クラスターでは、マイナーバージョンの自動アップグレードを有効にする必要があります」というセキュリティ課題の修正方法について解説します。

ポリシーの説明

[ElastiCache.2] ElastiCache クラスターでは、マイナーバージョンの自動アップグレードを有効にする必要があります

ElastiCache の Security Hub コントロール – AWS Security Hub

このコントロールは、Amazon ElastiCache がキャッシュクラスターにマイナーバージョンアップグレードを自動的に適用するかどうかを評価します。キャッシュクラスターにマイナーバージョンアップグレードが自動的に適用されていない場合、コントロールは失敗します。

ElastiCacheは、頻繁にセキュリティアップデートやパフォーマンス改善を含むマイナーバージョンをリリースします。自動アップグレードを有効にすることで、これらの重要な修正を自動的に適用し、手動でのメンテナンス作業を減らしつつ、クラスターのセキュリティと安定性を維持できます。

修復方法

AWSコンソールでの修正手順

  1. ElastiCache > Redis OSS キャッシュに移動します。
  2. 対象のキャッシュ名を選択後、「アクション」から変更を選択
  3. メンテナンスの項目でマイナーバージョンの自動アップグレードの「有効化」にチェックする
  4. チェック後、変更をプレビューで変更内容に問題ければ「変更する」を選択

Terraformでの修復手順

ElastiCache for Redisクラスターの自動マイナーバージョンアップグレードを有効にするためのTerraformコードと、重要な修正ポイントを説明します。

# KMS key for 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
}

# 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" # 例: "6.2" などメジャー.マイナーを固定し、パッチだけ自動更新
  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 auto minor version upgrade
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

  # ★重要: バージョン設定
  engine               = "redis"
  engine_version      = var.engine_version

  # ★重要: 自動マイナーバージョンアップグレードの有効化
  auto_minor_version_upgrade = true

  # ★重要: メンテナンス設定
  maintenance_window         = "mon:03:00-mon:04:00"
  notification_topic_arn    = var.sns_topic_arn

  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]

  # 暗号化設定
  at_rest_encryption_enabled = true
  transit_encryption_enabled = true
  kms_key_id                = aws_kms_key.elasticache.arn
  auth_token                = var.auth_token

  # クラスター設定
  num_cache_clusters       = var.number_of_nodes
  automatic_failover_enabled = true
  multi_az_enabled        = true

  # バックアップ設定
  snapshot_retention_limit = 7
  snapshot_window         = "02:00-03:00"

  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 = "ElastiCache 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 "sns_topic_arn" {
  description = "SNS topic ARN for notifications"
  type        = string
}

variable "tags" {
  description = "Tags for resources"
  type        = map(string)
  default     = {}
}

# Data sources
data "aws_caller_identity" "current" {}

主要な修正ポイントは以下の通りです:

  1. 自動マイナーバージョンアップグレードの有効化(最重要):
resource "aws_elasticache_replication_group" "redis" {
  # この設定が最も重要
  auto_minor_version_upgrade = true
}

エンジンバージョンとメンテナンス設定:

# バージョン設定
engine_version      = "6.x"  # 最新の安定バージョンを使用

# メンテナンス設定
maintenance_window = "mon:03:00-mon:04:00"
notification_topic_arn = var.sns_topic_arn

この設定により:

  • 自動マイナーバージョンアップグレード
  • セキュリティパッチの自動適用
  • バージョン更新の通知
  • バックアップと復旧の確保

が実現されます。

注意:

  • メンテナンスウィンドウはアプリケーションの低負荷時間帯に設定
  • クラスターモード有効 (sharding) の場合、自動マイナーアップグレードは現状適用されません。バージョン管理は手動で行ってください
  • 自動アップグレード前にテスト環境での検証を推奨
  • バージョンアップグレードの影響を考慮したアプリケーション設計が必要

最後に

今回は、ElastiCacheクラスターまたはレプリケーショングループでマイナーバージョンの自動アップグレードを有効にする方法についてご紹介しました。自動アップグレードを有効にすることで、セキュリティリスクを低減し、クラスターの安定性を向上させることができます。

この問題の検出は弊社が提供するSecurifyのCSPM機能で簡単に検出及び管理する事が可能です。

運用が非常に楽に出来る製品になっていますので、ぜひ興味がある方はお問い合わせお待ちしております。

最後までお読みいただきありがとうございました。この記事が皆さんの役に立てば幸いです

この記事をシェアする

クラウドセキュリティ対策実践集一覧へ戻る

貴社の利用状況に合わせた見積もりを作成します。

料金プランを詳しく見る