Skip to content

Azure multi subscription scanning feature#112

Merged
sureshcsdp merged 4 commits into
mainfrom
PR110
Mar 21, 2026
Merged

Azure multi subscription scanning feature#112
sureshcsdp merged 4 commits into
mainfrom
PR110

Conversation

@sureshcsdp
Copy link
Copy Markdown
Collaborator

@sureshcsdp sureshcsdp commented Mar 21, 2026

Azure Multi-Subscription Scanning — Implementation Highlights

What's new

CleanCloud now scans all Azure subscriptions in parallel with a single service principal. Findings are aggregated into one report with a per-subscription cost breakdown — same experience as AWS multi-account, but simpler architecture.


Architecture

No hub-and-spoke. One service principal with Reader at Management Group level inherits access to all subscriptions underneath. Same credential, different subscription_id per scan.

3 discovery modes:

  • All accessible (default, no flag)
  • --management-group — auto-discover via Management Group
  • --subscription (repeatable) — explicit list

Core changes

  • session.py — list_subscriptions() returns [{id, name}] dicts; added list_subscriptions_in_management_group() via ManagementGroupsAPI
  • scan.py — new SubscriptionScanResult dataclass; parallel scan across all subscriptions; per-subscription error isolation; findings tagged with account_id/account_name
  • command.py — --management-group flag; per_subscription breakdown in JSON output
  • summary.py — per-subscription breakdown in human output
  • pyproject.toml — azure-mgmt-managementgroups>=1.0.0

Reliability improvements (also in this PR)

  • Retry logic — 429/500/503 retried up to 3 times with exponential backoff; respects Retry-After header; capped at 60s
  • Dedup bug fix — skipped rules now carry subscription_id/subscription_name context; no longer silently dropped across subscriptions
  • Output cleanup — removed nested progress bars (flickered in CI); failure messages truncated to rule name + error type
  • Deterministic ordering — results sorted by subscription_name
  • Rule timeout — future.result(timeout=120) prevents hung Azure API calls blocking CI
  • Defensive guard — result if result is not None else [] protects engine from buggy rules returning None
  • Inner pool reduced — max_workers=2 per subscription (down from 4), max 8 concurrent API streams

scan-action

Added subscription and management-group inputs to cleancloud-io/scan-action.


Tests

9 new tests covering retry logic: transient retries, exhaustion, Retry-After header, exponential backoff, 60s cap, non-retryable errors (403, 404).

Comment thread README.md
# Multi-subscription — Azure only (optional)
--management-group ID Scan all subscriptions under a Management Group
--subscription ID Scan a single subscription (default: all accessible)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we have : Multi-Account Scanning (AWS only) section currently..
do we need a separate one for azure for parity ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

thanks for highlighting.. just added it

def list_subscriptions_in_management_group(self, management_group_id: str) -> List[dict]:
"""
List all subscriptions under a Management Group.
Requires Microsoft.Management/managementGroups/read permission.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

do we need to add this read perm to the docs: Microsoft.Management/managementGroups/read ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It's already documented in docs/azure.md — in the Multi-Subscription Scanning section, so guess thats fine as is - no changed needed?

javvaji-devops
javvaji-devops previously approved these changes Mar 21, 2026
Comment thread pyproject.toml
"azure-identity>=1.19.0",
"azure-mgmt-resource>=23.0.0",
"azure-mgmt-subscription>=3.0.0",
"azure-mgmt-managementgroups>=1.0.0",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can you increase the release version too as we will be releasing a new version ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

thanks, just fixed

Copy link
Copy Markdown
Collaborator

@javvaji-devops javvaji-devops left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@sureshcsdp sureshcsdp merged commit 2c323bf into main Mar 21, 2026
17 checks passed
@sureshcsdp sureshcsdp deleted the PR110 branch March 21, 2026 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants