ããã«ã¡ã¯ãSRE2課ã®ç¦å³¶ã§ãã
- ã¯ããã«
- ãã¤ã³ã
- æ¤è¨¼
- â ACMã§è¨¼ææ¸ã®çºè¡
- â¡EC2ã¤ã³ã¹ã¿ã³ã¹ã®ä½æï¼ç¹å®ã®AMIãå©ç¨ãããï¼
- â¢IAMãã¼ã«ã®ä½æ
- â£â¢ã§ä½æããIAMãã¼ã«ã証ææ¸ã«é¢é£ä»ã
- â¤â¢ã§ä½æããIAMãã¼ã«ã«ããªã·ã¼é©ç¨
- â¥â¡ã§ä½æããEC2ã«IAMãã¼ã«ãã¢ã¿ãã
- â¦Nginxã®è¨å®
- çµããã«
- ãã¾ã
ã¯ããã«
ä»åã¯ã以ä¸ã®ã¢ãããã¼ããå®éã«è©¦ãã¦ã¿ã¾ããã®ã§ãããã°ã«ã¾ã¨ãããã¨æãã¾ãã
ä»ã¾ã§ã¯ãACMã§çºè¡ãã証ææ¸ãEC2ã§å©ç¨ãããã¨ãã§ãã¾ããã§ããã
ããããä»åã®ã¢ãããã¼ãã«ããã
ç¹å®ã®AMIããä½æããEC2ã«
ACMã§çºè¡ãã証ææ¸(Publicããã³Private)ã
å©ç¨å¯è½ã¨ãªãã¾ããã
æ¤è¨¼ã«ã¯ã以ä¸ã®AWSã®ããã¥ã¡ã³ããåèã«ãããã¾ããã
Nitro Enclaves application: AWS Certificate Manager for Nitro Enclaves - AWS Nitro Enclaves
ãã¤ã³ã
- ç¾æç¹(10/29æç¹)ã§ã¯ãNginxã®ã¿ãµãã¼ããã¦ããã¾ãã
â»ä»ã®Webãµã¼ãã½ããã¦ã§ã¢ã¯ãä»å¾è¿½å ãµãã¼ããããäºå®ã®ããã§ãã ACMã«IAMãã¼ã«ãé¢é£ä»ãããã®ã§ãããç¾æç¹(10/29æç¹)ã§ã¯ãAWS CLIv2ã§ã¯ãªããv1ããããå®è¡ã§ãã¾ããã§ããã
ï¼aws-cli/2.0.60ã«ã¯ãassociate-enclave-certificate-iam-roleã³ãã³ããããã¾ããã§ãã...ï¼- aws-cli/2.0.61ããassociate-enclave-certificate-iam-roleã使ããããã«ãªãã¾ããã
- EC2ã«ã¯ãACMã¨ã¼ã¸ã§ã³ã(/usr/bin/p11ne-agent)ãèµ·åãã¾ãã
- EC2ã¤ã³ã¹ã¿ã³ã¹ã«ãEnclaves Supportãã¨ããè¨å®å¤ã追å ããã¦ãã¾ããã
â»ããã³ã³ããå¤æ´ãããã¿ã³ãè¦ã¤ãããªãã£ããããCLIããã®ã¿å¤æ´å¯è½ããã§ãã - ç¹å®ã®AMIããµãã¼ããã¦ããã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ãã¯è¦ç¢ºèªã§ãã
ï¼--dry-runãæåãã¦ããå®éã«ä½æããã¨å¤±æããã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ããããã¾ãããï¼
â»--dry-runãæåããã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ãä¸è¦§ã¯ãæå¾ã«è¨è¼ãã¦ããã¾ãã(2020/11/11æç¹)
æ¤è¨¼
ã§ã¯ãããããæ¤è¨¼ãã¦ããã¾ãã
â ACMã§è¨¼ææ¸ã®çºè¡
ä»åã¯ãå ¬é証ææ¸ãå©ç¨ãã¾ããã®ã§ã çºè¡ã¯ä»¥ä¸ã®ããã¥ã¡ã³ããåèã«å®æ½ãã¾ãã
âå
¬é証ææ¸ã®è¦æ±
https://docs.aws.amazon.com/ja_jp/acm/latest/userguide/gs-acm-request-public.html
証ææ¸ãçºè¡ãã¾ãããããã®å¾ã«è¨¼ææ¸ã®ARNãå©ç¨ãããããå¤æ°ã«å®ç¾©ãã¦ããã¾ãã
CERTARN=""
ä¾ï¼
CERTARN="arn:aws:acm:ap-northeast-1:xxxxxxxxxxxxxx:certificate/xxxxxxxxxxxxxxxxxxxxxxxx"
â¡EC2ã¤ã³ã¹ã¿ã³ã¹ã®ä½æï¼ç¹å®ã®AMIãå©ç¨ãããï¼
ãªã¼ã¸ã§ã³ã«ãã£ã¦ãå©ç¨ã§ããAMIã¯ä»¥ä¸ã®éãã¨ãªãã¾ãã
us-east-1âami-02fa3c4d1f12632a1
us-east-2âami-000d7dc3e9ccae7d4
us-west-2âami-057b2b88789d1c84c
eu-central-1âami-0738562c059302222
eu-west-1âami-0f6444b7dfa686df6
eu-west-2âami-08c96941f8b4617da
eu-west-3âami-0e0e7a03eec2a41b6
eu-north-1âami-0559b8814edf3321c
ap-east-1âami-099f011eb57f563d2
ap-northeast-1âami-088ab55ef296edbb1
ap-southeast-1âami-0fdbbac04c25021d2
ap-southeast-2âami-0c8174530d0ec5cbc
ap-south-1âami-041d0d4bb66b8dcd3
sa-east-1âami-0ddec972a8d04b740
ä»åã¯ãæ±äº¬ãªã¼ã¸ã§ã³(ap-northeast-1)ã®AMIãå©ç¨ãã¾ããã
ã¾ããèµ·åã§ããã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ãã®è¨è¼ãããã¥ã¡ã³ãã«ãªããåé ã«è¨è¼ãã¦ããã¾ããã
--dry-runã§æåãã¦ãå®éã«å®è¡ããã¨ä½æã§ããªãã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ããããã¾ããã®ã§ã
å©ç¨ããã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ãã使ãããã¯ãè¦ç¢ºèªã§ãã
â»ä»åã¯ããã¾ãã¾èµ·åã§ãããm5.xlargeãã使ç¨ãã¾ããã
ç°å¢å¤æ°ãå®ç¾©ãã¾ãã â»ããã©ã«ãVPCãåå¨ããå¿ è¦ãããã¾ãã
AMIID="" INSTANCETYPE="" KEYPEA=""
ä¾ï¼
AMIID="ami-088ab55ef296edbb1" INSTANCETYPE="m5.xlarge" KEYPEA="fk-test-key"
å¤æ°ãå®ç¾©ãããã以ä¸ã®ã³ãã³ããã³ããã§å®è¡ãã¾ãã
aws ec2 run-instances --image-id ${AMIID} --count 1 --instance-type ${INSTANCETYPE} --key-name ${KEYPEA} --enclave-options 'Enabled=true'
ã¾ããã¤ã³ã¹ã¿ã³ã¹ã«ã¯ããEnclaves Supportãã¨ããè¨å®å¤ãå¢ãã¦ããã
ãã®è¨å®ãæå¹ã«ãããããä¸è¨ã³ãã³ãã§ã--enclave-options 'Enabled=true'ããæå®ãã¦ãã¾ãã
â»ããã³ã³ããã¯è¨å®ãå¤æ´ãããã¿ã³ãè¦å½ãããªãã£ãã®ã§ããããããCLIããã®ã¿å¤æ´ãã§ããè¨å®å¤ã®ããã§ãã
ãªããã¤ã³ã¹ã¿ã³ã¹IDã¯ãã®å¾ãå©ç¨ãããããå¤æ°ã«å®ç¾©ãã¦ããã¾ãã
INSTANCEID=""
ä¾ï¼
INSTANCEID="i-xxxxxxxxx"
â¢IAMãã¼ã«ã®ä½æ
以ä¸ã®éãããã¡ã¤ã«ãä½æãã¾ãã
ãã¡ã¤ã«åï¼acm-role.json
{ "Version":"2012-10-17", "Statement":[ { "Effect":"Allow", "Principal":{ "Service":"ec2.amazonaws.com" }, "Action":"sts:AssumeRole" } ] }
以ä¸ã®ã³ãã³ãããã®ã¾ã¾å®è¡ããIAMãã¼ã«ãä½æãã¾ãã
â»ããã§ã¯ãä¿¡é ¼é¢ä¿ã®ã¿ãè¨å®ããå®éã®æ¨©é(ããªã·ã¼)ã¯ãâ¤ã§è¡ãã¾ãã
aws iam create-role --role-name acm-role --assume-role-policy-document file://acm-role.json
ã¾ããä½æããIAMãã¼ã«ã®ARNããã®å¾ãå©ç¨ãããããå¤æ°ã«å®ç¾©ãã¦ããã¾ãã
ROLEARN=""
ä¾ï¼
ROLEARN="arn:aws:iam::xxxxxxxxxxx:role/acm-role"
â£â¢ã§ä½æããIAMãã¼ã«ã証ææ¸ã«é¢é£ä»ã
â ã§ä½æãã証ææ¸ã®ARNããã³â¢ã§ä½æããIAMãã¼ã«ã®ARNã å¤æ°ã«å®ç¾©ãã¦ããããã以ä¸ã®ã³ãã³ãããã®ã¾ã¾å®è¡ãã¾ãã
aws ec2 associate-enclave-certificate-iam-role --certificate-arn ${CERTARN} --role-arn ${ROLEARN}
ä¸è¨ã³ãã³ããå®è¡å¾ãåºåããã ãCertificateS3BucketNameãããã³ãEncryptionKmsKeyIdããæ§ãã¦ããã¾ãã ï¼â¤ã§å©ç¨ãã¾ããï¼
â¤â¢ã§ä½æããIAMãã¼ã«ã«ããªã·ã¼é©ç¨
以ä¸ã®éãããã¡ã¤ã«ãä½æãã¾ãã
ãã¡ã¤ã«åï¼acm-role-policies.json
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:GetObject" ], "Resource": ["arn:aws:s3:::CertificateS3BucketName/*"]ãâ ç·¨é }, { "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "kms:Decrypt" ], "Resource": "arn:aws:kms:ap-northeast-1:*:key/EncryptionKmsKeyId"ãâ ç·¨é } ] }
â»ããªã·ã¼ã®CertificateS3BucketNameããã³EncryptionKmsKeyIdãâ£ã§åºåãããçµæã«å¤æ´ãã¾ãã
以ä¸ã®ã³ãã³ãã§ããªã·ã¼ãé©ç¨ãã¾ãã
aws iam put-role-policy --role-name acm-role --policy-name acm-role-policy --policy-document file://acm-role-policies.json
â¥â¡ã§ä½æããEC2ã«IAMãã¼ã«ãã¢ã¿ãã
â¡ã§ä½æããEC2ã®ã¤ã³ã¹ã¿ã³ã¹IDãå¤æ°ã«å®ç¾©ãã¦ããã¾ãã®ã§ã以ä¸ã®ã³ãã³ãããã®ã¾ã¾ãå®è¡ãã¾ãã
aws iam create-instance-profile --instance-profile-name acm-instance-profile aws iam add-role-to-instance-profile --instance-profile-name acm-instance-profile --role-name acm-role aws ec2 associate-iam-instance-profile --instance-id ${INSTANCEID} --iam-instance-profile Name=acm-instance-profile
â¦Nginxã®è¨å®
ããããNginxã®è¨å®ãè¡ãã¾ãã ã¾ããâ¡ã§ä½æããEC2ã«SSHã§ãã°ã¤ã³ãã¾ãã â»ãããããããã©ã«ãã®SGãä»ä¸ããã¦ãããããé©åãªéä¿¡è¨å®ãè¡ãå¿ è¦ãããã¾ãã
/etc/nitro_enclaves/acm.yamlã®ç·¨é
sudo mv /etc/nitro_enclaves/acm.example.yaml /etc/nitro_enclaves/acm.yaml
ã»viçã§ã/etc/nitro_enclaves/acm.yamlãã®ãcertificate_arnããç·¨éãã¾ãã
è¨å®ä¾ï¼
certificate_arn: "arn:aws:acm:ap-northeast-1:xxxxxxxxxxxxxx:certificate/xxxxxxxxxxxxxxxxxxxxxxxxxx"
/etc/nginx/nginx.confã®ç·¨é
mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.org
vi /etc/nginx/nginx.conf
以ä¸ã®å 容ãè²¼ãä»ãã¾ãã â»server_name(â )ã®ã¿ãç·¨éãã¾ãã
# For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; ssl_engine pkcs11; # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 4096; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; server { listen 80; listen [::]:80; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } # Settings for a TLS enabled server. # server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name example.com;ãâ ç·¨é root /usr/share/nginx/html; ssl_protocols TLSv1.2; ssl_session_cache shared:SSL:1m; ssl_session_timeout 10m; ssl_prefer_server_ciphers on; # Set this to the stanza path configured in /etc/nitro_enclaves/acm.yaml include "/etc/pki/nginx/nginx-acm.conf"; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } }
å¤æ´ç¹ãç¥ãããå ´åã以ä¸ã®ã³ãã³ãã§ç¢ºèªãå¯è½ã§ãã
diff /etc/nginx/nginx.conf /etc/nginx/nginx.conf.org
æå¾ã«ä»¥ä¸ã®ã³ãã³ããå®è¡ããè¨å®å®äºã§ãï¼ï¼
â»ACMã¨ã¼ã¸ã§ã³ããèµ·åãã¦ãã¾ãã
sudo systemctl start nitro-enclaves-acm.service
以ä¸ã®ã³ãã³ãã§èµ·åãã¦ãããã¨ã確èªãã¾ãã
sudo systemctl status nitro-enclaves-acm.service
ã¾ããã©ãã§ãããã§ãããä¸è¨ãµã¼ãã¹ã«ã¯ãACMã¨ã¼ã¸ã§ã³ããèµ·åå¾ãnginx.serviceãèµ·åããããã«è¨å®ããã¦ããããã§ããã 以ä¸ã®ã³ãã³ãã§nginxãèµ·åããã¦ãããã¨ã確èªã§ãã¾ãã
sudo systemctl status nginx.service
å¾ã¯ããã©ã¦ã¶ãããããªãã¯IPãããã¯è¨¼ææ¸ã®ãã¡ã¤ã³åã§ã¢ã¯ã»ã¹ã§ãããã¨ã確èªãã¾ãã
https://ãããªãã¯IP or https://証ææ¸ã®ãã¡ã¤ã³å
çµããã«
ããæ¤è¨¼ã§ããããªã¨æã£ã¦ãã¾ããããaws cliv2ã§ã¯ãIAMãã¼ã«ãACMã®è¨¼ææ¸ã«é¢é£ä»ãã§ããªãã£ããã èµ·åã§ããã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ããè¦ã¤ããã®ã«è¦å´ãããã¨äºæ³ä»¥ä¸ã«ã¯ã¾ã£ã¦ãã¾ãã¾ãã...
ã©ãªããã®ãå½¹ã«ç«ã¦ãã°å¹¸ãã§ãã
ãã¾ã
dry-runãæåããã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ãä¸è¦§
確èªã³ãã³ã
aws ec2 run-instances --image-id ${AMIID} --count 1 --instance-type ${INSTANCETYPE} --key-name ${KEYPEA} --enclave-options 'Enabled=true' --dry-run
dry-runãæåããã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ã | ||||||
---|---|---|---|---|---|---|
c5.xlarge | c5.2xlarge | c5.4xlarge | c5.9xlarge | c5.12xlarge | c5.18xlarge | c5.24xlarge |
c5a.xlarge | c5a.2xlarge | c5a.4xlarge | c5a.8xlarge | c5a.12xlarge | c5a.16xlarge | c5a.24xlarge |
c5d.xlarge | c5d.2xlarge | c5d.4xlarge | c5d.9xlarge | c5d.12xlarge | c5d.18xlarge | c5d.24xlarge |
c5n.xlarge | c5n.2xlarge | c5n.4xlarge | c5n.9xlarge | c5n.18xlarge | - | - |
g4dn.xlarge | g4dn.2xlarge | g4dn.4xlarge | g4dn.8xlarge | g4dn.12xlarge | g4dn.16xlarge | - |
i3en.xlarge | i3en.2xlarge | i3en.3xlarge | i3en.6xlarge | i3en.12xlarge | i3en.24xlarge | - |
inf1.xlarge | inf1.2xlarge | inf1.6xlarge | inf1.24xlarge | - | - | - |
m5.xlarge | m5.2xlarge | m5.4xlarge | m5.8xlarge | m5.12xlarge | m5.16xlarge | m5.24xlarge |
m5a.xlarge | m5a.2xlarge | m5a.4xlarge | m5a.8xlarge | m5a.12xlarge | m5a.16xlarge | m5a.24xlarge |
m5ad.xlarge | m5ad.2xlarge | m5ad.4xlarge | m5ad.8xlarge | m5ad.12xlarge | m5ad.16xlarge | m5ad.24xlarge |
m5d.xlarge | m5d.2xlarge | m5d.4xlarge | m5d.8xlarge | m5d.12xlarge | m5d.16xlarge | m5d.24xlarge |
m5dn.xlarge | m5dn.2xlarge | m5dn.4xlarge | m5dn.8xlarge | m5dn.12xlarge | m5dn.16xlarge | m5dn.24xlarge |
m5n.xlarge | m5n.2xlarge | m5n.4xlarge | m5n.8xlarge | m5n.12xlarge | m5n.16xlarge | m5n.24xlarge |
p3dn.24xlarge | - | - | - | - | - | - |
r5.xlarge | r5.2xlarge | r5.4xlarge | r5.8xlarge | r5.12xlarge | r5.16xlarge | r5.24xlarge |
r5a.xlarge | r5a.2xlarge | r5a.4xlarge | r5a.8xlarge | r5a.12xlarge | r5a.16xlarge | r5a.24xlarge |
r5ad.xlarge | r5ad.2xlarge | r5ad.4xlarge | r5ad.8xlarge | r5ad.12xlarge | r5ad.16xlarge | r5ad.24xlarge |
r5d.xlarge | r5d.2xlarge | r5d.4xlarge | r5d.8xlarge | r5d.12xlarge | r5d.16xlarge | r5d.24xlarge |
r5dn.xlarge | r5dn.2xlarge | r5dn.4xlarge | r5dn.8xlarge | r5dn.12xlarge | r5dn.16xlarge | r5dn.24xlarge |
r5n.xlarge | r5n.2xlarge | r5n.4xlarge | r5n.8xlarge | r5n.12xlarge | r5n.16xlarge | r5n.24xlarge |
z1d.xlarge | z1d.2xlarge | z1d.3xlarge | z1d.6xlarge | z1d.12xlarge | - | - |