説明
Fargate の assign_public_ip: true は各タスクにパブリック IPv4 アドレスを要求します。直接接続にはインターネットゲートウェイへの経路とセキュリティグループの許可が必要です。アプリケーションの認証は別途適用されます。
想定される影響
直接接続するトラフィックには、ロードバランサーのアクセス制御が適用されません。
対処方法
直接公開が不要ならプライベートサブネットで assign_public_ip: false を指定します。イメージ取得、ログ送信、外部呼び出しに必要な NAT や対応する VPC エンドポイントを先に用意してください。ロードバランサーからの通信を制限し、デプロイ後は IPv6 を含む実際の接続を確認します。
例
クラスター、awsvpc のタスク定義、実際のサブネットとセキュリティグループが必要です。
変更前
yaml
- name: ECS 서비스 생성
community.aws.ecs_service:
state: present
name: example-public-ip-service
cluster: my-ecs-cluster
task_definition: my-task-def:1
desired_count: 2
launch_type: FARGATE
network_configuration:
subnets:
- subnet-aaaa1111
- subnet-bbbb2222
security_groups:
- sg-cccc3333
assign_public_ip: true
変更後
yaml
- name: ECS 서비스 생성
community.aws.ecs_service:
state: present
name: example-private-service
cluster: my-ecs-cluster
task_definition: my-task-def:1
desired_count: 2
launch_type: FARGATE
network_configuration:
subnets:
- subnet-aaaa1111
- subnet-bbbb2222
security_groups:
- sg-cccc3333
assign_public_ip: false
example-private-service は別のサービスです。既存の example-public-ip-service への公開経路をなくすには、そのサービスを別途変更または廃止してください。