diff --git a/docs/tutorials/quick-inventory.md b/docs/tutorials/quick-inventory.md index 0c5654d10f..6221446967 100644 --- a/docs/tutorials/quick-inventory.md +++ b/docs/tutorials/quick-inventory.md @@ -6,7 +6,7 @@ Prowler allows you to execute a quick inventory to extract the number of resourc Currently, it is only available for AWS provider. -- You can use option `-i`/`--scan-inventory` to execute it: +- You can use option `-i`/`--quick-inventory` to execute it: ```sh prowler -i ``` diff --git a/docs/tutorials/scan-inventory.md b/docs/tutorials/scan-inventory.md new file mode 100644 index 0000000000..6257844c5e --- /dev/null +++ b/docs/tutorials/scan-inventory.md @@ -0,0 +1,39 @@ +# Scan Inventory + +The scan-inventory feature is a tool that generates a JSON report within the `/output/inventory/` directory and the scanned service. This feature allows you to perform a inventory of the resources existing in your provider that are scanned by Prowler. + +## Usage + +To use the scan-inventory feature, run Prowler with the `--scan-inventory` option. For example: + +``` +prowler --scan-inventory +``` + +This will generate a JSON report within the `/output/inventory/` directory and the scanned service. + +## Output Directory Contents + +The contents of the `/output/` directory and the scanned service depend on the Prowler execution. This directory contains all the information gathered during scanning, including a JSON report containing all the gathered information. + +## Limitations + +The scan-inventory feature has some limitations. For example: + +* It is only available for the AWS provider. +* It only contains the information retrieved by Prowler during the execution. + +## Example + +Here's an example of how to use the scan-inventory feature and the contents of the `/output/inventory/` directory and the scanned service: + +`prowler aws -s ec2 --scan-inventory` + +``` +/output/inventory/aws directory + | + |-- ec2 + | | + | |-- ec2_output.json +``` +In this example, Prowler is run with the `-s ec2` and `--scan-inventory` options for the AWS provider. The `/output/inventory/aws` directory contains a JSON report showing all the information gathered during scanning. diff --git a/mkdocs.yml b/mkdocs.yml index d696191908..10cd0dad99 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -55,6 +55,7 @@ nav: - Dashboard: tutorials/dashboard.md - Fixer (remediations): tutorials/fixer.md - Quick Inventory: tutorials/quick-inventory.md + - Scan Inventory: tutorials/scan-inventory.md - Slack Integration: tutorials/integrations.md - Configuration File: tutorials/configuration_file.md - Logging: tutorials/logging.md diff --git a/prowler/__main__.py b/prowler/__main__.py index b75d11a33a..06bb700a0f 100644 --- a/prowler/__main__.py +++ b/prowler/__main__.py @@ -73,6 +73,7 @@ from prowler.providers.aws.models import AWSOutputOptions from prowler.providers.azure.models import AzureOutputOptions from prowler.providers.common.inventory import run_prowler_inventory from prowler.providers.common.provider import Provider +from prowler.providers.common.quick_inventory import run_provider_quick_inventory from prowler.providers.gcp.models import GCPOutputOptions from prowler.providers.kubernetes.models import KubernetesOutputOptions @@ -257,6 +258,11 @@ def prowler(): args, bulk_checks_metadata, global_provider.identity ) + # Run the quick inventory for the provider if available + if hasattr(args, "quick_inventory") and args.quick_inventory: + run_provider_quick_inventory(global_provider, args) + sys.exit() + # Execute checks findings = [] diff --git a/prowler/lib/cli/parser.py b/prowler/lib/cli/parser.py index 809a6b447e..2309d8742c 100644 --- a/prowler/lib/cli/parser.py +++ b/prowler/lib/cli/parser.py @@ -378,18 +378,3 @@ Detailed documentation at https://docs.prowler.com action="store_true", help="Send a summary of the execution with a Slack APP in your channel. Environment variables SLACK_API_TOKEN and SLACK_CHANNEL_NAME are required (see more in https://docs.prowler.cloud/en/latest/tutorials/integrations/#slack).", ) - - def __init_inventory_parser__(self): - inventory_parser = self.common_providers_parser.add_argument_group( - "ScanInventory" - ) - inventory_parser.add_argument( - "--scan-inventory", - action="store_true", - help="Run Prowler in inventory mode", - ) - inventory_parser.add_argument( - "-i", - nargs="?", - help="Output folder path for the inventory", - ) diff --git a/prowler/providers/aws/lib/arguments/arguments.py b/prowler/providers/aws/lib/arguments/arguments.py index 471d3a16c7..c3df623117 100644 --- a/prowler/providers/aws/lib/arguments/arguments.py +++ b/prowler/providers/aws/lib/arguments/arguments.py @@ -93,12 +93,19 @@ def init_parser(self): help="Send only Prowler failed findings to SecurityHub", ) # AWS Quick Inventory - aws_quick_inventory_subparser = aws_parser.add_argument_group("Inventory") + aws_quick_inventory_subparser = aws_parser.add_argument_group("Quick Inventory") aws_quick_inventory_subparser.add_argument( - "--scan-inventory", + "--quick-inventory", "-i", action="store_true", - help="Run Prowler Inventory. The inventory will be stored in an output json file.", + help="Run Prowler Quick Inventory. The inventory will be stored in an output csv by default", + ) + # AWS Scan Inventory + aws_scan_inventory_subparser = aws_parser.add_argument_group("Scan Inventory") + aws_scan_inventory_subparser.add_argument( + "--scan-inventory", + action="store_true", + help="Run Prowler Scan Inventory. The inventory will be stored in an output json file.", ) # AWS Outputs aws_outputs_subparser = aws_parser.add_argument_group("AWS Outputs to S3") diff --git a/prowler/providers/common/inventory.py b/prowler/providers/common/inventory.py index d7c9aec7ff..42df5c1e69 100644 --- a/prowler/providers/common/inventory.py +++ b/prowler/providers/common/inventory.py @@ -1,7 +1,6 @@ import importlib import json import os -import shutil from collections import deque from datetime import datetime @@ -108,16 +107,6 @@ def run_prowler_inventory(checks_to_execute, provider): except Exception as e: print("Exception: ", e) - - with open(f"{output_folder_path}/output_metadata.json", "w+") as fp: - json.dump(meta_json_file, fp=fp, default=str, indent=4) - - # end of all things - folder_to_compress = f"{output_folder_path}" - output_zip_file = f"{output_folder_path}/prowler-scan-compressed" # The output file (without extension) - - # Compress the folder into a zip file - shutil.make_archive(f"{output_zip_file}", "zip", folder_to_compress) print( f"\n{Style.BRIGHT}{Fore.GREEN}Scan inventory for {provider} results: {orange_color}{output_folder_path}" ) diff --git a/prowler/providers/common/quick_inventory.py b/prowler/providers/common/quick_inventory.py new file mode 100644 index 0000000000..1023656caa --- /dev/null +++ b/prowler/providers/common/quick_inventory.py @@ -0,0 +1,26 @@ +import importlib +import sys + +from prowler.lib.logger import logger +from prowler.providers.aws.lib.quick_inventory.quick_inventory import quick_inventory + + +def run_provider_quick_inventory(provider, args): + """ + run_provider_quick_inventory executes the quick inventory for the provider + """ + try: + # Dynamically get the Provider quick inventory handler + provider_quick_inventory_function = f"{provider.type}_quick_inventory" + getattr(importlib.import_module(__name__), provider_quick_inventory_function)( + provider, args + ) + except Exception as error: + logger.critical( + f"{error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}" + ) + sys.exit(1) + + +def aws_quick_inventory(provider, args): + quick_inventory(provider, args) diff --git a/tests/lib/cli/parser_test.py b/tests/lib/cli/parser_test.py index 07a31f482f..d726a38117 100644 --- a/tests/lib/cli/parser_test.py +++ b/tests/lib/cli/parser_test.py @@ -974,11 +974,17 @@ class Test_Parser: assert parsed.quick_inventory def test_aws_parser_quick_inventory_long(self): - argument = "--scan-inventory" + argument = "--quick-inventory" command = [prowler_command, argument] parsed = self.parser.parse(command) assert parsed.quick_inventory + def test_aws_parser_scan_inventory_long(self): + argument = "--scan-inventory" + command = [prowler_command, argument] + parsed = self.parser.parse(command) + assert parsed.scan_inventory + def test_aws_parser_output_bucket_short(self): argument = "-B" bucket = "test-bucket"