diff --git a/prowler/CHANGELOG.md b/prowler/CHANGELOG.md index c107c68b1b..a28998cab6 100644 --- a/prowler/CHANGELOG.md +++ b/prowler/CHANGELOG.md @@ -17,6 +17,7 @@ All notable changes to the **Prowler SDK** are documented in this file. - Oracle Cloud provider with CIS 3.0 benchmark [(#8893)](https://github.com/prowler-cloud/prowler/pull/8893) - Support for Atlassian Document Format (ADF) in Jira integration [(#8878)](https://github.com/prowler-cloud/prowler/pull/8878) - Add Common Cloud Controls for AWS, Azure and GCP [(#8000)](https://github.com/prowler-cloud/prowler/pull/8000) +- `cloudstorage_bucket_lifecycle_management_enabled` check for GCP provider [(#8936)](https://github.com/prowler-cloud/prowler/pull/8936) ### Changed diff --git a/prowler/providers/gcp/services/cloudstorage/cloudstorage_bucket_lifecycle_management_enabled/cloudstorage_bucket_lifecycle_management_enabled.py b/prowler/providers/gcp/services/cloudstorage/cloudstorage_bucket_lifecycle_management_enabled/cloudstorage_bucket_lifecycle_management_enabled.py index 3a936a4f29..a2911e8326 100644 --- a/prowler/providers/gcp/services/cloudstorage/cloudstorage_bucket_lifecycle_management_enabled/cloudstorage_bucket_lifecycle_management_enabled.py +++ b/prowler/providers/gcp/services/cloudstorage/cloudstorage_bucket_lifecycle_management_enabled/cloudstorage_bucket_lifecycle_management_enabled.py @@ -1,17 +1,18 @@ from prowler.lib.check.models import Check, Check_Report_GCP -from prowler.providers.gcp.services.cloudstorage.cloudstorage_client import cloudstorage_client +from prowler.providers.gcp.services.cloudstorage.cloudstorage_client import ( + cloudstorage_client, +) + class cloudstorage_bucket_lifecycle_management_enabled(Check): - """Ensure Cloud Storage buckets have lifecycle management enabled with at least one valid rule. - + Reports PASS if a bucket has at least one valid lifecycle rule (with a supported action and condition), otherwise FAIL. """ def execute(self) -> list[Check_Report_GCP]: - """Run the lifecycle management check for each Cloud Storage bucket. Returns: @@ -27,25 +28,29 @@ class cloudstorage_bucket_lifecycle_management_enabled(Check): ) rules = bucket.lifecycle_rules - + if rules: valid_rules = [] for rule in rules: action_type = rule.get("action", {}).get("type") condition = rule.get("condition") - if action_type in ("Delete", "SetStorageClass", "AbortIncompleteMultipartUpload") and condition: + if ( + action_type + in ( + "Delete", + "SetStorageClass", + "AbortIncompleteMultipartUpload", + ) + and condition + ): valid_rules.append(rule) if valid_rules: report.status = "PASS" - report.status_extended = ( - f"Bucket {bucket.name} has lifecycle management enabled with {len(valid_rules)} valid rule(s)." - ) + report.status_extended = f"Bucket {bucket.name} has lifecycle management enabled with {len(valid_rules)} valid rule(s)." else: report.status = "FAIL" - report.status_extended = ( - f"Bucket {bucket.name} has lifecycle rules configured but none are valid." - ) + report.status_extended = f"Bucket {bucket.name} has lifecycle rules configured but none are valid." findings.append(report) return findings diff --git a/prowler/providers/gcp/services/cloudstorage/cloudstorage_service.py b/prowler/providers/gcp/services/cloudstorage/cloudstorage_service.py index f7ec966ece..7d155d254f 100644 --- a/prowler/providers/gcp/services/cloudstorage/cloudstorage_service.py +++ b/prowler/providers/gcp/services/cloudstorage/cloudstorage_service.py @@ -36,7 +36,7 @@ class CloudStorage(GCPService): lifecycle = bucket.get("lifecycle") if isinstance(lifecycle, dict): rules = lifecycle.get("rule") - if isinstance(rules, list): + if isinstance(rules, list): lifecycle_rules = rules self.buckets.append(