Shared Provider Framework
Overview
The shared provider framework in prowler/providers/common/ defines the contract and routing helpers that every provider implementation plugs into. The core entry point is prowler/…/provider.py, where the abstract Provider class requires concrete providers to expose type, identity, session, audit_config, setup_session(), and print_credentials(). It also carries the process-wide provider singleton through Provider.set_global_provider() and Provider.get_global_provider(), which shared output code reads later.
Provider discovery has two routes in prowler/…/provider.py. Built-in providers are packages under prowler.providers discovered with pkgutil.iter_modules, excluding common; external providers are loaded from the prowler.providers entry point group. Provider.get_available_providers() returns both. Provider.get_class() resolves a name by preferring built-ins, importing prowler.providers.<provider>.<provider>_provider, and fetching <ProviderName>Provider; only if the name is not built in does it load an entry-point class. Entry-point results, including misses, are memoized in Provider._ep_providers, and returned objects must be subclasses of Provider.
CLI construction is centralized in Provider.init_global_provider() in prowler/…/provider.py. It resolves the provider class, loads the provider-specific fixer config through load_and_validate_config_file(), and then dispatches by exact provider name for built-ins, translating parsed CLI arguments into the provider constructor signature. Unknown or external providers fall through to the dynamic contract: provider_class.from_cli_args(arguments, fixer_config) may either return a provider instance or set the global provider itself. The exact-name dispatch matters because provider names containing built-in substrings must not be routed to a built-in branch.
The same class also defines the newer cross-provider API/UI contract. sdk_only defaults to True, so Provider.get_app_providers() only exposes provider classes that import successfully and opt in with sdk_only = False. get_scan_arguments() and get_connection_arguments() translate a stored provider_uid plus secret dict into constructor or test_connection() kwargs; the base implementation passes the secret through and adds mutelist content only for scans. get_credentials_schema() exposes secret validation models by secret type, while output/reporting hooks such as get_output_options(), get_stdout_detail(), get_finding_output_data(), get_html_assessment_summary(), generate_compliance_output(), display_compliance_table(), and get_mutelist_finding_args() are intentionally non-abstract so providers can migrate incrementally but will fail at runtime if a caller needs an unimplemented hook. Tool-wrapper providers can set is_external_tool_provider = True to let metadata/check loading code treat them differently before instantiation.
Shared CLI parser integration lives in prowler/…/arguments.py. init_providers_parser(self) iterates Provider.get_available_providers(): built-ins are expected to expose prowler.providers.<provider>.lib.arguments.arguments.init_parser, while external providers may expose init_parser on their provider class. Built-in parser import failures are stored on self._builtin_load_failures; enforce_invoked_provider_loaded(self) later decides whether to warn or exit based on the invoked provider, using only sys.argv[1] and the aliases in PROVIDER_ALIASES (microsoft365→m365, oci→oraclecloud). Provider argument validation is similarly routed to a built-in provider's validate_arguments() function if present, otherwise it defaults to success. Common output-format guardrails in this file enforce that json-asff is AWS-only and sarif is IaC-only; tests/…/common_arguments_test.py covers those behaviors.
prowler/…/models.py holds shared data and output setup. Audit_Metadata is a pydantic model for scan progress counters. ProviderOutputOptions copies common CLI output fields, creates output and compliance directories when output modes are requested and fixer mode is not active, and mutates the global provider audit config for cross-provider options: --shodan updates shodan_api_key, and --scan-secrets-validate forces secrets_validate = True. default_output_options() is the fallback for external providers that do not implement get_output_options(), deriving prowler-output-<provider.type>-<timestamp> unless arguments.output_filename is set.
Low-level built-in detection is isolated in prowler/…/builtin.py to avoid import cycles through prowler.providers.common.provider. is_builtin_provider() safely checks whether prowler.providers.<provider> exists, returning False for absent plugin packages instead of propagating parent-package lookup failures. Check routing uses builtin_check_module(provider, service, check_name) to form prowler.providers.<provider>.services.<service>.<check_name>.<check_name>, and is_builtin_check() distinguishes “this check is not shipped here” from “a built-in check exists but its imports are broken.” tests/…/builtin_test.py documents the key edge cases: external checks on built-in providers return False, missing third-party dependencies inside a built-in check re-raise, and textual-prefix module names are not mistaken for missing check parents.
Quick inventory dispatch is small and provider-type based. prowler/…/quick_inventory.py builds <provider.type>_quick_inventory and invokes it from the same module; currently only aws_quick_inventory() exists and delegates to prowler.providers.aws.lib.quick_inventory.quick_inventory.quick_inventory. A non-AWS provider calling this path without a matching function exits through the shared critical logger path.
Coupling
- If a built-in provider package or class is renamed, update the naming contract in prowler/…/provider.py:
Provider.get_class()importsprowler.providers.<provider>.<provider>_providerand expects<provider.capitalize()>Provider. A provider whose package exists but whose expected class is missing raisesImportErrorand will not fall back to a same-named plugin. - If a provider is added or its CLI arguments change, update both its argument parser under
prowler.providers.<provider>.lib.arguments.argumentsand the exact-name constructor branch in prowler/…/provider.py.init_global_provider()manually maps parsedNamespaceattributes to constructor kwargs for every built-in provider. - If argument parsing aliases change, keep
PROVIDER_ALIASESand_invoked_provider_from_argv()in prowler/…/arguments.py aligned with the main parser’s argv normalization.enforce_invoked_provider_loaded()only inspects the first argv token, so drift can make missing built-in dependencies warn when they should fail loud, or vice versa. - If output formats are added with provider-specific constraints, add guardrails beside
validate_asff_usage()andvalidate_sarif_usage()in prowler/…/arguments.py and test them undertests/providers/common/. Otherwise invalid provider/output combinations can survive parsing and fail later in output generation. - If shared output options mutate provider config, verify callers have initialized the global provider first.
ProviderOutputOptionsin prowler/…/models.py callsProvider.get_global_provider()and writesprovider._audit_configfor Shodan and secret validation options. - If check discovery for plugins changes, preserve the exception distinctions in prowler/…/builtin.py.
is_builtin_check()intentionally returnsFalsefor absent SDK checks so entry-point checks can be considered, but re-raises dependency/import failures from real built-in checks so broken built-ins are not silently treated as plugins. - If a provider wants API/UI exposure, it must set
sdk_only = Falseand keepProvider.get_class()import-safe.Provider.get_app_providers()in prowler/…/provider.py suppresses providers whose class import fails.
Risks
- prowler/…/provider.py contains a long manual
init_global_provider()dispatch table. If a provider constructor signature changes without updating its branch, CLI initialization fails with a criticalTypeErrorand exits before scanning. - prowler/…/models.py assumes a global provider exists when
shodanorscan_secrets_validateoptions are set. IfProviderOutputOptionsis constructed beforeProvider.set_global_provider()/provider initialization, those options can raise or mutate the wrong provider state. - prowler/…/quick_inventory.py dispatches by dynamic function name and only defines
aws_quick_inventory(). If a non-AWS provider reachesrun_provider_quick_inventory(), the missing function is logged as critical and the process exits.