ããã«ã¡ã¯ï¼
AWSããããªãæãæè¡4課ã®å±±æ¬(é称ã¤ãã¾ã³)ã§ã
æ¨æ¥ã¯å®è³ª9æéãããå¯ã¾ãã
ä»æ¥ã¯ãAWS Systems Manager(以ä¸ãSSM)ã®æ°æ©è½ã«ã¤ãã¦ç´¹ä»ãã¾ã
- ã»ãã·ã§ã³ããã¼ã¸ã£ã¼ã使ç¨ãããã¼ã«ã«ãã¼ãã¨ãªã¢ã¼ããã¼ãéã®ãã©ãã£ãã¯ã®è»¢éãå¯è½ã« ( 2019/08/28 )
- AWS System Manager Sessions Manager ã使ç¨ããæ°ãã â Port Forwarding ( 2019/09/02 )
SSMã§ãã¼ããã©ã¯ã¼ãã£ã³ã°æ©è½ãæä¾ããããã«ãªãã¾ããï½ (ææ) ãã©ã¤ãã¼ããµããããã®EC2ã«sshãRDPã§æ¥ç¶ããéã«ã¯ã å¤ãã®å ´åã«ããè¸ã¿å°ãµã¼ãã使ã£ã¦ãã¼ããã©ã¯ã¼ãã£ã³ã°ããã¦ãã¾ã (â»1) â»1 å³å¯ã«ã¯ã2019å¹´7æã®ã¢ãããã¼ãã«ãããSSHã®ãã³ããªã³ã°ã«ã¤ãã¦ã¯ããããµãã¼ããã¦ãã¾ã ã»ãã·ã§ã³ããã¼ã¸ã£ã¼ã SSH 㨠SCP ã®ãã³ããªã³ã°ãµãã¼ããéå§ ( 2019/07/09 )
è¸ã¿å°ãµã¼ãã£ã¦ä½ï¼
è¸ã¿å°ãµã¼ãã¯ããã©ã¤ãã¼ããµããããããããªãã¯ãµããããã«ããåEC2ã«æ¥ç¶ããéã«ãå ¥ãå£ã¨ãªããµã¼ãã®ãã¨ã§ã è¸ã¿å°ãµã¼ãã¯ãæ ç¹ãªã©ã®ã°ãã¼ãã«IPããã¢ã¯ã»ã¹ãä¸æã«å¼ãåãã¦ãVPCå ã«ããä»ã®EC2ã«ã¢ã¯ã»ã¹å¯è½ã«ãã¾ã
- è¸ã¿å°ãµã¼ã(Bastion)ã®å³
- åEC2ã®ã»ãã¥ãªãã£ã°ã«ã¼ãã«ã¯ãsshãRDPã®ãã¼ããè¸ã¿å°ãµã¼ãã«å¯¾ãã¦éæ¾ãã¦ãããè¸ã¿å°ãµã¼ãããã¢ã¯ã»ã¹å¯è½ã«ãã¾ã
- ãããªãã¯ãµããããã«é ç½®ããè¸ã¿å°ãµã¼ãã®ã»ãã¥ãªãã£ã°ã«ã¼ãã«ã¯ãæ¥ç¶æ ç¹ã®IPã¢ãã¬ã¹(32ãããæ¨å¥¨)ããã®sshã¾ãã¯RDPã®ã¿ã許å¯ãã¦ããã¾ã
- 1,2ã®è¨å®ã«ãããæ ç¹ããè¸ã¿å°ãµã¼ãã«æ¥ç¶(RDP/ssh)ããè¸ã¿å°ãµã¼ãããåEC2ã«æ¥ç¶(RDP/ssh)å¯è½ã«ãªãã¾ã
å³ã«æ¸ãã¦ããªããã®ã®ããã¡ãããè¸ã¿å°ãµã¼ãããä»ã®AZã«ãããµããããã®EC2ãããããªãã¯ãµããããã®EC2ã«ãæ¥ç¶å¯è½ã«ãã¾ã ã¾ããè¸ã¿å°ãµã¼ããã®ãã®ãããã«ãAZ(è¤æ°ã®AZã«ãããã1å°ã¯æ§ç¯ããç¶æ )ã«ãããã¨ããAWSã¯æ¨å¥¨ãã¦ãã¾ã å ¬å¼ããã¥ã¡ã³ãã§ã¯ãè¸ã¿å°ãµã¼ãã®ãã¨ãBastion(è¦å¡)ã¨è¨ã£ã¦ãã¾ã Windowsã§ã¯ãRD Gateway ã¨ããæè¡ã使ããè¸ã¿å°ãµã¼ããæ§ç¯ãã¾ã
- ãåè
ãã¼ããã©ã¯ã¼ãã£ã³ã°ã£ã¦ä½ï¼
Clientã®æå®ãã¼ãã«æ¥ãéä¿¡ãããªã¢ã¼ããµã¼ãã¼(EC2)ã®æå®ãã¼ãã«ãè¸ã¿å°ãµã¼ããå©ç¨ãã¦ããã©ã¯ã¼ãã£ã³ã°(転é)ããæ©è½ã«ãªãã¾ã
- ãã¼ããã©ã¯ã¼ãã£ã³ã°ã®å³
Clientãããã¼ããã©ã¯ã¼ãã£ã³ã°ãè¨å®ããã¨ã Clientã®ãã¼ã(å³ã®ä¾ãªãã9999ãã¼ã)ã«ssh/RDP æ¥ç¶ããéã«ã EC2ã®æå®ãã¼ã(å³ã®ä¾ãªãã22ãã¼ã)ã«æ¥ç¶ããããã«ãªãã¾ã Clientå©ç¨è ã¯ãè¸ã¿å°ãµã¼ããæèãããClientããç´æ¥EC2ã«ç¹ãããã«ãªãã¾ã ãã¼ããã©ã¯ã¼ãã£ã³ã°ããéã®åææ¡ä»¶ã¯ä»¥ä¸ã§ã
- Clientãããã¼ããã©ã¯ã¼ãã£ã³ã°ã«ä½¿ç¨ãããããã³ã«(sshãªã©)ã使ããè¸ã¿å°ãµã¼ãã«æ¥ç¶å¯è½ãªãã¨
- è¸ã¿å°ãµã¼ãããEC2ã®æå®ãã¼ã(å³ã®ä¾ãªãã22ãã¼ã)ã«æ¥ç¶å¯è½ãªãã¨
- Clientã®æå®ãã¼ã(å³ã®ä¾ãªãã9999ãã¼ã)ã¯æªä½¿ç¨ã«ãªã£ã¦ãã¦ã空ãã¦ãããã¨
- è¸ã¿å°ãµã¼ãã¨EC2ã®OSèªè¨¼æ å ±ãæã£ã¦ãããã¨
é·ããªããããå ·ä½çãªå®è¡æ¹æ³ã¯ç¤ºãã¾ãã 端æ«ãmacãªãsshã³ãã³ã(-Lãªãã·ã§ã³)ã端æ«Windowsãªãã¿ã¼ããã«ã½ãã(Teratermãªã©)ã«ã¦è¨å®ãå®è¡ã§ãã¾ã
ãAWS System Manager Sessions Manager ã使ç¨ããæ°ãã â Port Forwardingãã£ã¦ä½ï¼
æ¬é¡ã«ãªãã¾ã
- ãAWS System Manager Sessions Manager ã使ç¨ããæ°ãã â Port Forwardingãã®å³
Clientã®æå®ãã¼ãã«æ¥ãéä¿¡ãããªã¢ã¼ããµã¼ãã¼(EC2)ã®æå®ãã¼ãã«ãSSMãå©ç¨ãã¦ããã©ã¯ã¼ãã£ã³ã°(転é)ããæ©è½ã«ãªãã¾ã SSM ããè¸ã¿å°ãµã¼ãã®ä»£ããã«ãªãã¾ã
- æ¥ç¶æ ç¹ã®IPã¢ãã¬ã¹(32ãããæ¨å¥¨)ããã®sshã¾ãã¯RDPã®ã¿ã許å¯ããã«ã¯ãIAMã¦ã¼ã¶ã¼ã«ã¢ã¿ããããIAMãã¼ã«ã使ç¨ãã¾ã
ã¾ããIAMãã¼ã«ãå©ç¨ãã¦ãæ¥ç¶å¯è½ãªEC2ãå¶å¾¡ãããã¨ãå¯è½ã«ãªã£ã¦ãã¾ã
å®éã«ãã£ã¦ã¿ã
IAM Policy ã§ã®IPå¶å¾¡çã¯ããã Administratorã«è¿ãIAMã¦ã¼ã¶ã¼æ¨©éã§ãåãã¢ã«ã¦ã³ãã®EC2ã«ã端æ«(Client)ãããã¼ããã©ã¯ã¼ãã£ã³ã°ãã¦ã¿ã¾ãã
Clientã®æºå
å³ã®ä¸è¨ç®æã«ãªãã¾ã
Macç·¨
- awscliã®ã¤ã³ã¹ãã¼ã«
- ä¸è¨ã³ãã³ãã«ããææ°ãã¼ã¸ã§ã³ã® AWS Command Line Interface (CLI) ã«ã¢ãããã¼ã
$ sudo pip install -U awscli ãåºåçç¥ã $ aws --version aws-cli/1.16.235 Python/3.7.2 Darwin/18.7.0 botocore/1.12.225
- ã¢ã¯ã»ã¹ãã¼ã»ã·ã¼ã¯ã¬ãããã¼ã®è¨å®
$ aws configure AWS Access Key ID [********************]:xxxxxxxxxxxxxxxx AWS Secret Access Key [********************]:xxxxxxxxxxxxxxxxxx Default region name [ap-northeast-1]: Default output format [None]:
- Session Manager Plugin ã®ã¤ã³ã¹ãã¼ã«
- ä¸è¨ãªã³ã¯åèã«ãSystems Manager CLI æ¡å¼µæ©è½ ãã¤ã³ã¹ãã¼ã«
$ curl "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/mac/sessionmanager-bundle.zip" -o "sessionmanager-bundle.zip" ãåºåçç¥ã $ unzip sessionmanager-bundle.zip ãåºåçç¥ã $ sudo ./sessionmanager-bundle/install -i /usr/local/sessionmanagerplugin -b /usr/local/bin/session-manager-plugin ãåºåçç¥ã $ session-manager-plugin --version 1.1.31.0
Windowsç·¨
- awscliã®ã¤ã³ã¹ãã¼ã«
- ä¸è¨ãåèã«ã¤ã³ã¹ãã¼ã«ãã¾ã (ãã£ããã£ã¯ç³ã訳ããã¾ãããè¼ãã¾ãã...)
$ aws --version aws-cli/1.16.234 Python/3.6.0 Windows/10 botocore/1.12.224
- ã¢ã¯ã»ã¹ãã¼ã»ã·ã¼ã¯ã¬ãããã¼ã®è¨å®
$ aws configure AWS Access Key ID [********************]:xxxxxxxxxxxxxxxx AWS Secret Access Key [********************]:xxxxxxxxxxxxxxxxxx Default region name [ap-northeast-1]: Default output format [None]:
- Session Manager Plugin ã®ã¤ã³ã¹ãã¼ã«
- ä¸è¨ãåèã«ã¤ã³ã¹ãã¼ã«ãã¾ã (ãã£ããã£ã¯ç³ã訳ããã¾ãããè¼ãã¾ãã...)
$ session-manager-plugin --version 1.1.31.0
EC2ã®æºå
å³ã®ä¸è¨ç®æã«ãªãã¾ã
EC2 ( Wiindows Server 2016 ) ä½æ
Windows Server 2016 ã1å°ç«ã¦ã¦æ¤è¨¼ããããã ä¸è¨æé ãå®æ½ãã¾ãã (ãã£ããã£ã¯ç³ã訳ããã¾ãããè¼ãã¾ãã...)
- VPCãä½æãããã®ä¸ã«Private ãµãããããä½æ
- Privateãµããããã«ãEC2ã®SSMã¨ã¼ã¸ã§ã³ããå©ç¨ããVPCã¨ã³ããã¤ã³ãä½æã(以ä¸4ã¤)
ã¨ã³ããã¤ã³ã |
---|
com.amazonaws.ap-northeast-1.ec2 |
com.amazonaws.ap-northeast-1.ec2messages |
com.amazonaws.ap-northeast-1.ssm |
com.amazonaws.ap-northeast-1.ssmmessages |
- Privateãµããããã«EC2ãä½æ
å©ç¨ããAMI |
---|
Windows_Server-2016-English-Full-Base-2019.08.16 (ami-068721b34f85a5a99) |
- EC2ã¨ãVPCã¨ã³ããã¤ã³ããéä¿¡ã§ããããã«ãã»ãã¥ãªãã£ã°ã«ã¼ããå¤æ´
- EC2ã«ä»ä¸ããIAMãã¼ã«ãä½æããä¸è¨1ã¤ã®SSMç¨ããªã·ã¼ãã¢ã¿ãããã
IAM Policy |
---|
AmazonEC2RoleforSSM |
- EC2ã«ãSSM ã®ãã³ãã³ãã®å®è¡ãæ©è½ã§ä¸è¨ãå®è¡ããSSMã¨ã¼ã¸ã§ã³ãã®ãã¼ã¸ã§ã³ãã¢ãããã¼ã ( AMIããèµ·åããã¤ã³ã¹ã¿ã³ã¹ã« Systems Manager ã®ã¨ã¼ã¸ã§ã³ãã¯ã¤ã³ã¹ãã¼ã«ããã¦ãããããã¢ãããã¼ãã®ã¿è¡ãã¾ã )
- 2.3.634.0 â 2.3.701.0 ã«ä¸ããã¾ãã
ã³ãã³ãã®ããã¥ã¡ã³ã |
---|
AWS-UpdateSSMAgent |
- EC2ã«ãã»ãã·ã§ã³ããã¼ã¸ã£ããããã¢ã¯ã»ã¹ããä¸è¨ã³ãã³ãã«ãããAdministratorã®ãã¹ã¯ã¼ããå¤æ´ããRDPæã®OSèªè¨¼ãå¯è½ã«ãã¦ãã
$ net user Administrator hogehoge(ãã¹ã¯ã¼ã) The command completed successfully.
ãã¼ããã©ã¯ã¼ãã£ã³ã°ãã¦ã¿ã
試ãã«Windows端æ«ãããã£ã¦ã¿ã¾ã
- Clientã«ã¦ãSSMã®API(aws ssm start-session)ãå®è¡ããSSMãå©ç¨ãã¦ãEC2ã«ãã¼ããã©ã¯ã¼ãã£ã³ã°ãã¾ã
$ aws ssm start-session --target i-xxxxxxxxxxxxxxxxx --document-name AWS-StartPortForwardingSession --parameters "portNumber=3389,localPortNumber=13389" Starting session with SessionId: xxxxxxxxxxxxxxxx
- ããããæ°ç§å¾ã«ãClientã®æå®ãã¼ã(ä¾ãªã13389ãã¼ã)ã«ã»ãã·ã§ã³ãéããæ¨ã®ã¡ãã»ã¼ã¸ã追å ããã¾ã
$ aws ssm start-session --target i-xxxxxxxxxxxxxxxxx --document-name AWS-StartPortForwardingSession --parameters "portNumber=3389,localPortNumber=13389" Starting session with SessionId: xxxxxxxxxxxxxxxx Port 13389 opened for sessionId xxxxxxxxxxxxxxxx â ã»ãã·ã§ã³ãéãã â
- ãRemote Desktop æ¥ç¶ãããClientã®æå®ãã¼ãã«æ¥ç¶ããRDPå¯è½ãªãã¨ã確èªãã¾ã
- æåããã¨ãã³ãã¯ã·ã§ã³ç¢ºçã«æåããã¡ãã»ã¼ã¸ãåºã¾ã
$ aws ssm start-session --target i-xxxxxxxxxxxxxxxxx --document-name AWS-StartPortForwardingSession --parameters "portNumber=3389,localPortNumber=13389" Starting session with SessionId: xxxxxxxxxxxxxxxx Port 9999 opened for sessionId xxxxxxxxxxxxxxxx Connection accepted for session xxxxxxxxxxxxxxxx â ã³ãã¯ã·ã§ã³ç¢ºçã«æå â
- Remote Desktop æ¥ç¶ãåæãã¾ãã¯[Ctrl] + c ãæ¼ãã¨ãã»ãã·ã§ã³çµäºã¨ãªãã¾ã
$ aws ssm start-session --target i-xxxxxxxxxxxxxxxxx --document-name AWS-StartPortForwardingSession --parameters "portNumber=3389,localPortNumber=13389" Starting session with SessionId: xxxxxxxxxxxxxxxx Port 9999 opened for sessionId xxxxxxxxxxxxxxxx Connection accepted for session xxxxxxxxxxxxxxxx Exiting session with sessionId: xxxxxxxxxxxxxxxx â ã»ãã·ã§ã³çµäº â
Windowsã§æåããã³ãã³ã
è¼ãã¦ããã¾ã
$ aws ssm start-session --target i-xxxxxxxx --document-name AWS-StartPortForwardingSession --parameters "portNumber=3389,localPortNumber=13389"
Powershellã§ã¯åºæ¥ã¾ããã§ãã....
$ Get-SSMSession -State Active # âããã¾ã§ã¯æåãã¦ãStatus : Connectedãã«ãªããã®ã®ãå®éã«æ¥ç¶åºæ¥ã¾ããã§ãã ( ä¸æãããããæ¹è¦ã¤ãããããã°æ¸ãã¾ã
macã§æåããã³ãã³ã
$ aws ssm start-session --target i-xxxxxxxx \ --document-name AWS-StartPortForwardingSession \ --parameters '{"portNumber":["3389"],"localPortNumber":["13389"]}'
è¸ã¿å°ãµã¼ãã»SSMãããããã®éç¨è² è·ãèãã
è¸ã¿å°ã¨SSMããããããéç¨ããã«ããããä½ãéç¨è² è·ã¨ãªããããèãã¦ã¿ã¾ãã ãã£ãããä¸è¨ã¨èãã¾ãã ã»è¸ã¿å°ã¯EC2ã§ãããã¨ã»ã»ãã¥ãªãã£ã°ã«ã¼ãã®ç®¡çãããã㨠ã»SSMã¯IAMããªã·ã¼ã®ç®¡çãClientã®ã¢ã¯ã»ã¹ãã¼ç®¡çãããã㨠詳細ã¯ä¸ã«æ¸ãã¦ã¿ã¾ã
è¸ã¿å°ãµã¼ãã«ãããéç¨è² è·
- èå¼±æ§ã®æ¤ç¥ã¨ãããé©ç¨
- ã¦ã¤ã«ã¹å¯¾ç
- ããã¯ã¢ããã®åå¾
- ã·ã¹ãã ãã°ç®¡ç
- ã»ãã¥ãªãã£ã°ã«ã¼ãã«ããClientããè¸ã¿å°ãµã¼ãã¸ã®æ¥ç¶å IPã¢ãã¬ã¹å¶å¾¡
- ã»ãã¥ãªãã£ã°ã«ã¼ãã«ããè¸ã¿å°ãµã¼ãããåEC2ã¸ã®æ¥ç¶å¶å¾¡
- ãã¼ããã©ã¯ã¼ãã£ã³ã°ã使ç¨ããEC2ã¸ã®æ¥ç¶æ¹æ³ã®å¨ç¥
- è¸ã¿å°ãµã¼ãã®OSèªè¨¼æ å ±(éµãªã©)管ç
- åEC2ã®OSèªè¨¼æ å ±(éµãªã©)管ç
- ãã«ãAZæ§æãªã©ã«ãããAZé害ãèæ ®ãããªã«ããªæé ã®æºå
SSMã«ãããéç¨è² è·
- Clientã«AWS CLIãã¤ã³ã¹ãã¼ã«ãããã¨
- AWS CLIã§ä½¿ãã¢ã¯ã»ã¹ãã¼ã®å®æçãªãã¼ãã¼ã·ã§ã³
- ã¢ã¯ã»ã¹ãã¼ãªã©ãã¤ã³ã¿ã¼ãããã«æµåºããªãããã®æè²ã¨å®æãã§ãã¯
- EC2ã«å ¥ã£ã¦ããSSMã¨ã¼ã¸ã§ã³ãã®å®æçãªã¢ãããã¼ã
- EC2ã«å ¥ã£ã¦ããSSMã§å©ç¨ããVPC Endpointã¨ã»ãã¥ãªãã£ã°ã«ã¼ãè¨å®
- IAM Role ã«ãããAPIå®è¡ãããClientã®æ¥ç¶å IPã¢ãã¬ã¹å¶å¾¡
- IAM Role ã«ãããAPIå®è¡ãããClientã®æ¥ç¶å ã¤ã³ã¹ã¿ã³ã¹ã®ç®¡ç
- SSMã®APIãå©ç¨ããæ¥ç¶æ¹æ³ã®å¨ç¥
- åEC2ã®OSèªè¨¼æ å ±(éµãªã©)管ç
- SSMã®SLAã¯99.9%(æ)ã§ãããæéã§40ã50åã®åæ¢æéã許容ã§ãããã¨
- ããã¼ã¸ããµã¼ãã¹ãªã®ã§ä¸èº«ã®å®è£ ã¯è¦ããªããããé害æã«ãããã°ãã«ãã
- æ°ããæ©è½ã§ãããã¾ã å®çãã¦ããªã
ææ
è¨å®æ¹æ³ãä»çµã¿ã«è¤éããããã è¸ã¿å°ãµã¼ãã¨æ¯è¼ãã¦èããã¨ãã«ããããä¹ãæãããï¼ãã¨ã¯ãæ£ç´ãªããªããããããªããªãã¨æãã¾ãã ããããã¨ã¦ãé åçãªæ©è½ã«æãã¾ãã è¸ã¿å°ãµã¼ãã使ãå ´åãã»ãã¥ãªãã£ã°ã«ã¼ãã®ç®¡çããããã¨ã«ãªãã¾ã WEBãµã¼ãã¹ã«ããã¦ã¯ãã¦ã¼ã¶ã¼ããã®WEBã¢ã¯ã»ã¹ãåãä»ããããã«ããã»ãã¥ãªãã£ã°ã«ã¼ãã®ç®¡çããããã¨ã«ãªãã¾ã ã»ãã¥ãªãã£ã°ã«ã¼ãã«å¯¾ãã誤ã£ããªãã¬ã¼ã·ã§ã³ã§ããµã¼ãã¹ã«ä¸ããå½±é¿ãèããã¨ãSSM ã使ãã®ã¯è¯ãããã«æãã¾ãã ããä¸æ©è¸ã¿è¾¼ãã§ãæ¥åã§å©ç¨ã§ããå ·ä½çãªå®è£ ãèãã¦ã¿ããã¨æãã¾ãã ããã§ã¯çæ§ãè¯ãSSMã©ã¤ãããâª