Introducing a new way to review your PRs.

Read the announcement

azure / azure-cli

Azure Command-Line Interface

View on GitHub

13 documents · Updated Nov 16, 2026

docs / storage-commands

Azure Storage command module

Overview

The Azure Storage CLI module is rooted at src/…/__init__.py. StorageCommandsLoader.load_command_table first loads generated AAZ commands from src/azure-cli/azure/cli/command_modules/storage/aaz/latest/** through load_aaz_command_table, then overlays the hand-written command table from src/…/commands.py. Argument loading is centralized in src/…/_params.py, and command help is registered by importing src/…/_help.py from the loader.

commands.py mixes three command families:

  • Management-plane commands use ResourceType.MGMT_STORAGE and management SDK operation groups from src/…/_client_factory.py, such as cf_sa, cf_mgmt_blob_services, cf_mgmt_file_services, cf_mgmt_file_shares, cf_blob_container_mgmt, cf_mgmt_policy, cf_or_policy, and cf_local_users. These back az storage account, service properties, management policies, network rules, local users, storage container-rm, and generated/custom storage share-rm commands.
  • Data-plane commands use StorageCommandGroup.storage_command* helpers in __init__.py, which automatically add storage-account credential arguments and, for OAuth-capable commands, --auth-mode {login,key}. commands.py registers data-plane groups for blobs/containers, Azure Files shares/directories/files, queues/messages, tables/entities, ADLS Gen2 file systems/directories/files/access, CORS, logging, metrics, and AzCopy-backed transfer helpers.
  • Generated AAZ commands under src/azure-cli/azure/cli/command_modules/storage/aaz/latest/storage/** provide newer management-plane implementations. commands.py also manually installs selected AAZ-derived wrapper classes, for example ShareRmCreate, ShareRmUpdate, ShareRmDelete, ShareRmShow, and ShareRmList from src/…/file.py, plus AccountMigrationStart, FileServiceUsage, and AdvancedPlatformMetricUpdate.

Authentication for data-plane commands is documented for users in doc/storage_data_plane_commands_auth.md and implemented by the argument registration and validators. StorageCommandGroup._register_data_plane_account_arguments in __init__.py adds --account-name, --connection-string, service endpoint options such as --blob-endpoint/--file-endpoint, --account-key, and --sas-token. StorageCommandGroup._register_data_plane_oauth_arguments adds --auth-mode and requires --enable-file-backup-request-intent for file share OAuth paths. validate_client_parameters in _validators.py resolves AZURE_STORAGE_* config/environment values, parses connection strings, strips leading ? from SAS tokens, sets secondary location mode for *-secondary account names, attaches an AAD token credential for --auth-mode login, and otherwise falls back to querying the storage account key through the management plane when only a valid account name is available.

Client creation is in src/…/_client_factory.py. Blob, queue, table, Azure Files, and ADLS factories build track 2 SDK clients from connection strings, account URLs, keys, SAS tokens, or token credentials. File share clients enforce the extra OAuth requirement: cf_share_service and cf_share_file_client raise if a token credential is used without --enable-file-backup-request-intent, then pass token_intent='backup' to the files SDK. Table clients convert shared key and SAS into the credential types expected by azure.data.tables.

Custom operation modules under src/azure-cli/azure/cli/command_modules/storage/operations/ contain the behavior that the command table points at. operations/blob.py handles blob/container data-plane commands, service properties, SAS generation, URL creation, blob restore, batch copy/upload/download/delete, and large block sizing during uploads. operations/file.py, operations/directory.py, and operations/fileshare.py handle Azure Files data-plane operations, share-RM wrappers, recursive batch transfer/delete helpers, URL/SAS creation, NFS-related parameters, and safe local download path handling. operations/queue.py and operations/table.py wrap track 2 queue/table APIs for create/delete/exists/list, SAS generation, message and entity operations, pagination, and continuation marker shapes. operations/filesystem.py, operations/fs_directory.py, and operations/fs_file.py implement ADLS Gen2 file system/path operations, ACL recursion, deleted path listing, SAS URI generation, and path URL normalization. operations/azcopy.py is the command shim for az storage copy, remove, blob sync, and ADLS directory transfer; the executable resolution and auth handoff live in src/…/util.py.

Shared helpers in src/…/util.py, storage_url_helpers.py, track2_util.py, sdkutil.py, and url_quote_util.py support wildcard expansion, short-lived SAS creation for copy sources, safe download path joining, URL parsing/quoting, track 2 paging, and storage model translation. Output shaping and table views live in src/…/_transformers.py and _format.py; exception translation lives in src/…/_exception_handler.py plus the exception handlers wired by StorageCommandGroup.

Tests for this module are under src/azure-cli/azure/cli/command_modules/storage/tests/latest/. Unit-style coverage includes validator behavior in test_storage_validators.py, AzCopy executable/auth behavior in test_storage_azcopy_util.py, URL parsing in test_storage_url_helpers.py, AAZ management/resource command registration in test_storage_management_aaz_unit.py and test_storage_resource_aaz_unit.py, context cache tests, and account/container unit tests. Scenario tests cover major command surfaces such as account, blob, container, file/share, ADLS Gen2, queue, table, SAS, OAuth, CORS, encryption scope, AzCopy, ACL, and batch operations.

Routing/coverage note: this doc owns src/azure-cli/azure/cli/command_modules/storage/** and doc/storage_data_plane_commands_auth.md, including command registration, generated AAZ storage commands, storage data-plane auth, validators, operation modules, AzCopy helpers, help text, and storage command tests.

Coupling

  • If a command is registered with g.storage_command* or g.storage_custom_command* in src/…/commands.py, verify that its resource_type maps to the right endpoint option in StorageCommandGroup._register_data_plane_account_arguments in src/…/__init__.py; the endpoint flag name (--blob-endpoint, --file-endpoint, --queue-endpoint, --table-endpoint, or --service-endpoint) is chosen from that resource type.
  • If adding or changing OAuth support for a data-plane command in commands.py, check both StorageCommandGroup._register_data_plane_oauth_arguments in __init__.py and validate_client_parameters in src/…/_validators.py; commands not registered with the OAuth helper will not receive --auth-mode, and the validator only attaches token_credential when that argument is present.
  • If changing Azure Files OAuth behavior, update both _register_data_plane_oauth_arguments in __init__.py and the file client factories in src/…/_client_factory.py; the argument registration exposes --enable-file-backup-request-intent, while cf_share_service and cf_share_file_client enforce and translate it to the SDK's backup token intent.
  • If changing storage credential parsing, keep doc/storage_data_plane_commands_auth.md, validate_client_parameters in _validators.py, _client_factory.py, and src/…/test_storage_validators.py aligned; the user-facing doc says the default is to query an account key, and the validator/factories implement that fallback and environment-variable behavior.
  • If a batch transfer command changes accepted source/destination forms, update the corresponding validators in _validators.py, helper SAS routines in src/…/util.py, and operation implementations in operations/blob.py, operations/file.py, or operations/azcopy.py; batch copy/upload/download paths are split between validator-side namespace rewriting and operation-side traversal.
  • If generated AAZ command signatures under src/azure-cli/azure/cli/command_modules/storage/aaz/latest/** change, check any custom wrapper class in operations/file.py, operations/account.py, or operations/advanced_platform_metric.py that subclasses the generated class; wrappers override argument schema hooks, pre-operations, post-operations, or output transforms instead of using the generated command unchanged.
  • If changing help or parameter names, update both src/…/_params.py and src/…/_help.py; help examples often reference deprecated aliases or auth guidance that is not derived from parameter definitions.

Risks

  • validate_client_parameters in src/…/_validators.py may query an account key through _query_account_key when only --account-name is supplied. If invalid names, untrusted URLs, or connection-string fragments reach this fallback, the CLI can make unintended management-plane calls or leak credential-looking values in diagnostics; src/…/test_storage_validators.py has explicit regression tests for rejecting invalid account names before key lookup.
  • Copy and batch source validators in src/…/_validators.py synthesize source URLs and short-lived SAS tokens before operation modules run. If _validate_source_account_name, _validate_storage_url_recognized, or source_is_validated_same_account handling regresses, copy commands in operations/blob.py and operations/file.py can sign or trust attacker-controlled origins; test_storage_validators.py covers unrecognized storage URLs and invalid source account names.
  • Batch downloads in src/…/blob.py and src/…/file.py write service-provided blob/file names to local paths. If get_safe_download_path in src/…/util.py is bypassed or weakened, malicious names such as ../ paths can escape the destination directory.
  • AzCopy integration spans src/…/azcopy.py, src/…/util.py, and credential/url validators in _validators.py. If URL origin checks or executable resolution change, the CLI may append SAS tokens to untrusted URLs or execute an unexpected azcopy binary; test_storage_azcopy_util.py and the AzCopy sections of test_storage_validators.py are the regression suite for these cases.