description |
---|
Update : 2020-12-20 |
Network Firewall์ ๊ธฐ๋ณธ ๋์ ์ดํด๋ฅผ ์ํด, ๊ฐ์ฅ ๊ธฐ๋ณธ์ด ๋๋ ๋์์ธ์ ๋จผ์ ๊ตฌ์ฑํด ๋ด ๋๋ค.
์๋ ๊ทธ๋ฆผ์ ์ด๋ฒ Chapter์์ ๊ตฌ์ฑํด ๋ณผ ์ํคํ ์ณ ์ ๋๋ค. ์ธํฐ๋ท์ผ๋ก ๋ถํฐ AWS ์์์ ๋ณดํธํ๊ธฐ ์ํด, ๋คํธ์ํฌ ๋ฐฉํ๋ฒฝ ์๋ธ๋ท์ ๋ฐฐ์นํ๊ณ ์ธํฐ๋ท์ ํต๊ณผํ๋ ๋ชจ๋ ํธ๋ํฝ์ ๋คํธ์ํฌ ๋ฐฉํ๋ฒฝ์ ํต๊ณผํ๊ฒ ํ๋ ์ผ๋ฐ์ ์ธ On Prem๊ตฌ์ฑ๊ณผ ์ ์ฌํฉ๋๋ค.
Cloudformation์ ํตํด ๊ธฐ๋ณธ์ด ๋๋ VPC๊ตฌ์ฑ์ ๋จผ์ ๊ตฌ์ฑํฉ๋๋ค.
๋จผ์ ์๋์ Cloudformation์ ๋ฐฐํฌํฉ๋๋ค. Cloudformation ๊ตฌ์ฑ์ ๋ฐฐํฌํ๊ฒ ๋๋ฉด ์๋์ ๊ฐ์ ๊ตฌ์ฑ์ด ์๋ฃ๋ฉ๋๋ค.
Routing Table ๊ตฌ์ฑ๊ณผ Network Firewall ๊ตฌ์ฑ์ ๋ค์๋จ๊ณ์ ๋ณ๋๋ก ์งํํ๊ฒ ๋ฉ๋๋ค.
Cloud9 ํฐ๋ฏธ๋์์ ์๋ Github์์ ์ค์ต์ ์ฌ์ฉํ Cloudformation yml ํ์ผ์ ๋ค์ด๋ก๋ ๋ฐ์ต๋๋ค.
git clone https://github.com/whchoi98/aws-nwfw-source
์์ ๋ค์ด๋ก๋ ๋ฐ์ git ํ์ผ ์ค์์**"singleaz-vpc1-az-a.yml"
** ํ์ผ์ ์
๋ก๋ ํฉ๋๋ค.
Cloud9์์ ์ง์ file์ ์ ๋ก๋ํ๊ธฐ ์ํด์๋ ์๋์ ๊ฐ์ด S3๋ฅผ ํ์ฉํ ์๋ ์์ต๋๋ค.
##S3 Bucket ์์ฑํฉ๋๋ค.
##Bucket name์ ๊ณ ์ ํด์ผ ํฉ๋๋ค.
export bucket_name="usernameDate"
echo "export bucket_name=${bucket_name}" | tee -a ~/.bash_profile
aws s3 mb s3://${bucket_name}
#์์ฑํ S3 Bucket์ผ๋ก ํ์ผ์ ๋ชจ๋ ๋ณต์ฌํด ๋ก๋๋ค.
cd ~/environment/aws-nwfw-source
# Cloud9์์ ๋ณ๊ฒฝ๋๋ ํ์ผ์ S3์ ๋๊ธฐํ ํฉ๋๋ค.
aws s3 sync ./ s3://${bucket_name}
## option - copy๋ฅผ ํตํด ์ฌ์ฉํด๋ ๊ฐ๋ฅํฉ๋๋ค.
aws s3 cp ./ s3://${bucket_name} --recursive
## LAB์์ ์ฌ์ฉํ Object์ ๊ทผ์ ํ์ฉํฉ๋๋ค.
aws s3api put-object-acl --bucket ${bucket_name} --key EKSVPC3AZ.yml --acl public-read
S3 URL ํ์์ ์์ฑํ ๋ฒํท ์ด๋ฆ๊ณผ ๋ฆฌ์ ์ฃผ์, Object ๋ก ์์ฑ๋์ด ์์ต๋๋ค. ์ถ๋ ฅ๊ฐ์ ๋ณต์ฌํด ๋ก๋๋ค.
echo https://${bucket_name}.s3.ap-northeast-1.amazonaws.com/singleaz-vpc1-az-a.yml
- stack name : Stack name์ ์ ์ํฉ๋๋ค.
- VPC Parameters - AvailablilityZoneA : AZ๋ฅผ ์ ํํฉ๋๋ค.
- KeyPair:์ฌ์ฉํ KeyPair๋ฅผ ์ ํํฉ๋๋ค. (์ฌ์ ์ keypair๋ฅผ ์์ฑํด ๋์ด์ผ ํฉ๋๋ค.)
- LatestAmiId: ์ต์ ์ Amazon Linux2 ์ด๋ฏธ์ง๊ฐ ์๋ ์ ์ธ๋ฉ๋๋ค.
10๋ถ ํ๋ฉด ๋ชจ๋ ์์์ด ์์ฑ๋ฉ๋๋ค.
{% hint style="info" %} ๋ณธ ๋ฉ์์๋ EC2์ ์์๋ค์ ์์ฝ๊ฒ ์ ๊ทผ ํ ์ ์๋๋ก ๋ชจ๋ Session Manager ์ ๊ทผ ๊ตฌ์ฑ์ Cloudformation์ผ๋ก ๋ฐฐํฌํฉ๋๋ค. AWS ์ฝ์์ด๋, ๋ค๋ฅธ ๋ฐฐํฌ ๋๊ตฌ๋ก ๊ตฌ์ฑํ์ ๋ ๋ฉ์ ์งํํ๋๋ฐ๋ ์ด์๊ฐ ์์ต๋๋ค. {% endhint %}
๋จผ์ Network Firewall์ ์์ฑํฉ๋๋ค. ๊ธฐ๋ณธ Firewall Policy๊ฐ ์์ฑ๋์ด ์์ง ์๊ธฐ ๋๋ฌธ์, ํจ๊ป ์์ฑํฉ๋๋ค.
service - VPC - AWS Network Firewall - Firewall - Create
๋ฅผ ์ ํํ๊ณ , Firewall๊ณผ Firewall Policy๋ฅผ ์์ฑํฉ๋๋ค.
๊ธฐ์กด์ Firewall Policy๊ฐ ์๋ค๋ฉด ์์ฑํ Firewall์ ์ฐ๊ฒฐํ ์ ์์ต๋๋ค.
- Name : ๋ฐฉํ๋ฒฝ ์ด๋ฆ์ ์ ์ํฉ๋๋ค.
- Description(Optional) : ๋ฐฉํ๋ฒฝ์ ๋ํ ์ค๋ช ์ ์ ์ํฉ๋๋ค.
- VPC : ์์ฑํ VPC๋ฅผ ์ ํํฉ๋๋ค. (eg. VPC1)
- Firewall subnets - Availability Zone : AZ Zone์ ์ ํํฉ๋๋ค. (eg. us-west-2a)
Firewall subnets - Subnet : ์์ฑํ ๋ฐฉํ๋ฒฝ์ฉ Subnet์ ์ ํํฉ๋๋ค. (eg. VPC1-FWSubnet1) - New Firewall policy name : ์ ๊ท ์์ฑํ NWFW์ ๋ฐฉํ๋ฒฝ ์ ์ฑ ์ด๋ฆ์ ์ ์ํฉ๋๋ค.
- Description(Optional) : ๋ฐฉํ๋ฒฝ ์ ์ ๋ํ ์ค๋ช ์ ์ ์ํฉ๋๋ค.
- Firewall Tag : Firewall ์์์ ๋ํ Tag๋ฅผ ์ ์ํฉ๋๋ค.
๋ฐฉํ๋ฒฝ์ ์์ฑํ๊ณ ๋๋ฉด, provisoning
์ํ๊ฐ ์งํ๋๋ฉฐ ์๋ฃ๊น์ง 5๋ถ ๋ด์ธ๊ฐ ์์๋ฉ๋๋ค.
์ ์์ ์ผ๋ก ์ค์น๋๋ฉด ์๋ ๊ทธ๋ฆผ์ฒ๋ผ Status:Ready
์ํ๋ก ๋ณ๊ฒฝ๋ฉ๋๋ค.
์์ฑํ Firewall์ ์ ํํ๊ณ Firewall details
๋ฅผ ์ ํํ๋ฉด, ํด๋น ์๋ธ๋ท์ Endpoint๊ฐ ์ ์์ ์ผ๋ก ์์ฑ๋ ๊ฒ์ ํ์ธ ํ ์ ์์ต๋๋ค.
Service-VPC-Virtual Private Cloud-Endpoint
๋ฉ๋ด์์ Firewall Endpoint๋ฅผ ํ์ธ ํ ์ ์์ต๋๋ค.
{% hint style="info" %} Endpoint ๋ฉ๋ด์์ ํน์ด์ ์ ๋ฐ๊ฒฌํ ์ ์์ต๋๋ค. Endpoint type์ด GatewayLoadBalancer ๋ผ๋ ๊ฒ์ ๋๋ค. ์ด๊ฒ์ Firewall Endpoint๊ฐ ๋ณ๋๋ก ์์ฑ๋์ง ์๊ณ , GatewayLoadBalancer๋ฅผ ๊ทธ๋๋ก ์ฌ์ฉํ๋ค๋ ๊ฒ์ ๋๋ค. ์ฆ ๋์๋ฐฉ์์ด GatewayLoadBalancer๋ฅผ ์ด์ฉํ๋ค๋ ๊ฒ์ ์ ์ ์์ต๋๋ค. {% endhint %}
์ด์ ๋ผ์ฐํ ํ ์ด๋ธ์ ์ ์ํ๊ณ , ์ธํฐ๋ท๊ณผ EC2๊ฐ์ ํต์ ์ ํ์ธํด ๋ด ๋๋ค.
์ธ๋ถ ์ธํฐ๋ท ํธ๋ํฝ์ธ Firewall Endpoint๋ฅผ ๊ฒฝ์ ํ๋๋ก ๋ผ์ฐํ ํ ์ด๋ธ์ ๊ตฌ์ฑํ๊ธฐ ์ํด์๋ InternetGateway ์ ๋ผ์ฐํ ํ ์ด๋ธ ๊ตฌ์ฑ์ด ํ์ํฉ๋๋ค. AWS์์๋ ์ด๋ฌํ Edge์์์ ๋ผ์ฐํ ํ ์ด๋ธ ๊ตฌ์ฑ์ด ๊ฐ๋ฅํ๋๋ก VPC Ingress Routing์ ์ง์ํฉ๋๋ค.
Service - VPC - Virtual Private Cloud - Route Table - Create route table
์ ๊ท ์์ฑํ InternetGateway์ฉ ๋ผ์ฐํ
ํ
์ด๋ธ์ ์ ํํ๊ณ , Edge Associations
๋ฅผ ์ ํํฉ๋๋ค.
InternetGateway์ฉ ๋ผ์ฐํ ํ ์ด๋ธ์ InternetGateway(์ดํ IGW)์ ์ฐ๊ฒฐํฉ๋๋ค.
์ฐ๊ฒฐํ๋ฉด ์๋์ ๊ฐ์ด ์ ์์ ์ผ๋ก IGW์ ๋ผ์ฐํ ํ ์ด๋ธ(Ingress Routing)์ด ์์ฑ๋ฉ๋๋ค.
์ด์ ์ธํฐ๋ท์์ ์ ์ ๋๋ ํธ๋ํฝ์ด Firewall Endpoint๋ฅผ ํฅํ๋๋ก Ingress Routing์ ์ค์ ํฉ๋๋ค.
Route - Edit Routes
๋ฅผ ์ ํํ๊ณ ์์ ํฉ๋๋ค.
๋ชฉ์ ์ง๋ **0.0.0.0/0
**์ ์ค์ ํ๊ณ , Target์ **Gateway Load Balancer Endpoint
**๋ฅผ ์ ํํฉ๋๋ค.โ
{% hint style="info" %} Target์ด Gateway Load Balancer Endpoint๊ฐ ๋์ด์ผ ํ๋ ์ด์ ๋ ์์ ์ค๋ช ํ์์ต๋๋ค. {% endhint %}
Gateway Load Balancer Endpoint๋ฅผ ์ ํํ๊ฒ ๋๋ฉด, Network Firewall์ ์์ฑํ ์ดํ์ ์๋ ์์ฑ๋ VPC Endpoint๋ฅผ ํ์ธํ ์ ์์ต๋๋ค. ํด๋น Endpoint๋ฅผ ์ ํํ๊ณ ๋ผ์ฐํ ํ ์ด๋ธ์ ์๋ฃํฉ๋๋ค.
์ด์ 10.1.1.0/24 ๋ก ์ธ๋ถ์์ ์ธ์ ๋๋ ํธ๋ํฝ์ ๋ชจ๋ Firewall์ ๊ฒฝ์ ํ๊ฒ ๋ฉ๋๋ค.
FW Subnet์ ์ธํฐ๋ท์ผ๋ก ํฅํ๋ ํธ๋ํฝ์ ๋ํ ๋ผ์ฐํ ์์ฑ์ ํฉ๋๋ค. Ingress Routing์ ๋ณ๋๋ก ๊ตฌ์ฑํ ํ์๊ฐ ์์ต๋๋ค. VPC๋ฅผ ๊ตฌ์ฑํ ๋ CIDR๋ฅผ ์์ฑํ๋ฉด ์๋์ผ Local Routing์ด ๊ตฌ์ฑ๋๊ธฐ ๋๋ฌธ์ ๋๋ค.
FW Subnet Routing Table์ ์ ํํ๊ณ , Route-Edit Routes
๋ฅผ ์ ํํฉ๋๋ค.
Ingress Routing์ Local์ด ์ด๋ฏธ ๊ตฌ์ฑ๋์ด ์์ผ๋ฏ๋ก ๋ณ๋ ๊ตฌ์ฑ์์ด, Egress Routing์ ๋ํ ๊ตฌ์ฑ๋ง ํฉ๋๋ค.
์ธ๋ถ๋ก ํฅํ๋ ํธ๋ํฝ์ ๋ชจ๋ ๋ชฉ์ ์ง IGW๋ก ํฅํ๋๋ก ๊ตฌ์ฑํ๊ณ ์ ์ฅํฉ๋๋ค.
Firewall ์๋ธ๋ท์ ์ํ ๋ผ์ฐํ ๊ตฌ์ฑ์ด ์ ์์ ์ผ๋ก ๋์๋์ง ํ์ธํฉ๋๋ค.
Ingress Routing์ ์ด๋ฏธ Local Routing ๊ตฌ์ฑ์ด ์๋์ผ๋ก ๋์ด ์์ผ๋ฏ๋ก, Egress Routing์ ๋ํ ์ฒ๋ฆฌ๋ง ํฉ๋๋ค.
Protect Subnet์ ์ํ ๋ผ์ฐํ
์ ์ ํํ๊ณ , Route-Edit Routes
๋ฅผ ์ ํํด์ Egress Routing ๊ตฌ์ฑ์ ํฉ๋๋ค.
Protect Subnet์ ์ํ ์์๋ค์ด ์ธ๋ถ๋ก ํธ๋ํฝ์ ๋ณด๋ผ ๋ ๋ชจ๋ Firewall์ ํต๊ณผํ๋๋ก, ๋ชจ๋ ๋ผ์ฐํ ๋ชฉ์ ์ง๋ฅผ Firewall VPC Endpoint๋ก ํฅํ๊ฒ ๊ตฌ์ฑํฉ๋๋ค.
Protect Subnet์ ์ํ ๋ผ์ฐํ ํ ์ด๋ธ์ด ์ ์์ ์ผ๋ก ๊ตฌ์ฑ๋์๋ ์ง ํ์ธํฉ๋๋ค.
์ด์ ๋ชจ๋ ๋ผ์ฐํ ๊ตฌ์ฑ์ ์๋ฃ๋์์ต๋๋ค. ์์ Cloudformation ์ ํตํด์ ์์ฑํ EC2 ์์๋ค์ ๋ํ Security Group์ ์ด๋ฏธ ์ค์ ๋์ด ์์ต๋๋ค.
๋ํ System Manager๋ฅผ ํตํ Session Manager๊ตฌ์ฑ๋ Cloudformation์ ํตํด ๊ตฌ์ฑ๋์ด ์์ต๋๋ค. ๋ณธ ๋ฉ์์๋ Session Manager๋ฅผ ํตํด์ ์ ์ํด์ ์ํํฉ๋๋ค.
{% hint style="success" %} Protect Subnet์ EC2 ์์์ IGW์ 1:1 NAT ๊ตฌ์ฑ์ด ๋๋๋ก ์ค์ ๋์ด ์์ต๋๋ค. Session Manager ๋ฟ๋ง ์๋๋ผ, SSH ์ ์๋ ๊ฐ๋ฅํฉ๋๋ค. ํ์ง๋ง ๋ณด์ ์ ์ฑ ํ ์คํธ๋ฅผ ํ๊ธฐ ์ด๋ ต๊ธฐ ๋๋ฌธ์ Session Manager๋ก ์ ์ํ๋ ๊ฒ์ ๊ถ๊ณ ํฉ๋๋ค. {% endhint %}
Service - System Manager - Session Manager
๋ฅผ ์ ํํ๊ณ , **Start Session
**์ ์ ํํฉ๋๋ค.
EC2์ ์ด๋ฏธ System Manager Agent๊ฐ ์ค์น๋์ด Web์์ ์ ์์ด ๊ฐ๋ฅํฉ๋๋ค. ์ ์์ ์ํ๋ EC2 ์ธ์คํด์ค๋ฅผ ์ ํํ๊ณ **Start Session
**์ ์์ํฉ๋๋ค.
AWS CLI ๊ฐ ์ค์น๋ ๊ฒฝ์ฐ์๋ Session Manager Plugin์ ์ค์นํ์ฌ, CLI๋ก ๊ตฌ์ฑ๊ณผ ์ํ์ด ๊ฐ๋ฅํฉ๋๋ค. (AWS CLI์ฉ Session Manager Plugin ์ค์น )
๋ณธ ๋ฉ์์๋ Cloudshell์ ์ฌ์ฉํด์, Session Manager๋ฅผ ์ฌ์ฉํฉ๋๋ค.
Service - Cloudshell
์ ์ ํํ์ฌ, Cloudshell ์ฝ์์ ์คํํฉ๋๋ค. ์๋์ ๊ฐ์ด session-manager-plugin ์ ์ค์นํ๊ณ , ๋ฉ์ ํ์ํ yml ๋ฐ source ๋ค์ ์ค์นํฉ๋๋ค.
curl "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/linux_64bit/session-manager-plugin.rpm" -o "session-manager-plugin.rpm"
sudo yum install -y session-manager-plugin.rpm
git clone https://github.com/whchoi98/useful-shell
์์ Git์ ํตํด ๋ค์ด๋ก๋ ๋ฐ์ํ์ผ ๊ฐ์ด๋ฐ shell ๋๋ ์๋ aws cli๋ฅผ ํตํด ๋ฐฐํฌ๋ ์ธ์คํด์ค id๋ฅผ ํ์ธํฉ๋๋ค.
./useful-shell/aws_ec2_ext.sh >>vpc1-ec2.txt
vpc1-ec2.txt ๊ฒฐ๊ณผ์ ์์ ๋๋ค.
-----------------------------------------------------------------------------------------------------------------------------------------
| DescribeInstances |
+-----------------+-------------+----------------------+-----------+------------------------+----------+--------------+-----------------+
| Protect-EC2-101| us-west-2a | i-040d4d15aebc8fb32 | t3.small | ami-0e472933a1395e172 | running | 10.1.1.101 | 52.34.16.59 |
| Protect-EC2-102| us-west-2a | i-068a26aee30adb069 | t3.small | ami-0e472933a1395e172 | running | 10.1.1.102 | 35.166.81.128 |
+-----------------+-------------+----------------------+-----------+------------------------+----------+--------------+-----------------+
์ธ์คํด์ค id๋ฅผ Shell์ ์ ์ฅํด ๋ก๋๋ค.
export VPC1_AZA_101="i-040d4d15aebc8fb32"
export VPC1_AZA_102="i-068a26aee30adb069"
echo "export VPC1_AZA_101=$VPC1_AZA_101" | tee -a ~/.bash_profile
echo "export VPC1_AZA_102=$VPC1_AZA_102" | tee -a ~/.bash_profile
echo $VPC1_AZA_101
echo $VPC1_AZA_102
์๋์ ๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก Session Manager๋ฅผ ํตํด ์ธ์คํด์ค์ ์ ์ํฉ๋๋ค.
#VPC1 AZ-A EC2-101
aws ssm start-session --target $VPC1_AZA_101 --region ap-northeast-1
sudo -s
su ec2-user
cd ~
#VPC1 AZ-A EC2-102
aws ssm start-session --target $VPC1_AZA_102 --region ap-northeast-1
sudo -s
su ec2-user
cd ~
๊ฐ ์ธ์คํด์ค์์ ์๋ ๋ช ๋ น์ ํตํด ์์ฑ๋ EC2 ์ธ์คํด์ค๋ค์ local(Private) IP ์ฃผ์์ ๊ณต์ธ(Public) IP๋ฅผ ํ์ธํฉ๋๋ค.
curl http://169.254.169.254/latest/meta-data/local-ipv4
curl http://169.254.169.254/latest/meta-data/public-ipv4
curl -s ifconfig.co
๋จผ์ ์ฌ์ฉ์ ์น๋ธ๋ผ์ฐ์ ์์ ๊ฐ ์ธ์คํด์ค์ Public IP ์ฃผ์๋ก ์๋ ์น์ฌ์ดํธ์ ์ ๊ทผํด ๋ด ๋๋ค.
http://ec2-101-public-ip/ec2meta-webpage/index.php
http://ec2-102-public-ip/ec2meta-webpage/index.php
๋ชจ๋ ์ธ์คํด์ค์ ์ ์์ ์ผ๋ก ์ ์๋๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค.
{% hint style="info" %} ๋ฐฉํ๋ฒฝ์ ํต๊ณผํ๋ ํธ๋ํฝ ํ๋ฆ์ด์ง๋ง , ๋ณ๋์ ์ ์ฑ ์์ด๋ ์ ์์ ์ผ๋ก ์น๋ธ๋ผ์ฐ์ ๊ฐ ์ถ๋ ฅ์ด ๋ฉ๋๋ค. ์ด ๊ตฌ์ฑ์ ํตํด ์ ์ ์๋ ๊ฒ์, ๊ธฐ๋ณธ ๋ฐฉํ๋ฒฝ ์ ์ ๋ฌต์์ ํ์ฉ์ด๋ผ๋ ๊ฒ์ ์ ์ ์์ต๋๋ค. {% endhint %}
์ด์ ํธ๋ํฝ์ ํ๋ฆ์ ์๋์ ๊ฐ์ด ์ดํด ํ ์ ์์ต๋๋ค.
EC2-101์์ EC2-102๋ก Curl์ ํตํด ํธ๋ํฝ ํ๋ฆ์ ํ์ธ ํด ๋ณผ ์ ์์ต๋๋ค. ์๋ ๋ช ๋ น์ CloudShell์์ Session Manager๋ฅผ ์ ์ํ ์ํ์์ ์คํํด ๋ด ๋๋ค.
#EC2-101
curl -I http://ec2-102-public-ip/ec2meta-webpage/index.php
#EC2-102
sudo tcpdump -i eth0 src ec2-101-public-ip
์๋ ์ฒ๋ผ ๊ฒฐ๊ณผ๊ฐ ์ถ๋ ฅ๋ฉ๋๋ค.
[ec2-user@ip-10-1-1-101 ~]$ curl -I http://35.166.81.128/ec2meta-webpage/index.php
HTTP/1.1 200 OK
Date: Tue, 15 Dec 2020 23:47:15 GMT
Server: Apache/2.4.46 () PHP/5.4.16
Upgrade: h2,h2c
Connection: Upgrade
X-Powered-By: PHP/5.4.16
Content-Type: text/html; charset=UTF-8
[ec2-user@ip-10-1-1-102 ~]$ sudo tcpdump -i eth0 src 52.34.16.59
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
23:47:11.940652 IP ec2-52-34-16-59.us-west-2.compute.amazonaws.com.45606 > ip-10-1-1-102.us-west-2.compute.internal.http: Flags [S], seq 3254533980, win 26883, options [mss 1460,sackOK,TS val 2878837554 ecr 0,nop,wscale 7], length 0
23:47:11.968465 IP ec2-52-34-16-59.us-west-2.compute.amazonaws.com.45606 > ip-10-1-1-102.us-west-2.compute.internal.http: Flags [.], ack 3141908793, win 211, options [nop,nop,TS val 2878837576 ecr 3940610722], length 0
23:47:11.968479 IP ec2-52-34-16-59.us-west-2.compute.amazonaws.com.45606 > ip-10-1-1-102.us-west-2.compute.internal.http: Flags [P.], seq 0:102, ack 1, win 211, options [nop,nop,TS val 2878837577 ecr 3940610722], length 102: HTTP: HEAD /ec2meta-webpage/index.ph HTTP/1.1
์ด์ ์์ฑ๋ Firewall๊ณผ Firewall Policy์ Rule(๋ณด์ ๊ท์น)์ ์ค์ ํ์ฌ, ์์ธํ ๋ณด์ ๊ท์น๋ค์ ์ค์ ํด ๋ด ๋๋ค.
๋จผ์ Firewall ๊ตฌ์ฑ์ ์๋์ ๊ฐ์ ๋ฐฉ์์ผ๋ก ๊ตฌ์ฑํ ์ ์์ต๋๋ค.
- Firewall ์ ์์ฑํฉ๋๋ค.
- Firewall Policy๋ฅผ ์์ฑํฉ๋๋ค.
- Stateless Rule ์ ์์ฑํฉ๋๋ค.
- Stateful Rule์ ์์ฑํฉ๋๋ค.
- Stateful Rule์ Domain list ์ ์์ฑํฉ๋๋ค.
- Stateful Rule์ Suricata IPS Rule์ ์์ฑํฉ๋๋ค.
์์ Firewall๊ณผ Firewall ์ ์ฑ ์ ์์ฑ ์๋ฃํ์ต๋๋ค. (Task2. Network Firewall ๊ธฐ๋ณธ ๊ตฌ์ฑ)
Network Firewall์ ์ ์ฑ ์ ์ดํดํ๊ธฐ ์ํด ์๋ ๊ทธ๋ฆผ์ ์ดํดํด์ผ ํฉ๋๋ค.
์์ฑํ Firewall Policy๋ฅผ ์ ํํฉ๋๋ค.
VPC - AWS Network Firewall
์๋ก์ด Stateless Rule Group ์์ฑ์ ํฉ๋๋ค.
Create and add new stateless rule group
Stateless rule group์ ์์ฑํฉ๋๋ค.
- Name : Stateless Rule ์ด๋ฆ์ ์ ์ํฉ๋๋ค.
- Capacity : Rule Group์ Rule์ ์ซ์๋ฅผ ์ ์ํฉ๋๋ค.(์ต๋ 10,000๊ฐ)
- Priority : Stateless Rule์ Priority๋ฅผ ์ ์ํฉ๋๋ค. Rule ๋ฒํธ๋ฅผ ์๋ฏธํ๋ฉฐ Rule ๋ฒํธ๊ฐ ์ฐ์ ์์๋ฅผ ๊ฐ์ง๊ฒ ๋ฉ๋๋ค. (NACL๊ณผ ๊ท์น ๋์ผ)
- Protocol : ํ๋กํ ์ฝ์ ์ ์ํฉ๋๋ค.
- Source IP/Port
- Destination IP/Port
- Action : Pass/Drop/Forward to stateful rule groups ๋ฅผ ์ ํํฉ๋๋ค.
- Add rule : ์์ฑํ Rule์ ์ถ๊ฐํฉ๋๋ค.
Rule์ ์ถ๊ฐํ๋ฉด , ์ถ๊ฐ๋ Rule ์ ํ์ธํ๊ณ ์์ฑ์๋ฃํฉ๋๋ค.
์์ฑํ ๋ฃฐ์ ํ์ธํ๊ธฐ ์ํด ์ธ๋ถ์์ ์ธ์คํด์ค์ ๊ณต์ธ IP ์ฃผ์๋ก ICMP๋ฅผ ์์ฒญํด ๋ด ๋๋ค. 10.1.1.101์ Mapping ๋ ๊ณต์ธ IP์ฃผ๋ก๋ก ICMP๊ฐ ๊ฑฐ๋ถ๋๊ณ , 10.1.1.102์ Mapping๋ ๊ณต์ธ IP์ฃผ์๋ ์๋ตํฉ๋๋ค. (NACL๊ณผ ์ ์ฌํฉ๋๋ค.)
์๋ก์ด Stateful Rule Group ์์ฑ์ ํฉ๋๋ค.
VPC-Firewall policies - ์์ฑํ Policy - Stateful rule groups - Add rule groups - Create and add new stateful rule group
Stateful rule group์ ์์ฑํฉ๋๋ค.
- Name : Stateful Rule ์ด๋ฆ์ ์ ์ํฉ๋๋ค.
- Capacity : Rule Group์ Rule์ ์ซ์๋ฅผ ์ ์ํฉ๋๋ค.(์ต๋ 10,000๊ฐ)
- Stateful rule group options : 5 tuple์ ์ ํํฉ๋๋ค.
- Protocol : ํ๋กํ ์ฝ์ ์ ์ํฉ๋๋ค.
- Source IP/Port
- Destination IP/Port
- Traffic direction : Any/Forward๋ฅผ ์ ํํฉ๋๋ค .
- Action : Pass,Drop,Alert ์ ์ ํํฉ๋๋ค.
SSH ์ ๋ํ ์ ์ฑ ์ ์์๋ก ์์ฑํด ๋ด ๋๋ค. (10.1.1.101 ์ธ์คํด์ค์ ๋ํ SSH Drop)
Rule์ ์ถ๊ฐํ๋ฉด , ์ถ๊ฐ๋ Rule ์ ํ์ธํ๊ณ ์์ฑ์๋ฃํฉ๋๋ค.
์์ ์์ฑํ Cloud9์์ ๊ฐ EC2 ์ธ์คํด์ค๋ก ssh ์ ์์ ์คํํด ๋ด ๋๋ค.
ssh -i ~/environment/anfwkey.pem ec2-user@ec2-101-public-ip
ssh -i ~/environment/anfwkey.pem ec2-user@ec2-102-public-ip
Stateful Rule์ ์ํด์ , EC20-102(10.1.1.102) ์ธ์คํด์ค๋ง ์ ์์ด ๊ฐ๋ฅํฉ๋๋ค.
์๋ก์ด Stateful Rule Group ์์ฑ์ ํฉ๋๋ค.
VPC-Firewall policies - ์์ฑํ Policy - Stateful rule groups - Add rule groups - Create and add new stateful rule group
Stateful rule group์ ์์ฑํฉ๋๋ค.
- Name : Stateful Rule ์ด๋ฆ์ ์ ์ํฉ๋๋ค.
- Capacity : Rule Group์ Rule์ ์ซ์๋ฅผ ์ ์ํฉ๋๋ค.(์ต๋ 10,000๊ฐ)
- Stateful rule group options : Domain list์ ์ ํํฉ๋๋ค.
- Domain list - Rule์ ์ ์ํ ๋๋ฉ์ธ์ ์ ์ํฉ๋๋ค. (์. www.google.com)
- Protocol : HTTP/HTTPS ๋ฅผ ์ ํํฉ๋๋ค.
- Action : Allow/Deny ์ ํํฉ๋๋ค.
www.google.com์ Filteringํ๋ ์์ ๋ฅผ ์ค์ ํด ๋ด ๋๋ค.
Task.VPC Route Table ๊ตฌ์ฑ-4.ํธ๋ํฝ ํ๋ฆ ํ์ธ ์์ ๊ตฌ์ฑํ CloudShell์์ 2๊ฐ์ ์ฐฝ์ ์ด๊ณ , ์๋๊ณผ ๊ฐ์ ๋ช ๋ น์ ํตํด ๊ฐ๊ฐ์ ์ธ์คํด์ค์ Session Manager๋ฅผ ํตํด ์ ์ํฉ๋๋ค.
aws ssm start-session --target $VPC1_AZA_101
sudo -s
su ec2-user
cd ~
curl -I www.google.com
aws ssm start-session --target $VPC1_AZA_102
sudo -s
su ec2-user
cd ~
curl -I www.google.com
์๋์ ๊ฐ์ด ๋ชจ๋ ์ธ์คํด์ค์์ www.google.com ์ ์ ์์ด filtering ๋ฉ๋๋ค.
Suricata๋ IDS(ํ์ง)/IPS(ํ์ง,์ฐจ๋จ)๊ฐ ๊ฐ๋ฅํ Open source ๋๊ตฌ ์ ๋๋ค. Snort์ ์๋ฒฝํ๊ฒ ํธํ์ด ๊ฐ๋ฅํ๋ฉฐ, ๋ฉํฐ ์ฐ๋ ๋ ์ง์๊ณผ GPU ์ง์๋ฑ์ผ๋ก ์ฑ๋ฅ ๋ถ๋ถ์์ ๋์ ํ๊ฐ๋ฅผ ๋ฐ๊ณ ์์ต๋๋ค. (2020๋ ๋ถํฐ Snort 3.0 ์ถ์์ ํจ๊ป ๋ฉํฐ ์ฐ๋ ์ง ์ง์)
AWS Network Firewall์ Stateful IPS๋ Suricata IPS๋ฅผ ํตํด์, Deep Inspection๊ตฌํ์ด ๊ฐ๋ฅํฉ๋๋ค. ๋ํ ์์ฉ๋๊ตฌ์ ์ฐ๊ณ๋ ๊ฐ๋ฅํฉ๋๋ค. (2020๋ 12์ ํ์ฌ ๊ธฐ์ค Fortinet ์ง์- ์์ฉ)
์๋ก์ด Stateful Rule Group ์์ฑ์ ํฉ๋๋ค.
VPC-Firewall policies - ์์ฑํ Policy - Stateful rule groups - Add rule groups - Create and add new stateful rule group
Stateful rule group์ ์์ฑํฉ๋๋ค.
- Name : Stateful Rule ์ด๋ฆ์ ์ ์ํฉ๋๋ค.
- Capacity : Rule Group์ Rule์ ์ซ์๋ฅผ ์ ์ํฉ๋๋ค.(์ต๋ 10,000๊ฐ)
- Stateful rule group options : Suricata IPS Rule์ ์ ํํฉ๋๋ค.
- Suricata IPS Rule์ ์ค์ ํฉ๋๋ค.
www.google.com์ Filteringํ๋ ์์ ๋ฅผ ์ค์ ํด ๋ด ๋๋ค.
IPS Rule์ ์๋์ ๊ฐ์ด ๊ตฌ์ฑํด ๋ด ๋๋ค.
# 10.1.1.101 ์ ์์ค๋ก Contents์ AWS๊ฐ ํฌํจ๋๋ฉด Alert์ ๋ฐ์.
alert tcp 10.1.1.101 any -> any any (msg: "No access to the EC2-1 Webpage"; content: "AWS"; sid: 101; rev:1;)
alert tcp 10.1.1.102 any -> any any (msg: "No access to the EC2-1 Webpage"; content: "AWS"; sid: 102; rev:1;)
# 10.1.1.101,10.1.1.102 ๋ฅผ ์ ์ํ๋ User Agent๊ฐ Firefox ๋ธ๋ผ์ฐ์ ๋ Drop.
drop http any any -> [10.1.1.101,10.1.1.102] any (msg: "User agent"; http.user_agent; content:"Firefox"; sid:103; rev:1;)
{% hint style="info" %} Suricata Rule์ https://suricata.readthedocs.io/en/latest/index.html ์ ์ฐธ๊ณ ํ์ฌ์ , ์ ์ฑ ์ ์์ฑํ ์ ์์ต๋๋ค. {% endhint %}
๊ฐ ์ธ์คํด์ค์ ์ ์ํด์, ์๋ ๋ช ๋ น์ ํตํด ์ ์ ํ๊ฑฐ๋, Web ๋ธ๋ผ์ฐ์ ์์ ์ ์ํด ๋ด ๋๋ค.
#EC2-101
curl -I http://ec2-102-public-ip/ec2meta-webpage/index.php
#EC2-102
curl -I http://ec2-101-public-ip/ec2meta-webpage/index.php
์ฌ์ฉ์ ๋ธ๋ผ์ฐ์ ์์, Firefox์ Chrom์ ํตํด์ EC2-101,102์ ๊ณต์ธ IP ์ฃผ์๋ก ์ ์ํด ๋ด ๋๋ค. ์๋์์ ์ฒ๋ผ Firefox๋ ์ ์๋์ง ์์ต๋๋ค.
Network Firewall์ Logging ๋ชฉ์ ์ง๋ฅผ 3๊ฐ์ง ์ง์ํฉ๋๋ค.
- S3 - bucket name๊ณผ Prefix๋ฅผ ์ค์ ํฉ๋๋ค.
- Cloudwatch - Cloudwatch Log group์ ์ง์ ํฉ๋๋ค.
- Kinesis data firehose - Kinesis data firehose delivery stream name์ ์ค์ ํฉ๋๋ค.
Cloudwatch log group์ ์ง์ ํ๊ณ , Log๋ฅผ ์ดํด๋ด ๋๋ค.
Cloudwatch - Cloudwatch logs - log groups
๋ฅผ ์ ํํ๊ณ , Create log group
์ ์ ํํด์ Log Group์ ์์ฑํฉ๋๋ค.
Alert , Flow log group์ ๊ฐ๊ฐ ์์ฑํฉ๋๋ค.
- Log group name : NWFW-Alert , NWFW-Flow
์์ฑ๋ Log group์ ํ์ธํฉ๋๋ค.
์ด์ ๋ค์ Network Firewall์์ Logging ๊ตฌ์ฑ์ ์งํํฉ๋๋ค.
VPC-Firewalls- ์์ฑํ Firewall
Firewall details ๋ฉ๋ด๋ฅผ ์ ํํ๊ณ , logging ๋ฉ๋ด์์ Edit ๋ฅผ ์ ํํฉ๋๋ค.
VPC -Firewalls - ์์ฑํ Firewall - Firewall details - Logging - Edit
firewall loggig์ ๊ตฌ์ฑํฉ๋๋ค.
- log type - Alert, Flow ๋ก๊ทธ๋ฅผ ์ ํํฉ๋๋ค.
- log destination for alert - Alert logging ๋ชฉ์ ์ง๋ฅผ ์ ํํฉ๋๋ค.
- log destination for flows - flow logging ๋ชฉ์ ์ง๋ฅผ ์ ํํฉ๋๋ค.
Lab ์์๋ ์์ ์ด๋ฏธ ์์ฑํ CloudWatch log group์ ์ ํํฉ๋๋ค.
์ฌ์ฉ์ ๋ฉํ์์ EC2 101,102 ์ ๊ณต์ธ ์ฃผ์๋ก Firefox๋ก ์ ์ํด ๋ด ๋๋ค.
๊ฐ ์ธ์คํด์ค์ ์ ์ํด์, ์๋ ๋ช ๋ น์ ํตํด ์ ์ ํ๊ฑฐ๋, Web ๋ธ๋ผ์ฐ์ ์์ ์ ์ํด ๋ด ๋๋ค.
#EC2-101
curl -I http://ec2-102-public-ip/ec2meta-webpage/index.php
#EC2-102
curl -I http://ec2-101-public-ip/ec2meta-webpage/index.php
์ฌ์ฉ์ ๋ธ๋ผ์ฐ์ ์์, Firefox์ Chrom์ ํตํด์ EC2-101,102์ ๊ณต์ธ IP ์ฃผ์๋ก ์ ์ํด ๋ด ๋๋ค. ์๋์์ ์ฒ๋ผ Firefox๋ ์ ์๋์ง ์์ต๋๋ค. ๊ด๋ จ ๋ก๊ทธ๋ฅผ CloudWatch์์ ํ์ธํด ๋ด ๋๋ค.
Cloudwatch์์ Alert log๋ฅผ ์ ํํฉ๋๋ค.
Cloudwatch - Cloudwatch logs - log groups - Alert log
Block ๋ ๋ก๊ทธ๋ฅผ ํ์ธํฉ๋๋ค. Signature ID 103์ ์ํด์ Block ๋ ๊ฒ์ ํ์ธ ํ ์ ์์ต๋๋ค.
# 10.1.1.101,10.1.1.102 ๋ฅผ ์ ์ํ๋ User Agent๊ฐ Firefox ๋ธ๋ผ์ฐ์ ๋ Drop.
drop http any any -> [10.1.1.101,10.1.1.102] any (msg: "User agent"; http.user_agent; content:"Firefox"; sid:103; rev:1;)
Firewall ์ ๋ํ ๊ฐ๋จํ ๋ชจ๋ํฐ๋ง์ ์๋ ๋ฉ๋ด๋ฅผ ํตํด์ ํ์ธ ํ ์ ์์ต๋๋ค.
VPC - Firewall - ์์ฑํ Firewall - Monitoring
- Stateless ReceivedPackets
- Stateless DroppedPackets
- Stateless PassedPackets
- Stateful ReceivedPackets
- Stateful DroppedPackets
- Stateful PassedPackets
1.Network Firewall policy ์์ Rule ์ ๊ฑฐ
VPC - Firewall Policies - Firewall Polices ์ ํ - Stateleess Rule/Stateful rule group ์ ๊ฑฐ
2. Route Table์์ GWLB Endpoint ์ ๊ฑฐ
VPC-IGW-RT ์์ Egde Associations ์ ๊ฑฐ / VPC-IGW ์ ๊ฑฐ.
Virtual Private Cloud - Route Table - VPC1-IGW-RT - Edge Associations - IGW Uncheck
VPC-ProtectSubnet1-RT ์์ GWLB Endpoint route ์ ๊ฑฐ
Virtual Private Cloud - Route Table - VPC1-ProtectSubnet1-RT ์ ํ - GWLB Endpoint Route ์ ๊ฑฐ
3. Network Firewall logging ๊ตฌ์ฑ ์ ๊ฑฐ
VPC - Firewall - Firewall Details - Logging - Edit - Loggig ํด์ .
4. Network Firewall ์ ๊ฑฐ
VPC - Firewall - ์ ๊ฑฐ
5. Cloudformation ์์ Stack ์ ๊ฑฐ
Cloudformation - Stacks - Stack ์ ํ - ์ญ์