Alibaba Cloud Provider Classes Architecture
The Alibaba Cloud provider implementation follows the general Provider structure. This section focuses on the Alibaba Cloud-specific implementation, highlighting how the generic provider concepts are realized for Alibaba Cloud in Prowler. For a full overview of the provider pattern, base classes, and extension guidelines, see Provider documentation.Main Class
- Location:
prowler/providers/alibabacloud/alibabacloud_provider.py - Base Class: Inherits from
Provider(see base class details). - Purpose: Central orchestrator for Alibaba Cloud-specific logic, session management, credential validation, and configuration.
- Key Alibaba Cloud Responsibilities:
- Initializes and manages Alibaba Cloud sessions (supports Access Keys, STS Temporary Credentials, RAM Role Assumption, ECS RAM Role, OIDC Authentication, and Credentials URI).
- Validates credentials using STS GetCallerIdentity.
- Loads and manages configuration, mutelist, and fixer settings.
- Discovers and manages Alibaba Cloud regions.
- Provides properties and methods for downstream Alibaba Cloud service classes to access session, identity, and configuration data.
Data Models
- Location:
prowler/providers/alibabacloud/models.py - Purpose: Define structured data for Alibaba Cloud identity, session, credentials, and region info.
- Key Alibaba Cloud Models:
AlibabaCloudCallerIdentity: Stores caller identity information from STS GetCallerIdentity (account_id, principal_id, arn, identity_type).AlibabaCloudIdentityInfo: Holds Alibaba Cloud identity metadata including account ID, user info, profile, and audited regions.AlibabaCloudCredentials: Stores credentials (access_key_id, access_key_secret, security_token).AlibabaCloudRegion: Represents an Alibaba Cloud region with region_id and region_name.AlibabaCloudSession: Manages the session and provides methods to create service clients.
AlibabaCloudService (Service Base Class)
- Location:
prowler/providers/alibabacloud/lib/service/service.py - Purpose: Abstract base class that all Alibaba Cloud service-specific classes inherit from. This implements the generic service pattern (described in service page) specifically for Alibaba Cloud.
- Key Alibaba Cloud Responsibilities:
- Receives an
AlibabacloudProviderinstance to access session, identity, and configuration. - Manages regional clients for services that are region-specific.
- Provides
__threading_call__method to make API calls in parallel by region or resource. - Exposes common audit context (
audited_account,audited_account_name,audit_resources,audit_config) to subclasses.
- Receives an
Exception Handling
- Location:
prowler/providers/alibabacloud/exceptions/exceptions.py - Purpose: Custom exception classes for Alibaba Cloud-specific error handling.
- Key Alibaba Cloud Exceptions:
AlibabaCloudClientError: General client errorsAlibabaCloudNoCredentialsError: No credentials foundAlibabaCloudInvalidCredentialsError: Invalid credentials providedAlibabaCloudSetUpSessionError: Session setup failuresAlibabaCloudAssumeRoleError: RAM role assumption failuresAlibabaCloudInvalidRegionError: Invalid region specifiedAlibabaCloudHTTPError: HTTP/API errors
Session and Utility Helpers
- Location:
prowler/providers/alibabacloud/lib/ - Purpose: Helpers for argument parsing, mutelist management, and other cross-cutting concerns.
Specific Patterns in Alibaba Cloud Services
The generic service pattern is described in service page. You can find all the currently implemented services in the following locations:- Directly in the code, in location
prowler/providers/alibabacloud/services/ - In the Prowler Hub for a more human-readable view.
Alibaba Cloud Service Common Patterns
- Services communicate with Alibaba Cloud using the official Alibaba Cloud Python SDKs. Documentation for individual services can be found in the Alibaba Cloud SDK documentation.
- Every Alibaba Cloud service class inherits from
AlibabaCloudService, ensuring access to session, identity, configuration, and client utilities. - The constructor (
__init__) always callssuper().__init__with the service name, provider, and optionallyglobal_service=Truefor services that are not regional (e.g., RAM). - Resource containers must be initialized in the constructor. For regional services, resources are typically stored in dictionaries keyed by region and resource ID.
- All Alibaba Cloud resources are represented as Pydantic
BaseModelclasses, providing type safety and structured access to resource attributes. - Alibaba Cloud SDK functions are wrapped in try/except blocks, with specific handling for errors, always logging errors.
- Regional services use
self.regional_clientsto maintain clients for each audited region. - The
__threading_call__method is used for parallel execution across regions or resources.
Example Service Implementation
Specific Patterns in Alibaba Cloud Checks
The Alibaba Cloud checks pattern is described in checks page. You can find all the currently implemented checks:- Directly in the code, within each service folder, each check has its own folder named after the name of the check. (e.g.
prowler/providers/alibabacloud/services/ram/ram_no_root_access_key/) - In the Prowler Hub for a more human-readable view.
Check Report Class
TheCheckReportAlibabaCloud class models a single finding for an Alibaba Cloud resource in a check report. It is defined in prowler/lib/check/models.py and inherits from the generic Check_Report base class.
Purpose
CheckReportAlibabaCloud extends the base report structure with Alibaba Cloud-specific fields, enabling detailed tracking of the resource, resource ID, ARN, and region associated with each finding.
Constructor and Attribute Population
When you instantiateCheckReportAlibabaCloud, you must provide the check metadata and a resource object. The class will attempt to automatically populate its Alibaba Cloud-specific attributes from the resource, using the following logic:
-
resource_id:- Uses
resource.idif present. - Otherwise, uses
resource.nameif present. - Defaults to an empty string if not available.
- Uses
-
resource_arn:- Uses
resource.arnif present. - Defaults to an empty string if not available.
- Uses
-
region:- Uses
resource.regionif present. - Defaults to an empty string if not available.
- Uses
Check_Report class, from which you always have to set the status and status_extended attributes in the check logic.
Example Usage
Authentication Methods
The Alibaba Cloud provider supports multiple authentication methods, prioritized in the following order:- Credentials URI - Retrieve credentials from an external URI endpoint
- OIDC Role Authentication - For applications running in ACK with RRSA enabled
- ECS RAM Role - For ECS instances with attached RAM roles
- RAM Role Assumption - Cross-account access with role assumption
- STS Temporary Credentials - Pre-obtained temporary credentials
- Permanent Access Keys - Static access key credentials
- Default Credential Chain - Automatic credential discovery
Regions
Alibaba Cloud has multiple regions across the globe. By default, Prowler audits all available regions. You can specify specific regions using the--regions CLI argument:
prowler/providers/alibabacloud/config.py.
