Slide 1

Slide 1 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 「線を引っこ抜け!」 と言われたら 荒木靖宏 Yasuhiro Araki JAWS DAYS 2021

Slide 2

Slide 2 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 荒木靖宏 です。どうぞよろしく アマゾン ウェブ サービス ジャパン 技術統括本部 プリンシパルソリューションアーキテクト 2011年からAWSのソリューションアーキテクトです 好きなサービスはAWS DirectConnectとEC2 Spot 今日は「線をひっこぬけ!」と言われたときに使 えるツールを作ってる話をします

Slide 3

Slide 3 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. サービス作り楽しんでますか!

Slide 4

Slide 4 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. https://aws.amazon.com/architecture/this-is-my-architecture/

Slide 5

Slide 5 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 普段から やっておくことやってますか?

Slide 6

Slide 6 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS Command Line Interface (AWS CLI) AWS tools and software development kits (SDKs) AWS CloudFormation

Slide 7

Slide 7 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 現実は違いますよね

Slide 8

Slide 8 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 環境保存にAWS Backup 「データがあればなんとかなる」 → AWS Backup で楽ちんバックアップ Amazon EBS、Amazon RDS、Amazon DynamoDB、 Amazon EFS、Amazon FSx、Amazon EC2、AWS Storage Gateway に対応 AWS Backup

Slide 9

Slide 9 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Trusted Advisorつかおう Amazon S3 バケットのアクセス許可(無料) ルートアカウントの Multi-Factor Authentication(無料) 以下は有料(AWSサポート ビジネスorエンタープライズ必要) Amazon RDS セキュリティグループのアクセスリスク AWS CloudTrail のログ記録 Amazon Route 53 および SPF のリソースレコードセット 公開されているアクセスキー AWS IAM パスワードポリシー AWS IAM アクセスキーの更新 AWS Trusted Advisor

Slide 10

Slide 10 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. さて、ここにトラブル発⽣

Slide 11

Slide 11 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 通信とめても らえますか?

Slide 12

Slide 12 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 線をひっこぬけ!

Slide 13

Slide 13 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 自動化中です 公開場所と時期: 未定&トライし ます 実装済: アカウント確認、R53、 Cloudfront、SES 未実装: VPC、IAMによるリソース制限 最後の手段 https://github.com/qphoney/balus もよろしくね $ ruby hikkonuki-02.rb all 100: Checking key exposed or not 100 OK. No exposed access keys 110: Checking SSO (check 110) -- Not Yet Support 200: Checking CloudTrail 200 OK trail.araki.net us-west-2 200 OK aws-cloudtrail-logs-750753468831-c91ece05 multi_re 300: Checking Route53 300Checkwww.araki.net. in Route53 (略) 300 Check debian01.araki.in. in Route53 310: Checking Cloudfront 310 Check EUBDU8YK7UUV7 d1o8tzajvzomha.cloudfront.net 310 Check EUBDU8YK7UUV7 jp.t.araki.in 310 Check EUBDU8YK7UUV7 awstips.s3.amazonaws 400: Checking SES 400 OK No SES af-south-1 (略) 400 OK No SES us-west-2 (以下実装中)

Slide 14

Slide 14 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 以降、解説

Slide 15

Slide 15 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 100 まずはアカウントをどうにかする MFAを有効に! Trusted Advisorを立ち上げて公開されたキーがないか確認 AWS Trusted Advisor aws support describe-trusted-advisor-checks --region us-east-1 --language en | jq -c ".checks[] | [ .category , .name , .id]" | sort ["security","Exposed Access Keys","12Fnkplxxx"] % aws support describe-trusted-advisor-check-result --region us-east-1 -- language en --check-id 12Fnkplxxx { "result": { "checkId": "12Fnkplxxx", "timestamp": "2021-03-11T10:20:04Z", "status": "ok", 以下略

Slide 16

Slide 16 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 110 SSOをしていたら切る(未実装) シングルサインオンは裏口になりかねない describe-permission-set して delete-permission-setする (乱暴だな!) 参考資料 【AWS CLI】AWS SSOのアクセス権の設定方法 https://blog.serverworks.co.jp/aws-cli-sso-create-account-assignment aws sso-admin list-instances --query "Instances[].InstanceArn" --output text AWS Single Sign- On

Slide 17

Slide 17 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 200 CloudTrailを全リージョンで有効に 全リージョン有効化設定がfalseになってないか確認。 IsMultiRegionTrail がTrueになってりゃOK. for region in $(aws ec2 describe-regions | jq -r ".Regions[].RegionName | @text") do echo "[$region]" ; aws --region $region cloudtrail describe-trails | jq '.trailList[] | if .IsMultiRegionTrail == false then .Name else empty end' ; done AWS CloudTrail 参考資料

Slide 18

Slide 18 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 3xx 作業中宣言をつくる 特定サービスやwww.ドメイン名がないか調べる 300: Route53を調べる 310: CloudFrontを調べる 「メンテ中宣言」のページ CFをつかってるならば楽勝。すぐにOriginをS3に設定する。 SSL証明書が変わることは避けるべき。CFを使っていない場合は仕方ない ので証明書そのままで新規にEC2へ 証明書いちらんの確認はかんたん aws acm list-certificates

Slide 19

Slide 19 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 4xx SES そもそも止めろというときの理由あるあるのひとつはemail のOutboundだったりする。SESをつかっているものがない かチェック IAMコンソールを使用して既存のSMTPユーザを削除。 ses:SendRawEmailを消す { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "ses:SendRawEmail", "Resource": "*" 以下略

Slide 20

Slide 20 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 5xx VPC • VPCを特定 • まずはSGで遮断 • NACLで遮断する • Route Tableをいじる • VPN&DirectConnectをおとす • InternetGatewayをおとす • NATGWやNATインスタンスをお とす • VPC endpointをおとす 同一サブネット内での通信制御ができ ない VPC内の通信に閉じることはできる 特別な出入り口を持っている場合をふ さげる 内部での通信は維持できる 外部への漏洩は一見なくなる 内部での通信は維持できる VPC向けサービスを止められる 実装予定

Slide 21

Slide 21 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 6xx VPCの外のリソースはIAMが基本。加えて • S3はアカウント単位でパブリックアクセスブロックを有効に • バケット単位のブロックでは、管理不十分バケット経由の漏洩注意 • CodeCommitはgit用のsshとHTTPS鍵をrevokeを。 • PublicのECR (コンテナレジストリ)は消すのみ(Privateにできない) • WorkdocsはAdmin control panelからIP制限する • RDSはVPC セキュリティグループ、DB セキュリティグループ、EC2-Classic セキュリティグループという 3 種類のセキュリティグループに注意 • LambdaはIAMでイベントから呼びされないようにする • APIGWもアクセス制限が基本 実装予定

Slide 22

Slide 22 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 役に立つぞ Detective & CloudWatch Synthetics & VPC Reachability Analyzer Amazon Detective

Slide 23

Slide 23 text

© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. (再掲)自動化スクリプトについて 公開場所と時期: 未定&トライし ます 実装済: アカウント確認、R53、 Cloudfront、SES 未実装: VPC、IAMによるリソース制限 最後の手段 https://github.com/qphoney/balus もよろしくね $ ruby hikkonuki-02.rb all 100: Checking key exposed or not 100 OK. No exposed access keys 110: Checking SSO (check 110) -- Not Yet Support 200: Checking CloudTrail 200 OK trail.araki.net us-west-2 200 OK aws-cloudtrail-logs-750753468831-c91ece05 multi_re 300: Checking Route53 300Checkwww.araki.net. in Route53 (略) 300 Check debian01.araki.in. in Route53 310: Checking Cloudfront 310 Check EUBDU8YK7UUV7 d1o8tzajvzomha.cloudfront.net 310 Check EUBDU8YK7UUV7 jp.t.araki.in 310 Check EUBDU8YK7UUV7 awstips.s3.amazonaws 400: Checking SES 400 OK No SES af-south-1 (略) 400 OK No SES us-west-2 (以下実装中)