AWS Provider
Overview
The AWS provider is rooted at prowler/…/aws_provider.py. AwsProvider.__init__ is the lifecycle entry point used before AWS checks run: it loads the AWS provider config, resolves region exclusions, creates the original boto3 session, validates credentials through STS, builds AWSIdentityInfo, optionally assumes the scan role, fetches optional AWS Organizations metadata, discovers enabled account regions, resolves tag/ARN-scoped audit resources, initializes the AWS mutelist, and finally registers itself with Provider.set_global_provider(self). The state shared with services is carried by the dataclasses in prowler/…/models.py: AWSSession keeps both current_session and original_session, AWSIdentityInfo keeps account/partition/profile/audited regions, and AWSOrganizationsInfo stores Organizations context.
Credential setup in prowler/…/aws_provider.py supports the normal boto3 chain, explicit aws_access_key_id/aws_secret_access_key/aws_session_token, AWS CLI profiles, MFA session tokens, and STS AssumeRole. set_session_config merges defaults from prowler/…/config.py, including the Prowler boto3 user-agent, standard retry mode, and connect/read timeouts from PROWLER_AWS_BOTO3_* variables. setup_assumed_session wraps assumed role credentials in botocore RefreshableCredentials, so scans refresh by reusing session.original_session. prowler/…/aws_set_up_session.py is a narrower session setup helper that mirrors much of the provider flow, but AwsProvider.__init__ is the main path used by the provider.
Region and partition handling is centralized in prowler/…/aws_provider.py. get_aws_region_for_sts, get_profile_region, get_partition_bootstrap_candidates, and sts_call_with_partition_failover choose bootstrap STS regions using explicit scan regions, PROWLER_AWS_PARTITION, the boto3 session region, partition defaults, and finally excluded regions as last resort. get_aws_enabled_regions asks EC2 for enabled regions; generate_regional_clients then intersects service availability from prowler/…/aws_regions_by_service.json, the provider's audited regions, enabled regions, and _excluded_regions before creating boto3 clients. Global services call get_default_region(..., global_service=True), which returns the first botocore region for the active partition instead of a user-selected region.
Every AWS service under prowler/providers/aws/services/<service>/ follows the same pattern. The service implementation, such as prowler/…/ec2_service.py, prowler/…/s3_service.py, or prowler/…/iam_service.py, subclasses AWSService from prowler/…/service.py. That base class copies account, partition, audit resources, expected checks, config, fixer config, and current session from the global provider; creates regional_clients for regional services; creates a single client for the default/global region; and provides __threading_call__ for parallel regional or resource hydration. The companion <service>_client.py file, for example prowler/…/ec2_client.py or prowler/…/s3_client.py, instantiates the service at import time from Provider.get_global_provider().
Checks live in prowler/…/<check_name>.py. They import the service singleton from <service>_client.py, iterate the hydrated resource models, and return Check_Report_AWS findings. For example, prowler/…/s3_bucket_public_access.py combines s3_client.buckets and s3control_client.account_public_access_block, then fills status, extended status, resource id, ARN, and region. Resource models are usually pydantic models declared in the service file itself, such as Bucket and PublicAccessBlock in prowler/…/s3_service.py or Instance, SecurityGroup, and Snapshot in prowler/…/ec2_service.py.
Scan scoping is provider-driven. AwsProvider stores explicit resource_arn values directly in _audit_resources; for resource_tags, get_tagged_resources queries the Resource Groups Tagging API through regional clients. Services then call is_resource_filtered while listing resources, as shown in prowler/…/ec2_service.py, prowler/…/s3_service.py, and prowler/…/iam_service.py. ARN-scoped scans also call get_checks_to_execute_by_audit_resources, which parses ARN service/subservice names in AwsProvider.get_checks_from_input_arn to narrow check execution. The AWS CLI flags for these behaviors are defined in prowler/…/arguments.py, including --profile, --role, --region, --excluded-region, --resource-tag, --resource-arn, Security Hub output flags, S3 output flags, boto3 timeout/retry flags, --scan-unused-services, and --fixer.
Muting and Organizations are AWS-specific provider concerns. prowler/…/mutelist.py loads a mutelist from local files, S3 URIs, Lambda ARNs, or DynamoDB table ARNs using the active AWS session, validates it through the common mutelist base, and checks AWS findings by account, check id, region, resource id, and flattened tags. prowler/…/organizations.py reads organizations:DescribeAccount, ListTagsForResource, and OU parent metadata; AwsProvider.__init__ tries the current scan session first, optionally an explicit organizations_role_arn, and falls back to the original session for management-account to member-account flows.
Tests under tests/providers/aws/ mirror these layers. tests/…/conftest.py autostarts moto and fails tests if a request reaches a real amazonaws.com endpoint. tests/…/utils.py provides partition/region constants and set_mocked_aws_provider, which creates an AwsProvider, replaces its session/identity/config fields, and sets Audit_Metadata so service and check tests can instantiate services without a full real bootstrap. tests/…/aws_provider_test.py covers provider lifecycle, STS partition failover, assume-role/MFA, Organizations metadata fallback, region exclusions, service-region routing, session config, mutelist sources, and ARN-based check selection. Service tests such as tests/…/s3_service_test.py and tests/…/ec2_service_test.py validate resource hydration, while check tests such as tests/…/s3_bucket_public_access_test.py patch the singleton service clients that checks import.
The assignment includes permissions/aws/**, but there is no permissions/aws tree in this checkout. AWS permission additions visible in the covered area are therefore represented only indirectly by service API calls and by the top-level permissions/prowler-additions-policy.json, which is outside this doc's owned paths.
Coupling
- If a new AWS service folder or boto3 service name is added under
prowler/providers/aws/services/, also update prowler/…/aws_regions_by_service.json;AwsProvider.generate_regional_clientswill otherwise return no regional clients even though the service code exists. - If a service client singleton file like prowler/…/s3_client.py changes import-time behavior, verify affected check tests patch the same symbol imported by the check file. Checks such as prowler/…/s3_bucket_public_access.py hold module-level singleton references, so patching
Provider.get_global_providerafter import is not enough. - If
AwsProvider.__init__changes identity, region exclusion, or session fields, verifyAWSService.__init__in prowler/…/service.py still receivesprovider.identity,provider.session.current_session,provider.audit_resources,provider.audit_config, andprovider.audit_metadata.expected_checksin the expected shape. - If ARN parsing or resource-filter routing changes in prowler/…/aws_provider.py or prowler/…/arn.py, update both CLI validation in prowler/…/arguments.py and tests in tests/…/aws_provider_test.py; ARN-based scans rely on string service/subservice extraction to choose checks.
- If STS region selection changes in prowler/…/aws_provider.py, verify partition tests in tests/…/aws_provider_test.py; role assumption, credential validation, Organizations lookup, and
test_connectionall reuse the chosen STS region and can silently route to the wrong partition. - If a service hydrates optional or expensive data based on config, keep the provider config key, service hydration, and check expectations aligned. For example, prowler/…/s3_service.py only samples object ACLs when
s3_bucket_object_public_enabledis true, and tests/…/s3_service_test.py asserts both the disabled default and enabled behavior.
Risks
- prowler/…/service.py swallows exceptions from futures in
__threading_call__; if a service method fails before recording partial state, checks can run against incomplete resources and produce missing or false PASS findings without a hard failure. - prowler/…/aws_provider.py has two session bootstrap implementations: the main
AwsProvider.__init__flow and the mirror helper in prowler/…/aws_set_up_session.py. A fix applied to only one path can leave SDK/session consumers with different STS region, timeout, or assume-role behavior. - prowler/…/aws_provider.py parses
resource_arnstrings manually inget_checks_from_input_arn; malformed-but-accepted ARNs or new AWS ARN resource shapes can choose the wrong service/subservice checks, causing scoped scans to skip relevant checks. - prowler/…/s3_service.py creates a normal regional client map and then indexes it by each bucket's discovered region. If the user excludes or omits a bucket's region after bucket listing, bucket hydration methods can miss data and checks like prowler/…/s3_bucket_public_access.py may omit that bucket.