feat(scan-inventory): take back changes from quick inventory

This commit is contained in:
pedrooot
2024-10-02 15:45:01 -06:00
parent 3ef1d41630
commit 2cf1f22235
9 changed files with 90 additions and 31 deletions
+1 -1
View File
@@ -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 <provider> -i
```
+39
View File
@@ -0,0 +1,39 @@
# Scan Inventory
The scan-inventory feature is a tool that generates a JSON report within the `/output/inventory/<provider>` 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 <provider> --scan-inventory
```
This will generate a JSON report within the `/output/inventory/<provider>` directory and the scanned service.
## Output Directory Contents
The contents of the `/output/<provider>` 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/<provider>` 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.
+1
View File
@@ -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
+6
View File
@@ -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 = []
-15
View File
@@ -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",
)
@@ -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")
-11
View File
@@ -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}"
)
@@ -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)
+7 -1
View File
@@ -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"