iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 25
1
自我挑戰組

Linux學習系列 第 25

AWS VPC 、 IAM、KMS

  • 分享至 

  • xImage
  •  

Amazon AWS VPC, Subnet, Routing Table & IGW explained
照著這部影片學習

可以把這系列的教學看完:
AWS VPC Public and Private Subnets

Amazon Virtual Private Cloud (Amazon VPC)
Amazon Virtual Private Cloud
想成雲端的網路
可以選擇自己的 IP 地址範圍、建立子網路,以及配置路由表和網路閘道。
還有選擇公有和私有網路,例如: Web伺服器建立公有子網路,而資料庫或應用程式伺服器等後端系統放在不能存取網際網路的私有子網路。

Subnet

這邊應該不是指ip地址哪部分是網路,哪部分是主機。而是子網路,就是CIDR把Host ID一部分拿去當 Net ID,而那部分就是原本網路(VPC)的子網路。

Routing table

Computer Networking Tutorial - 39 - Routing Tables Explained
8.1.1 路由表產生的類型
當要封包傳到伺服器時,會經過多個路由器,要怎麼判斷要傳到哪個路由器、要從哪個網路介面傳,這時候就需要主機的路由表。
每一部主機都有自己的路由表,須要透過自己的路由表來傳遞封包到下一個路由器。若傳送出去後,該封包就得要透過下一個路由器的路由表來傳送了,此時與自己主機的路由表就沒有關係

路由表的欄位:
第11篇 基本路由表的填寫
https://ithelp.ithome.com.tw/upload/images/20181107/20111994IXrraP0RLu.png

Internet Gateway(IGW)

要連到internet,就要創建Internet Gateway,然後attach 到vpc

開始創建vpc
https://ithelp.ithome.com.tw/upload/images/20190106/20111994aCSTwwsaxg.png
https://ithelp.ithome.com.tw/upload/images/20181107/20111994fXyJvnxi1s.png

有些東西會連著vpc一起創建,像是:network acl、route table。
https://ithelp.ithome.com.tw/upload/images/20190421/20111994YilxH1iIm9.png

接著創建subnet
可以連到internet的subnet:
https://ithelp.ithome.com.tw/upload/images/20181107/20111994O5VYQTCgxi.png
不能連到internet的subnet:
https://ithelp.ithome.com.tw/upload/images/20181107/20111994iNis7b3z1K.png

要連到internet就要有Internet Gateways
創建一個Internet Gateways,一個VPC只能有一個internet gataway,然後attach到VPC
https://ithelp.ithome.com.tw/upload/images/20190106/20111994tBGVfJQw2z.png

接著在路由表新增Internet Gateways
https://ithelp.ithome.com.tw/upload/images/20181107/201119942VyNmRWeV8.png

因為創了兩個子網路,有一個是私有網路,不能連到internet。所以在新建一個路由表,這個路由表沒有Internet Gateways。記得路由表要選到對的VPC,不然subnet會找不到路由表,接著subnet在更改路由表就可以了。

所以總結步驟:先創一個VPC,在創兩個subnet(一個可以連internet,另一個不能),接著創一個Internet Gateways,在創兩個路由表(一個有Internet Gateways,一個沒有),最後在確認subnet的路由表

接著就可以來創主機測試了
更改成設定的VPC
然後subnet先選擇public,這邊的public ip要開啟,不然就沒辦法用putty登入主機了
https://ithelp.ithome.com.tw/upload/images/20181107/20111994wTVsU3gsZK.png

網路介面可以選擇192.168.10.100
不要選擇192.168.10.0、192.168.10.1、192.168.10.2、192.168.10.3、192.168.10.255
這些項目是用來:
192.168.10.0 Network address
192.168.10.1 VPC router
192.168.10.2 VPC DNS
192.168.10.3 AWS保留的,目前沒功能
192.168.10.255 Network broadcast address(VPC沒有broadcast功能,但是還是保留)
https://ithelp.ithome.com.tw/upload/images/20181107/20111994hvj8alr2SD.png

接著主機創好後,就可以看到主機的私有ip就是192.168.10.100
常用指令:
Ifconfig 查看網路介面卡,可以確認subnet設定的ip
lsblk 查看硬碟
df 查看filesystem

接著打開主機,指令:ping google.com 就可以確認有沒有連internet了。ctrl+c,離開ping

接著在創一個主機,代表不能連internet的主機,但是可以從VPC的另一台主機(剛才創建的那台)連到這台主機
https://ithelp.ithome.com.tw/upload/images/20181107/20111994HzjvPniEjp.png

接著在public server輸入指令:ping 192.168.10.32
192.168.10.32 代表 private server
但是要更改private server的防火牆,允許ICMP
ping成功就代表有連到
https://ithelp.ithome.com.tw/upload/images/20181107/20111994g2BLXKFTzg.png

如果要連入(imbound)private internet的主機怎麼辦?就是把私鑰放到public server,在public server使用ssh連線就可以了。
連到之後,可以在private server ping google.com,就可以知道是連不到網路的。

最後有講到telnet,還是不太懂telnet,先跳過

接著來讀:
AWS Virtual Private Cloud – VPC – Certification

一 VPC有個Tenancy的選項

Tenancy有兩個選項:
1 Default(在這個狀況開EC2的話,如果EC2要是Dedicated instance,就得在創建EC2時選擇Dedicated instance)
2 Dedicated(如果在這個VPC下開EC2,這個EC2會是Dedicated instance,就算在創建EC2的選項沒有選Dedicated)
https://ithelp.ithome.com.tw/upload/images/20190509/20111994oVVHXIEVYN.png
EC2的Tenancy選項:
https://ithelp.ithome.com.tw/upload/images/20190509/20111994QAy6VcJONM.png

二 創建一個vpc會自動創建:Network ACL、DHCP options set、Route table

https://ithelp.ithome.com.tw/upload/images/20190509/20111994Lwli6MyzHx.png

三 如果要刪掉VPC,會把跟這著VPC相關的網路東西刪掉:

https://ithelp.ithome.com.tw/upload/images/20190509/20111994G4cnWgCSpf.png

四 每個subnet的CIDR是不能重疊的,如果VPC是192.168.0.0/16,然後其中一個subnet也是192.168.0.0/16,那在這個VPC就只能有一個subnet:

https://ithelp.ithome.com.tw/upload/images/20190509/20111994sm7kxLqQ4g.png

五 Network Interface:當成網路卡

一 可以有多個private IP address
二 每個private IP address都可以有一個Elastic IP address
三 可以有多個防火牆(security group)
四 一個MAC address
五 一個source/destination check flag

如圖:可以有多個防火牆(security group),elastic fabric adapter好像是用來減低延遲和增加傳輸量
https://ithelp.ithome.com.tw/upload/images/20190509/20111994bVnzGOWlsR.png

如果有Elastic Fabric Adapters,得在EC2關機的時候裝網卡,如果是一般的網卡可以直接裝到EC2,所以一台EC2可以有多個網卡
https://ithelp.ithome.com.tw/upload/images/20190509/20111994d1LvDWLTzm.png

如圖:網卡可以有多個private ip,每個private ip可以有一個public ip
https://ithelp.ithome.com.tw/upload/images/20190509/20111994f7rQgzXsT2.png

六 Elastic IP address (EIP)

Elastic IP address (EIP)就是一個固定的公有ip,收錢的方式是:當EC2關機的時候,才收錢。
(因為這個固定的公有ip被你佔用了,可是你沒使用,所以收錢)

繼續讀
AWS Virtual Private Cloud – VPC – Certification

整理
1

VPC allows VPC Peering connections with other VPC within the same or different AWS accounts

VPC Peering connections就是 兩個VPC互連的一個方式。可以是不同帳號的VPC, VPC Peering connections是單向的,所以要雙向的話,就要再創一條相反的 。 VPC Peering connections同樣路徑 只能有一個,所以在創下去會覆蓋。以上可能有誤,這邊很清楚:AWS VPC Peering

2

NAT device enables instances in a private subnet to connect to the Internet or other AWS services, but prevents the Internet from initiating connections with the instances.

NAT device 就是 用來讓 private subnet 可以連到網路的 , 但是 網路 是不知道 有private subnet,因為網路找到的是NAT device。

3

Egress-only Internet Gateway 是 IPV6的Internet Gateway

4 VPC Flow Logs

Security groups 是 EC2的防火牆 (stateful -- > 允許 進EC2 ,就允許出EC2 )

Network access control lists (ACLs) 是 subnet的防火牆 (stateless ,如果允許SSH 連入 , 就得在自己設定允許SSH 連出 )

VPC Flow Logs 是 用來看 進出 vpc的 IP!!!

https://ithelp.ithome.com.tw/upload/images/20200127/20111994rziB99fg8u.png

參考:
VPC Flow Logs - Log Breakdown
VPC Flow Logs - Cheat Sheet

接著看AWS VPC Endpoints – Certification

就是VPC 連到其他的AWS服務:

VPC endpoint enables creation of a private connection between VPC to supported AWS services and VPC endpoint services powered by PrivateLink using its private IP address

VPC endpoint不用連到外面的網路:

VPC Endpoint does not require a public IP address, access over the Internet, NAT device, a VPN connection or AWS Direct Connect

VPC and an AWS service 要在同個region:

Endpoint cannot be created between a VPC and an AWS service in a different region.

VPC Endpoints,主要分為兩種 Interface endpoints 跟 Gateway endpoints
Gateway endpoints專給Amazon S3 和 DynamoDB

參考:
VPC endpoints
VPC Endpoints - Interface Endpoints
VPC Follow Along - VPC Endpoints

VPC Peering Overview

VPC 跟 VPC互連

AWS 用存在的infrastructure 來VPC Peering ,不是用VPN或是單獨的硬體:

AWS uses the existing infrastructure of a VPC to create a VPC peering connection; it is neither a gateway nor a VPN connection, and does not rely on a separate piece of physical hardware.

VPC Peering不會 故障 或是 超過頻寬

There is no single point of failure for communication or a bandwidth bottleneck

AWS VPC VPN – CloudHub Connections – Certification

VPC VPN connections 用來 在自己的 電腦 連到 AWS ,要用 VPN 大概是因為安全關係。

VPC VPN connections are used to extend on-premise data centers to AWS

什麼是Software VPN? ,就是使用者 自己在EC2 安裝 VPN軟體 ,自己設定VPN

1 VPN connection can be setup by running a software VPN like OpenVPN appliance on an EC2 instance in the VPC
2 AWS does not provide or maintain software VPN appliances; however, there are range of products provided by partners and open source communities

AWS IAM Role

IAM 全名是:AWS Identity (身分識別) and Access (AWS服務 可不可以使用 ) Management
參考:
IAM — AssumeRoleWithWebIdentity
IAM — Cross-Account Roles

這邊了解 IAM 的 Role

AWS IAM Role – Certification
就是 不用在創一個帳號(使用者) , 也可以 使用 AWS的服務

整理
1
IAM Role plays a very important role in the following scenarios:(IAM Role的使用場景)

Services like EC2 instance running an application that needs to access other AWS services
EC2裡的應用程式需要 使用AWS服務。像是S3

Allowing users from different AWS accounts have access to AWS resources in different account, instead of having to create users
如果要 用 另一個帳號裡的AWS服務 , 不一定要在 那個帳號 裡 再創一個user ,可以 透過 AWS ROLE 使用 另一個帳號裡AWS服務
參考:AWS - IAM Cross Account Access

Company uses a Corporate Authentication mechanism and don’t want the User to authenticate twice or create duplicate users in AWS
跟前面類似,就是只要有role,就可以不用重複創建 users

Applications allowing login through external authentication mechanism e.g. Amazon, Facebook, Google etc
透過其他機制驗證 , 像是登入 ,e.g. Amazon, Facebook, Google etc

2
Role 主要有兩部分: Trust policy 和 Permissions policy

Trust policy ( 什麼東西 有權利 使用AWS服務)

o Trust policy defines – who can assume the role
o Trust policy involves setting up a trust between the account that owns the resource (trusting account) (哪個帳戶擁有資源) 、
the account who owns the user that needs access to the resources(帳戶底下哪個使用者可以使用資源) (trusted account)

如圖:
https://ithelp.ithome.com.tw/upload/images/20200128/20111994ppSyhbVXri.png

web身分應該是指這個:

Users can sign in to a web identity provider, such as Login with Amazon, Google, or any IdP that is compatible with OpenID connect (OIDC).

Permissions policy (AWS服務)

o Permissions policy defines – what they can access
o Permissions policy determines authorization, which grants the user of the role the needed permissions to carry out the desired tasks on the resource

3
AWS Security Token Service (STS) 暫時性 的創建 role? (擁有時間限定的權限)

 AWS Security Token Service (STS) helps create and provide trusted users with temporary security credentials that can control access to AWS resources

4

OpenID Connect-compatible identity provider
應該就是指 Amazon, Google 這些可以 外掛 帳密 的公司
,所以手機登入帳密的問題,關鍵字就是: Identity Providers and Federation 、Web Identity Federation
參考:IAM Role – Identity Providers and Federation
https://media.amazonwebservices.com/blog/2013/iam_web_identity_federation_1.png

AWS KMS

AWS Key Management Service
來源:AWS Key Management Service – KMS – Overview
KMS — Customer Master Keys
KMS — CLI Commands

https://jayendrapatil.com/wp-content/uploads/2019/08/key-hierarchy-cmk.png

關鍵字:AES-256、Envelope Encryption

Customer Master Keys (CMKs) : 加密 Data Keys
Data Keys (Envelop Keys) : 加密 資料

接著 S3 加密部分:
AWS S3 Data Protection – Certification
Notes for AWS Certified Solutions Architect Associate

S3 encryptions(s3加密三種類型)

1 SSE-S3(Server-Side Encryption-S3): Data and master keys managed by S3.

2 SSE-C(customer代表顧客,所以使用者可以自己管理加密鑰匙): The user manages the encryption keys.
That means, if you lose the encryption key, you lose the object.

3 SSE-KMS: AWS manages the data key, the user manages the master key.

https://ithelp.ithome.com.tw/upload/images/20200128/201119947kwke0pa4V.png


上一篇
AWS EBS 、 S3 、 RDS、Storage Gateway、Instance Store Storage
下一篇
AWS ELB 、 CloudFront 、 Route 53 、 SNS 、 Lambda、CloudFormation、SQS
系列文
Linux學習30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言