Repository navigation
[NeuroShield] az neuroshield: Add new extension for NeuroShield - #10586
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The test leaves queued mitigations able to modify a pre-existing VM after it exits, and its assertions miss the ranking-field mismatch between the recorded response and generated schema.
2 open issues
What changed in this PR
Adds the preview az neuroshield extension for managing Microsoft.NetworkSecurity resources through API version 2026-10-01-preview, using the repository’s generated AAZ command framework.
Changes:
- Adds NeuroShield lifecycle commands, protected-resource management, findings, mitigations, summaries, and operation-status queries.
- Implements GET + PUT updates, paginated lists, and asynchronous protected-resource operations.
- Adds extension packaging, usage documentation, service registration, and scenario tests.
| File | Description |
|---|---|
src/service_name.json |
Registers the NeuroShield service mapping. |
src/neuroshield/setup.py |
Defines extension packaging and initial version. |
src/neuroshield/setup.cfg |
Adds a packaging configuration placeholder. |
src/neuroshield/README.md |
Documents prerequisites, installation, and usage. |
src/neuroshield/HISTORY.rst |
Records the initial preview release. |
src/neuroshield/azext_neuroshield/tests/latest/test_neuroshield.py |
Adds lifecycle and mitigation scenarios with recording redaction. |
src/neuroshield/azext_neuroshield/tests/latest/__init__.py |
Initializes the latest test package. |
src/neuroshield/azext_neuroshield/tests/__init__.py |
Initializes the test package. |
src/neuroshield/azext_neuroshield/custom.py |
Adds custom-command scaffolding. |
src/neuroshield/azext_neuroshield/commands.py |
Adds a custom command-table hook. |
src/neuroshield/azext_neuroshield/azext_metadata.json |
Declares preview status and minimum CLI version. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/summary/_show.py |
Retrieves the fleet summary singleton. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/summary/_list.py |
Lists fleet summaries. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/summary/__init__.py |
Exports summary commands. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/summary/__cmd_group.py |
Registers the summary command group. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/protected_resource/mitigation/_show.py |
Retrieves an individual mitigation. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/protected_resource/mitigation/_rollback.py |
Requests mitigation rollback. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/protected_resource/mitigation/_list.py |
Lists a protected resource’s mitigations. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/protected_resource/mitigation/_execute.py |
Approves and queues mitigation execution. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/protected_resource/mitigation/__init__.py |
Exports resource-level mitigation commands. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/protected_resource/mitigation/__cmd_group.py |
Registers resource-level mitigation commands. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/protected_resource/finding/_show.py |
Retrieves an individual finding. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/protected_resource/finding/_rollback.py |
Rolls back eligible mitigations for a finding. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/protected_resource/finding/_mitigate.py |
Queues awaiting-approval mitigations for a finding. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/protected_resource/finding/_list.py |
Lists a protected resource’s findings. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/protected_resource/finding/__init__.py |
Exports resource-level finding commands. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/protected_resource/finding/__cmd_group.py |
Registers resource-level finding commands. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/protected_resource/_wait.py |
Waits for protected-resource conditions. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/protected_resource/_trigger_inventory_upload.py |
Requests a fresh agent inventory upload. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/protected_resource/_show.py |
Retrieves protected-resource details. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/protected_resource/_list.py |
Lists protected resources with pagination. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/protected_resource/_delete.py |
Deletes protected resources with asynchronous polling. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/protected_resource/_create.py |
Registers protected resources and target identities. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/protected_resource/__init__.py |
Exports protected-resource commands. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/protected_resource/__cmd_group.py |
Registers the protected-resource group. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/operation_status/_show.py |
Retrieves asynchronous operation status. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/operation_status/__init__.py |
Exports the operation-status command. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/operation_status/__cmd_group.py |
Registers the operation-status group. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/mitigation/_list.py |
Lists mitigations across protected resources. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/mitigation/__init__.py |
Exports fleet-level mitigation listing. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/mitigation/__cmd_group.py |
Registers the fleet-level mitigation group. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/finding/_list.py |
Lists findings across protected resources. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/finding/__init__.py |
Exports fleet-level finding listing. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/finding/__cmd_group.py |
Registers the fleet-level finding group. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/_update.py |
Updates resources using GET + PUT. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/_show.py |
Retrieves a NeuroShield resource. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/_list.py |
Lists resources by subscription or resource group. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/_delete.py |
Deletes NeuroShield resources with confirmation. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/_create.py |
Creates NeuroShield resources and response settings. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/__init__.py |
Exports NeuroShield lifecycle commands. |
src/neuroshield/azext_neuroshield/aaz/latest/neuroshield/__cmd_group.py |
Registers the top-level command group. |
src/neuroshield/azext_neuroshield/aaz/latest/__init__.py |
Initializes the latest generated-command package. |
src/neuroshield/azext_neuroshield/aaz/__init__.py |
Initializes the AAZ package. |
src/neuroshield/azext_neuroshield/_params.py |
Adds a custom argument-loading hook. |
src/neuroshield/azext_neuroshield/_help.py |
Adds custom-help scaffolding. |
src/neuroshield/azext_neuroshield/__init__.py |
Loads generated commands into Azure CLI. |
Review effort: Balanced
| self.cmd("neuroshield protected-resource finding rollback " + pr_args + " --finding-id {finding}", | ||
| checks=[self.check("length(value)", 0)]) |
| self.cmd("neuroshield protected-resource mitigation show " + pr_args + " -n {mitigation}", checks=[ | ||
| self.check("properties.status", "AwaitingApproval"), | ||
| self.check("properties.isRollbackable", True), |
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
Copilot-Session: a9affa1e-8ca2-4612-a25d-d353cd9ef77a
| self.assertEqual(self._wait_mitigation(self.kwargs["mitigation"], ("Succeeded", "Failed", "Skipped")), | ||
| "Succeeded") | ||
| self.cmd("neuroshield protected-resource mitigation rollback " + pr_args + " --mitigation-id {mitigation}", | ||
| checks=[self.check("name", "{mitigation}")]) | ||
| self.assertEqual(self._wait_mitigation(self.kwargs["mitigation"], ("RolledBack", "RollbackFailed")), | ||
| "RolledBack") | ||
|
|
||
| # Mitigating a finding approves all its AwaitingApproval mitigations, but only one runs at a | ||
| # time and the rest stay queued once it succeeds. Rollback then targets the succeeded one. | ||
| def test_neuroshield_finding_mitigation(self): | ||
| pr_args = self._use_finding("danlope-scale-vm-01-k8ex8x", "CVE-2026-43284-danlope-scale-vm-01") | ||
|
|
||
| queued = self.cmd("neuroshield protected-resource finding mitigate " + pr_args + " --finding-id {finding}", | ||
| checks=[self.check("length(value) > `0`", True)]).get_output_in_json()["value"] | ||
| names = {m["name"] for m in queued} | ||
| for _ in range(60): | ||
| mitigations = self.cmd("neuroshield protected-resource mitigation list " + pr_args).get_output_in_json() | ||
| succeeded = [m["name"] for m in mitigations | ||
| if m["name"] in names and m["properties"]["status"] == "Succeeded"] | ||
| if succeeded: | ||
| break | ||
| if self.is_live: | ||
| time.sleep(30) | ||
| else: | ||
| self.fail(f"no mitigation of {self.kwargs['finding']} succeeded") | ||
| self.cmd("neuroshield protected-resource finding rollback " + pr_args + " --finding-id {finding}", | ||
| checks=[self.check("value[].name", succeeded)]) | ||
| self.assertEqual(self._wait_mitigation(succeeded[0], ("RolledBack", "RollbackFailed")), "RolledBack") |
There was a problem hiding this comment.
Waiting for one successful mitigation only partially resolves this concern. The finding-mitigation recording queues three mitigations, then observes one Failed, one Succeeded and one still Queued. Rollback confirms only the successful mitigation becomes RolledBack; the remaining queued work is neither cancelled nor verified settled before the test exits.
Both mitigation tests also perform rollback only on the success path. A polling/assertion failure after submission skips cleanup entirely, leaving changes or queued work against a pre-existing VM.
Please use a disposable test-owned VM, or track every submitted mitigation and implement failure-safe cleanup using the service-supported cancellation/completion flow, rolling back all successful rollbackable mitigations. Verify that no outstanding work can modify the shared VM after the test finishes; finding rollback must not be treated as cancellation of queued work.
There was a problem hiding this comment.
Thanks mansoor sarfraz (@msarfraz), agreed. The test can leave a Queued mitigation on the shared VM, and rollback only runs on the success path.
Some constraints:
- The API has no cancel operation (only
execute/mitigate/rollback/show/list), so the CLI cannot cancel queued work. - Findings come from the Neuron agent on a real VM, so I cannot easily use a disposable VM owned by the test. The tests rely on a NeuroShield environment provided by the service team.
Planned change: register cleanup with addCleanup so it also runs on failure, wait for every submitted mitigation to reach a terminal state, then roll back all Succeeded ones that support rollback.
Satya-Kotha1008 could you confirm:
- Is there (or will there be) a supported way to cancel Queued mitigations? If not, will they eventually run on the VM?
- Can you prepare fresh AwaitingApproval mitigations so I can re-record live after the test change?
There was a problem hiding this comment.
mansoor sarfraz (@msarfraz) Service team confirmed there's no cancel API, but Queued mitigations won't run once another mitigation of the same finding has Failed or been RolledBack. I'll update the tests to register failure-safe cleanup via addCleanup, wait for all submitted mitigations to reach a terminal state, and roll back every Succeeded rollbackable one. After that, nothing left in the queue can modify the VM. I'll re-record against a fresh VM in the same NeuroShield. Does that address your concern?
There was a problem hiding this comment.
This addresses the concern in principle, but please implement it before merge. Register failure-safe cleanup before submitting actions in both mitigation tests, track the submitted mitigations, and roll back every successful rollbackable mitigation. Please also handle the service’s permanently blocked Queued state explicitly: waiting only for terminal statuses may never complete. Use bounded polling and the service-supported condition proving that remaining queued work cannot execute, and report cleanup failures explicitly. Refresh the recordings and include coverage showing cleanup still runs after a polling/assertion failure. No cancellation API is required.
There was a problem hiding this comment.
Thanks mansoor sarfraz (@msarfraz), good catch on the permanently Queued state. I'll implement this before merge: register cleanup before submitting actions in both tests, track submitted mitigations, roll back every Succeeded rollbackable one, use bounded polling that stops once remaining Queued mitigations are provably blocked (a sibling has Failed/RolledBack), raise cleanup failures explicitly, add coverage that cleanup runs after a polling/assertion failure, and refresh the recordings.
There was a problem hiding this comment.
mansoor sarfraz (@msarfraz) I've addressed this in the latest commit:
- The cleanup is now registered before any mitigation is submitted. It tracks every submitted mitigation and polls with a bounded limit until they settle.
- The cleanup rolls back every mitigation that succeeded. That includes a queued (already approved) mitigation that starts after an earlier one fails or is rolled back. I confirmed this behavior live, and Satya-Kotha1008 confirmed it matches the design: mitigations still awaiting approval stay blocked.
- Any cleanup failure (not rollbackable, RollbackFailed, or still running after the poll limit) now fails the test with an explicit message.
- I added an offline unit test that forces a failure and checks that the cleanup still rolls everything back.
- I refreshed the recordings against the new resources, and the test VMs were left with nothing Succeeded or Queued.
This also corrects my earlier comment: a queued mitigation does run once the previous one fails or is rolled back.
| self.exists("properties.cveId"), | ||
| ]) | ||
| self.cmd("neuroshield protected-resource mitigation show " + pr_args + " -n {mitigation}", checks=[ | ||
| self.check("properties.status", "AwaitingApproval"), |
There was a problem hiding this comment.
The published API and AAZ schema define rank as a relative priority, with 1 being highest. The recorded mitigation response instead contains score: 55 and no rank. AAZ discards the unmodeled score, so the current CLI output exposes neither value, while these assertions still pass.
Please align the service response with the published contract, refresh the recording, and assert that the actual ranking field survives CLI deserialization. Do not equate score 55 with rank 55 or rename the generated field alone. If score is the intended service contract, update OpenAPI, AAZ and generated CLI consistently.
There was a problem hiding this comment.
Thanks mansoor sarfraz (@msarfraz), confirmed. AAZ models properties.rank (relative priority, 1 is highest), but the service returns score (for example 55, 78) and no rank. AAZ drops score, so the CLI shows neither value. The semantics also differ, so renaming the field alone would be wrong.
Satya-Kotha1008 which field is the intended contract?
- If
rank: please fix the service response, and I will re-record and add an assertion on the field. - If
score: OpenAPI / AAZ need to be updated first, then I will regenerate the CLI and add the assertion.
There was a problem hiding this comment.
mansoor sarfraz (@msarfraz) Service team confirmed rank is the intended contract; the service-side fix is in manifest rollout (1-2 days). The CLI/AAZ already model rank, so no CLI change is needed. Are you OK for me to proceed now, and I'll re-record and add a rank assertion once the rollout completes (in this PR if it lands in time, otherwise a follow-up)?
There was a problem hiding this comment.
Thanks for confirming that rank is the intended contract. Agreed that no CLI/AAZ schema change is needed. Please refresh the recording after the service rollout and assert that properties.rank survives CLI deserialization, preferably in this PR. If this must be deferred, please link a tracked follow-up and obtain explicit maintainer acceptance of the temporary validation gap; the rollout plan alone does not demonstrate that the field works.
There was a problem hiding this comment.
Thanks mansoor sarfraz (@msarfraz), agreed. I'll keep this in this PR: once the service rollout completes, I'll refresh the recording and assert properties.rank survives CLI deserialization.
There was a problem hiding this comment.
mansoor sarfraz (@msarfraz) Done. The service now returns rank, the tests assert properties.rank, and I refreshed the recordings (they no longer contain score).
Register cleanup before submitting mitigations, poll with a bound until settled, roll back all succeeded mitigations (including queued ones resumed after rollback), report cleanup failures, add offline cleanup coverage, assert properties.rank, and refresh recordings. Copilot-Session: 7969e7d6-9be0-4eb1-a00a-15dd8b06bbcf
outdated.
|
[Release] Update index.json for extension [ neuroshield-1.0.0b1 ] : https://dev.azure.com/msazure/One/_build/results?buildId=191635587&view=results |


This checklist is used to make sure that common guidelines for a pull request are followed.
Related command
az neuroshieldNew preview extension
neuroshieldfor NeuroShield (Microsoft.NetworkSecurity, API2026-10-01-preview).Satya-Kotha1008 FYI, a few notes on the CLI design:
az neuroshieldinstead ofaz networksecurity neuroshield, since NeuroShield is the only resource type here and the shorter name is easier to use.updatecommands use GET + PUT (standard AAZ generic update) instead of PATCH.az neuroshield protected-resource finding/mitigation.Operations_Listis not exposed as a command; useaz provider operation show --namespace Microsoft.NetworkSecurity.General Guidelines
azdev style <YOUR_EXT>locally? (pip install azdevrequired)python scripts/ci/test_index.py -qlocally? (pip install azdevrequired)For new extensions:
About Extension Publish
There is a pipeline to automatically build, upload and publish extension wheels.
Once your pull request is merged into main branch, a new pull request will be created to update
src/index.jsonautomatically.You only need to update the version information in file setup.py and historical information in file HISTORY.rst in your PR but do not modify
src/index.json.