Skip to content

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

Open
Bharat Purwar (bharatpurwar) wants to merge 5 commits into
Azure:devfrom
bharatpurwar:users/bharatpurwar/afsmsi2
Open

Bharat Purwar (bharatpurwar) wants to merge 5 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)

Review

Reviewed head eb0a33f0f62911982b44cfcf980374723748bb45. One confirmed user-intent finding; no deterministic findings. CI passed but issue-scenario regression coverage is unverified.

Confirmed finding

P3 — AzureWorkload silently ignores the new --yes flag. In src/azure-cli/azure/cli/command_modules/backup/, _params.py:221-222 exposes it for storage-account re-registration. The changed custom_base.py:524-529 guard rejects other Azure Files-only arguments but omits yes, then forwards to custom_wl.py:201-233, which has no confirmation or yes handling. Thus az backup container register --workload-type MSSQL --resource-id VALID_ARM_ID --yes accepts an inapplicable option without warning. Reject yes=True on this branch, or explicitly warn. Extend tests/latest/test_custom_afs.py:17-29 with this case and retain AzureStorage confirmation-bypass coverage. This confirms reviewer item4131267524.

Evaluated reviewer feedback

The default-AzureWorkload/AzureFileShare concern is already addressed: custom_base.py:518-520 rejects it and directs users to AzureStorage; tests/latest/test_custom_afs.py:31-35 asserts the rejection. The wrong-resource-group concern is incorrect: custom_afs.py:133-143 keeps the source storage-account ARM ID separately, and SDK11.1.0 documents AzureStorageContainer.resource_group as the Recovery Services Vault resource group. These two comments are not additional findings.

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 1 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.

Paths below are relative to src/azure-cli/azure/cli/command_modules/backup/. tests/latest/test_afs_commands.py:356-358 is recording-only: its exact-head decorator skips live mode. Its registration fixture uses one vault/account resource group; tests/latest/test_custom_afs.py:122-141 checks identity payload without distinct groups. The scenario checks registration fields and completed restore jobs, not restored data.

In tests/latest/recordings/test_afs_msi_reregistration_protection_restore.yaml:3130-3135,4289-4294, target-folder request specs are absent from scenario invocations at test_afs_commands.py:459-478; source/target subscription IDs are normalized to the same placeholder. Recorded API-version occurrences alone do not prove exact-head cross-subscription behavior.

Before approval, perform a focused rerun/re-record against this SHA with separate vault/account resource groups and distinct subscriptions, asserting outgoing identity/target/folder fields and restored content. Cover fresh registration, KeyBased↔identity switching, cancellation/--yes, primary full-share/item restore and KeyBased CRR+CSR. Reconcile the source issue's acceptance criteria. These are verification requests, not Agent execution claims.

Risk assessment

59/100 · High · High confidence

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

  • Change scope: 10 changed files, 7057 changed lines (+6986 / -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).

This branch has not been deployed

No deployments
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