🙆♀️
Cloud Armor DDOS 対策
Cloud ArmorでのDDoS対策設定について説明します。
modules/security/cloud_armor.tf
resource "google_compute_security_policy" "policy" {
name = "ddos-protection-policy"
description = "DDoS保護のためのセキュリティポリシー"
# デフォルトルール(最後に評価)
rule {
action = "deny(403)"
priority = "2147483647"
match {
versioned_expr = "SRC_IPS_V1"
config {
src_ip_ranges = ["*"]
}
}
description = "デフォルト拒否ルール"
}
# 許可されたIPレンジ
rule {
action = "allow"
priority = "1000"
match {
versioned_expr = "SRC_IPS_V1"
config {
src_ip_ranges = var.allowed_ip_ranges
}
}
description = "社内IPを許可"
}
# レートリミット - グローバルしきい値
rule {
action = "rate_based_ban"
priority = "1100"
match {
versioned_expr = "SRC_IPS_V1"
config {
src_ip_ranges = ["*"]
}
}
rate_limit_options {
rate_limit_threshold {
count = 100 # 1分間あたりの最大リクエスト数
interval_sec = 60
}
conform_action = "allow"
exceed_action = "deny(429)"
enforce_on_key = "IP"
ban_duration_sec = 300 # 5分間のブロック
}
description = "レートリミットルール"
}
# L7 DDoS防御
rule {
action = "deny(403)"
priority = "1200"
match {
expr {
expression = "evaluatePreconfiguredExpr('xss-stable')"
}
}
description = "XSS攻撃の防止"
}
rule {
action = "deny(403)"
priority = "1300"
match {
expr {
expression = "evaluatePreconfiguredExpr('sqli-stable')"
}
}
description = "SQLインジェクション防止"
}
# HTTPフラッド防止
rule {
action = "rate_based_ban"
priority = "1400"
match {
expr {
expression = "request.method == 'POST'"
}
}
rate_limit_options {
rate_limit_threshold {
count = 50 # POSTリクエストの制限
interval_sec = 60
}
conform_action = "allow"
exceed_action = "deny(429)"
enforce_on_key = "IP"
ban_duration_sec = 300
}
description = "HTTPフラッド防止"
}
# 不審なUser-Agentのブロック
rule {
action = "deny(403)"
priority = "1500"
match {
expr {
expression = "!has(request.headers['user-agent']) || request.headers['user-agent'].contains('bot') || request.headers['user-agent'].contains('crawler')"
}
}
description = "不審なUser-Agentをブロック"
}
# 地理的制限(必要な場合)
rule {
action = "deny(403)"
priority = "1600"
match {
expr {
expression = "origin.region_code == 'KP'"
}
}
description = "特定地域からのアクセスをブロック"
}
# OWASP Top 10対策
rule {
action = "deny(403)"
priority = "1700"
match {
expr {
expression = "evaluatePreconfiguredExpr('rce-stable')"
}
}
description = "リモートコード実行の防止"
}
# アダプティブプロテクション設定
adaptive_protection_config {
layer_7_ddos_defense_config {
enable = true
rule_visibility = "STANDARD"
}
}
# JSON/YAMLペイロード検査
rule {
action = "deny(403)"
priority = "1800"
match {
expr {
expression = "request.headers['content-type'].contains('application/json') && request.body.size > 8192"
}
}
description = "JSONペイロードサイズの制限"
}
}
# WAFログ設定
resource "google_logging_project_sink" "cloud_armor_logs" {
name = "cloud-armor-logs"
destination = "storage.googleapis.com/${google_storage_bucket.security_logs.name}"
filter = "resource.type=\"http_load_balancer\" AND jsonPayload.enforcedSecurityPolicy.name=\"${google_compute_security_policy.policy.name}\""
unique_writer_identity = true
}
resource "google_storage_bucket" "security_logs" {
name = "cloud-armor-security-logs"
location = "ASIA-NORTHEAST1"
force_destroy = true
lifecycle_rule {
condition {
age = 90
}
action {
type = "Delete"
}
}
}
主なDDoS対策機能:
-
レートリミット:
- IP毎のリクエスト数制限
- 超過時の一時的ブロック
-
L7 DDoS防御:
- XSS攻撃対策
- SQLインジェクション対策
- リモートコード実行対策
-
HTTPフラッド対策:
- POSTリクエストの制限
- 大量リクエストのブロック
-
アダプティブプロテクション:
- 機械学習による異常トラフィック検知
- 自動対応
-
地理的制限:
- 特定地域からのアクセスブロック
-
ペイロード検査:
- JSON/YAMLペイロードサイズ制限
- 異常なペイロードのブロック
-
ログ記録とモニタリング:
- セキュリティイベントのログ記録
- 90日間のログ保持
これらの設定により:
- Layer 7 DDoS攻撃からの防御
- 自動化された攻撃の検知とブロック
- 正常なトラフィックの保護
- 詳細なセキュリティログの記録
が実現できます。
Discussion