Skip to content

[Backup] az backup container register: Add managed identity support for Azure Files backup - #34146

Merged
JaysonTaiMicrosoft merged 8 commits into
Azure:devfrom
bharatpurwar:users/bharatpurwar/afsmsi2
Oct 20, 2026
Merged

JaysonTaiMicrosoft merged 8 commits into
Azure:devfrom
bharatpurwar:users/bharatpurwar/afsmsi2

Conversation

@bharatpurwar

@bharatpurwar Bharat Purwar (bharatpurwar) commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

🤖 PR Validation — ⚠️ Review suggested

Breaking Changes Tests
⚠️ None ️✔️ 130/130
⚠️AzureCLI-BreakingChangeTest
⚠️backup
rule cmd_name rule_message suggest_message
⚠️ 1006 - ParaAdd backup container register cmd backup container register added parameter access_type
⚠️ 1006 - ParaAdd backup container register cmd backup container register added parameter mi_system_assigned
⚠️ 1006 - ParaAdd backup container register cmd backup container register added parameter mi_user_assigned
⚠️ 1006 - ParaAdd backup container register cmd backup container register added parameter storage_account
⚠️ 1006 - ParaAdd backup container register cmd backup container register added parameter yes
⚠️ 1009 - ParaPropRemove backup container register cmd backup container register update parameter resource_id: removed property required=True
⚠️ 1010 - ParaPropUpdate backup container register cmd backup container register update parameter workload_type: updated property choices from ['MSSQL', 'SAPASE', 'SAPAseDatabase', 'SAPHANA', 'SAPHanaDBInstance', 'SAPHanaDatabase', 'SQLDataBase'] to ['AzureFileShare', 'MSSQL', 'SAPASE', 'SAPAseDatabase', 'SAPHANA', 'SAPHanaDBInstance', 'SAPHanaDatabase', 'SQLDataBase']
⚠️ 1006 - ParaAdd backup protection enable-for-azurefileshare cmd backup protection enable-for-azurefileshare added parameter access_type
⚠️ 1006 - ParaAdd backup protection enable-for-azurefileshare cmd backup protection enable-for-azurefileshare added parameter mi_system_assigned
⚠️ 1006 - ParaAdd backup protection enable-for-azurefileshare cmd backup protection enable-for-azurefileshare added parameter mi_user_assigned
⚠️ 1006 - ParaAdd backup protection enable-for-azurefileshare cmd backup protection enable-for-azurefileshare added parameter yes
⚠️ 1006 - ParaAdd backup restore restore-azurefiles cmd backup restore restore-azurefiles added parameter mi_system_assigned
⚠️ 1006 - ParaAdd backup restore restore-azurefiles cmd backup restore restore-azurefiles added parameter mi_user_assigned
⚠️ 1006 - ParaAdd backup restore restore-azurefiles cmd backup restore restore-azurefiles added parameter target_resource_group_name
⚠️ 1006 - ParaAdd backup restore restore-azurefiles cmd backup restore restore-azurefiles added parameter target_subscription_id
⚠️ 1006 - ParaAdd backup restore restore-azurefileshare cmd backup restore restore-azurefileshare added parameter mi_system_assigned
⚠️ 1006 - ParaAdd backup restore restore-azurefileshare cmd backup restore restore-azurefileshare added parameter mi_user_assigned
⚠️ 1006 - ParaAdd backup restore restore-azurefileshare cmd backup restore restore-azurefileshare added parameter target_subscription_id

Summary

  • add explicit KeyBased, system-assigned identity, and user-assigned identity registration and re-registration for Azure Files backup containers
  • preserve or select storage-account authentication during protection and include managed identity information in primary-region restores
  • support cross-subscription Azure Files restore targets while preserving KeyBased full-share cross-region restore behavior
  • update command help/table output and add focused unit and recorded scenario coverage

Replacement PR

Validation

  • changed Python files compile successfully with the installed Azure CLI Python
  • scenario recording parses successfully with 121 interactions
  • all 134 affected recorded requests use api-version=2026-08-01; no 2026-07-01 requests remain
  • git diff --check passes
  • the original implementation was live-validated for UAMI cross-subscription restore and KeyBased CRR+CSR

Bharat Purwar and others added 3 commits September 29, 2026 13:50
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 29, 2026 08:22
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Registration can misroute Azure Files and send incorrect storage-account resource-group metadata.

Review effort: Balanced
Findings: 3 Medium severity

Open (3)
What changed in this PR

Extends Azure Files Backup with managed-identity registration, protection, and cross-subscription restore support.

Changes:

  • Adds KeyBased, system-assigned, and user-assigned identity workflows.
  • Adds subscription-aware restore targeting and output/help updates.
  • Adds focused unit and recorded scenario coverage.
File Description
tests/​latest/​test_custom_afs.py Adds focused identity and restore tests.
tests/​latest/​test_afs_commands.py Adds an end-to-end backup scenario.
tests/​latest/​recordings/​test_afs_msi_reregistration_protection_restore.yaml Records scenario service interactions.
custom_base.py Routes and validates new options.
custom_afs.py Implements registration and restore behavior.
commands.py Registers the generalized container handler.
_params.py Defines new CLI arguments.
_help.py Adds usage examples.
_format.py Displays authentication details.
_client_factory.py Supports subscription-specific clients.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +129 to +140
source_resource_id = helper.get_model_property(
properties, 'container_id', 'containerId') or helper.get_model_property(
properties, 'source_resource_id', 'sourceResourceId')

payload = AzureStorageContainer(
friendly_name=helper.get_model_property(properties, 'friendly_name', 'friendlyName'),
backup_management_type=backup_management_type,
source_resource_id=source_resource_id,
resource_group=resource_group_name,
operation_type=operation_type,
access_type=access_type,
identity_info=identity_info)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had tested, it doesnt affect. There is sourceResourceId which is correctly populated

Comment on lines +512 to +517
if backup_management_type.lower() != "azureworkload":
raise InvalidArgumentValueError(
"Container registration supports AzureWorkload and AzureStorage backup management types.")
if workload_type is None:
raise RequiredArgumentMissingError(
"--workload-type is required with --backup-management-type AzureWorkload.")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines +521 to +524
if storage_account is not None or access_type is not None or mi_system_assigned or mi_user_assigned:
raise ArgumentUsageError(
"Azure Files managed identity arguments are only supported with "
"--backup-management-type AzureStorage.")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AzureWorkload registration has no confirmation prompt, so  --yes  has no functional effect. So no need to change

@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

🔔 Routing this PR to @Azure/act-observability-squad.

@yonzhan

Copy link
Copy Markdown
Collaborator

Please fix CI issues

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@bharatpurwar

Bharat Purwar (bharatpurwar) commented Sep 30, 2026 •

Copy link
Copy Markdown
Member Author

Hi team, Yong Zhang (@yonzhan) , can you please review if the CI issues are due to current pr changes. Based on copilot
"
The style environment automatically upgraded Pylint from 4.0.9 to 4.1.1. Pylint 4.1.1 started reporting pre-existing issues outside the Backup module:
"

@necusjz

Copy link
Copy Markdown
Member

Hi team, Yong Zhang (Yong Zhang (@yonzhan)) , can you please review if the CI issues are due to current pr changes. Based on copilot " The style environment automatically upgraded Pylint from 4.0.9 to 4.1.1. Pylint 4.1.1 started reporting pre-existing issues outside the Backup module: "

code freeze until next Mon, will take a look during this period.

@bharatpurwar

Copy link
Copy Markdown
Member Author

Hi Ethan Yang (@necusjz) , Yong Zhang (@yonzhan)
Please review my earlier query

@necusjz

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@necusjz

Copy link
Copy Markdown
Member

Hi Ethan Yang (Ethan Yang (@necusjz)) , Yong Zhang (Yong Zhang (@yonzhan)) Please review my earlier query

it was fixed by d295b94.

@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@bharatpurwar

Copy link
Copy Markdown
Member Author

Hi Ethan Yang (@necusjz)
All checks are passing . please review

@bharatpurwar

Copy link
Copy Markdown
Member Author

Hi NoriZC
please review

@teresaritorto Teresa Ritorto (teresaritorto) added the Request X Engineering Agent Ask the agent to triage this issue or review this PR label Oct 14, 2026
@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

🔔 Routing this PR to @Azure/act-observability-squad.

@x-engineering-agent

x-engineering-agent Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

X Engineering Agent Report

Review — Comments

Bharat Purwar (@bharatpurwar)

No confirmed semantic defects found in the inspected changes at c670fef43bb6c98fc3dfaa395384bff415268d80. Upstream CI passed (52/52); regression coverage for the required scenario is not verified. No Agent tests ran.

Current evidence (paths below are relative to src/azure-cli/azure/cli/command_modules/backup/):

  • tests/latest/test_custom_afs.py:17-270 checks argument rejection, legacy workload routing, identity comparison, registration payload attributes/no-op/re-registration, UAMI restore attributes and mocked cross-region/cross-subscription routing. It does not verify serialized SDK request bodies or real destination-subscription clients.
  • tests/latest/test_afs_commands.py:492-606 now exercises --mi-system-assigned on all three requested commands: protection enable, full-share restore and directory restore. It asserts ConfigureBackup completion, container identity and completed restore jobs. However, tests/latest/recordings/test_afs_sami_protection_restore.yaml starts with the selected account already registered as SAMI; it contains no registration PUT. This does not establish fresh registration or KeyBased-to-SAMI transition behavior, nor restored-content correctness.
  • tests/latest/test_afs_commands.py:358-488 and tests/latest/recordings/test_afs_msi_reregistration_protection_restore.yaml cover UAMI-to-SAMI-to-UAMI re-registration, protection without identity overrides and two completed UAMI full-share restores. Both subscription variables use get_subscription_id() (lines 359-360), and the recording's source/target subscriptions match: this is not evidence of an actual cross-subscription restore. Its full-share request bodies also contain target-folder specs absent from the current scenario calls.

Both scenarios remain record_only. The author explained the preconfigured vault identities, accounts, UAMI/target and RBAC prerequisites; the earlier request for all three SAMI commands has been addressed in test code. Each recording contains 121 interactions with Backup API URLs retargeted to 2026-08-01; these author recordings are not a fresh validation of current SDK/service behavior.

Focused follow-up: validate serialized accessType, identityInfo and destination resource IDs for custom_afs.py:126-194,425-457,693-717, extending and rerunning azdev test test_custom_afs. Provision the explained prerequisites and make the two scenarios live-runnable before running azdev test test_afs_sami_protection_restore test_afs_msi_reregistration_protection_restore --live (currently skipped). Include fresh/KeyBased-to-SAMI registration, SAMI/UAMI transitions and genuinely distinct subscriptions; assert resulting container identity, restore-job completion and restored content. These are outstanding validation needs, not established runtime defects.

Test validation
  • Agent live test: Not run; this is a review-only PR. Check author-provided test evidence and upstream CI separately.
  • Regression coverage: For backup: 2 focused test file(s) and 2 recording file(s) changed. Scenario coverage is unverified; review the issue's required conditions, test setup, and assertions before approval. No linked issue was found in the PR timeline; inspect the source issue and its required scenario manually. Human review feedback identifies a scenario to verify: (at)bharat can you add scenario tests for --mi-system-assigned for the commands: - az backup protection enable-for-azurefileshare - az backup restore restore-azurefileshare - az backup restore restore-azurefiles Check the required setup and actual command output for each cited path; setup-only assertions do not establish that output. This comment predates the current head; recheck the latest diff. Human review feedback identifies a scenario to verify: (at)bharatpurwar Yes the tests use the recorded yaml files. Scenario tests should be replicable across all environments / subs as they typically follow a lifecycle. But since this is marked record_only these tests will not be re-recorded in --live mode locally or run in our scheduled live test runs. Usually, there should be a reason as to why it uses this exemption Check the required setup and actual command output for each cited path; setup-only assertions do not establish that output. This comment predates the current head; recheck the latest diff.
Risk assessment — 59/100 · High

The High rating is driven by security-sensitive behavior, public CLI behavior.

  • Change scope: 11 changed files, 13373 changed lines (+13302 / -71), including 7 production files.
  • Affected components: backup
  • Risk drivers: security-sensitive behavior (+28); public CLI behavior (+18)
  • Regression evidence: Changed regression tests are included, reducing risk.
  • Confidence: High because changed-line patches were available for every production file.
  • Required review: Owning-squad review is required for backup before merge.

Posted by x-engineering-agent (Reviewer)

@x-engineering-agent x-engineering-agent Bot added the X Engineering Agent Reviewed Agent reviewed this PR label Oct 14, 2026
@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

🔔 Routing this PR to @Azure/act-observability-squad.

@JaysonTaiMicrosoft

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@JaysonTaiMicrosoft JaysonTaiMicrosoft removed the X Engineering Agent Reviewed Agent reviewed this PR label Oct 18, 2026
@x-engineering-agent x-engineering-agent Bot added the X Engineering Agent Reviewed Agent reviewed this PR label Oct 18, 2026
@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

🔔 Routing this PR to @Azure/act-observability-squad.

Bharat Purwar and others added 2 commits October 19, 2026 11:18
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@JaysonTaiMicrosoft
JaysonTaiMicrosoft merged commit e127b8d into Azure:dev Oct 20, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

act-observability-squad Auto-Assign Auto assign by bot Backup Request X Engineering Agent Ask the agent to triage this issue or review this PR X Engineering Agent Reviewed Agent reviewed this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants