container security...2019/11/25 · id プロバイダーでaws api...
TRANSCRIPT
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Fumihide NarioSolutions Architect
Amazon Web Services Japan
Nov. 25, 2019
Container Security
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
⾃⼰紹介名前
成尾 ⽂秀(なりお ふみひで)
所属アマゾン ウェブ サービス ジャパン 株式会社技術統括本部 ソリューションアーキテクト
好きなAWSサービスAmazon Simple Storage Service (Amazon S3)Amazon Elastic Container Service (Amazon ECS)Amazon Elastic Kubernetes Service (Amazon EKS)
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Agenda
• AWSにおけるセキュリティ
• コンテナセキュリティ• 権限管理• ネットワーク• ログ・モニタリング• コンテナイメージ• その他
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWSにおけるセキュリティ
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
クラウドセキュリティ
クラウドセキュリティ https://aws.amazon.com/jp/security/
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS責任共有モデル
責任共有モデル https://aws.amazon.com/jp/compliance/shared-responsibility-model/
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
セキュリティは大丈夫?(物理セキュリティ)
• Amazonは数年間にわたり、⼤規模なデータセンターを構築
• 重要な特性:– 場所の秘匿性– 周囲の厳重なセキュリティ– 物理アクセスの厳密なコントロール– 2要素認証を2回以上で管理者がアクセス
• 完全管理された、必要性に基づくアクセス• 全てのアクセスは記録され、監査対象• 職務の分離
AWSコンプライアンス http://aws.amazon.com/jp/compliance/
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
セキュリティは大丈夫?(ネットワーク)
• Distributed Denial of Service (DDoS)対策: • 効果的かつ標準的な緩和対策を実施
• 中間者攻撃対策:• 全エンドポイントはSSLによって保護• 起動時に新しいEC2ホストキーを⽣成
• IPなりすまし対策:• ホストOSレベルで全て遮断
• 許可されていないポートスキャニング対策:• AWSサービス利⽤規約違反に該当• 検出され、停⽌され、ブロックされる• インバウンドのポートはデフォルトでブロックされているため、事実上無効
• パケットの盗聴対策:• プロミスキャスモードは不許可• ハイパーバイザ―レベルで防御
AWSコンプライアンス http://aws.amazon.com/jp/compliance/
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
セキュリティは大丈夫?(論理的セキュリティ)ハイパーバイザー(ホストOS)
• AWS管理者の拠点ホストからの個別のログイン• 全てのアクセスはロギングされ、監査される
ゲストOS(EC2インスタンス)• お客様による完全なコントロール• お客様が⽣成したいキーペアを使⽤
Firewall機能の標準提供• AWS標準機能としてInbound/Outboundに対する
Firewall• AWSのお客様の権限、責任で設定
AWSコンプライアンス http://aws.amazon.com/jp/compliance/
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
セキュリティは大丈夫?(データセキュリティ)• データを配置する物理的なリージョンはお客様が指定
• AWSは、法令遵守等やむをえない場合を除き、お客様のデータを指定されたリージョンからお客様への通告なしに移動しない
• お客様のデータが 権限のない⼈々に流出しないようにするストレージ 廃棄プロセスを保持
• DoD 5220.22-M(⽶国国防総省⽅式)– 3回の書き込みでの消去を実施– 固定値→補数→乱数
• NIST 800-88(メディアサニタイズのための ガイドライン)– 情報処分に対する体制、運営やライフサイクルに関するガイドライン– 情報処分に対しする組織的に取り組み
• 上記の⼿順を⽤い ハードウェアデバイスが廃棄できない場合、デバイスは業界標準の慣⾏に従って、消磁するか、物理的に破壊
AWSコンプライアンス http://aws.amazon.com/jp/compliance/
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コンテナセキュリティ
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コンテナのセキュリティを考える
• 2つの視点• AWSを利⽤する上で通常考えるセキュリティ• コンテナワークロードを利⽤する上で考えるセキュリティ
• 権限管理• ネットワーク• ログ・モニタリング• コンテナイメージ• その他
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
全体感
ECS EC2 起動モード
権限管理• IAM ユーザー• IAM ポリシー/ロール
コンテナネットワーク• Private Subnet• PrivateLink• NAT Gateway
コンテナイメージ• PrivateLink• 脆弱性スキャン
ログ・モニタリング• CloudTrail• VPCフローログ
その他• コントロールプレーン
• EC2管理、更新• データプレーン
• EC2管理、更新
ECS Fargate起動モード
権限管理• IAM ユーザー• IAM ポリシー/ロール
コンテナネットワーク• Private Subnet• NAT Gateway
コンテナイメージ• PrivateLink• 脆弱性スキャン
ログ・モニタリング• CloudTrail• VPCフローログ
その他• コントロールプレーン
• プラットフォーム更新
EKS
権限管理• IAM ユーザー• IAM ポリシー/ロール
コンテナネットワーク• Private Subnet• PrivateLink• NAT Gateway• Endpoint
コンテナイメージ• PrivateLink• 脆弱性スキャン
ログ・モニタリング• CloudTrail• VPCフローログ
その他• アドミッションコントローラー• コントロールプレーン
• EC2管理、更新• データプレーン
• EC2管理、更新
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
権限管理
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Identity and Access Management (IAM) ①
リソース(ECS, EKS, ECR etc)を使⽤できる権限を管理• AWSアカウントのルートユーザーは、最初の IAM ユーザーを作成するためだけに使⽤• ポリシー
• 複数の管理ポリシーが提供• AmazonECS_FullAccess, AmazonEC2ContainerServiceFullAccess etc
• 細かく制御することも可能
…"Effect": "Allow", "Action": "ecs:DescribeServices", "Resource": "arn:aws:ecs:*:*:service/*", "Condition": { “
StringEquals": {"ecs:ResourceTag/Owner": "${aws:username}"}}…
Amazon Elastic Container Service と IAM の連携 https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/userguide/security_iam_service-with-iam.htmlAmazon EKS と IAM の連携 https://docs.aws.amazon.com/ja_jp/eks/latest/userguide/security_iam_service-with-iam.html
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Identity and Access Management (IAM) ②
EKSでは IAMとKubernetes RBAC (Role Based Access Control ) が連携• IAMで許可を与えただけでは Kubernetes API サーバーへのコマンド実⾏は不可• Kubernetes 内の aws-auth ConfigMap にIAMユーザーのARNなど設定
K8sアクションの許可/却下
AWS IDをRBACで認可
K8s API
AWSIDを送信
AWS IDを検証1
2
3
4
Kubectl
クラスター認証の管理 https://docs.aws.amazon.com/ja_jp/eks/latest/userguide/managing-auth.htmlクラスターのユーザーまたは IAM ロールの管理 https://docs.aws.amazon.com/ja_jp/eks/latest/userguide/add-user-role.html
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Identity and Access Management (IAM) ③
アプリケーションがAWS各種サービスを使⽤する権限は IAMロールで指定IAMロールの利点
• 認証情報は STS(Security Token Service)で⼀時的な認証情報を⽣成• IAMユーザーの認証情報を外部に漏えいしてしまうリスクを低減• ⾃動的に認証情報をローテーション• アプリケーションに最低権限を与えることに適している• AWS SDK及びAWS CLIのサポート
ECS, EKSでの IAMロール利⽤⽅法• タスク⽤の IAMロール (Task IAM Roles)• EKSならサービスアカウントの IAMロール (IAM Roles for Service Accounts)
IAM ロール https://docs.aws.amazon.com/ja_jp/IAM/latest/UserGuide/id_roles.html
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ECS -タスク用の IAM ロール (Task IAM Roles) ①
タスクのコンテナで使⽤できる IAM ロールを指定• EC2起動モード、 Fargate起動モードどちらでも利⽤可能• EC2起動モードでは有効化にコンテナエージェントのバージョン 1.11.0 以上が必要
Amazon Simple Storage Service
Task
Task
Amazon DynamoDB
PolicyPolicy
タスク⽤の IAM ロール https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/developerguide/task-iam-roles.html
EC2 / Fargate
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ECS -タスク用の IAM ロール (Task IAM Roles) ②
IAM ロールを ECS のタスク定義または RunTask API オペレーションに関連付け
タスク⽤の IAM ロール https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/developerguide/task-iam-roles.htmlタスクの実⾏ https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/developerguide/ecs_run_task.html
タスク定義での指定 タスクの実⾏での指定(上書き)
AWS CLI
taskRoleArnを指定した json fileを⽤意しaws ecs run-task のオプションにて --overrides で指定
AWS CLI
タスク定義テンプレート( json file )を⽤意しaws ecs register-task-definition のオプションにて--cli-input-json で指定
マネジメントコンソール マネジメントコンソール
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
EKS -サービスアカウントのIAMロール (IAM Roles for Service Accounts) ①
Pod で使⽤される IAM Role を指定• EKS Kubernetes バージョン 1.14 クラスター、および 2019 年 9 ⽉ 3 ⽇以降にバージョ
ン 1.14 または 1.13 に更新されたクラスターで利⽤可能
サービスアカウントの IAM ロール https://docs.aws.amazon.com/ja_jp/eks/latest/userguide/iam-roles-for-service-accounts.html
Amazon Simple Storage Service
Pod
Pod
Amazon DynamoDB
PolicyPolicy
Worker Node
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
仕組みOpenID Connect (OIDC) を使⽤したフェデレーティッドアイデンティティを利⽤しID プロバイダーで AWS API コールを認証、有効な OIDC JSON ウェブトークン (JWT) を発⾏
1. OpenID Connect (OIDC)⽤の ID プロバイダーを作成(以下画像は⼀部IDをマスク処理済)
EKS -サービスアカウントのIAMロール (IAM Roles for Service Accounts) ②
サービスアカウントの技術概要の IAM ロールhttps://docs.aws.amazon.com/ja_jp/eks/latest/userguide/iam-roles-for-service-accounts-technical-overview.html
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
2. IAM Policy を作成しIAM Role にアタッチ3. K8s Service Account で IAM Roleを指定
4. Podから利⽤する Service Account を指定
…spec:template:spec:serviceAccountName: my-
serviceaccountcontainers:- image: myapp:1.2…
EKS -サービスアカウントのIAMロール (IAM Roles for Service Accounts) ③
apiVersion: v1kind: ServiceAccountmetadata:annotations:eks.amazonaws.com/role-arn: arn:aws:iam::AWS_ACCOUNT_ID:role/IAM_ROLE_NAME
name: my-serviceaccountnamespace: default
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
全体の流れ
EKS -サービスアカウントのIAMロール (IAM Roles for Service Accounts) ④
K8s API
kubectl apply (pod起動)
1
2Mutating Admission Controller により環境変数 AWS_IAM_ROLE_ARN および AWS_WEB_IDENTITY_TOKEN_FILEをセット及び aws-iam-token ボリュームをインジェクト
Pod
AWS STS
3 リクエスト
4 認証情報
Client
Kubernetes サービスアカウントに対するきめ細やかな IAM ロール割り当ての紹介https://aws.amazon.com/jp/blogs/news/introducing-fine-grained-iam-roles-service-accounts/
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
アクセスアドバイザーIAM エンティティ (ユーザー、グループ、ロール) が、最後に AWS サービスにアクセスした⽇付と時刻を表⽰する機能
データ追跡されるリージョン(2019/11/01現在)⽶国東部 (オハイオ)、⽶国東部(バージニア北部、⽶国⻄部(北カリフォルニア)、⽶国⻄部 (オレゴン、アジアパシフィック(東京)、アジアパシフィック (ソウル)、アジアパシフィック (シンガポール) 、アジアパシフィック (シドニー)、アジアパシフィック (ムンバイ) 、アジアパシフィック (⾹港) 、中東(バーレーン)、カナダ (中部)、欧州 (フランクフルト)、欧州 (ストックホルム) 、欧州 (アイルランド)、欧州 (ロンドン)、EU (パリ、南⽶ (サンパウロ)
IAMの最⼩限の権限に関する設定に利⽤
• IAM ポリシー内で未使⽤または最近使⽤されていないアクセス許可を識別
• 未使⽤のサービスに関するアクセス許可を削除したり、類似の使⽤パターンを持つユーザーをグループに再編成
• アカウントのセキュリティを改善
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
EC2インスタンスメタデータ
インスタンスメタデータからセキュリティ認証情報を取得
アプリケーションが各サービスを利⽤する時にはAWS 認証情報を使ってAPIリクエストに署名インスタンスメタデータから認証情報を取得
Amazon EC2 の IAM ロール https://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ECS - EC2 メタデータへのアクセス
EC2 起動モードかつネットワークモードが awsvpc または bridge の場合はコンテナのインスタンスプロファイルに⼊⼒されている認証情報にアクセスできないよう設定を変更する事が可能awspvcネットワークモードの場合
エージェントの ECS_AWSVPC_BLOCK_IMDS を true に設定(default: false)
bridge ネットワークモードの場合iptables の設定変更
sudo yum install -y iptables-services; sudo iptables --insert FORWARD 1 --in-interface docker+ --destination 169.254.169.254/32 --jump DROP
iptables のルール保存Amazon ECS-optimized Amazon Linux 2 AMI ならsudo iptables-save | sudo tee /etc/sysconfig/iptables && sudo systemctl enable --now iptables
Amazon ECS-optimized Amazon Linux AMI ならsudo service iptables save
タスク⽤の IAM ロール https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/developerguide/task-iam-roles.html
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Pod がワーカーノードのインスタンスプロファイルに提供される認証情報にアクセスできないよう iptables の設定を変更する事が可能
ワーカーノードで次の iptables コマンドを(root として)実⾏するか、ユーザーデータに以下スクリプトを使⽤し起動時に設定を実⾏
yum install -y iptables-servicesiptables --insert FORWARD 1 --in-interface eni+ --destination 169.254.169.254/32 --jump DROPiptables-save | tee /etc/sysconfig/iptables systemctl enable --now iptables
EKS - EC2 メタデータへのアクセス
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ネットワーク
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コンテナネットワーク – ECS ①
セキュリティの観点からコンテナの実⾏環境はプライベートサブネットを推奨
• インターネット向けに公開するサービスでは、ロードバランサーはパブリックサブネット
• コンテナからインターネット向けに通信が必要な場合には NAT ゲートウェイを利⽤
• ECR からのコンテナイメージの取得は PrivateLink 経由(後述)
• ECS でクラスター作成ウィザードを使⽤した場合• CloudFormation Template で AWS::AutoScaling::LaunchConfiguration セクションで、
AssociatePublicIpAddress プロパティを false に変更しスタックを更新
Amazon ECS コンテナインスタンスをプライベートサブネットのクラスターに登録するhttps://aws.amazon.com/jp/premiumsupport/knowledge-center/ecs-register-container-instance-subnet/
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コンテナネットワーク – ECS ②
セキュリティの観点からECS ネットワークモードにて awsvpc を利⽤
• タスク毎に独⾃の Elastic Network Interface (ENI)、プライマリプライベート IP アドレス、および内部 DNS ホスト名を取得
• VPCフローログを利⽤して送受信されるトラフィックをモニタリング(後述)
• タスク毎にセキュリティグループを設定可能
• 同じタスクに属するコンテナが、localhost インターフェイス経由で通信可能
タスクネットワーキングと awsvpc ネットワークモード https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/userguide/task-networking.htmlElastic Network Interface のトランキング https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/developerguide/container-instance-eni.html
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コンテナネットワーク – EKS ①
セキュリティの観点からコンテナの実⾏環境はプライベートサブネットを推奨• EKS ではワーカーノードにプライベートサブネット、Kubernetes にパブリックサブネットの使
⽤を推奨• インターネット向けロードバランサーが不要なら全てプライベートサブネット
• EKSではインターネット向けロードバランサーが使うサブネットを認識できるようパブリックサブネット側にタグ付け(Key: kubernetes.io/role/elb Value: 1)が必要
• コンテナからインターネット向けに通信が必要な場合には NAT ゲートウェイを利⽤• EKS Amazon VPC CNI plugin for Kubernetes の外部ソースネットワークアドレス変換 (External SNAT)を有
効に設定
• EKS Amazon VPC CNI plugin for Kubernetes• 各ワーカーノードで L-IPAM デーモン が IPアドレスをプールして Pod に割当• VPCフローログを利⽤し送受信されるトラフィックをモニタリング
• ECR からのコンテナイメージの取得は PrivateLink 経由(後述)クラスター VPC に関する考慮事項 https://docs.aws.amazon.com/ja_jp/eks/latest/userguide/network_reqs.html外部ソースネットワークアドレス変換 (SNAT) https://docs.aws.amazon.com/ja_jp/eks/latest/userguide/external-snat.html
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コンテナネットワーク – EKS ②
エンドポイントのパブリックアクセスの無効を選択可能
Amazon EKS クラスターエンドポイントのアクセスコントロールhttps://docs.aws.amazon.com/ja_jp/eks/latest/userguide/cluster-endpoint.html
パブリックアクセス プライベートアクセス 動作有効 無効 ・EKSのデフォルトの設定
・インターネットからAPIへアクセス可(kubectl)・VPC内のKubernetes API リクエスト(Control Plane ⇔ Data Plane)はVPC 内ではくAmazon のネットワークを経由
有効 有効 ・インターネットからAPIへアクセス可(kubectl)・VPC内のKubernetes API リクエスト(Control Plane ⇔ Data Plane)はプライベート VPC エンドポイントを経由
無効 有効 ・インターネットからAPIへアクセス不可(kubectl)・API サーバーへのトラフィックはすべて クラスターの VPC 内からルーティングが必要
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コンテナネットワーク – EKS ③
マネジメントコンソールからの変更か AWS CLI を利⽤して変更可能
aws eks --region region update-cluster-config --name dev --resources-vpc-config endpointPublicAccess=false,endpointPrivateAccess=true
API サーバーへのトラフィックはすべて クラスターの VPC 内からルーティングが必要• クラスターのVPCにある踏み台サーバー、Cloud 9環境• VPC とピアリングしているネットワーク• AWS Direct Connect (DX) または Virtual Private Network (VPN)※ワーカーノードが存在するVPC以外では Route 53 のインバウンド・アウトバウンドエンドポイントを利⽤した名前解決などの設定が必要(Blog 参照)
Amazon EKS クラスターエンドポイントのアクセスコントロールhttps://docs.aws.amazon.com/ja_jp/eks/latest/userguide/cluster-endpoint.htmlAmazon EKS クラスターエンドポイントへのプライベート接続とワーカノードVPC外からのDNS解決https://aws.amazon.com/jp/blogs/news/compute-enabling-dns-resolution-for-amazon-eks-cluster-endpoints/
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コンテナイメージの ECR からの取得
コンテナイメージをプライベートネットワーク経由で ECR から取得
• ECS ⽤のインターフェイス VPC エンドポイント (AWS PrivateLink)を作成• ecs-agent, ecs-telemetry, ecs 3つのエンドポイントを作成• EC2 起動モードの場合コンテナエージェントのバージョン 1.25.1以降が必要• Fargate 起動モードの場合、ECS 側のエンドポイントは不要
• ECR ⽤のインターフェイス VPC エンドポイント (AWS PrivateLink)を作成• ecr.dkr, ecr.api, s3, logs interface 4つのエンドポイントを必要に応じて作成• EC2 起動モードの場合
• ecr.dkr, ecr.api, s3 のエンドポイントがコンテナイメージのプルに必要
• Fargate 起動モードの場合• ecr.dkr, s3 のエンドポイントがコンテナイメージのプルに必要• awslogs ログドライバーを使⽤してログ情報を CloudWatch Logs に送信する場合は、logs.interface が必要
Amazon ECS インターフェイス VPC エンドポイント (AWS PrivateLink) https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/developerguide/vpc-endpoints.htmlAmazon ECR インターフェイス VPC エンドポイント (AWS PrivateLink) https://docs.aws.amazon.com/ja_jp/AmazonECR/latest/userguide/vpc-endpoints.html
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ログ・モニタリング
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
EKS コントロールプレーン
EKS コントロールプレーンのログを有効化ログタイプを選択して有効にすると CloudWatch Logs にクラスター毎に送信ログタイプは、監査 (audit) ログ、認証 (authenticator) ログ etc
マネジメントコンソールまたは AWS CLI コマンドを利⽤して有効化
aws eks --region us-west-2 update-cluster-config --name prod –logging \
'{"clusterLogging":[{"types":["api","audit","authenticator","controllerManager","scheduler"],"enabled":true}]}’
Amazon EKS コントロールプレーンのログ記録 https://docs.aws.amazon.com/ja_jp/eks/latest/userguide/control-plane-logs.html
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
CloudTrail を利用したモニタリング
ECS/EKS のすべての API コールをイベントとしてキャプチャ
ECS - タスク⽤の IAM ロール( Task IAM Roles )、EKS - サービスアカウントのIAMロール ( IAM Roles for Service Accounts ) に関してアクセスとイベントのロギングを利⽤可能
コンソールの [Event history (イベント履歴)] で過去 90 ⽇間のイベントを表⽰過去 90 ⽇間より前のイベントの記録を保持する場合は「証跡」を作成しS3に保存
AWS CloudTrail を使⽤した Amazon EKS API コールのログ作成 https://docs.aws.amazon.com/ja_jp/eks/latest/userguide/logging-using-cloudtrail.htmlAWS CloudTrail を使⽤した Amazon ECS API コールのログ作成 https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/developerguide/logging-using-cloudtrail.html証跡の作成 https://docs.aws.amazon.com/ja_jp/awscloudtrail/latest/userguide/cloudtrail-create-a-trail-using-the-console-first-time.html
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
VPCフローログ
ECS EC2起動モードにて awsvpc ネットワークモードを利⽤している場合ECS Fargate起動モードの場合、EKSの場合はVPCフローログが利⽤可能(※ EKS でデフォルトの Amazon VPC CNI plugin を使っている場合)
VPCフローログを作成してIP トラフィックに関する情報をキャプチャ• トラフィックのモニタリング• セキュリティグループによる許可/拒否のルールを確認
VPC フローログ https://docs.aws.amazon.com/ja_jp/vpc/latest/userguide/flow-logs.htmlフローログを使⽤する https://docs.aws.amazon.com/ja_jp/vpc/latest/userguide/working-with-flow-logs.html
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コンテナイメージ
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コンテナイメージ①
• プロセスの起動に root を使わない• パラメーターをコンテナイメージに埋め込まないAWS Secrets Manager シークレットまたは AWS Systems Managerパラメータストア を使い変数として扱う
ECS の場合はコンテナの定義内で指定可能Secrets Manager シークレット{"containerDefinitions": [{"secrets": [{"name": "environment_variable_name","valueFrom": "arn:aws:secretsmanager:region:aws_account_id:secret:secret_name-AbCdEf"
}]}]
}Systems Manager パラメータストアの場合は上記 valueFromで以下の指定"valueFrom": "arn:aws:ssm:region:aws_account_id:parameter/parameter_name"
機密データの指定 https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/developerguide/specifying-sensitive-data.html
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コンテナイメージ②
EKS の場合AWS SDK を含むコンテナイメージを作成し API から取得
InitContainersでAWS SDK を含むコンテナイメージからAWS Secrets Manager シークレットまたは AWS Systems Managerパラメータストア に対してAPIで取得した結果をVolumeに出⼒その後アプリケーションコンテナ側でVolumeから読み込むといった事も可能
パラメータストア パラメータからの AWS Secrets Manager シークレットの参照https://docs.aws.amazon.com/ja_jp/systems-manager/latest/userguide/integration-ps-secretsmanager.html
…spec:initContainers:- name: init-myserviceimage: amazonlinux:2
containers:- name: myapp-containerimage: myapp:1.2
…
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ECR –コンテナイメージのスキャン①
オープンソースの CoreOS Clair project を利⽤した脆弱性 (CVEs) の 静的スキャン• スキャン費⽤は無料• スキャンはAPIまたはマネジメントコンソールにて実⾏可能
aws ecr start-image-scan --repository-name name --image-id imageTag=tag_name --region us-east-2上記は imageTag で指定しているが imageDigest の指定も可能
• リポジトリ側で「プッシュ時にスキャン」を有効にするとイメージが push されたらスキャン実⾏
aws ecr create-repository --repository-name name --image-scanning-configuration scanOnPush=true --region us-east-2aws ecr put-image-scanning-configuration --repository-name name --image-scanning-configuration scanOnPush=true --region us-east-2
• 「プッシュ時にスキャン」が有効であっても後⽇発⾒された脆弱性を検知するため定期的なスキャン実施を推奨
イメージスキャン https://docs.aws.amazon.com/ja_jp/AmazonECR/latest/userguide/image-scanning.htmlAmazon ECRのネイティブなコンテナイメージスキャン機能についてhttps://aws.amazon.com/jp/blogs/news/amazon-ecr-native-container-image-scanning/
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ECR –コンテナイメージのスキャン②
実⾏結果はコンソールやAPIから確認CloudWatch Events からスキャン完了の通知を受信
スキャン結果は AWS SDKを利⽤して以下コマンドで取得可能aws ecr describe-image-scan-findings --repository-name prd --image-id imageTagt=latest上記は imageTag で指定しているが imageDigest の指定も可能
レスポンスのfindingsに含まれる情報の例name:CVE番号、description:詳細、uri:脆弱性に関する追加情報へのリンク、severity:緊急度
イベントと EventBridge https://docs.aws.amazon.com/ja_jp/AmazonECR/latest/userguide/ecr-eventbridge.htmldescribe-image-scan-findings https://docs.aws.amazon.com/cli/latest/reference/ecr/describe-image-scan-findings.html
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
その他
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
EKS -アドミッションコントローラー①
ポッドのセキュリティポリシー(PSP)• ルールに対してポッドの作成を検証• Kubernetes バージョン 1.13 以降• 設定をYAMLで⽤意して作成、変更、削除可能• デフォルトのポッドセキュリティポリシー ( eks.privileged ) は制限なし=PSP無効と同様
ポッドのセキュリティポリシー https://docs.aws.amazon.com/ja_jp/eks/latest/userguide/pod-security-policy.html
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
EKS -アドミッションコントローラー②
ルールの例
• プロセスを root ユーザーでは実⾏させないrunAsUser:
rule: 'MustRunAsNonRoot’
• コンテナのルートファイルシステムをRead Only にするreadOnlyRootFilesystem: false
• 特権コンテナを拒否するprivileged: false
• 特権昇格はさせないallowPrivilegeEscalation: false
ポッドのセキュリティポリシー https://docs.aws.amazon.com/ja_jp/eks/latest/userguide/pod-security-policy.htmlPod Security Policies - Kubernetes https://kubernetes.io/docs/concepts/policy/pod-security-policy/
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
EC2 管理
• ECS EC2 起動モード、EKS Worker Node では EC2 の管理が必要• OS 及び導⼊パッケージの脆弱性対応
• Amazon Linux セキュリティセンターで Amazon Linux 2 のセキュリティイベントまたはプライバシーイベントを追跡
• Amazon Inspector を使⽤してワーカーノードの意図しないネットワークアクセシビリティと、それらの Amazon EC2 インスタンスの脆弱性を確認
Amazon EKS での設定と脆弱性の分析 https://docs.aws.amazon.com/ja_jp/eks/latest/userguide/configuration-vulnerability-analysis.htmlAmazon Linux 2 Security Advisories https://alas.aws.amazon.com/alas2.html
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
アップデート・アップグレード
ECS (EC2 起動モード)• コンテナエージェントの更新• ECS-Optimized Amazon Linux AMI の更新
• AMI の Amazon SNS トピックの更新をサブスクライブして新しい AMI の通知を受信
ECS (Fargate 起動モード)• プラットフォームの更新(LATEST の利⽤を推奨)
EKS• クラスターの Kubernetes バージョンの更新
• クラスターの更新時に Kubernetes アドオンを変更しないので以下も個別に更新• Amazon VPC CNI プラグイン、DNS、KubeProxy
• ワーカーノードの更新
Amazon ECS コンテナエージェントの更新 https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/developerguide/ecs-agent-update.htmlAmazon ECS-Optimized Amazon Linux AMI の更新の通知のサブスクライブ https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/developerguide/ECS-AMI-SubscribeTopic.htmlAmazon EKS クラスターの Kubernetes バージョンの更新 https://docs.aws.amazon.com/ja_jp/eks/latest/userguide/update-cluster.htmlワーカーノードの更新 https://docs.aws.amazon.com/ja_jp/eks/latest/userguide/update-workers.html
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
まとめ 検討・対応が必要な部分
ECS EC2 起動モード
権限管理• IAM ユーザー• IAM ポリシー/ロール
コンテナネットワーク• Private Subnet• PrivateLink• NAT Gateway
コンテナイメージ• PrivateLink• 脆弱性スキャン
ログ・モニタリング• CloudTrail• VPCフローログ
その他• コントロールプレーン
• EC2管理、更新• データプレーン
• EC2管理、更新
ECS Fargate起動モード
権限管理• IAM ユーザー• IAM ポリシー/ロール
コンテナネットワーク• Private Subnet• NAT Gateway
コンテナイメージ• PrivateLink• 脆弱性スキャン
ログ・モニタリング• CloudTrail• VPCフローログ
その他• コントロールプレーン
• プラットフォーム更新
EKS
権限管理• IAM ユーザー• IAM ポリシー/ロール
コンテナネットワーク• Private Subnet• PrivateLink• NAT Gateway• Endpoint
コンテナイメージ• PrivateLink• 脆弱性スキャン
ログ・モニタリング• CloudTrail• VPCフローログ
その他• アドミッションコントローラー• コントロールプレーン
• EC2管理、更新• データプレーン
• EC2管理、更新