'Cloud&Container/AWS'에 해당되는 글 12건

  1. 2020.03.03 [AWS IoT] CA 인증서 등록
  2. 2020.02.25 [AWS] VPC 부터 EC2 생성해서 SSH 연결해보기

[AWS IoT] CA 인증서 등록

Cloud&Container/AWS 2020. 3. 3. 20:42

참고 문서)

https://docs.aws.amazon.com/iot/latest/developerguide/device-certs-your-own.html

 

$ openssl genrsa -out rootCA.key 2048
$ openssl req -x509 -new -extensions v3_ca -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.pem
Country Name (KR) []:KR
State or Province Name (full name) []:
Locality Name (eg, city) []:
Organization Name (eg, company) []:
Organizational Unit Name (eg, section) []:
Common Name (eg, fully qualified host name) []:
Email Address []:
$ openssl genrsa -out verificationCert.key 2048
$ aws iot get-registration-code 
{
    "registrationCode": "879216d3f0b9fee2e0947fe32fd4ed9670d65fa9aff3e67e590582db30f62878"
}
$ openssl req -new -key verificationCert.key -out verificationCert.csr
Country Name (KR) []:KR
State or Province Name (full name) []:
Locality Name (eg, city) []:
Organization Name (eg, company) []:
Organizational Unit Name (eg, section) []:
Common Name (eg, fully qualified host name) []:879216d3f0b9fee2e0947fe32fd4ed9670d65fa9aff3e67e590582db30f62878
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
$ openssl x509 -req -in verificationCert.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out verificationCert.pem -days 500 -sha256
$ aws iot register-ca-certificate --ca-certificate file://rootCA.pem --verification-cert file://verificationCert.pem
{
    "certificateArn": "arn:aws:iot:ap-northeast-2:99999999999:cacert/879216d3f0b9fee2e0947fe32fd4ed9670d65fa9aff3e67e590582db30f62878",
    "certificateId": "879216d3f0b9fee2e0947fe32fd4ed9670d65fa9aff3e67e590582db30f62878"
}
 
$ cat /etc/ssl/openssl.cnf
[ req ]
#default_bits = 2048
#default_md = sha256
#default_keyfile  = privkey.pem
distinguished_name = req_distinguished_name
extensions               = v3_ca # 추가 설정
req_extensions           = v3_ca # 추가 설정
attributes = req_attributes

[ v3_ca ]
basicConstraints         = CA:TRUE # 추가 설정

[ req_distinguished_name ]
countryName = Country Name (KR)
countryName_min = 2
countryName_max = 2
stateOrProvinceName = State or Province Name (full name)
localityName = Locality Name (eg, city)
0.organizationName = Organization Name (eg, company)
organizationalUnitName = Organizational Unit Name (eg, section)
commonName = Common Name (eg, fully qualified host name)
commonName_max = 64
emailAddress = Email Address
emailAddress_max = 64

[ req_attributes ]
challengePassword = A challenge password
challengePassword_min = 4
challengePassword_max = 20

 

위 테스트는 맥북에서 진행 된 것입니다.

Ubuntu 에서는 별도 설정 변경 없이 잘 되는 것으로 이야기 들었습니다.

저 위에 빨간색 부분이 달라 계속 오류가 발생을 했었습니다.

 

[에러메시지]

An error occurred (CertificateValidationException) when calling the RegisterCACertificate operation: CA certificate is not valid.

The CA certificate does not have the basicConstraints extension as true

:

[AWS] VPC 부터 EC2 생성해서 SSH 연결해보기

Cloud&Container/AWS 2020. 2. 25. 16:30

AWS 에서 쵝 인프라 및 네트워크를 구성 하고 Bastion 설정을 통해 SSH Tunneling 을 해보도록 하겠습니다.

(기억력을 돕기 위해 작성한 내용입니다.)

 

[AWS에서 초기 인프라 및 네트워크 구성 하기]
생성 하는 순서는 아래와 같이 진행을 하시면 됩니다.

1. VPC 생성을 합니다.
2. Subnet 생성을 합니다.
- Public Subnet
- Private Subnet
3. Route Table 생성을 합니다.
- Public Route Table
- Private Route Table
4. Subnet 과 Route Table 연결을 합니다.
5. Internet Gateway 생성을 합니다.
- 인터넷 전용 연결 게이트웨이로 사용 합니다.
6. VPC 와 Internet Gateway 연결을 합니다.
7. Route Table 에서 Internet Gateway 연결을 합니다.
- Public Route Table 을 연결 합니다.
8. Network ACL 과 Security Group 설정을 합니다.
- 생성한 자원들에 대한 접근 제어 설계를 통해 구성 합니다.
- Inbounds, Outbounds


[VPC 생성]
- 생성할 VPC Name tag 를 작성 합니다.
- vpc-startup
- IPv4 CIDR block 을 작성 합니다.
- 10.0.0.0/16
참고 글)
https://jjeong.tistory.com/1405
- IPv6 CIDR block 은 기본 "No IPv6 CIDR Block" 을 선택 합니다.
- Tenancy 는 "Default" 를 선택 합니다.

[Subnet 생성]
- 생성할 Subnet 의 Name tag 를 작성 합니다.
- sbn2a-prd-public
- sbn2b-prd-private
- 연결할 VPC 를 선택 합니다.
- 생성할 Availability Zone 을 선택 합니다.
- VPC CIDR 범위에 속하는 IPv4 CIDR block 을 등록 합니다.
- 10.0.0.0/20
- First IP : 10.0.0.0
- Last IP : 10.0.15.255
- AWS 내 Available IPv4 Addresses : 4091 개

[Route Table 생성]
- 생성할 Route Table 의 Name tag 를 작성 합니다.
- rtb-prd-public
- rtb-prd-private
- 연결할 VPC 를 선택 합니다.

[Subnet 과 Route Table 연결]
- Route Table 정보 화면에서 Subnet Associations 를 선택 합니다.
- Edit subnet associations 를 클릭 합니다.
- 연결할 Subnet 을 선택 합니다.

[Internet Gateway 생성 / VPC 와 연결]
- 생성할 Internet Gateway 의 Name tag 를 작성 합니다.
- 목록에서 생성한 IGW 를 선택 하고 Actions 에서 Attach to VPC 를 통해 연결 합니다.

[Route Table 에 Internet Gateway 연결]
- Public Route Table 에서 Routes 탭의 Edit routes 를 클릭 합니다.
- Add route 를 통해 IGW 를 등록 합니다.
- 0.0.0.0/0

[Network ACL 설정 및 Subnet 연결]
- Public zone 과 Private zone 에 대한 ACL 을 생성 합니다.
- 생성할 ACL 의 Name tag 를 작성 합니다.
- acl-prd-public
- acl-prd-private
- 연결할 VPC 를 선택 합니다.
- Public zone acl 에 SSH Tunnel Gateway 구성을 위한 Inbound Rule 을 생성 합니다.
- 초기 SSH 연결 테스트만 하기 위한 설정 입니다.
- SSH(22), TCP(6), 22, 0.0.0.0/0, ALLOW
- Private zone acl 에 Inbound Rule 을 생성 합니다.
- SSH Tunnel Gateway 에서 접속 할 수 있도록 SSH 오픈 및 Source 제한을 합니다.
- 설정한 ACL 을 Subnet 에 적용 될 수 있도록 연결 설정 합니다.

[Security Group 생성]
- 생성할 Security Group Name 을 작성 합니다.
- 사용할 VPC 를 선택 합니다.
- SSH Tunnel Gateway 구성을 위한 Inbound 를 설정 합니다.
-  SSH, TCP, 22, My IP 로 Add Rule 합니다.
- Outbound 는 All 로 구성 합니다.

여기까지 했으면 VPC, ZONE, Security 에 대한 기본 구성을 해본 것입니다.
이제 EC2 인스턴스를 생성해서 SSH Tunnel 용 Gateway (Bastion) 를 구성해 보도록 하겠습니다. 

[EC2 생성]
- Amazon Linux 2 AMI 를 선택 합니다.
t2.micro 를 선택 합니다. (저는 free tier 적용을 위해 선택 했기 때문에 용도와 목적에 맞게 선택 하시면 됩니다.)
- 생성할 VPC 를 선택 합니다.
- 생성할 Subnet 을 선택 합니다.
- Public IP 할당 여부를 선택 합니다. (Bastion 구성을 위해 Public IP 할당)
- Storage, Tag 설정 이후 Security Group 설정을 합니다.
- Select an existing security group 을 통해 이미 만들어 놓은 것을 선택 합니다.
- Key pair 를 다운받습니다.
- 인스턴스를 시작 합니다.

[SSH 연결]
$ ssh -i ec2key-prd-gw.pem ec2-user@ec2-xxx-xxx-xxx-xxx.ap-northeast-2.compute.amazonaws.com

[ssh-keygen on 맥북]
$ ssh-keygen -t rsa
$ cat .ssh/id_rsa.pub
ssh-rsa .....HENRYJEONG.local

[User 생성]

https://docs.aws.amazon.com/ko_kr/AWSEC2/latest/UserGuide/managing-users.html
[ec2-user@ip-42 ~]$ sudo adduser henryjeong
[ec2-user@ip-42 ~]$ sudo su - henryjeong
[henryjeong@ip-42 ~]$ mkdir .ssh
[henryjeong@ip-42 ~]$ chmod 700 .ssh
[henryjeong@ip-42 .ssh]$ touch authorized_keys
[henryjeong@ip-42 .ssh]$ chmod 600 authorized_keys
[henryjeong@ip-42 .ssh]$ vi authorized_keys

[User 로 접속]
$ ssh henryjeong@xxx.xxx.xxx.xxx
Last login: Tue Feb 25 07:23:45 2020

       __|  __|_  )
       _|  (     /   Amazon Linux 2 AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/
[henryjeong@ip-10-0-6-44 ~]$

# EC2 에 Public IP 는 생성이 되었으나 Public DNS 가 생성되지 않았을 경우 

Your answer

  • Go to console.aws.amazon.com.
  • Go To Services and then VPC.
  • Open Your VPCs.
  • Select your VPC connected to your EC2 and.
  • Choose Select Actions.
  • Click on Edit DNS Hostnames.
  • Then Change DNS hostnames: to YES.
: