From b28a8503a99fe533166abf0ef8ceac4f9dae34e7 Mon Sep 17 00:00:00 2001 From: "Andoni A." <14891798+andoniaf@users.noreply.github.com> Date: Wed, 16 Jul 2025 15:12:05 +0200 Subject: [PATCH] chore(mongodbatlas): remove unused attributtes --- prowler/providers/mongodbatlas/config.py | 20 ------------------- .../mongodbatlas/lib/mutelist/mutelist.py | 2 +- prowler/providers/mongodbatlas/models.py | 3 --- .../mongodbatlas/mongodbatlas_provider.py | 9 --------- .../services/clusters/clusters_service.py | 14 +------------ .../mongodbatlas/mongodbatlas_fixtures.py | 7 +------ .../mongodbatlas_provider_test.py | 15 +++----------- 7 files changed, 6 insertions(+), 64 deletions(-) diff --git a/prowler/providers/mongodbatlas/config.py b/prowler/providers/mongodbatlas/config.py index c2f8d47d32..74e3454b7c 100644 --- a/prowler/providers/mongodbatlas/config.py +++ b/prowler/providers/mongodbatlas/config.py @@ -2,26 +2,6 @@ from prowler.lib.logger import logger # MongoDB Atlas Provider Configuration -# Default API version -ATLAS_API_VERSION = "2025-01-01" - -# Default base URL -ATLAS_BASE_URL = "https://cloud.mongodb.com/api/atlas/v2" - -# Default timeout for API requests (in seconds) -ATLAS_REQUEST_TIMEOUT = 30 - -# Default pagination settings -ATLAS_DEFAULT_PAGE_SIZE = 100 -ATLAS_MAX_PAGES = 50 - -# Rate limiting settings -ATLAS_MAX_RETRIES = 3 -ATLAS_RETRY_DELAY = 1 - -# Supported cluster types for encryption checks -ATLAS_CLUSTER_TYPES = ["REPLICASET", "SHARDED", "GEOSHARDED"] - # Supported encryption providers ATLAS_ENCRYPTION_PROVIDERS = ["AWS", "AZURE", "GCP", "NONE"] diff --git a/prowler/providers/mongodbatlas/lib/mutelist/mutelist.py b/prowler/providers/mongodbatlas/lib/mutelist/mutelist.py index dd9f5b751a..345dde0ef9 100644 --- a/prowler/providers/mongodbatlas/lib/mutelist/mutelist.py +++ b/prowler/providers/mongodbatlas/lib/mutelist/mutelist.py @@ -24,7 +24,7 @@ class MongoDBAtlasMutelist(Mutelist): return self.is_muted( account_name, finding.check_metadata.CheckID, - "*", # MongoDB Atlas doesn't have regions in the same way as AWS + "*", # TODO: Study regions in MongoDB Atlas finding.resource_name, unroll_dict(unroll_tags(finding.resource_tags)), ) diff --git a/prowler/providers/mongodbatlas/models.py b/prowler/providers/mongodbatlas/models.py index 171bb78342..cda427177a 100644 --- a/prowler/providers/mongodbatlas/models.py +++ b/prowler/providers/mongodbatlas/models.py @@ -19,9 +19,6 @@ class MongoDBAtlasIdentityInfo(BaseModel): user_id: str username: str - email: Optional[str] = None - first_name: Optional[str] = None - last_name: Optional[str] = None roles: Optional[List[str]] = [] diff --git a/prowler/providers/mongodbatlas/mongodbatlas_provider.py b/prowler/providers/mongodbatlas/mongodbatlas_provider.py index cf4aee08b4..d0196d7bde 100644 --- a/prowler/providers/mongodbatlas/mongodbatlas_provider.py +++ b/prowler/providers/mongodbatlas/mongodbatlas_provider.py @@ -247,9 +247,6 @@ class MongodbatlasProvider(Provider): identity = MongoDBAtlasIdentityInfo( user_id=session.public_key, # Use public key as identifier username=f"api-key-{session.public_key[:8]}", # Create a username from public key - email=None, # Not available from orgs endpoint - first_name=None, # Not available from orgs endpoint - last_name=None, # Not available from orgs endpoint roles=["API_KEY"], # Indicate this is an API key authentication ) @@ -268,15 +265,9 @@ class MongodbatlasProvider(Provider): def print_credentials(self): """Print the MongoDB Atlas credentials""" report_lines = [ - f"MongoDB Atlas User: {Fore.YELLOW}{self.identity.username}{Style.RESET_ALL}", f"MongoDB Atlas User ID: {Fore.YELLOW}{self.identity.user_id}{Style.RESET_ALL}", ] - if self.identity.email: - report_lines.append( - f"MongoDB Atlas Email: {Fore.YELLOW}{self.identity.email}{Style.RESET_ALL}" - ) - if self.organization_id: report_lines.append( f"Organization ID Filter: {Fore.YELLOW}{self.organization_id}{Style.RESET_ALL}" diff --git a/prowler/providers/mongodbatlas/services/clusters/clusters_service.py b/prowler/providers/mongodbatlas/services/clusters/clusters_service.py index 5d49f41d90..510a00f2cc 100644 --- a/prowler/providers/mongodbatlas/services/clusters/clusters_service.py +++ b/prowler/providers/mongodbatlas/services/clusters/clusters_service.py @@ -49,7 +49,6 @@ class Clusters(MongoDBAtlasService): clusters = {} try: - # Get projects first to iterate through them from prowler.providers.mongodbatlas.services.projects.projects_client import ( projects_client, ) @@ -82,7 +81,6 @@ class Clusters(MongoDBAtlasService): project_clusters = {} try: - # Get all clusters in the project with pagination clusters_data = self._paginate_request(f"/groups/{project_id}/clusters") for cluster_data in clusters_data: @@ -112,25 +110,18 @@ class Clusters(MongoDBAtlasService): """ cluster_name = cluster_data.get("name", "") - # Get encryption at rest configuration encryption_provider = self._get_encryption_at_rest_provider(cluster_data) - # Get backup configuration backup_enabled = self._get_backup_enabled(cluster_data) - # Extract provider settings provider_settings = cluster_data.get("providerSettings", {}) - # Extract replication specs replication_specs = cluster_data.get("replicationSpecs", []) - # Extract auto scaling settings auto_scaling = cluster_data.get("autoScaling", {}) - # Extract connection strings connection_strings = cluster_data.get("connectionStrings", {}) - # Extract tags tags = cluster_data.get("tags", []) return Cluster( @@ -167,13 +158,11 @@ class Clusters(MongoDBAtlasService): Optional[str]: Encryption provider or None """ try: - # Check if encryption at rest is enabled encryption_at_rest = cluster_data.get("encryptionAtRestProvider") if encryption_at_rest: return encryption_at_rest - # Check provider settings for encryption provider_settings = cluster_data.get("providerSettings", {}) encrypt_ebs_volume = provider_settings.get("encryptEBSVolume", False) @@ -197,10 +186,9 @@ class Clusters(MongoDBAtlasService): bool: True if backup is enabled, False otherwise """ try: - # Check for backup enabled flag backup_enabled = cluster_data.get("backupEnabled", False) - # Also check for pit enabled as an indicator of backup + # Also check for point-in-time enabled as an indicator of backup pit_enabled = cluster_data.get("pitEnabled", False) return backup_enabled or pit_enabled diff --git a/tests/providers/mongodbatlas/mongodbatlas_fixtures.py b/tests/providers/mongodbatlas/mongodbatlas_fixtures.py index 7457447425..100a055f74 100644 --- a/tests/providers/mongodbatlas/mongodbatlas_fixtures.py +++ b/tests/providers/mongodbatlas/mongodbatlas_fixtures.py @@ -16,9 +16,6 @@ ATLAS_BASE_URL = "https://cloud.mongodb.com/api/atlas/v2" # Test user identity USER_ID = "test_public_key" USERNAME = "api-key-test_pub" -EMAIL = None -FIRST_NAME = None -LAST_NAME = None # Test project PROJECT_ID = "test_project_id" @@ -95,9 +92,7 @@ def set_mocked_mongodbatlas_provider( identity: MongoDBAtlasIdentityInfo = MongoDBAtlasIdentityInfo( user_id=USER_ID, username=USERNAME, - email=EMAIL, - first_name=FIRST_NAME, - last_name=LAST_NAME, + roles=["API_KEY"], ), audit_config: dict = None, organization_id: str = None, diff --git a/tests/providers/mongodbatlas/mongodbatlas_provider_test.py b/tests/providers/mongodbatlas/mongodbatlas_provider_test.py index f30f2238e8..d7fb54f40a 100644 --- a/tests/providers/mongodbatlas/mongodbatlas_provider_test.py +++ b/tests/providers/mongodbatlas/mongodbatlas_provider_test.py @@ -17,9 +17,6 @@ from tests.providers.mongodbatlas.mongodbatlas_fixtures import ( ATLAS_BASE_URL, ATLAS_PRIVATE_KEY, ATLAS_PUBLIC_KEY, - EMAIL, - FIRST_NAME, - LAST_NAME, MOCK_ORGS_RESPONSE, USER_ID, USERNAME, @@ -43,9 +40,7 @@ class TestMongodbatlasProvider: return_value=MongoDBAtlasIdentityInfo( user_id=USER_ID, username=USERNAME, - email=EMAIL, - first_name=FIRST_NAME, - last_name=LAST_NAME, + roles=["API_KEY"], ), ), ): @@ -58,7 +53,6 @@ class TestMongodbatlasProvider: assert provider.session.public_key == ATLAS_PUBLIC_KEY assert provider.session.private_key == ATLAS_PRIVATE_KEY assert provider.identity.username == USERNAME - assert provider.identity.email == EMAIL def test_setup_session_with_credentials(self): """Test session setup with provided credentials""" @@ -108,9 +102,6 @@ class TestMongodbatlasProvider: assert identity.user_id == USER_ID assert identity.username == USERNAME - assert identity.email == EMAIL - assert identity.first_name == FIRST_NAME - assert identity.last_name == LAST_NAME assert identity.roles == ["API_KEY"] @patch("requests.get") @@ -159,7 +150,7 @@ class TestMongodbatlasProvider: return_value=MongoDBAtlasIdentityInfo( user_id=USER_ID, username=USERNAME, - email=EMAIL, + roles=["API_KEY"], ), ), ): @@ -198,7 +189,7 @@ class TestMongodbatlasProvider: return_value=MongoDBAtlasIdentityInfo( user_id=USER_ID, username=USERNAME, - email=EMAIL, + roles=["API_KEY"], ), ), ):