[アップデート] Amazon Inspector で特定の EC2 インスタンスをスキャン対象外にできるようになっていました

2023.10.27

札幌オフィスの中川です。

Amazon Inspector のよくある質問を見ていると、特定の EC2 インスタンス をスキャンの対象外にできる記述がありました。

ドキュメント履歴を見ると、2023年9月から 特定の EC2 インスタンスを対象外にできるようになっていたようです。

Amazon Inspector はスキャンされた Amazon EC2 インスタンスの数に応じて課金されます。すべてのインスタンスが脆弱性管理されていることが望ましいですが、同じ構成のインスタンスが複数稼働する環境ではコストの兼ね合いで一部インスタンスは対象外としたかったケースはあったのではないでしょうか。

本記事ではEC2のスキャン対象外機能で確認した内容を紹介します。

やってみた

Amazon Insector を既に有効化している環境で試します。

スキャンの除外はタグキー「InspectorEc2Exclusion」をインスタンスに付与して設定します。
タグを付与したインスタンスと付与していないインスタンスをそれぞれ作成してスキャンの動作を確認してみます。

タグ無し

タグ有り

Amazon Inspector のアカウント管理画面からインスタンスを表示すると、スキャン・スキャンしないで表示されていることを確認できました。

インスタンス別の検出結果を見ると、タグを付与しなかったインスタンスのみスキャン結果を確認できました。

タグを付与したインスタンスで /var/log/amazon/inspector/ 配下に出力される SSM プラグインのログを見てみました。

sh-5.2$ cat /var/log/amazon/inspector/scitor.log.2023-10-27-05
Fri Oct 27 05:37:32 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/main.go:44 main.execCmd(): Version: 1.0.904.0
Fri Oct 27 05:37:32 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/main.go:45 main.execCmd(): UTC Build Time: 2023-10-23T12:36:04+0000
Fri Oct 27 05:37:32 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/cmd/bpm.go:59 golang.a2z.com/inspectorssmplugin/cmd.ExecBpmScan(): bpm scan started
Fri Oct 27 05:37:32 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/identity/identity.go:44 golang.a2z.com/inspectorssmplugin/identity.NewIdentity(): ec2 metadata region=ap-northeast-1 instance-id=i-XXXXXX99a68 instance-type=t3.nano
Fri Oct 27 05:37:32 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/identity/identity.go:82 golang.a2z.com/inspectorssmplugin/identity.(*Identity).Credentials(): use ec2 role provider for credentials
Fri Oct 27 05:37:32 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/cmd/bpm.go:423 golang.a2z.com/inspectorssmplugin/cmd.removePathIf(): package scanner rejected root directory 'NO_PATHS_DEFINED'
Fri Oct 27 05:37:32 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/cmd/bpm.go:107 golang.a2z.com/inspectorssmplugin/cmd.ExecBpmScan(): files system traversal depth=-1 max directories under specified root=-1
Fri Oct 27 05:37:32 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/inventory/pacman/pacman_linux.go:104 golang.a2z.com/inspectorssmplugin/inventory/pacman.(*PackageManager).GetPythonPackageMetadataLocation(): using '' to gather python package locations
Fri Oct 27 05:37:32 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/inventory/pacman/pacman_linux.go:122 golang.a2z.com/inspectorssmplugin/inventory/pacman.(*PackageManager).GetPythonPackageMetadataLocation(): located '92' metadata files for python packages installed via platform package manager
Fri Oct 27 05:37:32 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/bpm/scanner/scanner.go:165 golang.a2z.com/inspectorssmplugin/bpm/scanner.(*Scanner).initialize(): extracted suffix from pattern "^/.*/[-.\w]+\.dist[-]info/METADATA$": "METADATA"
Fri Oct 27 05:37:32 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/bpm/scanner/scanner.go:165 golang.a2z.com/inspectorssmplugin/bpm/scanner.(*Scanner).initialize(): extracted suffix from pattern "^(?:/.*)?/[-.\w]+\.egg[-]info$": "info"
〜〜〜略〜〜〜
Fri Oct 27 05:37:33 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/bpm/filefinder/filefinder.go:84 golang.a2z.com/inspectorssmplugin/bpm/filefinder.(*FileFinder).EnumerateFiles(): scanned 2331 directories under "/usr/lib"
Fri Oct 27 05:37:33 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/bpm/filefinder/filefinder.go:76 golang.a2z.com/inspectorssmplugin/bpm/filefinder.(*FileFinder).EnumerateFiles(): scanning directory "/usr/lib64"
〜〜〜略〜〜〜
Fri Oct 27 05:37:33 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/bpm/filefinder/filefinder.go:84 golang.a2z.com/inspectorssmplugin/bpm/filefinder.(*FileFinder).EnumerateFiles(): scanned 290 directories under "/usr/lib64"
Fri Oct 27 05:37:33 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/bpm/filefinder/filefinder.go:76 golang.a2z.com/inspectorssmplugin/bpm/filefinder.(*FileFinder).EnumerateFiles(): scanning directory "/usr/local/lib"
Fri Oct 27 05:37:33 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/bpm/filefinder/filefinder.go:84 golang.a2z.com/inspectorssmplugin/bpm/filefinder.(*FileFinder).EnumerateFiles(): scanned 1 directories under "/usr/local/lib"
Fri Oct 27 05:37:33 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/bpm/filefinder/filefinder.go:76 golang.a2z.com/inspectorssmplugin/bpm/filefinder.(*FileFinder).EnumerateFiles(): scanning directory "/usr/local/lib64"
Fri Oct 27 05:37:33 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/bpm/filefinder/filefinder.go:84 golang.a2z.com/inspectorssmplugin/bpm/filefinder.(*FileFinder).EnumerateFiles(): scanned 2 directories under "/usr/local/lib64"
Fri Oct 27 05:37:33 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/cmd/bpm.go:183 golang.a2z.com/inspectorssmplugin/cmd.ExecBpmScan(): submitting packages findings as inventory report
Fri Oct 27 05:37:33 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/identity/identity.go:44 golang.a2z.com/inspectorssmplugin/identity.NewIdentity(): ec2 metadata region=ap-northeast-1 instance-id=i-XXXXXX99a68 instance-type=t3.nano
Fri Oct 27 05:37:33 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/identity/identity.go:82 golang.a2z.com/inspectorssmplugin/identity.(*Identity).Credentials(): use ec2 role provider for credentials
Fri Oct 27 05:37:33 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/inventory/bpm.go:89 golang.a2z.com/inspectorssmplugin/inventory.PackagesInventory.PublishPackages(): post inventory request for 13 packages with hash '1069a137450da2006a1f106f0da22e08'
Fri Oct 27 05:37:33 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [ERROR] MandoSecurityContentEvaluator/inventory/inventory.go:129 golang.a2z.com/inspectorssmplugin/inventory.sendReport(): failed to report inventory via ssm PutInventory: operation error SSM: PutInventory, https response error StatusCode: 400, RequestID: 9abae545-4ddd-4295-aa90-6284d85b4857, InvalidItemContentException: Your request contains contentHash with no content of inventory type Custom:InspectorThirdPartyPackage. The content of the type may never be sent, please resend the item with full content.
Fri Oct 27 05:37:33 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/inventory/bpm.go:98 golang.a2z.com/inspectorssmplugin/inventory.PackagesInventory.PublishPackages(): resend inventory request with content per service response: operation error SSM: PutInventory, https response error StatusCode: 400, RequestID: 9abae545-4ddd-4295-aa90-6284d85b4857, InvalidItemContentException: Your request contains contentHash with no content of inventory type Custom:InspectorThirdPartyPackage. The content of the type may never be sent, please resend the item with full content.
Fri Oct 27 05:37:33 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/inventory/bpm.go:104 golang.a2z.com/inspectorssmplugin/inventory.PackagesInventory.PublishPackages(): succeeded posting package collection inventory item
Fri Oct 27 05:37:33 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/identity/identity.go:44 golang.a2z.com/inspectorssmplugin/identity.NewIdentity(): ec2 metadata region=ap-northeast-1 instance-id=i-XXXXXX99a68 instance-type=t3.nano
Fri Oct 27 05:37:33 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/identity/identity.go:82 golang.a2z.com/inspectorssmplugin/identity.(*Identity).Credentials(): use ec2 role provider for credentials
Fri Oct 27 05:37:33 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/cmd/bpm.go:359 golang.a2z.com/inspectorssmplugin/cmd.logStats(): scan elapsed(ms)=799 directories=2624 files=19632 packages=13
Fri Oct 27 05:37:33 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/cmd/bpm.go:363 golang.a2z.com/inspectorssmplugin/cmd.logStats(): scan cpu pct samples=4 histogram=[0 25 25 0 0 0 0 0 25 25]
Fri Oct 27 05:37:33 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/cmd/bpm.go:367 golang.a2z.com/inspectorssmplugin/cmd.logStats(): scan mem pct samples=6 histogram=[100 0 0 0 0 0 0 0 0 0]
Fri Oct 27 05:37:33 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/cmd/bpm.go:218 golang.a2z.com/inspectorssmplugin/cmd.ExecBpmScan(): packages scan completed
Fri Oct 27 05:37:34 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/appconfig/appconfig.go:144 golang.a2z.com/inspectorssmplugin/appconfig.CleanupLogs(): logs cleanup started
Fri Oct 27 05:37:34 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/appconfig/appconfig.go:166 golang.a2z.com/inspectorssmplugin/appconfig.CleanupLogs(): number of log files 1 is less than or equal the limit 7
Fri Oct 27 05:37:34 2023 UTC scitor 2168-0@ip-10-0-2-52.ap-northeast-1.compute.internal:0 [INFO] MandoSecurityContentEvaluator/appconfig/appconfig.go:169 golang.a2z.com/inspectorssmplugin/appconfig.CleanupLogs(): logs cleanup completed

タグを付与してもスキャン自体は実行されていることを確認できました。Inspector 上でタグから課金対象にならない処理してくれているようですね。

さいごに

Amazon Inspector は V2 になってから、SSM エージェントがインストールされた EC2 インスタンスはすべてスキャンされる仕様でしたが、アップデート で 特定の EC2 インスタンスをスキャン対象外にできるようになりました。 セキュリティとコストを両立しながら脆弱性管理をできるようになる嬉しいアップデートと思いました。

参考