Amazon Inspectorとは
re:Inventで発表になった新サービスで、執筆現在はPreviewで us-west-2 (オレゴン)リージョンにしかありません。
EC2インスタンスにエージェントを仕込むことで、OSやアプリケーションが設定したルールに沿っているか診断を行ってくれるサービスです。
AWS CLIを利用して、そんなAWS Inspectorを試してみましょう。
前提条件
デフォルトVPCの存在
デフォルトVPCが存在すること。
Inspectorへの権限
Inspectorに対してフル権限があること。
EC2への権限
EC2インスタンス起動権限があること。
AWS CLIのバージョン
以下のバージョンで動作確認済
- AWS CLI 1.9.9
aws --version
aws-cli/1.9.9 Python/2.6.6 Linux/2.6.32 botocore/1.3.9
- 事前作業
===========
0.1. リージョンの決定
Inspectorは現在Previewでus-west-2(オレゴン)にしかないのでオレゴンにします。
(カレントユーザが利用するカレントリージョンも切り変わります。)
export AWS_DEFAULT_REGION='us-west-2'
0.2. 変数の確認
プロファイルとリージョンが想定のものになっていることを確認します。
aws configure list
Name Value Type Location
---- ----- ---- --------
profile <not set> None None
access_key ****************M73Q shared-credentials-file
secret_key ****************YWg/ shared-credentials-file
region us-west-2 env AWS_DEFAULT_REGION
0.3. AWSアカウントIDの取得
AWS_ID=$( aws iam get-user --query 'User.Arn' --output text | sed 's/^.*:://' | sed 's/:.*$//' ) && echo ${AWS_ID}
454200CLI555
- 診断用EC2インスタンスの準備
===========
1.1. VPCIDの取得
VPC_ID=`aws ec2 describe-vpcs --filters Name=isDefault,Values=true --query 'Vpcs[].VpcId' --output text` && echo ${VPC_ID}
vpc-xxxxxxxx
1.2. キーペアの作成
EC2_KEY_NAME="handson" && echo ${EC2_KEY_NAME}
FILE_SSH_KEY="${HOME}/.ssh/${EC2_KEY_NAME}.pem" && echo ${FILE_SSH_KEY}
aws ec2 create-key-pair --key-name ${EC2_KEY_NAME} --query 'KeyMaterial' --output text > ${FILE_SSH_KEY} && cat ${FILE_SSH_KEY} && chmod 600 ${FILE_SSH_KEY}
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAly2hbGNZKdoInU5W7UkXiIiOPKnNsBvGtJonl6oEE/KPtilnpYwwsE9+R+d0
cBoqNYy2QPjSB2VWq8h2Fb7oaZsttGCQ2ULPJMU8q10JBYnAlke+kvyj2LPBuIJtvVTnZ5NokJbc
Dh9gN27kFcWYE2099Iu9m3Mz6uPR8c2pzgoSzqapcgn3mtZV7av4mSX//siHhwx8k8RT3dCm+IFR
(本当はもっと長い)
oY0qjQ3QLUM9/fbcL+U4mDsiBotbAp70yTFJupREYrA5AoGAS6aP6xl/QW4hS/r1HZZLgbd5uWdn
Alcjcxy1fed70YVZDHTZUTTIxRCu/ZedvHQovSgmG+PwZhkvhFd15QtBLfLAjL3W9cE1qhUGIi7S
PqRjDB83ivjFRa3fBunC0ebWnCE0E53yzujRZvBPFmAtdDh7nIpevHXJCm0cmZCVuq4=
-----END RSA PRIVATE KEY-----
1.3. セキュリティグループの作成
SG_NAME="handson"
aws ec2 create-security-group --group-name ${SG_NAME} --description ${SG_NAME} --vpc-id ${VPC_ID}
SG_ID=`aws ec2 describe-security-groups --filter Name=group-name,Values=${SG_NAME} --query 'SecurityGroups[].GroupId' --output text` && echo ${SG_ID}
{
"GroupId": "sg-59c3e63d"
}
sg-59c3e63d
外部からのHTTP接続とSSHログインをセキュリティグループに追加
(12.34.56.789/32 は適宜自分のアドレスへ書き換えてください)
aws ec2 authorize-security-group-ingress --group-id ${SG_ID} --protocol 'tcp' --port 80 --cidr 0.0.0.0/0
aws ec2 authorize-security-group-ingress --group-id ${SG_ID} --protocol 'tcp' --port 22 --cidr 12.34.56.789/32
(戻り値なし)
1.4. 診断試験用EC2インスタンスの構築
AMI IDの取得:
AMI_NAME='amzn-ami-hvm-2015.09.0.x86_64-gp2'
AMI_ID=`aws ec2 describe-images --filters Name=name,Values=${AMI_NAME} --query 'Images[].ImageId' --output text` && echo ${AMI_ID}
ami-9ff7e8af
インスタンスの起動:
aws ec2 run-instances --image-id ${AMI_ID} --associate-public-ip-address --instance-type t2.micro --key-name ${EC2_KEY_NAME} --region ${AWS_DEFAULT_REGION} --security-group-ids ${SG_ID}
{
"OwnerId": "454200CLI555",
"ReservationId": "r-a112f757",
"Groups": [],
"Instances": [
{
"Monitoring": {
"State": "disabled"
},
"PublicDnsName": "",
"RootDeviceType": "ebs",
"State": {
"Code": 0,
"Name": "pending"
},
"EbsOptimized": false,
"LaunchTime": "2015-11-25T15:05:31.000Z",
"PrivateIpAddress": "172.31.18.115",
"ProductCodes": [],
"VpcId": "vpc-fd543898",
"StateTransitionReason": "",
"InstanceId": "i-3ef4b3fa",
"ImageId": "ami-9ff7e8af",
"PrivateDnsName": "ip-172-31-18-115.us-west-2.compute.internal",
"KeyName": "handson",
"SecurityGroups": [
{
"GroupName": "handson",
"GroupId": "sg-59c3e63d"
}
],
"ClientToken": "",
"SubnetId": "subnet-8e0870eb",
"InstanceType": "t2.micro",
"NetworkInterfaces": [
{
"Status": "in-use",
"MacAddress": "02:99:bc:70:59:33",
"SourceDestCheck": true,
"VpcId": "vpc-fd543898",
"Description": "",
"NetworkInterfaceId": "eni-6954d410",
"PrivateIpAddresses": [
{
"PrivateDnsName": "ip-172-31-18-115.us-west-2.compute.internal",
"Primary": true,
"PrivateIpAddress": "172.31.18.115"
}
],
"PrivateDnsName": "ip-172-31-18-115.us-west-2.compute.internal",
"Attachment": {
"Status": "attaching",
"DeviceIndex": 0,
"DeleteOnTermination": true,
"AttachmentId": "eni-attach-7dc5d676",
"AttachTime": "2015-11-25T15:05:31.000Z"
},
"Groups": [
{
"GroupName": "handson",
"GroupId": "sg-59c3e63d"
}
],
"SubnetId": "subnet-8e0870eb",
"OwnerId": "454200CLI555",
"PrivateIpAddress": "172.31.18.115"
}
],
"SourceDestCheck": true,
"Placement": {
"Tenancy": "default",
"GroupName": "",
"AvailabilityZone": "us-west-2b"
},
"Hypervisor": "xen",
"BlockDeviceMappings": [],
"Architecture": "x86_64",
"StateReason": {
"Message": "pending",
"Code": "pending"
},
"RootDeviceName": "/dev/xvda",
"VirtualizationType": "hvm",
"AmiLaunchIndex": 0
}
]
}
1.5. インスタンスへのタグ付け
Inspectorの調査対象とするための識別用にEC2インスタンスへ任意のタグを設定します。
ここで設定したタグをInspector側でも設定することで、これが調査対象の識別子になります。
Keyを inspector 、Valueを handson とすることにします。
TAG_KEY='inspector'
TAG_VALUE='handson'
インスタンスIDの取得
EC2_INSTANCE_ID=`aws ec2 describe-instances --query 'Reservations[].Instances[].InstanceId' --output text` && echo ${EC2_INSTANCE_ID}
i-3ef4b3fa
インスタンスにタグを設定
aws ec2 create-tags --resources ${EC2_INSTANCE_ID} --tags Key="${TAG_KEY}",Value="${TAG_VALUE}"
(戻り値なし)
1.6. パブリックIPアドレスの取得
EC2_PUBLIC_IP=`aws ec2 describe-instances --instance-id ${EC2_INSTANCE_ID} --query "Reservations[].Instances[].PublicIpAddress" --output text` && echo ${EC2_PUBLIC_IP}
54.xxx.xxx.xxx
1.7. SSHでインスタンスへログイン
起動完了まで数分かかります。ちょっとビールでも飲んでから次のコマンドへ進みます。
ssh -l ec2-user -i ${FILE_SSH_KEY} ${EC2_PUBLIC_IP}
The authenticity of host '54.xxx.xxx.xxx (54.xxx.xxx.xxx)' can't be established.
RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.
Are you sure you want to continue connecting (yes/no)?
yes
Warning: Permanently added '54.xxx.xxx.xxx' (RSA) to the list of known hosts.
__| __|_ )
_| ( / Amazon Linux AMI
___|\___|___|
https://aws.amazon.com/amazon-linux-ami/2015.09-release-notes/
3 package(s) needed for security, out of 28 available
Run "sudo yum update" to apply all updates.
[ec2-user@ip-172-31-21-47 ~]$
1.8. Inspectorエージェントのインストール
公式サイトからダウンロードします。
wget https://s3-us-west-2.amazonaws.com/inspector.agent.us-west-2/latest/install
--2015-11-26 12:41:58-- https://s3-us-west-2.amazonaws.com/inspector.agent.us-west-2/latest/install
s3-us-west-2.amazonaws.com をDNSに問いあわせています... 54.231.176.46
s3-us-west-2.amazonaws.com|54.231.176.46|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 10436 (10K) [binary/octet-stream]
`install' に保存中
100%[======================================>] 10,436 --.-K/s 時間 0s
2015-11-26 12:41:58 (22.9 MB/s) - `install' へ保存完了 [10436/10436]
root権限でインストールを行います。
sudo bash ./install
Validated signature with:
Validated package sha256 hash matches expected value.
Installing with yum...
読み込んだプラグイン:priorities, update-motd, upgrade-helper
/tmp/inspector.b3nZ9iRz/InspectorAgent-1.0.96.0-100096.x86_64.rpm を調べています: InspectorAgent-1.0.96.0-100096.x86_64
/tmp/inspector.b3nZ9iRz/InspectorAgent-1.0.96.0-100096.x86_64.rpm をインストール済みとして設定しています
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ InspectorAgent.x86_64 0:1.0.96.0-100096 を インストール
--> 依存性の処理をしています: libpcap のパッケージ: InspectorAgent-1.0.96.0-100096.x86_64
--> 依存性の処理をしています: libpcap.so.1()(64bit) のパッケージ: InspectorAgent-1.0.96.0-100096.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ libpcap.x86_64 14:1.4.0-1.20130826git2dbcaa1.10.amzn1 を インス トール
--> 依存性解決を終了しました。
依存性を解決しました
================================================================================
Package アーキテクチャー
バージョン リポジトリー 容量
================================================================================
インストール中:
InspectorAgent
x86_64 1.0.96.0-100096 /InspectorAgent-1.0.96.0-100096.x86_64 19 M
依存性関連でのインストールをします:
libpcap x86_64 14:1.4.0-1.20130826git2dbcaa1.10.amzn1
amzn-main 144 k
トランザクションの要約
================================================================================
インストール 1 パッケージ (+1 個の依存関係のパッケージ)
合計容量: 19 M
総ダウンロード容量: 144 k
インストール容量: 19 M
Downloading packages:
libpcap-1.4.0-1.20130826git2dbcaa1.10.amzn1.x86_64.rpm | 144 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
インストール中 : 14:libpcap-1.4.0-1.20130826git2dbcaa1.10.amzn 1/2
インストール中 : InspectorAgent-1.0.96.0-100096.x86_64 2/2
crond ???????????: [ OK ]
検証中 : InspectorAgent-1.0.96.0-100096.x86_64 1/2
検証中 : 14:libpcap-1.4.0-1.20130826git2dbcaa1.10.amzn 2/2
インストール:
InspectorAgent.x86_64 0:1.0.96.0-100096
依存性関連をインストールしました:
libpcap.x86_64 14:1.4.0-1.20130826git2dbcaa1.10.amzn1
完了しました!
読み込んだプラグイン:priorities, update-motd, upgrade-helper
ロックファイル /var/run/yum.pid が存在します: PID 2589 として別に実行されていま す。
Another app is currently holding the yum lock; waiting for it to exit...
他のアプリケーション: yum
メモリー: 35 M RSS (244 MB VSZ)
開始 : Thu Nov 26 05:03:34 2015 - 00:01 秒経過
状態 : 実行中、PID: 2589
/tmp/inspector.b3nZ9iRz/InspectorAgent-1.0.96.0-100096.x86_64.rpm を調べています: InspectorAgent-1.0.96.0-100096.x86_64
エラー: 何もしません
Notice:
By installing the Amazon Inspector Agent, you agree that your use is subject to the terms of your existing
AWS Customer Agreement or other agreement with Amazon Web Services, Inc. or its affiliates governing your
use of AWS services. You may not install and use the Amazon Inspector Agent unless you have an account in
good standing with AWS.
* * *
Current running agent reports version as: 1.0.96.0
This install script was created to install agent version: 1.0.96.0
In most cases, these version numbers should be the same.
HTTP/1.1 200 OK
x-amz-id-2: h1O/eI8QEiOnWHehL+UMGOzOwxf7L9vfZamw+n7g8a0FtF155FJRV4XdytcM1X0LrcgPckGRUmg=
x-amz-request-id: 777F555AA4F364F6
Date: Thu, 26 Nov 2015 05:03:41 GMT
Last-Modified: Wed, 11 Nov 2015 18:27:01 GMT
ETag: "7861805d4dfb5cf7e2d2972cea567ca7"
Accept-Ranges: bytes
Content-Type: binary/octet-stream
Content-Length: 10998
Server: AmazonS3
1.9. nginxのインストール
サンプルアプリケーションとしてnginxをインストールします。
sudo yum -y install nginx ; sudo chkconfig nginx on
読み込んだプラグイン:priorities, update-motd, upgrade-helper
amzn-main/latest | 2.1 kB 00:00
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ nginx.x86_64 1:1.8.0-10.25.amzn1 を インストール
(中略。かなりの行数が流れます)
インストール:
nginx.x86_64 1:1.8.0-10.25.amzn1
依存性関連をインストールしました:
GeoIP.x86_64 0:1.4.8-1.5.amzn1 gd.x86_64 0:2.0.35-11.10.amzn1
gperftools-libs.x86_64 0:2.0-11.5.amzn1 libXpm.x86_64 0:3.5.10-2.9.amzn1
libunwind.x86_64 0:1.1-10.8.amzn1
完了しました!
1.10. 再起動
再起動しないと有効にならないので再起動します。
sudo reboot
Broadcast message from ec2-user@ip-172-31-21-47
(/dev/pts/0) at 5:10 ...
The system is going down for reboot NOW!
Connection to 54.xxx.xxx.xxx closed by remote host.
Connection to 54.xxx.xxx.xxx closed.
以上で診断用EC2インスタンスは準備完了です。
(多分動くので省略しますが、エージェントやnginxの動作確認は適宜行ってください)
- IAMロールの作成
==================
2.1. ロールドキュメントの作成
もう診断用EC2インスタンスへログインすることはありません。再び管理用端末から作業を続けます。
IAM_ROLE_NAME="inspector"
FILE_ROLE_DOC="iam-role-${IAM_ROLE_NAME}.json" && echo ${FILE_ROLE_DOC}
iam-role-inspector.json
cat << EOF > ${FILE_ROLE_DOC}
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "inspector.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
JSONファイルを作成したら、フォーマットが壊れてないか必ず確認します。
jsonlint -q ${FILE_ROLE_DOC}
2.2. ロールポリシードキュメントの作成
FILE_ROLE_POLICY_DOC="iam-role-${IAM_ROLE_NAME}-policy.json" && echo ${FILE_ROLE_POLICY_DOC}
iam-role-inspector-policy.json
cat << EOF > ${FILE_ROLE_POLICY_DOC}
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:Describe*"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
EOF
JSONファイルを作成したら、フォーマットが壊れてないか必ず確認します。
jsonlint -q ${FILE_ROLE_POLICY_DOC}
2.3. ロールの作成
cat << ETX
IAM_ROLE_NAME: ${IAM_ROLE_NAME}
FILE_ROLE_DOC: ${FILE_ROLE_DOC}
ETX
aws iam create-role --role-name ${IAM_ROLE_NAME} --assume-role-policy-document file://${FILE_ROLE_DOC}
{
"Role": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "inspector.amazonaws.com"
}
}
]
},
"RoleId": "AROAIJJMSMXYT5ZXYUZCM",
"CreateDate": "2015-11-26T01:57:27.629Z",
"RoleName": "inspector",
"Path": "/",
"Arn": "arn:aws:iam::454200CLI555:role/inspector"
}
}
2.4. ロールの確認
aws iam get-role --role-name ${IAM_ROLE_NAME}
{
"Role": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "inspector.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
},
"RoleId": "AROAIJJMSMXYT5ZXYUZCM",
"CreateDate": "2015-11-26T01:57:27Z",
"RoleName": "inspector",
"Path": "/",
"Arn": "arn:aws:iam::454200CLI555:role/inspector"
}
}
2.5. ロールポリシーの作成
IAM_ROLE_POLICY_NAME="${IAM_ROLE_NAME}-policy"
cat << ETX
IAM_ROLE_NAME: ${IAM_ROLE_NAME}
IAM_ROLE_POLICY_NAME: ${IAM_ROLE_POLICY_NAME}
FILE_ROLE_POLICY_DOC: ${FILE_ROLE_POLICY_DOC}
ETX
aws iam put-role-policy --role-name ${IAM_ROLE_NAME} --policy-name ${IAM_ROLE_POLICY_NAME} --policy-document file://${FILE_ROLE_POLICY_DOC}
(戻り値なし)
2.6. ロールポリシーの確認
aws iam get-role-policy --role-name ${IAM_ROLE_NAME} --policy-name ${IAM_ROLE_POLICY_NAME}
{
"RoleName": "inspector",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:Describe*"
],
"Resource": "*",
"Effect": "Allow"
}
]
},
"PolicyName": "inspector-policy"
}
2.7. IAMロールのARN取得
IAM_ROLE_ARN=`aws iam get-role --role-name ${IAM_ROLE_NAME} --query 'Role.Arn' --output text` && echo ${IAM_ROLE_ARN}
arn:aws:iam::454200CLI555:role/inspector
- Inspectorの構築
====================
3.1. InspectorへのIAM Role設定
aws inspector register-cross-account-access-role --role-arn ${IAM_ROLE_ARN}
{
"message": "Cross-account access role registered successfully"
}
3.2. Resource Groupの作成
診断対象とするEC2インスタンスに付与したタグを定義します。項番1.5.と同じタグの内容です。
RESOURCE_GROUP_ARN=`aws inspector create-resource-group --resource-group-tags "[{\"key\":\"${TAG_KEY}\",\"values\":[\"${TAG_VALUE}\"]}]" --output text` && echo ${RESOURCE_GROUP_ARN}
arn:aws:inspector:us-west-2:454200CLI555:resourcegroup/0-zje554OG
3.3. Applicationの作成
Resource Groupを用いてApplicationを作成します。
APPLICATION_NAME="handson"
APPLICATION_ARN=`aws inspector create-application --application-name "${APPLICATION_NAME}" --resource-group-arn ${RESOURCE_GROUP_ARN} --output text` && echo ${APPLICATION_ARN}
arn:aws:inspector:us-west-2:454200CLI555:application/0-q3ClefUn
3.4. 実行したい診断の選択
Rules Packages 一覧からどの診断を行うか決めます。
aws inspector list-rules-packages
{
"rulesPackageArnList": [
"arn:aws:inspector:us-west-2:758058086616:rulespackage/0-11B9DBXp",
"arn:aws:inspector:us-west-2:758058086616:rulespackage/0-LfLjwILF",
"arn:aws:inspector:us-west-2:758058086616:rulespackage/0-LzUxcT5A",
"arn:aws:inspector:us-west-2:758058086616:rulespackage/0-Pv9mELS9",
"arn:aws:inspector:us-west-2:758058086616:rulespackage/0-X1KXtawP",
"arn:aws:inspector:us-west-2:758058086616:rulespackage/0-ldNfZf6r"
]
}
なんとCLIではarn一覧が出力されるのみで、内容一覧は出ないのです。
describe-rules-packageコマンドで1つずつarnを指定して内容を確認する必要が有ります。とりえあず1番下を。
RULES_PACKAGE_ARN="arn:aws:inspector:us-west-2:758058086616:rulespackage/0-ldNfZf6r"
aws inspector describe-rules-package --rules-package-arn ${RULES_PACKAGE_ARN}
{
"rulesPackage": {
"description": {
"parameters": [],
"key": {
"id": "rule package description id",
"facility": "arn:aws:inspector:us-west-2:758058086616:rulespackage/0-ldNfZf6r"
}
},
"rulesPackageName": "PCI DSS 3.0 Readiness",
"rulesPackageArn": "arn:aws:inspector:us-west-2:758058086616:rulespackage/0-ldNfZf6r",
"version": "1.0",
"provider": "Amazon Web Services, Inc."
}
}
PCI DSS 3.0 準拠かどうか診断するものだそうで。嫌な響きですが今回はこれにしましょう。
3.5. Assessmentの作成
診断を行うルール(Assessment)を作成します。定期実行する診断間隔を指定します。
900秒(15分)が最短でここでは900秒としますが頻度が短ければそれだけ費用がかさむのでご利用は計画的に。
DURATION=900
ASSESSMENT_NAME="handson"
ASSESSMENT_ARN=`aws inspector create-assessment --application-arn ${APPLICATION_ARN} --assessment-name ${ASSESSMENT_NAME} --duration-in-seconds ${DURATION} --output text` && echo ${ASSESSMENT_ARN}
arn:aws:inspector:us-west-2:454200CLI555:application/0-q3ClefUn/assessment/0-ScIKJCEp
Assessmentに先ほど選んだRules Packageを追加します。
aws inspector attach-assessment-and-rules-package --assessment-arn ${ASSESSMENT_ARN} --rules-package-arn ${RULES_PACKAGE_ARN}
{
"message": "Successfully attached arn:aws:inspector:us-west-2:454200CLI555:application/0-q3ClefUn/assessment/0-ScIKJCEp to arn:aws:inspector:us-west-2:758058086616:rulespackage/0-ldNfZf6r"
}
3.6. 診断の開始
Assessmentのデータ収集を開始させます。
aws inspector start-data-collection --assessment-arn ${ASSESSMENT_ARN}
{
"message": "Successfully started data collection for assessment with ID: arn:aws:inspector:us-west-2:454200CLI555:application/0-q3ClefUn/assessment/0-6mIhKNCv"
}
続いてAssessmentの実行
aws inspector run-assessment --assessment-arn ${ASSESSMENT_ARN} --run-name ${RUN_NAME}
{
"runArn": "arn:aws:inspector:us-west-2:454200CLI555:application/0-q3ClefUn/assessment/0-ScIKJCEp/run/0-WKlfMrre"
}
診断完了まで15分かかります。
ビールをおかわりしてゆっくり飲みながら待ちましょう。
- 診断結果の確認
=================
4.1. 結果一覧の表示
aws inspector list-findings
{
"findingArnList": [
"arn:aws:inspector:us-west-2:454200CLI555:application/0-q3ClefUn/assessment/0-6mIhKNCv/run/0-iyUhAnQZ/finding/null-0bmtREUN",
"arn:aws:inspector:us-west-2:454200CLI555:application/0-q3ClefUn/assessment/0-6mIhKNCv/run/0-iyUhAnQZ/finding/null-AoYzKyUy",
"arn:aws:inspector:us-west-2:454200CLI555:application/0-q3ClefUn/assessment/0-6mIhKNCv/run/0-iyUhAnQZ/finding/null-EJnIeL9F",
"arn:aws:inspector:us-west-2:454200CLI555:application/0-q3ClefUn/assessment/0-6mIhKNCv/run/0-iyUhAnQZ/finding/null-HnUxQBpi",
"arn:aws:inspector:us-west-2:454200CLI555:application/0-q3ClefUn/assessment/0-6mIhKNCv/run/0-iyUhAnQZ/finding/null-NbTqUn34",
"arn:aws:inspector:us-west-2:454200CLI555:application/0-q3ClefUn/assessment/0-6mIhKNCv/run/0-iyUhAnQZ/finding/null-UfR5otmV",
"arn:aws:inspector:us-west-2:454200CLI555:application/0-q3ClefUn/assessment/0-6mIhKNCv/run/0-iyUhAnQZ/finding/null-X3Ff03Ny"
]
}
CLIですからわかりやすく表示されるわけがありません。
結果のarn一覧が出力されるのでこれらを1つずつ内容を確認していく必要があります。
4.2. 結果の内容確認
結果一覧のFinding arnを指定して内容を確認します。
FINDING_ARN="arn:aws:inspector:us-west-2:454200CLI555:application/0-q3ClefUn/assessment/0-6mIhKNCv/run/0-iyUhAnQZ/finding/null-0bmtREUN"
aws inspector describe-finding --finding-arn ${FINDING_ARN}
{
"finding": {
"runArn": "arn:aws:inspector:us-west-2:454200CLI555:application/0-q3ClefUn/assessment/0-6mIhKNCv/run/0-iyUhAnQZ",
"severity": "Informational",
"recommendation": {
"parameters": [
{
"name": "INSECURE_PROTOCOL_LIST",
"value": "www-http (port 80, World Wide Web HTTP), smtp (port 25, Simple Mail Transfer)"
},
{
"name": "INSTANCE_ID",
"value": "i-ba7b3a7e"
}
],
"key": {
"id": "PCI DSS Requirement 1.1.6 - Use Secure Protocols-recommendation",
"facility": "arn:aws:inspector:us-west-2:758058086616:rulespackage/0-ldNfZf6r"
}
},
"rulesPackageArn": "arn:aws:inspector:us-west-2:758058086616:rulespackage/0-ldNfZf6r",
"userAttributes": [],
"findingArn": "arn:aws:inspector:us-west-2:454200CLI555:application/0-q3ClefUn/assessment/0-6mIhKNCv/run/0-iyUhAnQZ/finding/null-0bmtREUN",
"ruleName": "PCI DSS Requirement 1.1.6 - Use Secure Protocols",
"finding": {
"parameters": [
{
"name": "INSECURE_PROTOCOL_LIST",
"value": "www-http (port 80, World Wide Web HTTP), smtp (port 25, Simple Mail Transfer)"
},
{
"name": "INSTANCE_ID",
"value": "i-ba7b3a7e"
}
],
"key": {
"id": "PCI DSS Requirement 1.1.6 - Use Secure Protocols-finding",
"facility": "arn:aws:inspector:us-west-2:758058086616:rulespackage/0-ldNfZf6r"
}
},
"attributes": [
{
"value": "www-http (port 80, World Wide Web HTTP), smtp (port 25, Simple Mail Transfer)",
"key": "INSECURE_PROTOCOL_LIST"
},
{
"value": "i-ba7b3a7e",
"key": "INSTANCE_ID"
}
],
"agentId": "i-ba7b3a7e",
"description": {
"parameters": [
{
"name": "INSECURE_PROTOCOL_LIST",
"value": "www-http (port 80, World Wide Web HTTP), smtp (port 25, Simple Mail Transfer)"
},
{
"name": "INSTANCE_ID",
"value": "i-ba7b3a7e"
}
],
"key": {
"id": "PCI DSS Requirement 1.1.6 - Use Secure Protocols-description",
"facility": "arn:aws:inspector:us-west-2:758058086616:rulespackage/0-ldNfZf6r"
}
}
}
}
セキュアでないプロトコル(HTTP,SMTP)が使われていることを指摘されていますね。
これらはPCI DSS 3.0では使用が禁止されていますからその通りでございます。
結果一覧のarn数だけこれを繰り返し内容を確認しましょう。
-
まとめ
===========
Inspectorは設定した間隔で定期実行されます。
診断結果をもとに対策を行うと、次回診断で指摘されなくなります。
Findingsが何も出力されなくなる状態を目指すことになります。
これでセキュリティが向上すると良いですね。 -
Inspector全削除の方法
===========
使い続ける場合は当然この項目は必要有りません。
以下は削除方法です。基本的に構築した逆の順序に削除していきます。
6.1. Runの削除
Run一覧で動作中のRun arnを取得します。
aws inspector list-runs
{
"runArnList": [
"arn:aws:inspector:us-west-2:454214976215:application/0-q3ClefUn/assessment/0-6mIhKNCv/run/0-iyUhAnQZ"
]
}
取得したarnを指定してRunを削除
aws inspector delete-run --run-arn arn:aws:inspector:us-west-2:454214976215:application/0-q3ClefUn/assessment/0-6mIhKNCv/run/0-iyUhAnQZ
{
"message": "Successfully deleted run arn:aws:inspector:us-west-2:454214976215:application/0-q3ClefUn/assessment/0-6mIhKNCv/run/0-iyUhAnQZ"
}
6.2. Assessmentの削除
Assessment一覧からAssessment arnを取得します。
aws inspector list-assessments
{
"assessmentArnList": [
"arn:aws:inspector:us-west-2:454214976215:application/0-q3ClefUn/assessment/0-6mIhKNCv"
]
}
取得したarnを指定してAssessmentを削除
aws inspector delete-assessment --assessment-arn arn:aws:inspector:us-west-2:454214976215:application/0-q3ClefUn/assessment/0-6mIhKNCv
{
"message": "Successfully deleted assessment arn:aws:inspector:us-west-2:454214976215:application/0-q3ClefUn/assessment/0-6mIhKNCv"
}
6.3. Applicationの削除
Application一覧からApplication arnを取得します。
aws inspector list-applications
{
"applicationArnList": [
"arn:aws:inspector:us-west-2:454214976215:application/0-q3ClefUn"
]
}
取得したarnを指定してApplicationを削除
aws inspector delete-application --application-arn arn:aws:inspector:us-west-2:454214976215:application/0-q3ClefUn
{
"message": "Successfully deleted application arn:aws:inspector:us-west-2:454214976215:application/0-q3ClefUn"
}
6.4. バグ?
現在Previewだからでしょうか、Resource Groupを削除する方法がありません。
マネジメントコンソールではResource Groupは見えずApplicationの内部で制御されているようで、Applicationを削除すると内部処理で同時に削除されますがCLIでは削除できません。
放置しても費用は発生しないし無視することにします。
6.5. その他
EC2インスタンス, IAMロールなどその他のリソースの削除については本題からそれますので割愛します。
完了
Inspectorは無料枠が無いので、ハンズオン完了後は課金を避けたい場合は削除してください。