Repository: prowler-cloud/prowler

Issue:
[Bug]: Unbound local variable `checks_multi_account`
### Steps to Reproduce

1. What command are you running:
  `prowler aws -M html json -f us-west-2 -w allowlist.yaml --ignore-exit-code-3`
2. Cloud provider you are launching: AWS
3. Environment you have: single account
4. See error

### Expected behavior

Prowler analyzes the account and successfully returns a report.

### Actual Result with Screenshots or Logs

```
 _ __  _ __ _____      _| | ___ _ __
| '_ \| '__/ _ \ \ /\ / / |/ _ \ '__|
| |_) | | | (_) \ V  V /| |  __/ |
| .__/|_|  \___/ \_/\_/ |_|\___|_|v3.7.1
|_| the handy cloud security tool

Date: 2023-07-13 10:33:15


This report is being generated using credentials below:

AWS-CLI Profile: [default] AWS Filter Region: [us-west-2]
AWS Account: [************] UserId: [**************]
Caller Identity ARN: [arn:aws:sts::************:assumed-role/AWSReservedSSO_AdministratorAccess_*******/****@****.***]

Executing 284 checks, please wait...

2023-07-13 10:33:17,306 [File: allowlist.py:144] 	[Module: allowlist]	 CRITICAL: UnboundLocalError -- cannot access local variable 'checks_multi_account' where it is not associated with a value[130]
-> Scanning accessanalyzer service |⚠︎                                       | (!) 0/284 [0%] in 0.2s 
```


### How did you install Prowler?

From pip package (pip install prowler)

### Environment Resource

We are seeing the error on multiple environments:
- CI/CD build node
- Local macOS workstation

### OS used

1. RHEL
2. macOS 13.4

### Prowler version

3.7.1

### Pip version

23.0.1

### Context

Prowler performs as expected in version `3.7.0`, and fails on `3.7.1`

We are using an `allowlist.yaml` file, with our account number specified instead of using a `*` for the account.
[Bug]: Unbound local variable `checks_multi_account`
### Steps to Reproduce

1. What command are you running:
  `prowler aws -M html json -f us-west-2 -w allowlist.yaml --ignore-exit-code-3`
2. Cloud provider you are launching: AWS
3. Environment you have: single account
4. See error

### Expected behavior

Prowler analyzes the account and successfully returns a report.

### Actual Result with Screenshots or Logs

```
 _ __  _ __ _____      _| | ___ _ __
| '_ \| '__/ _ \ \ /\ / / |/ _ \ '__|
| |_) | | | (_) \ V  V /| |  __/ |
| .__/|_|  \___/ \_/\_/ |_|\___|_|v3.7.1
|_| the handy cloud security tool

Date: 2023-07-13 10:33:15


This report is being generated using credentials below:

AWS-CLI Profile: [default] AWS Filter Region: [us-west-2]
AWS Account: [************] UserId: [**************]
Caller Identity ARN: [arn:aws:sts::************:assumed-role/AWSReservedSSO_AdministratorAccess_*******/****@****.***]

Executing 284 checks, please wait...

2023-07-13 10:33:17,306 [File: allowlist.py:144] 	[Module: allowlist]	 CRITICAL: UnboundLocalError -- cannot access local variable 'checks_multi_account' where it is not associated with a value[130]
-> Scanning accessanalyzer service |⚠︎                                       | (!) 0/284 [0%] in 0.2s 
```


### How did you install Prowler?

From pip package (pip install prowler)

### Environment Resource

We are seeing the error on multiple environments:
- CI/CD build node
- Local macOS workstation

### OS used

1. RHEL
2. macOS 13.4

### Prowler version

3.7.1

### Pip version

23.0.1

### Context

Prowler performs as expected in version `3.7.0`, and fails on `3.7.1`

We are using an `allowlist.yaml` file, with our account number specified instead of using a `*` for the account.


Discussion:

Resolving patch:
diff --git a/prowler/providers/aws/lib/allowlist/allowlist.py b/prowler/providers/aws/lib/allowlist/allowlist.py
--- a/prowler/providers/aws/lib/allowlist/allowlist.py
+++ b/prowler/providers/aws/lib/allowlist/allowlist.py
@@ -126,8 +126,8 @@ def is_allowlisted(allowlist, audited_account, check, region, resource, tags):
         # want to merge allowlisted checks from * to the other accounts check list
         if "*" in allowlist["Accounts"]:
             checks_multi_account = allowlist["Accounts"]["*"]["Checks"]
+            allowlisted_checks.update(checks_multi_account)
         # Test if it is allowlisted
-        allowlisted_checks.update(checks_multi_account)
         if is_allowlisted_in_check(
             allowlisted_checks,
             audited_account,


Test patch:
diff --git a/tests/providers/aws/lib/allowlist/allowlist_test.py b/tests/providers/aws/lib/allowlist/allowlist_test.py
--- a/tests/providers/aws/lib/allowlist/allowlist_test.py
+++ b/tests/providers/aws/lib/allowlist/allowlist_test.py
@@ -305,6 +305,30 @@ def test_is_allowlisted_all_and_single_account(self):
             )
         )
 
+    def test_is_allowlisted_single_account(self):
+        allowlist = {
+            "Accounts": {
+                AWS_ACCOUNT_NUMBER: {
+                    "Checks": {
+                        "check_test": {
+                            "Regions": [AWS_REGION],
+                            "Resources": ["prowler"],
+                        }
+                    }
+                }
+            }
+        }
+
+        assert is_allowlisted(
+            allowlist, AWS_ACCOUNT_NUMBER, "check_test", AWS_REGION, "prowler", ""
+        )
+
+        assert not (
+            is_allowlisted(
+                allowlist, AWS_ACCOUNT_NUMBER, "check_test", "us-east-2", "test", ""
+            )
+        )
+
     def test_is_allowlisted_in_region(self):
         # Allowlist example
         allowlisted_regions = [AWS_REGION, "eu-west-1"]