インターネット通信が制限された環境でエージェントをインストールしたくてやったこと

記事タイトルとURLをコピーする

この記事は約6分で読めます。

この記事は1年以上前に書かれたものです。
内容が古い可能性がありますのでご注意ください。

エンタープライズクラウド部の松田です。こんにちは。

今回は業務で行った技術検証の記録になります。
少々雑多な記事になりますがお付き合い頂けますと幸いです。

やりたいこと

  • EC2インスタンスをSSMマネージドノードにしたい
  • EC2インスタンスのOSログをCloudWatch Logsに出力したい

です。

一見簡単ですが、以下の前提があります。

  • EC2インスタンスはRocky Linux 9を採用
  • インターネット向けの通信は明示的に許可したドメイン以外は通信不可(Network FirewallによりBlock)
  • EC2へのログインにはSession Managerを使用すること

言い換えると、要求を実現するために次のような課題があります。

  1. SSMエージェントとCloudWatchエージェントをどうやってインストールするか?
  2. SSMおよびCloudWatchのエンドポイントへの通信経路をどう準備するか?

各課題に対し、どのようにアプローチするかを考えます。

1. 各エージェントをどうやってインストールするか

今回採用したRocky LinuxのAMIにはSSMエージェントがプリインストールされていないため、ユーザー側でインストールする必要があります。インストールのためにログインしようにも、今回EC2インスタンスはプライベートサブネットに配置するため、直接SSHで接続することはできません。また、エージェントをインストールするためだけに踏み台を起動するのも面倒です。

ということで今回は、ユーザーデータでSSMエージェントとCloudWatchエージェントをインストールすることにします。

2. SSMおよびCloudWatchのエンドポイントへの通信経路をどう準備するか

Network Firewallで通信を許可するか、VPCエンドポイントを使用するかの2択があり得そうです。

明確に優劣はありませんが、今回はVPCエンドポイントを使うことにします。

やったこと

環境準備

検証用に、以下の環境を準備します。

VPCエンドポイントを配置することで、インターネットを介さず(言い換えればNetwork Firewallで検査されることなく)必要なAWSエンドポイントに到達できます。 配置したVPCエンドポイントと、用途は以下の通りです。

VPCエンドポイント
(サービス名)
用途
SSM Messeges
(com.amazonaws.ap-northeast-1.ssmmessages)
セッションマネージャー用
EC2 Messages
(com.amazonaws.ap-northeast-1.ec2messages)
セッションマネージャー用
SSM
(com.amazonaws.ap-northeast-1.ssm)
セッションマネージャー用
パラメータストアからCloudWatchエージェントのコンフィグを取得する用
CloudWatch Logs
(com.amazonaws.ap-northeast-1.logs)
CloudWatch LogsにOSログを出力する用
S3
(com.amazonaws.ap-northeast-1.s3)
SSMエージェントおよびCloudWatchエージェントのインストーラをダウンロードする用
※これだけGateway型

なお環境構築に使用したCloudFormationテンプレートは本記事末に記載しています。

ネットワークの確認

まずはルーティングが意図した通りに設定されているかを確認するため、サブネット「protected-a」にAmazon Linux 2023のインスタンスを起動し、セッションマネージャーで接続できるか確認したところ、問題なく接続できました。

このことから、以下のことが言えます。

  • EC2に付与するIAMロール(の権限)が正しいこと。
  • 「protected-a」から以下のAWSのエンドポイントに到達できること。
    • ssm
    • ssmmessages
    • ec2messages

なおこの時点では、インターネット向けの通信は全てNetwork FirewallによりBlockされる設定としていたため、インターネットを介してAWSのエンドポイントに到達できない状態でした。

AWSのエンドポイントへのアクセスが全てVPCエンドポイントを経由することを確認するため、念のため名前解決を行いましたが、プライベートIPアドレスが返ってきたので問題なさそうです。

[ssm-user@ip-10-156-64-80 ~]$ nslookup ssm.ap-northeast-1.amazonaws.com
Server:         10.156.64.2
Address:        10.156.64.2#53
Non-authoritative answer:
Name:   ssm.ap-northeast-1.amazonaws.com
Address: 10.156.64.73
Name:   ssm.ap-northeast-1.amazonaws.com
Address: 10.156.64.206

[ssm-user@ip-10-156-64-80 ~]$ nslookup ssmmessages.ap-northeast-1.amazonaws.com
Server:         10.156.64.2
Address:        10.156.64.2#53
Non-authoritative answer:
Name:   ssmmessages.ap-northeast-1.amazonaws.com
Address: 10.156.64.214
Name:   ssmmessages.ap-northeast-1.amazonaws.com
Address: 10.156.64.78

[ssm-user@ip-10-156-64-80 ~]$ nslookup ec2messages.ap-northeast-1.amazonaws.com
Server:         10.156.64.2
Address:        10.156.64.2#53
Non-authoritative answer:
Name:   ec2messages.ap-northeast-1.amazonaws.com
Address: 10.156.64.85
Name:   ec2messages.ap-northeast-1.amazonaws.com
Address: 10.156.64.200

Rocky Linuxで確認

上記のAmazon Linuxから、Rocky LinuxにSSH接続して色々確認します。

まず、SSMエージェントのインストーラがダウンロードできるか確認しておきます。SSMエージェントのインストーラがあるディレクトリにはS3エンドポイントからアクセスできるため、VPCエンドポイントがあればダウンロードできるはずです。

[ssm-user@ip-10-156-64-80 ~]$ curl -OL https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:23 --:--:--     0
curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to s3.amazonaws.com:443

できない。。。

ということで色々調べてみたところ、S3のGateway型エンドポイントのサービス名がそもそも com.amazonaws.ap-northeast-1.s3 だということに気付きました。上記では s3.amazonaws.com に対して curl を実行していたため、VPCエンドポイントでなくインターネットに通信が向いてしまい、Network FirewallによってBlockされていたようです。

ドキュメントをよく読むと、S3のサービスエンドポイントは、リージョンを明示的に指定する形式に置き換えが可能でしたので、URLを書き換えて改めてダウンロードしてみます。

curl -OL https://s3.ap-northeast-1.amazonaws.com/amazon-ssm-ap-northeast-1/latest/linux_arm64/amazon-ssm-agent.rpm

うまくいきました。

続いて、CloudWatchエージェントのインストーラも以下でダウンロードできました。こちらもS3からのダウンロードなので、明示的にリージョンを指定します。(参考)。

curl -OL https://amazoncloudwatch-agent-ap-northeast-1.s3.ap-northeast-1.amazonaws.com/redhat/arm64/latest/amazon-cloudwatch-agent.rpm

ついでに確認したこと

Rocky Linuxで yum update できるようにしたいので、Network Firewallで必要なドメインを許可する必要があります。とはいえどのドメインを許可すればよいか分からなかったので調べてみました。

色々調べた結果、/etc/yum.repos.d/ ディレクトリ内のファイルに書いてあった次のドメインをとりあえず許可してみることにしました。

  • mirrors.rockylinux.org
  • dl.rockylinux.org

この状態で一度 yum update してみます。

[rocky@ip-10-156-64-71 ~]$ sudo yum update
^CRocky Linux 9 - BaseOS                                                                    [                                                   ===                               ] ---  B/s |   0  B     --:-- ETRocky Linux 9 - BaseOS                                                                                                                                                            0.0  B/s |   0  B     05:34
Errors during downloading metadata for repository 'baseos':
  - Curl error (28): Timeout was reached for http://mirror.nishi.network/rocky/9.3/BaseOS/aarch64/os/repodata/repomd.xml [Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds]
  - Curl error (28): Timeout was reached for http://mirror-nrt.yuki.net.uk/rockylinux/9.3/BaseOS/aarch64/os/repodata/repomd.xml [Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds]
  - Curl error (28): Timeout was reached for http://repo.jing.rocks/rocky/9.3/BaseOS/aarch64/os/repodata/repomd.xml [Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds]
  - Curl error (28): Timeout was reached for http://ftp.ubuntu-tw.net/mirror/rockylinux/9.3/BaseOS/aarch64/os/repodata/repomd.xml [Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds]
  - Curl error (28): Timeout was reached for https://ftp.jaist.ac.jp/pub/Linux/rocky/9.3/BaseOS/aarch64/os/repodata/repomd.xml [Operation timed out after 30000 milliseconds with 0 out of 0 bytes received]
  - Curl error (35): SSL connect error for https://rocky-linux-asia-northeast2.production.gcp.mirrors.ctrliq.cloud/pub/rocky//9.3/BaseOS/aarch64/os/repodata/repomd.xml [error:0A000126:SSL routines::unexpected eof while reading]
  - Curl error (28): Timeout was reached for http://mirrors.asnet.am/rockylinux/9.3/BaseOS/aarch64/os/repodata/repomd.xml [Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds]
  - Curl error (28): Timeout was reached for https://ftp.iij.ad.jp/pub/linux/rocky/9.3/BaseOS/aarch64/os/repodata/repomd.xml [Operation timed out after 30000 milliseconds with 0 out of 0 bytes received]
  - Curl error (28): Timeout was reached for http://mirror.ossplanet.net/mirror/rockylinux/9.3/BaseOS/aarch64/os/repodata/repomd.xml [Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds]
  - Curl error (35): SSL connect error for https://rocky-linux-asia-northeast1.production.gcp.mirrors.ctrliq.cloud/pub/rocky//9.3/BaseOS/aarch64/os/repodata/repomd.xml [error:0A000126:SSL routines::unexpected eof while reading]
  - Curl error (28): Timeout was reached for http://mirrors.ipserverone.com/rocky/9.3/BaseOS/aarch64/os/repodata/repomd.xml [Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds]
  - Curl error (28): Timeout was reached for http://ftp.udx.icscoe.jp/Linux/rocky/9.3/BaseOS/aarch64/os/repodata/repomd.xml [Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds]
Error: Failed to download metadata for repo 'baseos': Librepo was interrupted by a signal

残念ながらエラーになってしまいましたが、アクセスがBlockされたドメインを出力してくれたので、追加で以下のドメインを許可してリトライしてたところ、上手くいきました。

  • mirror.nishi.network
  • mirror-nrt.yuki.net.uk
  • repo.jing.rocks
  • ftp.ubuntu-tw.net
  • ftp.jaist.ac.jp
  • rocky-linux-asia-northeast2.production.gcp.mirrors.ctrliq.cloud
  • mirrors.asnet.am
  • ftp.iij.ad.jp
  • mirror.ossplanet.net
  • rocky-linux-asia-northeast1.production.gcp.mirrors.ctrliq.cloud
  • mirrors.ipserverone.com
  • ftp.udx.icscoe.jp

ユーザーデータでインストール

ここまでの確認で、少なくとも手動ではSSMエージェントとCloudWatchエージェントをインストールできる状況だということが分かりました。最後にユーザーデータを使って、EC2起動時に初めから各エージェントがインストールされた状態に持って行けるか確認します。

ユーザーデータは以下としました。

#!/bin/bash
sudo yum update -y
sudo dnf install -y https://s3.ap-northeast-1.amazonaws.com/amazon-ssm-ap-northeast-1/latest/linux_arm64/amazon-ssm-agent.rpm
curl -OL https://amazoncloudwatch-agent-ap-northeast-1.s3.ap-northeast-1.amazonaws.com/redhat/arm64/latest/amazon-cloudwatch-agent.rpm
sudo rpm -U ./amazon-cloudwatch-agent.rpm
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c ssm:cw-agent-config-rocky9

なお事前にSSMパラメータストアで cw-agent-config-rocky9 という名前で以下のパラメータを作成しています。ここではCloudWatch LogsにOSログを出力する設定だけ入れています。

{
"logs": {
"logs_collected": {
"files": {
"collect_list": [
{
"file_path": "/var/log/**.log",
"log_group_name": "rocky9",
"log_stream_name": "{instance_id}",
"retention_in_days": 731
}
]
}
}
}
}

EC2を起動後、何も設定せずともセッションマネージャーで接続できました。

CloudWatch Logsロググループへのログ出力も正常に行われていました。

ということで、ユーザーデータで各エージェントを無事インストールできました。

まとめ

検証の記録は以上です。

S3のVPCエンドポイントを利用する際はリージョンを明示的に指定する必要がある、というのは地味ながら要注意かもですね。

ここまでお付き合い頂き、ありがとうございました。

おまけ

検証環境の構築に使ったCloudFormationテンプレートを載せておきます。

ルートを設定するテンプレート(route.yaml)とそれ以外(network.yaml)とで、2つのテンプレートに分けています。ルートの記述でNetwork FirewallのエンドポイントIDを指定する必要があるのですが、カスタムリソースを使わないとIDが取得できなかったため、もうめんどくさくなって手動でIDを拾ってパラメータとして渡すやり方にしています。結果テンプレートが2つになりました。

ちなみにEC2インスタンスは含まれませんのでご了承ください。

  • network.yaml
AWSTemplateFormatVersion: '2010-09-09'
Resources:
##########################
# Network Settings
##########################
# VPCs
Vpc:
Type: 'AWS::EC2::VPC'
DeletionPolicy: Delete
Properties:
CidrBlock: 10.156.64.0/24
EnableDnsHostnames: 'true'
EnableDnsSupport: 'true'
Tags:
- Key: Name
Value: vpc
# Subnets
SubnetPublicA:
Type: 'AWS::EC2::Subnet'
DeletionPolicy: Delete
Properties:
VpcId: !Ref Vpc
AvailabilityZone: ap-northeast-1a
CidrBlock: 10.156.64.32/27
MapPublicIpOnLaunch: 'false'
Tags:
- Key: Name
Value: subnet-public-a
SubnetPublicC:
Type: 'AWS::EC2::Subnet'
DeletionPolicy: Delete
Properties:
VpcId: !Ref Vpc
AvailabilityZone: ap-northeast-1c
CidrBlock: 10.156.64.160/27
MapPublicIpOnLaunch: 'false'
Tags:
- Key: Name
Value: subnet-public-c
SubnetInspectionA:
Type: 'AWS::EC2::Subnet'
DeletionPolicy: Delete
Properties:
VpcId: !Ref Vpc
AvailabilityZone: ap-northeast-1a
CidrBlock: 10.156.64.0/27
MapPublicIpOnLaunch: 'false'
Tags:
- Key: Name
Value: subnet-inspection-a
SubnetInspectionC:
Type: 'AWS::EC2::Subnet'
DeletionPolicy: Delete
Properties:
VpcId: !Ref Vpc
AvailabilityZone: ap-northeast-1c
CidrBlock: 10.156.64.128/27
MapPublicIpOnLaunch: 'false'
Tags:
- Key: Name
Value: subnet-inspection-c
SubnetProtectedA:
Type: 'AWS::EC2::Subnet'
DeletionPolicy: Delete
Properties:
VpcId: !Ref Vpc
AvailabilityZone: ap-northeast-1a
CidrBlock: 10.156.64.64/27
MapPublicIpOnLaunch: 'false'
Tags:
- Key: Name
Value: subnet-protected-a
SubnetProtectedC:
Type: 'AWS::EC2::Subnet'
DeletionPolicy: Delete
Properties:
VpcId: !Ref Vpc
AvailabilityZone: ap-northeast-1c
CidrBlock: 10.156.64.192/27
MapPublicIpOnLaunch: 'false'
Tags:
- Key: Name
Value: subnet-protected-c
# Gateways
Igw:
Type: 'AWS::EC2::InternetGateway'
DeletionPolicy: Delete
Properties:
Tags:
- Key: Name
Value: igw
IgwAttach:
Type: 'AWS::EC2::VPCGatewayAttachment'
DeletionPolicy: Delete
Properties:
VpcId: !Ref Vpc
InternetGatewayId: !Ref Igw
NgwA:
Type: 'AWS::EC2::NatGateway'
DeletionPolicy: Delete
Properties:
AllocationId: !GetAtt
- EipNgwA
- AllocationId
SubnetId: !Ref SubnetPublicA
Tags:
- Key: Name
Value: nat-a
EipNgwA:
Type: 'AWS::EC2::EIP'
DeletionPolicy: Delete
Properties:
Domain: vpc
NgwC:
Type: 'AWS::EC2::NatGateway'
DeletionPolicy: Delete
Properties:
AllocationId: !GetAtt
- EipNgwC
- AllocationId
SubnetId: !Ref SubnetPublicC
Tags:
- Key: Name
Value: nat-c
EipNgwC:
Type: 'AWS::EC2::EIP'
DeletionPolicy: Delete
Properties:
Domain: vpc
# Route tables
## For public subnets
RtbPublicA:
Type: 'AWS::EC2::RouteTable'
DeletionPolicy: Delete
Properties:
VpcId: !Ref Vpc
Tags:
- Key: Name
Value: rtb-public-a
AssociationRtbPublicA:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
DeletionPolicy: Delete
Properties:
SubnetId: !Ref SubnetPublicA
RouteTableId: !Ref RtbPublicA
RtbPublicC:
Type: 'AWS::EC2::RouteTable'
DeletionPolicy: Delete
Properties:
VpcId: !Ref Vpc
Tags:
- Key: Name
Value: rtb-public-c
AssociationRtbPublicC:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
DeletionPolicy: Delete
Properties:
SubnetId: !Ref SubnetPublicC
RouteTableId: !Ref RtbPublicC
## For inspection subnets
RtbInspectionA:
Type: 'AWS::EC2::RouteTable'
DeletionPolicy: Delete
Properties:
VpcId: !Ref Vpc
Tags:
- Key: Name
Value: rtb-inspection-a
AssociationRtbInspectionA:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
DeletionPolicy: Delete
Properties:
SubnetId: !Ref SubnetInspectionA
RouteTableId: !Ref RtbInspectionA
RtbInspectionC:
Type: 'AWS::EC2::RouteTable'
DeletionPolicy: Delete
Properties:
VpcId: !Ref Vpc
Tags:
- Key: Name
Value: rtb-inspection-c
AssociationRtbInspectionC:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
DeletionPolicy: Delete
Properties:
SubnetId: !Ref SubnetInspectionC
RouteTableId: !Ref RtbInspectionC
## For protected subnets
RtbProtectedA:
Type: 'AWS::EC2::RouteTable'
DeletionPolicy: Delete
Properties:
VpcId: !Ref Vpc
Tags:
- Key: Name
Value: rtb-protected-a
AssociationRtbProtectedA:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
DeletionPolicy: Delete
Properties:
SubnetId: !Ref SubnetProtectedA
RouteTableId: !Ref RtbProtectedA
RtbProtectedC:
Type: 'AWS::EC2::RouteTable'
DeletionPolicy: Delete
Properties:
VpcId: !Ref Vpc
Tags:
- Key: Name
Value: rtb-protected-c
AssociationRtbProtectedC:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
DeletionPolicy: Delete
Properties:
SubnetId: !Ref SubnetProtectedC
RouteTableId: !Ref RtbProtectedC
##########################
# VPC Endpoints
##########################
# s3 endpoint
VpceS3:
Type: AWS::EC2::VPCEndpoint
Properties:
RouteTableIds:
- !Ref RtbProtectedA
- !Ref RtbProtectedC
ServiceName: com.amazonaws.ap-northeast-1.s3
VpcEndpointType: Gateway
VpcId: !Ref Vpc
# ssm endpoint
VpceSSM:
Type: AWS::EC2::VPCEndpoint
Properties:
PrivateDnsEnabled: true
SecurityGroupIds:
- !Ref ScgForEndpoint
ServiceName: com.amazonaws.ap-northeast-1.ssm
SubnetIds:
- !Ref SubnetProtectedA
- !Ref SubnetProtectedC
VpcEndpointType: Interface
VpcId: !Ref Vpc
# ec2 messages endpoint
VpceEC2messages:
Type: AWS::EC2::VPCEndpoint
Properties:
PrivateDnsEnabled: true
SecurityGroupIds:
- !Ref ScgForEndpoint
ServiceName: com.amazonaws.ap-northeast-1.ec2messages
SubnetIds:
- !Ref SubnetProtectedA
- !Ref SubnetProtectedC
VpcEndpointType: Interface
VpcId: !Ref Vpc
# ssm messages endpoint
VpceSSMessages:
Type: AWS::EC2::VPCEndpoint
Properties:
PrivateDnsEnabled: true
SecurityGroupIds:
- !Ref ScgForEndpoint
ServiceName: com.amazonaws.ap-northeast-1.ssmmessages
SubnetIds:
- !Ref SubnetProtectedA
- !Ref SubnetProtectedC
VpcEndpointType: Interface
VpcId: !Ref Vpc
# cloudwatch logs endpoint
VpceLogs:
Type: AWS::EC2::VPCEndpoint
Properties:
PrivateDnsEnabled: true
SecurityGroupIds:
- !Ref ScgForEndpoint
ServiceName: com.amazonaws.ap-northeast-1.logs
SubnetIds:
- !Ref SubnetProtectedA
- !Ref SubnetProtectedC
VpcEndpointType: Interface
VpcId: !Ref Vpc
# Security Group for VPC Endpoint
ScgForEndpoint:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: for VPC Endpoint
GroupName: scg-vpc-endpoint
SecurityGroupIngress:
- CidrIp: 10.156.0.0/16
FromPort: 443
ToPort: 443
IpProtocol: tcp
SecurityGroupEgress:
- CidrIp: 0.0.0.0/0
IpProtocol: -1
Tags:
- Key: Name
Value: scg-vpc-endpoint
VpcId: !Ref Vpc
##########################
# Firewall settings
##########################
# Network firewall
NetworkFirewall:
Type: AWS::NetworkFirewall::Firewall
Properties:
DeleteProtection: True
Description: 'Shared Network Firewall'
FirewallName: nfw
FirewallPolicyArn: !Ref FirewallPolicy01
FirewallPolicyChangeProtection: False
SubnetChangeProtection: True
SubnetMappings:
- SubnetId: !Ref SubnetInspectionA
IPAddressType: IPV4
- SubnetId: !Ref SubnetInspectionC
IPAddressType: IPV4
Tags:
- Key: Name
Value: nfw-cbsi-prd-inspection
VpcId: !Ref Vpc
# Firewall Policy
FirewallPolicy01:
Type: AWS::NetworkFirewall::FirewallPolicy
Properties:
Description: 'for nfw-cbsi-prd-inspection'
FirewallPolicy:
StatefulDefaultActions:
- aws:drop_established
- aws:alert_established
StatefulEngineOptions:
RuleOrder: STRICT_ORDER
StatefulRuleGroupReferences:
- Priority: 1
ResourceArn: !Ref Fullopen
StatelessDefaultActions:
- aws:forward_to_sfe
StatelessFragmentDefaultActions:
- aws:forward_to_sfe
FirewallPolicyName: nfw-policy01
Tags:
- Key: Name
Value: nfw-policy01
# Network Firewall Logging
NetworkFirewallLog:
Type: AWS::NetworkFirewall::LoggingConfiguration
Properties:
FirewallArn: !Ref NetworkFirewall
LoggingConfiguration:
LogDestinationConfigs:
- LogType: ALERT
LogDestinationType: CloudWatchLogs
LogDestination:
logGroup: !Ref CloudWatchLogGroupAlert
- LogType: FLOW
LogDestinationType: CloudWatchLogs
LogDestination:
logGroup: !Ref CloudWatchLogGroupFlow
CloudWatchLogGroupAlert:
Type: 'AWS::Logs::LogGroup'
DeletionPolicy: Delete
Properties:
LogGroupName: nfw-alert
RetentionInDays: 90
Tags:
- Key: Name
Value: nfw-alert
CloudWatchLogGroupFlow:
Type: 'AWS::Logs::LogGroup'
DeletionPolicy: Delete
Properties:
LogGroupName: nfw-flow
RetentionInDays: 90
Tags:
- Key: Name
Value: nfw-flow
## Rule Group#1
Fullopen:
Type: AWS::NetworkFirewall::RuleGroup
Properties:
RuleGroupName: rgp-fullopen
Description: 'for test'
Type: STATEFUL
Capacity: 100
RuleGroup:
RulesSource:
RulesSourceList:
GeneratedRulesType: ALLOWLIST
Targets:
- .rockylinux.org
- mirror.nishi.network
- mirror-nrt.yuki.net.uk
- repo.jing.rocks
- ftp.ubuntu-tw.net
- ftp.jaist.ac.jp
- mirrors.asnet.am
- ftp.iij.ad.jp
- mirror.ossplanet.net
- rocky-linux-asia-northeast2.production.gcp.mirrors.ctrliq.cloud
- rocky-linux-asia-northeast1.production.gcp.mirrors.ctrliq.cloud
- mirrors.ipserverone.com
- ftp.udx.icscoe.jp
TargetTypes:
- TLS_SNI
- HTTP_HOST
RuleVariables:
IPSets:
HOME_NET:
Definition:
- 10.156.0.0/16
StatefulRuleOptions:
RuleOrder: STRICT_ORDER
Outputs:
RtbPublicA:
Value: !Ref RtbPublicA
Export:
Name: RtbPublicA
RtbPublicC:
Value: !Ref RtbPublicC
Export:
Name: RtbPublicC
RtbInspectionA:
Value: !Ref RtbInspectionA
Export:
Name: RtbInspectionA
RtbInspectionC:
Value: !Ref RtbInspectionC
Export:
Name: RtbInspectionC
RtbProtectedA:
Value: !Ref RtbProtectedA
Export:
Name: RtbProtectedA
RtbProtectedC:
Value: !Ref RtbProtectedC
Export:
Name: RtbProtectedC
Igw:
Value: !Ref Igw
Export:
Name: Igw
NgwA:
Value: !Ref NgwA
Export:
Name: NgwA
NgwC:
Value: !Ref NgwC
Export:
Name: NgwC
  • routes.yaml
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
FirewallEndpointA:
Type: String
Description: (Required) Enter NFW endpoint ID AZ-a!"
FirewallEndpointC:
Type: String
Description: (Required) Enter NFW endpoint ID AZ-c!"
Resources:
# routes for public subnets
PublicRouteA0:
Type: 'AWS::EC2::Route'
DeletionPolicy: Delete
Properties:
RouteTableId: !ImportValue RtbPublicA
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !ImportValue Igw
PublicRouteA1:
Type: 'AWS::EC2::Route'
DeletionPolicy: Delete
Properties:
RouteTableId: !ImportValue RtbPublicA
DestinationCidrBlock: 10.156.64.64/27
VpcEndpointId: !Ref FirewallEndpointA
PublicRouteA2:
Type: 'AWS::EC2::Route'
DeletionPolicy: Delete
Properties:
RouteTableId: !ImportValue RtbPublicA
DestinationCidrBlock: 10.156.64.192/27
VpcEndpointId: !Ref FirewallEndpointC
PublicRouteC0:
Type: 'AWS::EC2::Route'
DeletionPolicy: Delete
Properties:
RouteTableId: !ImportValue RtbPublicC
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !ImportValue Igw
PublicRouteC1:
Type: 'AWS::EC2::Route'
DeletionPolicy: Delete
Properties:
RouteTableId: !ImportValue RtbPublicC
DestinationCidrBlock: 10.156.64.192/27
VpcEndpointId: !Ref FirewallEndpointC
PublicRouteC2:
Type: 'AWS::EC2::Route'
DeletionPolicy: Delete
Properties:
RouteTableId: !ImportValue RtbPublicC
DestinationCidrBlock: 10.156.64.64/27
VpcEndpointId: !Ref FirewallEndpointA
# routes for inspection subnets
InspectionRouteA0:
Type: 'AWS::EC2::Route'
DeletionPolicy: Delete
Properties:
RouteTableId: !ImportValue RtbInspectionA
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !ImportValue NgwA
InspectionRouteC0:
Type: 'AWS::EC2::Route'
DeletionPolicy: Delete
Properties:
RouteTableId: !ImportValue RtbInspectionC
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !ImportValue NgwC
# routes for protected subnets
ProtectedRouteA1:
Type: 'AWS::EC2::Route'
DeletionPolicy: Delete
Properties:
RouteTableId: !ImportValue RtbProtectedA
DestinationCidrBlock: 0.0.0.0/0
VpcEndpointId: !Ref FirewallEndpointA
ProtectedRouteC1:
Type: 'AWS::EC2::Route'
DeletionPolicy: Delete
Properties:
RouteTableId: !ImportValue RtbProtectedC
DestinationCidrBlock: 0.0.0.0/0
VpcEndpointId: !Ref FirewallEndpointC

松田 渓(記事一覧)

2021年10月入社。散歩が得意です。