apex-azure-governance-discovery
Skill220 starsChanged 2 months agoMITView on GitHub
**ANALYSIS SKILL** — Azure Policy discovery: effective assignments (incl. MG-inherited), definitions/exemptions, effect classification, emits governance-constraints JSON. WHEN: 'Azure policy discovery', 'effective policy assignments', 'governance constraints', '04g-Governance Phase 1', 'refresh governance JSON'. DO NOT USE FOR: artifact writing, architecture mapping.
In this repository40 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .github/copilot-instructions.mdCopilot instructions
- apex-agent-authoringSkill
- apex-azure-adrSkill
- apex-azure-artifactsSkill
- apex-azure-bicep-patternsSkill
- apex-azure-cloud-migrateSkill
- apex-azure-complianceSkill
- apex-azure-computeSkill
- apex-azure-cost-optimizationSkill
- apex-azure-defaultsSkill
- apex-azure-deploySkill
- apex-azure-diagnosticsSkill
- apex-azure-kubernetesSkill
- apex-azure-kustoSkill
- apex-azure-prepareSkill
- apex-azure-quotasSkill
- apex-azure-rbacSkill
- apex-azure-reliabilitySkill
- apex-azure-resourcesSkill
- apex-azure-storageSkill
- apex-azure-upgradeSkill
- apex-azure-validateSkill
- apex-context-managementSkill
- apex-debug-log-exportSkill
- apex-entra-app-registrationSkill
- apex-github-operationsSkill
- apex-golden-principlesSkill
- apex-iac-commonSkill
- apex-mermaidSkill
- apex-microsoft-docsSkill
- apex-python-diagramsSkill
- apex-rfi-rfpSkill
- apex-terraform-patternsSkill
- apex-terraform-search-importSkill
- apex-terraform-testSkill
- apex-unslopSkill
- apex-vendor-promptingSkill
- apex-workflow-engineSkill
- apex-workflow-startSkill
The file
Files
Azure Governance Discovery Skill
Replaces the legacy governance-discovery-subagent with a deterministic script.
The skill exposes scripts/discover.py — a single batched REST traversal that
emits the schema-compliant 04-governance-constraints.json envelope. The parent
agent (04g-Governance) invokes it via run_in_terminal, reads a compact
one-line JSON status from stdout, and proceeds to artifact writing without ever
pulling raw Azure REST responses into LLM context.
When to Use
- Step 3.5 governance discovery for a project
- Refreshing the governance snapshot after policy changes
- Regenerating inputs for Step 4 (IaC Plan) and Step 5 (IaC Code)
When NOT to Use
- Writing
04-governance-constraints.md— that stays in the parent agent - Cross-referencing architecture resources — parent-side LLM work
- Challenger review orchestration — parent-side LLM work
- Any workflow that is not 04g-Governance
Rules
- Choose the source early — follow policy-source capture. The shared ALZ Corp baseline supports explicitly assumed Architecture, never target verification. Native target/read inputs use managed private capture when artifacts must remain anonymous; no user-prepared JSON.
- Stay deterministic — the discovery script is a single batched REST traversal; no LLM calls, no retries that hide errors, no inferred policy effects
- Use compact status for routing, then targeted envelope reads for decisions; recover all required evidence and diagnostics
- Schema compliance is mandatory — envelope MUST conform to
tools/schemas/governance-constraints.schema.json(schema_version: governance-constraints-v1) - Property paths are always strings — use
""for unresolvable paths, nevernull - Full assignment coverage is the default — Defender auto-assignments remain in collection and classification.
Legacy
--exclude-defender-autois explicit filtered coverage, never equivalent full evidence. - Exit codes are contract —
0= COMPLETE,1= PARTIAL,2= FAILED; argparse errors also return nonzero. COMPLETE is collection status, not planning approval - No artifact writing — the script emits JSON + a
.preview.md; the agent owns the final04-governance-constraints.mdcontent and traffic-light rendering - Never hand-edit the envelope — a re-run overwrites additions and any edit breaks the recorded signature; put additions in owner-controlled artifacts
- Reuse only current scoped evidence — project, subscription, options, schema, COMPLETE status, valid TTL and exemptions must match
- Resolve confirmations before review — all topics require current evidence-bound answers; unknowns block. See inline resolution
Steps
python .github/skills/apex-azure-governance-discovery/scripts/discover.py \
--project my-project \
--out agent-output/my-project/04-governance-constraints.jsonFlags:
| Flag | Meaning |
--project <name> | Required. Used only for cache key and provenance. |
--out <path> | Required. Full envelope written here (overwrites). |
--subscription <id|default> | Optional. default uses az account show. |
--arch <path> | Optional. Path to 02-architecture-assessment.md for preview mapping. |
--refresh | Force re-discovery even if <out> already exists. |
--include-defender-auto | Include Defender auto-assignments (the default; retained for compatibility). |
--exclude-defender-auto | Explicit legacy filtered coverage; cannot satisfy full-coverage feasibility. |
--validate-only | Validate a saved full-coverage snapshot offline; requires explicit subscription. |
--retain-rule-evidence | Retain/validate full rule objects and effective lineage inside an owner-only private snapshot outside Git. |
--verbose | Emit informational progress diagnostics to stderr. |
Exit codes:
| Code | Meaning |
0 | COMPLETE — discovery succeeded |
1 | PARTIAL — partial data written; parent should surface to user |
2 | FAILED — auth/network/permission error |
2 | Invalid arguments (argparse), distinguished from failures by diagnostics |
Stdout — always exactly one machine-readable JSON line first (using key "status",
whereas the persisted <out> envelope stores "discovery_status"), optional
human-readable preview after:
{
"status": "COMPLETE",
"cache_hit": false,
"assignment_total": 247,
"blockers": 18,
"caller_identity": 2,
"auto_remediate": 12,
"exempted": 3,
"out_path": "agent-output/my-project/04-governance-constraints.json"
}Output Contract
Private target-backed reconciliation uses --retain-rule-evidence for collection and offline validation.
It retains raw assignments, definitions, initiatives and exemptions plus every effective member rule,
including Audit and Disabled occurrences, with parameter lineage and a content digest inside the same snapshot.
Existing opaque private references and whole-file hashes cover this evidence; no new public raw artifact is created.
The directory must already be owner-only (0700) outside repositories without symlinks; snapshots/previews use 0600.
Summary-only caches fail this requirement without issuing a new Azure call. A bounded, authorized --refresh is needed;
cached rendering cannot reconstruct discarded rules. Legacy summary output remains available without this flag.
Collection COMPLETE, retained bodies and offline tests do not establish reconciliation, review or approval.
The script writes a JSON envelope conforming to
tools/schemas/governance-constraints.schema.json
(schema_version: governance-constraints-v1). Each finding carries both
bicepPropertyPath and azurePropertyPath (always strings — empty "" when
unresolvable, never null), plus category, exemption, and classification
("blocker" | "caller-identity" | "auto-remediate" | "informational";
pure requestContext().identity Deny policies set classification: "caller-identity" and identity_only: true;
exempted or DoNotEnforce Deny findings downgrade to "informational"). Top-level envelope also includes
policies (alias of findings), tags_required, allowed_locations, unresolved_scopes
(structured PARTIAL causes including ancestor_scope_forbidden for ancestor-MG HTTP 403s), and
discovery_metadata (L0 attestation envelope — MANDATORY).
For the full per-finding schema and additive fields, read
references/schema.md.
For the L0 envelope spec (shape, completeness-signature algorithm,
end-of-discovery self-check, refresh handoff, consumer protocol,
backward-compatibility rules), read
references/l0-envelope.md.
For the effect classification table and Defender-filter rationale, read
references/effect-classification.md.
Preview Markdown
The script also writes a sibling .preview.md file (e.g.,
04-governance-constraints.preview.md) with the H2 structure matching the
apex-azure-artifacts template. The agent copies this to
04-governance-constraints.md and annotates placeholder sections only.
Reference Index
References are split into two tiers so the agent loads only what it needs:
Load-always (the minimum to drive the core workflow):
references/terminal-commands.md— pre-built batched commands (Cmd 1–8) for the entire phase.
Load-on-demand (read only when the relevant decision point is reached):
references/effect-classification.md— effect-to-classification mapping, exemption downgrade, Defender filter rationalereferences/schema.md— output JSON envelope,findings[]structure, additive fieldsreferences/l0-envelope.md— canonical L0 envelope spec (shape, signature algorithm, self-check, refresh handoff, consumer protocol)references/inline-resolution-gate.md— Phase 2.7 protocol + signature/TTL short-circuitreferences/baseline-check.md— Phase 0.45 cached-baseline procedurereferences/policy-override-pattern.md— structuredoverrideobject shapereferences/reconciliation-disposition.md— Phase 2.5 disposition rulesreferences/resume-checks.md— Phase 0.4 short-circuit conditions (signature, TTL, confirmations)references/discover-output.md—discover.pystdout shape, exit codes, anti-patterns, discovery-signature persistence
Design Notes
- The collector traverses paginated assignments, definitions, initiatives and exemptions, resolving referenced definitions as needed; do not assume a fixed call count.
- Cache reuse checks project/subscription/options and COMPLETE envelope freshness,
including positive TTL, nonfuture timestamp and still-valid scoped exemptions.
--archregenerates the preview from current architecture even on a cache hit. - Signature verification, confirmation bindings and current review inputs remain consumer gates; the collector's cache hit alone cannot attest them.
- Filtering is based on assignment metadata and effective enforcement, not display-name claims. Review discovery_summary and diagnostics; do not claim an unmeasured reduction.
Testing
pytest .github/skills/apex-azure-governance-discovery/scripts/test_discover.py
# or
npm run test:governance-discoveryFixtures live in scripts/fixtures/ and simulate az rest responses via
subprocess.check_output monkeypatching — no Azure account required for tests.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

