Skip to content

feat: add enterprise governance and tenant controls - #292

Open
TFT444 wants to merge 17 commits into
devfrom
feat/257-enterprise-governance-controls
Open

TFT444 wants to merge 17 commits into
devfrom
feat/257-enterprise-governance-controls

Conversation

@TFT444

@TFT444 TFT444 commented Aug 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds AZ-GOV-001 through AZ-GOV-010, strict organization-owned policy configuration, read-only evidence collection, remediation playbooks and four framework mappings. Inherited Owner assignments and ARM pagination credential boundaries are covered. The engine regression now exercises public scan behavior against current dev rather than the removed private interface.

Runtime dependency inputs and Linux Python 3.11 hash locks include the patched aiohttp, multidict, Werkzeug and certifi versions. No new vulnerability suppressions were added.

Validation

  • Exact head: 85e97ed069d44c04fecab9ba29383c7c0ef31e4e.
  • Completed CI run: green, including backend, lint, security scans, dependency audit, container scan and builds.
  • Full backend suite: 1,679 passed, 3 skipped, 4 subtests passed; 88.81% coverage against the 80% gate.
  • The three skips are optional AI index/LLM checks, not newly skipped regressions.

Focused governance checks: 52 passed. No live Azure subscription smoke test was performed.

Review status

Code and current-head CI are ready for independent re-review. Existing reviewer approvals and conversations are intentionally left for reviewers to confirm; this is not approval or merge authorization.

@github-actions

github-actions Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails
pip/aiohttp 3.14.5 UnknownUnknown
pip/certifi 2026.10.23 🟢 6.6
Details
CheckScoreReason
Code-Review🟢 7Found 5/7 approved changesets -- score normalized to 7
Maintained🟢 88 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 8
Security-Policy🟢 10security policy file detected
Binary-Artifacts🟢 10no binaries found in the repo
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Pinned-Dependencies🟢 5dependency not pinned by hash detected -- score normalized to 5
Token-Permissions🟢 10GitHub workflow tokens follow principle of least privilege
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Fuzzing⚠️ 0project is not fuzzed
License🟢 9license file detected
Signed-Releases⚠️ -1no releases found
Branch-Protection⚠️ 0branch protection not enabled on development/release branches
Packaging🟢 10packaging workflow detected
SAST⚠️ 0SAST tool is not run on all commits -- score normalized to 0
pip/mako 1.4.3 UnknownUnknown
pip/multidict 7.2.1 UnknownUnknown
pip/werkzeug 3.1.9 UnknownUnknown

Scanned Files

  • requirements.txt

@TFT444
TFT444 marked this pull request as ready for review August 20, 2026 14:07
@TFT444 TFT444 self-assigned this Aug 20, 2026

@ritiksah141 ritiksah141 left a comment

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.

All good on my side.

Approving it.

@TFT444
TFT444 requested a review from m-khan-97 August 24, 2026 22:07
@TFT444

TFT444 commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator Author

@m-khan-97 can you please review that pr. Thank you

@TFT444
TFT444 force-pushed the feat/257-enterprise-governance-controls branch from 2a1551d to 05378bd Compare August 27, 2026 22:19
@TFT444

TFT444 commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator Author

@ritiksah141 looks like your approval came through as a comment rather than a formal review approval. Could you re-submit it as an approval so the PR can move forward? No code changes since you reviewed it.

@parthrohit22 parthrohit22 left a comment

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.

Read the collector and the shared evaluator in full before touching individual rules, since all 10 route through them. Genuinely solid work in both: GovernanceCollector handles all three pagination shapes correctly (ARM nextLink, Resource Graph $skipToken, OData @odata.nextLink), and it defensively checks that a nextLink actually starts with the real ARM endpoint before following it - a real guard against a malformed or redirected pagination link, not something I see everywhere. Every evidence set (hierarchy, policy_assignments, locks, etc.) is independently nullable so one API failure can't corrupt or silently zero out an unrelated evidence set, load_governance_policy() fails loud on any missing/malformed field instead of defaulting, and test_missing_evidence_never_becomes_failure proving the indeterminate-handling discipline across all 10 rules in one parametrized test is good test design. No RULE_ID collisions, all 10 playbooks exist and pass bash -n, all four compliance framework JSONs have complete AZ-GOV-001..010 mappings. Ran the full suite myself in a clean clone: 737 passed, 3 skipped, 0 failed, ruff clean, CI 20/20 green.

One real bug though, confirmed with a repro rather than just reasoning about it - left inline on the specific line.

AZ-GOV-006 (excessive subscription Owners) undercounts real Owner exposure. The collector queries roleAssignments?...&$filter=atScope(), and Azure's atScope() filter returns assignments made at the queried scope and any ancestor scope that applies down to it - a management group grant included, not just direct subscription-level grants. But the AZ-GOV-006 branch only counts an Owner assignment toward the total when it's scoped exactly at the subscription. I fed evaluate() two real Owner assignments - one at the subscription, one inherited from a parent management group - against a policy capping Owners at 1, and got zero findings back. Two effective Owners, threshold of one, nothing flagged. test_gov_006_owner_threshold only ever constructs subscription-scoped fixtures, so this gap is genuinely untested. For a rule whose whole purpose is bounding effective Owner exposure, silently missing the most common enterprise pattern (Owner granted at a parent management group) is a real false negative, not a style nit.

Comment thread scanner/rules/_governance_common.py Outdated
item
for item in assignments
if normal(properties(item).get("roleDefinitionId")).endswith(OWNER_ROLE_ID)
and _assignment_scope(item) == normal(subscription_scope)

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.

This only counts an Owner assignment when it's scoped exactly at the subscription (_assignment_scope(item) == normal(subscription_scope)). But the collector's roleAssignments query uses $filter=atScope(), which Azure documents as returning assignments at the given scope and any scope above it that applies down - so a management-group-level Owner grant is included in assignments here, just with a scope that will never equal subscription_scope.

Verified with a direct repro: fed evaluate() one subscription-scoped Owner assignment and one Owner assignment whose id is rooted at /providers/Microsoft.Management/managementGroups/corp/..., against a policy with maximum_subscription_owners=1. Result was [] - two real effective Owners, zero findings, when it should have flagged with owner_count: 2.

Suggest counting any assignment in assignments that resolves to Owner and applies to this subscription (i.e. don't filter on exact scope equality here) rather than only ones scoped directly at the subscription - _assignment_scope(item) is still useful to report where the grant originates in the finding metadata, just not as a filter that excludes inherited grants from the count.

@m-khan-97

Copy link
Copy Markdown
Collaborator

@TFT444, please address Parth’s substantive governance/API review findings first, then rebase onto current dev and remove the now-obsolete temporary ChromaDB audit exclusions introduced before #317 merged. Request rereview only after the corrected head passes the full suite.

@TFT444
TFT444 force-pushed the feat/257-enterprise-governance-controls branch from 05378bd to 14f9d83 Compare August 29, 2026 00:53
@TFT444

TFT444 commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator Author

@parthrohit22 the one bug you confirmed is fixed: AZ-GOV-006 now counts all Owner assignments returned by atScope(), including those inherited from parent management groups, not just subscription-scoped ones. Added a regression test with an MG-scoped fixture to pin the behavior. Also removed the now-obsolete chromadb pip-audit exclusions (chromadb was removed in PR #317) and rebased onto current dev. All 22 governance tests pass.

@TFT444
TFT444 force-pushed the feat/257-enterprise-governance-controls branch from 14f9d83 to c645347 Compare August 31, 2026 23:15
@TFT444
TFT444 requested a review from parthrohit22 August 31, 2026 23:22
@TFT444

TFT444 commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator Author

@m-khan-97 @ritiksah141 @parthrohit22 rebase and the requrent fixes are done. Have a Look Please.

thank you

ritiksah141
ritiksah141 previously approved these changes Sep 1, 2026
parthrohit22
parthrohit22 previously approved these changes Sep 1, 2026

@parthrohit22 parthrohit22 left a comment

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.

Confirmed the AZ-GOV-006 fix — _governance_common.py now counts every Owner assignment atScope() returns instead of filtering to subscription-exact scope, which is the right call since that filter is exactly what was discarding management-group-inherited grants. Ran the new regression test myself: test_gov_006_owner_threshold and the parametrized test_missing_evidence_never_becomes_failure case both pass.

Approving.

@TFT444

TFT444 commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

Thank you for approving merging now as every requirement met.

@TFT444
TFT444 dismissed stale reviews from parthrohit22 and ritiksah141 via ab79b6b September 1, 2026 15:22
@TFT444
TFT444 force-pushed the feat/257-enterprise-governance-controls branch from c645347 to ab79b6b Compare September 1, 2026 15:22
… prevent SSRF

Signed-off-by: Tanvir Farhad <tamimtarafder12@gmail.com>
@TFT444

TFT444 commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author

@m-khan-97 the URL validation fix is in place: both _get_all() and _post_values() now use urlparse with an exact netloc == 'management.azure.com' check, rejecting lookalike hosts, userinfo, unexpected ports, and non-HTTPS schemes. Warning logs are emitted (not silent returns) when a continuation is rejected. Regression tests cover valid ARM pagination, lookalike host, userinfo URL, unexpected port, and rejected-continuation behaviour. 17 tests pass. Could you re-review when you get a chance? Thanks.

@TFT444

TFT444 commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author

@parthrohit22 @m-khan-97 All blocking concerns are addressed. Please re-review when you get a chance.

TFT444 added 4 commits October 4, 2026 17:46
…graph, exc_info on collection failures, exact GUID match via rsplit

Signed-off-by: Tanvir Farhad <tamimtarafder12@gmail.com>
…alogue

Signed-off-by: Tanvir Farhad <tamimtarafder12@gmail.com>
…interface

Signed-off-by: Tanvir Farhad <tamimtarafder12@gmail.com>
Signed-off-by: Tanvir Farhad <tamimtarafder12@gmail.com>
@TFT444
TFT444 requested a review from parthrohit22 October 8, 2026 22:29
@TFT444

TFT444 commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator Author

@ritiksah141 @parthrohit22 could you please re-review the latest head (c56bd81)?

Governance integration conflicts, engine dispatch, compliance documentation and dependency fixes are updated.

The fixes are pushed and all checks are passing on this head (the deployment skip is expected). Please review the updated code and tests, and update your review decision or resolve the relevant conversations when satisfied.

parthrohit22
parthrohit22 previously approved these changes Oct 12, 2026

@parthrohit22 parthrohit22 left a comment

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.

Re-reviewed c56bd81. My approval was dismissed by later pushes, so re-checking what changed since 732361e:

  • _post_graph() now passes allow_redirects=False (my non-blocking point), so all three credentialed calls are pinned to the ARM origin.
  • _is_valid_arm_continuation() and the fail-closed return None are unchanged. The new warnings log the rejected nextLink with %r, so a crafted URL can't inject lines into the log.
  • _strings() strips trailing slashes, so a management-group ID written as .../mg-root/ in the policy file still matches.
  • The dev merge is clean. Against dev, the diff is only the governance work, and the new ISO mappings use 2022 control IDs (A.5.15, A.5.1, A.8.9, A.5.18), which the mapping-pack validator accepts.
  • 303ed7a keeps the findings helpers out of the coverage-evaluator interface, with tests.

Approving. @m-khan-97, your 8 Sep change request (ARM pagination) is fixed on this head. It needs your re-review to clear.

@TFT444

TFT444 commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator Author

@m-khan-97, the ARM pagination credential-boundary issue you identified has been fixed since commit 732361e (merged Sep 8). parthrohit22 re-reviewed and confirmed the fix in their Oct 12 re-review (see their APPROVED comment on c56bd81). Could you take a final look and clear your CHANGES_REQUESTED so this can merge? The fix addresses all three vectors you listed (suffix host, userinfo, unexpected port) via strict netloc comparison plus allow_redirects=False on all credentialed calls.

…le replays

load_context() stored the governance snapshot on the azure_client object
without associating it with a subscription ID. When a scan evaluated rules
across multiple subscriptions in one process, all subscriptions after the
first would read the first subscription's snapshot instead of collecting
their own.

Added a _governance_snapshot_cache_sub sentinel alongside the cache. If the
stored subscription does not match the current call, the cache is invalidated
and a fresh GovernanceCollector.collect() is run for the new subscription.

Signed-off-by: Tanvir Farhad <tamimtarafder12@gmail.com>
Added TestLoadContextCaching with three cases:
- cache populated on first call
- cache reused for the same subscription (collector called only once)
- cache invalidated when subscription changes (stale-replay guard)

Signed-off-by: Tanvir Farhad <tamimtarafder12@gmail.com>
m-khan-97
m-khan-97 previously approved these changes Oct 18, 2026
Signed-off-by: Tanvir Farhad <tamimtarafder12@gmail.com>
Dependency lock updates are handled in #401 (fix/security-deps-python).
Removing from this PR to resolve conflict with dev.

Signed-off-by: Tanvir Farhad <tanvirfarhad007@gmail.com>
Signed-off-by: Tanvir Farhad <tamimtarafder12@gmail.com>

@parthrohit22 parthrohit22 left a comment

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.

Re-reviewed 21cea04. The code looks good:

  • The subscription-keyed snapshot cache (339a718) is right, and the three new tests cover first use, reuse and invalidation. AzureClient is created per scan, so the cache doesn't outlive a scan.
  • The ARM continuation fix that @m-khan-97 asked for is unchanged.
  • The files synced from dev in 85e97ed (engine.py, evaluation.py, azure_client.py, az_kv_006.py, docs/adding-a-rule.md) match dev exactly, so the net diff is only the governance work.

One change before merge. Since #381 landed, docs/adding-a-rule.md says new rules should expose evaluate(). A rule with only scan() is recorded as UNKNOWN / LEGACY_RULE_NOT_MIGRATED, and every compliance control mapped to it reads UNKNOWN. All ten AZ-GOV rules are scan()-only, so they'd join the #380 migration backlog on the day they merge.

They all go through _governance_common.evaluate(), so this should be one contained change:

  • Return RuleEvaluations from the shared evaluator and add a module-level evaluate() to each rule, keeping scan() as a thin wrapper.
  • When the governance policy is missing or invalid, or the collector fails, report ERROR (or NOT_APPLICABLE when no policy is configured on purpose) instead of an empty list.
  • Use subscription_scope_id(subscription_id) for subscription-level results.
  • Register PASS/FAIL fixtures in tests/test_rule_evaluation_contract.py.

…contract

Each governance rule now reports per-resource PASS/FAIL/ERROR/NOT_APPLICABLE
via evaluate(), with scan() a thin wrapper over its FAIL findings. Missing
evidence and an unset or invalid governance policy fail closed as ERROR
instead of reading as a silent pass. Snapshot collection moves behind
AzureClient.get_governance_snapshot; the subscription-keyed cache semantics
are unchanged. Contract fixtures are registered for all ten rules, with a
passing/failing scenario each so subscription-singular rules (001/002/006)
can satisfy the PASS and FAIL checks.

Signed-off-by: Tanvir Farhad <tamimtarafder12@gmail.com>
@TFT444

TFT444 commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks @parthrohit22. Addressed the Nov 2 blocker in 9ee9e55: all ten AZ-GOV rules now expose evaluate() and report per-resource PASS/FAIL/ERROR/NOT_APPLICABLE through the shared evaluator, with scan() a thin wrapper over the FAIL findings.

  • RuleEvaluations come from _governance_common; the FAIL finding dicts are unchanged (existing governance tests still pass against them).
  • Missing evidence (a control-plane list returning None) and an unset or invalid governance policy now fail closed as ERROR instead of an empty list; nothing-in-scope is NOT_APPLICABLE; subscription-level results use subscription_scope_id().
  • Snapshot collection moved behind AzureClient.get_governance_snapshot(). load_context still caches by subscription_id, so the cache semantics and the three cache tests are unchanged.
  • Contract fixtures are registered for all ten rules. Since AZ-GOV-001/002/006 are subscription-singular (one outcome per call), the harness now takes a passing and a failing scenario per rule rather than requiring one call to produce both.

Full test suite is green locally and ruff is clean.

@TFT444
TFT444 requested a review from parthrohit22 November 6, 2026 02:46
@TFT444

TFT444 commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

Note on the red check: SCA (pip-audit) is failing on oauthlib 4.0.0 (CVE-2026-49272, fixed in 4.0.1), a pinned transitive dependency. It is unrelated to this PR's governance changes, which add no dependencies. The advisory was published after this branch's last green run, and since the requirements here match the dev baseline, dev would fail the same scan. Happy to leave the fix to the dependency track (bump to 4.0.1 or an --ignore-vuln entry) so this PR stays scoped to the evaluate() migration, unless you'd prefer it handled here.

@parthrohit22 parthrohit22 left a comment

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.

Approved: the governance evaluation contract, ARM pagination validation, and rebase conflicts called out in review are resolved; regression coverage is in place and the suite is passing on the current head.

@parthrohit22 parthrohit22 left a comment

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.

Thanks for the rebase and for cleaning up the earlier issues. The governance evaluation contract, ARM pagination validation, and merge-conflict fixes are all in place, and the relevant regression coverage is passing. This gives me confidence the PR is ready to merge, so I’m approving it.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants