Amazon Inspector プレビューを試してみた #reinvent

2015.10.09

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

こんにちは、コカコーラ好きのカジです。

re:Invent 2015の10月7日のKyenoteでAmazon Inspectorという新サービスが発表されましたのでプレビュー版ですが、試してみました。

Amazon Inspectorとは

EC2上でInspector Agentがアプリケーションの情報やOSの動作状況を収集します。そして、潜在的な脆弱性がないかをルールと照合することで検査します。

Amazon Inspector AgentのサポートOS(2015/10現在)

  • Amazon Linux AMI 2015.03.1
  • Ubuntu Server 14.04 LTS

Amazon Inspector 制限(2015/10現在)

  • アプリケーション 50
  • アセスメント 500
  • 1 AWSアカウントあたり、500同時エージェント
  • リージョン US West (Oregon)でのみ利用可能

チェック対象のEC2を構築

対応のAMIを選択します。

Amazon-Inspector-kaji-EC2-01

EC2にTagを設定

EC2のTagで対象を決定します。 Inspectorで、Trueと設定してみました。このタグがついたインスタンスを後ほどのInspectorの設定でチェックします。

Amazon-Inspector-kaji-EC2-02

Amazon Inspector Agentのインストール

今回は、Amazon Linuxで実施しています。 マニュアルに記載の、wgetコマンドでダウンロード、インストールコマンドでインストールします。

% ssh -i Oregon-Test.pem ec2-user@xxx.xxx.xxx.xxx

       __|  __|_  )
       _|  (     /   Amazon Linux AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-ami/2015.03-release-notes/
10 package(s) needed for security, out of 90 available
Run "sudo yum update" to apply all updates.
Amazon Linux version 2015.09 is available.
$
$ wget https://s3-us-west-2.amazonaws.com/inspector.agent.us-west-2/latest/install
--2015-10-09 00:01:46--  https://s3-us-west-2.amazonaws.com/inspector.agent.us-west-2/latest/install
s3-us-west-2.amazonaws.com (s3-us-west-2.amazonaws.com) をDNSに問いあわせています... 54.231.168.42
s3-us-west-2.amazonaws.com (s3-us-west-2.amazonaws.com)|54.231.168.42|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 9855 (9.6K) [binary/octet-stream]
`install' に保存中

install                       100%[================================================>]   9.62K  --.-KB/s 時間 0s

2015-10-09 00:01:46 (102 MB/s) - `install' へ保存完了 [9855/9855]
$ ls -ltr
合計 12
-rw-rw-r-- 1 ec2-user ec2-user 9855 10月  7 21:41 install
$
$ sudo bash install
Validated signature with:
Validated package sha256 hash matches expected value.
Installing with yum...
読み込んだプラグイン:priorities, update-motd, upgrade-helper
/tmp/inspector.vFWhrH56/InspectorAgent-1.0.84.0-100084.x86_64.rpm を調べています: InspectorAgent-1.0.84.0-100084.x86_64
/tmp/inspector.vFWhrH56/InspectorAgent-1.0.84.0-100084.x86_64.rpm をインストール済みとして設定しています
依存性の解決をしています
amzn-main/latest                                                                              | 2.1 kB     00:00
amzn-updates/latest                                                                           | 2.3 kB     00:00
--> トランザクションの確認を実行しています。
---> パッケージ InspectorAgent.x86_64 0:1.0.84.0-100084 を インストール
--> 依存性の処理をしています: libpcap のパッケージ: InspectorAgent-1.0.84.0-100084.x86_64
--> 依存性の処理をしています: libpcap.so.1()(64bit) のパッケージ: InspectorAgent-1.0.84.0-100084.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ libpcap.x86_64 14:1.4.0-1.20130826git2dbcaa1.10.amzn1 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

=====================================================================================================================
 Package          アーキテクチャー
                           バージョン                                 リポジトリー                              容量
=====================================================================================================================
インストール中:
 InspectorAgent   x86_64   1.0.84.0-100084                            /InspectorAgent-1.0.84.0-100084.x86_64    24 M
依存性関連でのインストールをします:
 libpcap          x86_64   14:1.4.0-1.20130826git2dbcaa1.10.amzn1     amzn-main                                144 k

トランザクションの要約
=====================================================================================================================
インストール  1 パッケージ (+1 個の依存関係のパッケージ)

合計容量: 24 M
総ダウンロード容量: 144 k
インストール容量: 24 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.amzn1.x86_64                                1/2
  インストール中          : InspectorAgent-1.0.84.0-100084.x86_64                                                2/2
crond を再読み込み中: [  OK  ]
  検証中                  : InspectorAgent-1.0.84.0-100084.x86_64                                                1/2
  検証中                  : 14:libpcap-1.4.0-1.20130826git2dbcaa1.10.amzn1.x86_64                                2/2

インストール:
  InspectorAgent.x86_64 0:1.0.84.0-100084

依存性関連をインストールしました:
  libpcap.x86_64 14:1.4.0-1.20130826git2dbcaa1.10.amzn1

完了しました!
読み込んだプラグイン:priorities, update-motd, upgrade-helper
ロックファイル /var/run/yum.pid が存在します: PID 2437 として別に実行されています。
Another app is currently holding the yum lock; waiting for it to exit...
 他のアプリケーション: yum
   メモリー:  27 M RSS (242 MB VSZ)
    開始   : Fri Oct  9 00:02:26 2015 - 00:02 秒経過
    状態   : 実行中、PID: 2437
/tmp/inspector.vFWhrH56/InspectorAgent-1.0.84.0-100084.x86_64.rpm を調べています: InspectorAgent-1.0.84.0-100084.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.84.0
This install script was created to install agent version: 1.0.84.0
In most cases, these version numbers should be the same.
$

インストールが完了しました。

試しに、apacheもインストールしてみました。

$ sudo yum install httpd
<省略>
総ダウンロード容量: 1.5 M
インストール容量: 3.6 M
Is this ok [y/d/N]: y
Downloading packages:
<省略>

インストール:
  httpd.x86_64 0:2.2.31-1.6.amzn1

依存性関連をインストールしました:
  apr.x86_64 0:1.5.0-2.11.amzn1          apr-util.x86_64 0:1.4.1-4.17.amzn1  apr-util-ldap.x86_64 0:1.4.1-4.17.amzn1
  httpd-tools.x86_64 0:2.2.31-1.6.amzn1  mailcap.noarch 0:2.1.31-2.7.amzn1

完了しました!
$

AWS Inspector設定開始

日本リージョンでは以下のようなエラーが表示されますのでオレゴンに変更しましょう

Amazon-Inspector-kaji-00

Amazon-Inspector-kaji-01

Amazon-Inspector-kaji-02

Amazon-Inspector-kaji-03

Inspector用のIAMを初期設定内容も確認可能です。 Amazon-Inspector-kaji-04

Amazon-Inspector-kaji-05

PreviewでTag設定されたインスタンスがあるか、確認しておきましょう。 インスタンスの表示の確認が漏れていると最後に記載するエラーが発生します。 Amazon-Inspector-kaji-06

Amazon-Inspector-kaji-07

Amazon-Inspector-kaji-09

Amazon-Inspector-kaji-10

Durationで設定した期間待ちます。COLLECTING_DATAになるはずです。 Amazon-Inspector-kaji-11

終了するとCOMPLETEDに変化します。 Amazon-Inspector-kaji-12

詳細を確認した画面 Amazon-Inspector-kaji-13

チェック結果

今回は該当する脆弱性は無いようです。 Amazon-Inspector-kaji-14

実行時に以下のようなエラーが出た時

ここで私はInspectorのTag設定と、EC2のTag設定が不一致のため以下のような画面になりました。 Amazon-Inspector-kaji-error

また、上記エラー時のEC2側もinspectorのstatusは以下になりましたので参考にしてください。

異常時のAgent側のinspector status

falseが多くでます。

$ sudo /opt/aws/inspector/bin/inspector status
Agent version: 1.0.84.0
System release: Amazon Linux AMI release 2015.03 - 3.14.48-33.39.amzn1.x86_64
Configuration file path: /opt/aws/inspector/etc/agent.cfg
Service endpoint: arsenal.us-west-2.amazonaws.com
Kernel module path: /opt/aws/inspector/kmods/inspector.ko
Kernel module status: 104
Log file:
Msgs log max size: 33554432
Dns entries: false
Network connections: false
Listening ports: false
Listening ports info: false
Kernel modules: false
Code modules: false
Processes: false
Users: false
Groups: false
Instance metadata: false
Network interfaces: false
Package info: false
Terminals: false
Configuration info: false
Permissions: false
System performance: false
System performance update frequency: 1
System performance send frequency: 30
Process performance: false
Process performance update frequency: 1
Process performance send frequency: 30

Producer type: Service
Registered: true
Endpoint: arsenal.us-west-2.amazonaws.com
Instance-Id: i-cc8f7a08
Region: us-west-2a
IpAddress: 10.0.11.151
MacAddress: 02:3a:f2:74:17:55
Total events published: 3
Events published in last call: 0
AgentId: i-cc8f7a08
Collecting: false
Last registration attempt date: Fri 2015-10-09 00:12:34 UTC
Last registration date: Fri 2015-10-09 00:12:34 UTC
Last config retrieval attempt date: Fri 2015-10-09 00:30:11 UTC
Last config retrieval date: Fri 2015-10-09 00:30:11 UTC
$

正常時のAgent側のinspector status

trueになります。

$ sudo /opt/aws/inspector/bin/inspector status
Agent version: 1.0.84.0
System release: Amazon Linux AMI release 2015.03 - 3.14.48-33.39.amzn1.x86_64
Configuration file path: /opt/aws/inspector/etc/agent.cfg
Service endpoint: arsenal.us-west-2.amazonaws.com
Kernel module path: /opt/aws/inspector/kmods/inspector.ko
Kernel module status: 0
Log file:
Msgs log max size: 33554432
Dns entries: true
Network connections: true
Listening ports: true
Listening ports info: false
Kernel modules: true
Code modules: true
Processes: true
Users: true
Groups: true
Instance metadata: true
Network interfaces: true
Package info: true
Terminals: true
Configuration info: true
GlobalFile:/etc/bash.bashrc
GlobalFile:/etc/bashrc
GlobalFile:/etc/login.defs
GlobalFile:/etc/pam.conf
GlobalFile:/etc/pam.d/*
GlobalFile:/etc/profile
GlobalFile:/etc/samba/smb.conf
GlobalFile:/etc/ssh/sshd_config
GlobalFile:/etc/sysctl.conf
PerUserFile:.bash_login
PerUserFile:.bash_profile
PerUserFile:.bashrc
Permissions: true
GlobalDir:/bin
GlobalDir:/etc
GlobalDir:/lib
GlobalDir:/lib64
GlobalDir:/root
GlobalDir:/sbin
GlobalDir:/usr/bin
GlobalDir:/usr/lib64
GlobalDir:/usr/local/bin
GlobalDir:/usr/local/lib
GlobalDir:/usr/local/lib64
GlobalDir:/usr/local/sbin
GlobalDir:/usr/sbin
System performance: true
System performance update frequency: 1
System performance send frequency: 30
Process performance: true
Process performance update frequency: 1
Process performance send frequency: 30

Producer type: Service
Registered: true
Endpoint: arsenal.us-west-2.amazonaws.com
Instance-Id: i-cc8f7a08
Region: us-west-2a
IpAddress: 10.0.11.151
MacAddress: 02:3a:f2:74:17:55
Total events published: 787
Events published in last call: 3
AgentId: i-cc8f7a08
Collecting: true
Last registration attempt date: Fri 2015-10-09 00:38:41 UTC
Last registration date: Fri 2015-10-09 00:38:41 UTC
Last config retrieval attempt date: Fri 2015-10-09 01:09:46 UTC
Last config retrieval date: Fri 2015-10-09 01:09:46 UTC
Last event publishing attempt date: Fri 2015-10-09 01:10:06 UTC
Last event publishing date: Fri 2015-10-09 01:10:06 UTC
$

感想

Amazon Linux 2015.09でも試しましたが、カーネルエラーでInspector Agentがインストールできませんでした。今後修正されるかもしれません。 また、Inspector Agentのインストールは、Ansibleなどで一括にした方が早そうです。 Ubuntuも対応しているので、次回テストしてみたいと思います。 また、Ubuntuですとマニュアルの手順で操作すると脆弱性があった場合の表示内容も確認できるので試して次回ブログで掲載します。