auditex 2.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- auditex/__init__.py +23 -0
- auditex/__main__.py +4 -0
- auditex/answer_checks.py +292 -0
- auditex/answer_digest.py +407 -0
- auditex/answer_frames.json +40 -0
- auditex/assessment_review.py +355 -0
- auditex/assessment_sources.py +16 -0
- auditex/auth_runtime.py +218 -0
- auditex/bootstrap.py +340 -0
- auditex/ce_plus.py +684 -0
- auditex/cli.py +1599 -0
- auditex/command_builders.py +256 -0
- auditex/command_runner.py +386 -0
- auditex/compare.py +834 -0
- auditex/demo.py +476 -0
- auditex/evidence_db.py +8 -0
- auditex/explorer.py +1237 -0
- auditex/explorer_assets/LICENSE-lucide.txt +43 -0
- auditex/explorer_assets/explorer.css +509 -0
- auditex/explorer_assets/explorer.html +64 -0
- auditex/explorer_assets/explorer.js +990 -0
- auditex/explorer_assets/fonts/Barlow-400-latin-ext.woff2 +0 -0
- auditex/explorer_assets/fonts/Barlow-400-latin-ext.woff2.range +1 -0
- auditex/explorer_assets/fonts/Barlow-400-latin.woff2 +0 -0
- auditex/explorer_assets/fonts/Barlow-400-latin.woff2.range +1 -0
- auditex/explorer_assets/fonts/Barlow-600-latin-ext.woff2 +0 -0
- auditex/explorer_assets/fonts/Barlow-600-latin-ext.woff2.range +1 -0
- auditex/explorer_assets/fonts/Barlow-600-latin.woff2 +0 -0
- auditex/explorer_assets/fonts/Barlow-600-latin.woff2.range +1 -0
- auditex/explorer_assets/fonts/BarlowCondensed-600-latin-ext.woff2 +0 -0
- auditex/explorer_assets/fonts/BarlowCondensed-600-latin-ext.woff2.range +1 -0
- auditex/explorer_assets/fonts/BarlowCondensed-600-latin.woff2 +0 -0
- auditex/explorer_assets/fonts/BarlowCondensed-600-latin.woff2.range +1 -0
- auditex/explorer_assets/fonts/OFL.txt +93 -0
- auditex/exporters.py +95 -0
- auditex/external_assessments.py +319 -0
- auditex/features.py +15 -0
- auditex/gate.py +825 -0
- auditex/google_workspace/__init__.py +17 -0
- auditex/google_workspace/auth.py +403 -0
- auditex/google_workspace/client.py +688 -0
- auditex/google_workspace/collectors.py +998 -0
- auditex/google_workspace/findings.py +2330 -0
- auditex/google_workspace/normalize.py +773 -0
- auditex/google_workspace/run.py +1219 -0
- auditex/guided.py +338 -0
- auditex/local_answer.py +1045 -0
- auditex/mcp_paths.py +139 -0
- auditex/mcp_registry.py +270 -0
- auditex/mcp_server.py +1443 -0
- auditex/notify.py +763 -0
- auditex/operator_flow.py +47 -0
- auditex/output_writers.py +211 -0
- auditex/reporting.py +4699 -0
- auditex/rule_assessment.py +493 -0
- auditex/rules.py +356 -0
- auditex/run_bundle.py +544 -0
- auditex/scope_postcheck.py +81 -0
- auditex/scuba_adapters_aad.py +398 -0
- auditex/scuba_adapters_defender.py +162 -0
- auditex/scuba_adapters_exchange.py +63 -0
- auditex/scuba_adapters_powerplat.py +94 -0
- auditex/scuba_adapters_teams.py +230 -0
- auditex/scuba_projection.py +2345 -0
- auditex/scubagear_export.py +871 -0
- auditex/scubagear_prune_proof.py +575 -0
- auditex/setup_guide.py +668 -0
- auditex-2.0.0.data/data/auditex/agent/agent-prompt.md +60 -0
- auditex-2.0.0.data/data/auditex/agent/tenant-audit-skill.json +265 -0
- auditex-2.0.0.data/data/auditex/assets/auditex-logo-64.png +0 -0
- auditex-2.0.0.data/data/auditex/assets/auditex-logo.svg +14 -0
- auditex-2.0.0.data/data/auditex/configs/assessment-sources.json +145 -0
- auditex-2.0.0.data/data/auditex/configs/ce-plus-practice.json +1463 -0
- auditex-2.0.0.data/data/auditex/configs/collector-definitions.json +990 -0
- auditex-2.0.0.data/data/auditex/configs/collector-permissions.json +460 -0
- auditex-2.0.0.data/data/auditex/configs/collector-presets.json +82 -0
- auditex-2.0.0.data/data/auditex/configs/control-mappings.json +3560 -0
- auditex-2.0.0.data/data/auditex/configs/explainer-baselines.json +10987 -0
- auditex-2.0.0.data/data/auditex/configs/explainer-template.json +1 -0
- auditex-2.0.0.data/data/auditex/configs/explainer-what-to-collect.json +27838 -0
- auditex-2.0.0.data/data/auditex/configs/finding-templates.json +1503 -0
- auditex-2.0.0.data/data/auditex/configs/framework-catalog.json +509 -0
- auditex-2.0.0.data/data/auditex/configs/os-end-of-life.json +736 -0
- auditex-2.0.0.data/data/auditex/configs/report-sections.json +129 -0
- auditex-2.0.0.data/data/auditex/configs/risky-delegated-permissions.json +767 -0
- auditex-2.0.0.data/data/auditex/configs/rule-packs.json +1709 -0
- auditex-2.0.0.data/data/auditex/configs/scuba-policy-sections.json +1151 -0
- auditex-2.0.0.data/data/auditex/configs/scuba-rule-precheck.json +538 -0
- auditex-2.0.0.data/data/auditex/configs/scuba-scope-blind.json +197 -0
- auditex-2.0.0.data/data/auditex/configs/scuba-value-rules.json +22013 -0
- auditex-2.0.0.data/data/auditex/docs/guides/admin-permission-guide.md +507 -0
- auditex-2.0.0.data/data/auditex/docs/guides/ai-assessment.md +159 -0
- auditex-2.0.0.data/data/auditex/docs/guides/customer-handoff-guide.md +159 -0
- auditex-2.0.0.data/data/auditex/docs/guides/external-assessments.md +96 -0
- auditex-2.0.0.data/data/auditex/docs/guides/install-guide.md +377 -0
- auditex-2.0.0.data/data/auditex/docs/guides/local-answer.md +114 -0
- auditex-2.0.0.data/data/auditex/docs/guides/model-development.md +40 -0
- auditex-2.0.0.data/data/auditex/docs/guides/product-manual.md +521 -0
- auditex-2.0.0.data/data/auditex/docs/guides/reader-app-permissions.md +328 -0
- auditex-2.0.0.data/data/auditex/docs/guides/setup-guide.md +249 -0
- auditex-2.0.0.data/data/auditex/docs/guides/troubleshooting.md +214 -0
- auditex-2.0.0.data/data/auditex/docs/index.md +42 -0
- auditex-2.0.0.data/data/auditex/docs/legal/third-party-notices.md +117 -0
- auditex-2.0.0.data/data/auditex/docs/legal/trademarks.md +19 -0
- auditex-2.0.0.data/data/auditex/docs/provenance/explainer-baselines.md +98 -0
- auditex-2.0.0.data/data/auditex/docs/provenance/provenance.csv +44 -0
- auditex-2.0.0.data/data/auditex/docs/provenance/provenance.md +199 -0
- auditex-2.0.0.data/data/auditex/docs/reference/api-call-catalog.md +334 -0
- auditex-2.0.0.data/data/auditex/docs/reference/framework-mappings.md +638 -0
- auditex-2.0.0.data/data/auditex/docs/reference/output-contract.md +1878 -0
- auditex-2.0.0.data/data/auditex/docs/reference/security-privacy.md +1077 -0
- auditex-2.0.0.data/data/auditex/examples/demo_tenant/demo_tenant.json +1074 -0
- auditex-2.0.0.data/data/auditex/examples/demo_tenant/demo_tenant_remediated.json +1083 -0
- auditex-2.0.0.data/data/auditex/examples/google_workspace_sample.json +563 -0
- auditex-2.0.0.data/data/auditex/examples/sample_audit_bundle/admin_set_result.json +382 -0
- auditex-2.0.0.data/data/auditex/examples/sample_audit_bundle/endpoint_posture_result.json +363 -0
- auditex-2.0.0.data/data/auditex/examples/sample_audit_bundle/external_maester.json +38 -0
- auditex-2.0.0.data/data/auditex/examples/sample_audit_bundle/external_monkey365.json +66 -0
- auditex-2.0.0.data/data/auditex/examples/sample_audit_bundle/external_scubagear.json +41 -0
- auditex-2.0.0.data/data/auditex/examples/sample_audit_bundle/identity_controls_result.json +254 -0
- auditex-2.0.0.data/data/auditex/examples/sample_audit_bundle/known_bad_result.json +164 -0
- auditex-2.0.0.data/data/auditex/examples/sample_audit_bundle/sample_result.json +41 -0
- auditex-2.0.0.data/data/auditex/examples/sample_audit_bundle/update_rings_missing_result.json +103 -0
- auditex-2.0.0.data/data/auditex/profiles/app-readonly-full.md +11 -0
- auditex-2.0.0.data/data/auditex/profiles/exchange-reader.md +11 -0
- auditex-2.0.0.data/data/auditex/profiles/global-reader.md +11 -0
- auditex-2.0.0.data/data/auditex/profiles/intune-reader.md +11 -0
- auditex-2.0.0.data/data/auditex/profiles/security-reader.md +11 -0
- auditex-2.0.0.data/data/auditex/schemas/ai_context.schema.json +30 -0
- auditex-2.0.0.data/data/auditex/schemas/blocker.schema.json +14 -0
- auditex-2.0.0.data/data/auditex/schemas/blockers.schema.json +6 -0
- auditex-2.0.0.data/data/auditex/schemas/bundle_hashes.schema.json +38 -0
- auditex-2.0.0.data/data/auditex/schemas/capability_matrix.schema.json +41 -0
- auditex-2.0.0.data/data/auditex/schemas/ce_plus_practice.schema.json +653 -0
- auditex-2.0.0.data/data/auditex/schemas/collector_result.schema.json +13 -0
- auditex-2.0.0.data/data/auditex/schemas/explainer.schema.json +13 -0
- auditex-2.0.0.data/data/auditex/schemas/finding.schema.json +277 -0
- auditex-2.0.0.data/data/auditex/schemas/local_answer.schema.json +133 -0
- auditex-2.0.0.data/data/auditex/schemas/model_assessment-2026-10-27.1.schema.json +288 -0
- auditex-2.0.0.data/data/auditex/schemas/model_assessment-2026-10-27.schema.json +271 -0
- auditex-2.0.0.data/data/auditex/schemas/model_assessment-2026-10-28.schema.json +453 -0
- auditex-2.0.0.data/data/auditex/schemas/model_assessment-2026-10-29.schema.json +1245 -0
- auditex-2.0.0.data/data/auditex/schemas/model_assessment-2026-11-05.schema.json +1339 -0
- auditex-2.0.0.data/data/auditex/schemas/model_assessment.schema.json +1387 -0
- auditex-2.0.0.data/data/auditex/schemas/report_pack.schema.json +41 -0
- auditex-2.0.0.data/data/auditex/schemas/run_manifest.schema.json +195 -0
- auditex-2.0.0.data/data/auditex/schemas/summary.schema.json +32 -0
- auditex-2.0.0.data/data/auditex/schemas/targeted_users_coverage.schema.json +29 -0
- auditex-2.0.0.data/data/auditex/schemas/validation.schema.json +28 -0
- auditex-2.0.0.data/data/auditex/skills/app-readonly-escalation/SKILL.md +26 -0
- auditex-2.0.0.data/data/auditex/skills/auditex-operator/SKILL.md +43 -0
- auditex-2.0.0.data/data/auditex/skills/evidence-pack/SKILL.md +29 -0
- auditex-2.0.0.dist-info/METADATA +292 -0
- auditex-2.0.0.dist-info/RECORD +321 -0
- auditex-2.0.0.dist-info/WHEEL +5 -0
- auditex-2.0.0.dist-info/entry_points.txt +4 -0
- auditex-2.0.0.dist-info/licenses/LICENSE +202 -0
- auditex-2.0.0.dist-info/licenses/NOTICE +46 -0
- auditex-2.0.0.dist-info/top_level.txt +2 -0
- azure_tenant_audit/__init__.py +5 -0
- azure_tenant_audit/__main__.py +4 -0
- azure_tenant_audit/adapters/__init__.py +35 -0
- azure_tenant_audit/adapters/base.py +34 -0
- azure_tenant_audit/adapters/capabilities.py +43 -0
- azure_tenant_audit/adapters/m365_cli.py +156 -0
- azure_tenant_audit/adapters/m365dsc.py +124 -0
- azure_tenant_audit/adapters/powershell_graph.py +655 -0
- azure_tenant_audit/adapters/read_guard.py +738 -0
- azure_tenant_audit/adapters/teams_admin_rest.py +336 -0
- azure_tenant_audit/ai_context.py +159 -0
- azure_tenant_audit/api_inventory.py +927 -0
- azure_tenant_audit/argument_parser.py +121 -0
- azure_tenant_audit/assurance.py +349 -0
- azure_tenant_audit/attack_graph.py +986 -0
- azure_tenant_audit/auth_context.py +148 -0
- azure_tenant_audit/auth_runtime.py +81 -0
- azure_tenant_audit/autopilot.py +728 -0
- azure_tenant_audit/baselines.py +1372 -0
- azure_tenant_audit/break_glass.py +499 -0
- azure_tenant_audit/bundle_integrity.py +467 -0
- azure_tenant_audit/capability_gate.py +278 -0
- azure_tenant_audit/catalog.py +75 -0
- azure_tenant_audit/certificate_auth.py +342 -0
- azure_tenant_audit/chunk_reader.py +167 -0
- azure_tenant_audit/citations.py +45 -0
- azure_tenant_audit/cli.py +1323 -0
- azure_tenant_audit/cli_guard.py +335 -0
- azure_tenant_audit/collection_gaps.py +584 -0
- azure_tenant_audit/collection_markers.py +3 -0
- azure_tenant_audit/collector_runner.py +342 -0
- azure_tenant_audit/collectors/__init__.py +75 -0
- azure_tenant_audit/collectors/_capability_gated.py +169 -0
- azure_tenant_audit/collectors/_endpoint_reads.py +371 -0
- azure_tenant_audit/collectors/anti_phish_admission.py +345 -0
- azure_tenant_audit/collectors/app_consent.py +409 -0
- azure_tenant_audit/collectors/app_credentials.py +392 -0
- azure_tenant_audit/collectors/auth_methods.py +55 -0
- azure_tenant_audit/collectors/base.py +564 -0
- azure_tenant_audit/collectors/conditional_access.py +68 -0
- azure_tenant_audit/collectors/consent_policy.py +192 -0
- azure_tenant_audit/collectors/copilot_governance.py +68 -0
- azure_tenant_audit/collectors/cross_tenant_access.py +187 -0
- azure_tenant_audit/collectors/defender.py +80 -0
- azure_tenant_audit/collectors/defender_cloud_apps.py +43 -0
- azure_tenant_audit/collectors/directory_relationships.py +93 -0
- azure_tenant_audit/collectors/dns_posture.py +432 -0
- azure_tenant_audit/collectors/domains_hybrid.py +49 -0
- azure_tenant_audit/collectors/ediscovery.py +435 -0
- azure_tenant_audit/collectors/exchange.py +70 -0
- azure_tenant_audit/collectors/exchange_defender_commands.py +117 -0
- azure_tenant_audit/collectors/exchange_policy.py +438 -0
- azure_tenant_audit/collectors/external_identity.py +41 -0
- azure_tenant_audit/collectors/identity.py +262 -0
- azure_tenant_audit/collectors/identity_governance.py +297 -0
- azure_tenant_audit/collectors/identity_protection.py +125 -0
- azure_tenant_audit/collectors/intune.py +105 -0
- azure_tenant_audit/collectors/intune_depth.py +377 -0
- azure_tenant_audit/collectors/licensing.py +58 -0
- azure_tenant_audit/collectors/mailbox_forwarding.py +534 -0
- azure_tenant_audit/collectors/onedrive_posture.py +122 -0
- azure_tenant_audit/collectors/power_bi.py +83 -0
- azure_tenant_audit/collectors/power_platform.py +249 -0
- azure_tenant_audit/collectors/purview.py +274 -0
- azure_tenant_audit/collectors/reports_usage.py +162 -0
- azure_tenant_audit/collectors/security.py +78 -0
- azure_tenant_audit/collectors/sentinel_xdr.py +37 -0
- azure_tenant_audit/collectors/service_health.py +41 -0
- azure_tenant_audit/collectors/sharepoint.py +52 -0
- azure_tenant_audit/collectors/sharepoint_access.py +358 -0
- azure_tenant_audit/collectors/sharepoint_admin.py +440 -0
- azure_tenant_audit/collectors/targeted_users_coverage.py +799 -0
- azure_tenant_audit/collectors/teams.py +109 -0
- azure_tenant_audit/collectors/teams_policy.py +170 -0
- azure_tenant_audit/config.py +104 -0
- azure_tenant_audit/contracts.py +1084 -0
- azure_tenant_audit/cyber_essentials.py +195 -0
- azure_tenant_audit/data_handling.py +236 -0
- azure_tenant_audit/data_minimisation.py +201 -0
- azure_tenant_audit/detection_coverage.py +364 -0
- azure_tenant_audit/diagnostics.py +153 -0
- azure_tenant_audit/diffing.py +655 -0
- azure_tenant_audit/directory_relationships.py +31 -0
- azure_tenant_audit/dns_lookup.py +819 -0
- azure_tenant_audit/effective_admins.py +602 -0
- azure_tenant_audit/endpoint_posture.py +558 -0
- azure_tenant_audit/evidence_db.py +600 -0
- azure_tenant_audit/evidence_gates.py +186 -0
- azure_tenant_audit/evidence_refs.py +409 -0
- azure_tenant_audit/exchange_protection.py +237 -0
- azure_tenant_audit/explainer/__init__.py +52 -0
- azure_tenant_audit/explainer/adapter.py +35 -0
- azure_tenant_audit/explainer/baselines.py +450 -0
- azure_tenant_audit/explainer/collection.py +183 -0
- azure_tenant_audit/explainer/generate.py +224 -0
- azure_tenant_audit/explainer/render.py +214 -0
- azure_tenant_audit/explainer/textkit.py +336 -0
- azure_tenant_audit/explainer/view.py +100 -0
- azure_tenant_audit/exposure_lookup.py +498 -0
- azure_tenant_audit/external_sharing.py +529 -0
- azure_tenant_audit/finalize.py +373 -0
- azure_tenant_audit/findings.py +4648 -0
- azure_tenant_audit/friendly_names.py +165 -0
- azure_tenant_audit/graph.py +1098 -0
- azure_tenant_audit/guarded_io.py +1304 -0
- azure_tenant_audit/identity_controls.py +1698 -0
- azure_tenant_audit/normalize.py +3376 -0
- azure_tenant_audit/offline_replay.py +243 -0
- azure_tenant_audit/os_lifecycle.py +224 -0
- azure_tenant_audit/output.py +1109 -0
- azure_tenant_audit/output_redaction.py +2871 -0
- azure_tenant_audit/partner_domains.py +180 -0
- azure_tenant_audit/perf_runtime.py +106 -0
- azure_tenant_audit/power_bi.py +58 -0
- azure_tenant_audit/power_platform.py +141 -0
- azure_tenant_audit/presets.py +80 -0
- azure_tenant_audit/private_io.py +173 -0
- azure_tenant_audit/privileged_roles.py +246 -0
- azure_tenant_audit/probe.py +743 -0
- azure_tenant_audit/profiles.py +257 -0
- azure_tenant_audit/provider_registry.py +21 -0
- azure_tenant_audit/provider_runtime.py +127 -0
- azure_tenant_audit/resources.py +220 -0
- azure_tenant_audit/response.py +829 -0
- azure_tenant_audit/rule_parameters.py +167 -0
- azure_tenant_audit/run.py +552 -0
- azure_tenant_audit/run_files.py +182 -0
- azure_tenant_audit/scope_catalog.py +195 -0
- azure_tenant_audit/scuba_assessment.py +646 -0
- azure_tenant_audit/scuba_precheck.py +316 -0
- azure_tenant_audit/scuba_scope.py +213 -0
- azure_tenant_audit/secret_hygiene.py +717 -0
- azure_tenant_audit/selection.py +31 -0
- azure_tenant_audit/sensitive_users.py +178 -0
- azure_tenant_audit/shipped_content.py +122 -0
- azure_tenant_audit/strict_json.py +19 -0
- azure_tenant_audit/tenant_identity.py +267 -0
- azure_tenant_audit/text_validity.py +77 -0
- azure_tenant_audit/utils.py +38 -0
- azure_tenant_audit/value_rules/__init__.py +77 -0
- azure_tenant_audit/value_rules/aad_authz.py +140 -0
- azure_tenant_audit/value_rules/aad_pilot.py +439 -0
- azure_tenant_audit/value_rules/aad_roles.py +182 -0
- azure_tenant_audit/value_rules/catalogue.py +184 -0
- azure_tenant_audit/value_rules/conditional_access.py +673 -0
- azure_tenant_audit/value_rules/defender_cascade.py +274 -0
- azure_tenant_audit/value_rules/defender_dlp.py +209 -0
- azure_tenant_audit/value_rules/defender_phish.py +360 -0
- azure_tenant_audit/value_rules/defender_resolution.py +486 -0
- azure_tenant_audit/value_rules/defender_spam.py +222 -0
- azure_tenant_audit/value_rules/defender_targeted_users.py +182 -0
- azure_tenant_audit/value_rules/dns.py +339 -0
- azure_tenant_audit/value_rules/exo_open.py +56 -0
- azure_tenant_audit/value_rules/gates.py +52 -0
- azure_tenant_audit/value_rules/helpers.py +312 -0
- azure_tenant_audit/value_rules/lookups.py +311 -0
- azure_tenant_audit/value_rules/power_platform.py +149 -0
- azure_tenant_audit/value_rules/powerbi.py +138 -0
- azure_tenant_audit/value_rules/record.py +162 -0
- azure_tenant_audit/value_rules/sharepoint.py +125 -0
- azure_tenant_audit/versioning.py +47 -0
- azure_tenant_audit/waivers.py +304 -0
auditex/__init__.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Auditex product wrapper for the Azure tenant audit engine."""
|
|
2
|
+
|
|
3
|
+
from azure_tenant_audit.provider_registry import register_provider
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def _google_collectors():
|
|
7
|
+
from .google_workspace.collectors import REGISTRY
|
|
8
|
+
|
|
9
|
+
return REGISTRY
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# Every product entry point imports this package, including reports and exports
|
|
13
|
+
# that consume existing Google bundles without running a Google collector first.
|
|
14
|
+
register_provider("google_workspace", _google_collectors)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def main() -> int:
|
|
18
|
+
from .cli import main as cli_main
|
|
19
|
+
|
|
20
|
+
return cli_main()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
__all__ = ["main"]
|
auditex/__main__.py
ADDED
auditex/answer_checks.py
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
"""Fail-closed checks on a local model's answers, the renderer and the fixed-text fallback (DEC-113, DEC-119).
|
|
2
|
+
|
|
3
|
+
The model writes no text (DEC-119); it selects and arranges. For each digest item (``answer_digest``) it returns one
|
|
4
|
+
JSON object and nothing else, ``{"use": ["is-not-met", "requirement", "step-1"], "show": ["v4"]}``: ``use`` selects
|
|
5
|
+
sentences of the item's bank (``answer_digest.item_bank``: the fixed frames of ``answer_frames.json`` whose
|
|
6
|
+
preconditions hold on the item's rule facts, the baseline requirement and, for a not met item, the baseline
|
|
7
|
+
remediation steps), ``show`` selects values Auditex renders quoted. For the whole run it returns
|
|
8
|
+
``{"summary": ["run-counts"], "highlight": [1, 2]}``: run frames whose count preconditions hold
|
|
9
|
+
(``answer_digest.run_bank``), their counts filled by Auditex, and the numbers of the items to list first
|
|
10
|
+
(``answer_digest.highlightable``). Auditex renders every word; the rules decide every verdict and the order.
|
|
11
|
+
|
|
12
|
+
Item answer checks (anything else fails and the item shows ``fallback_text``):
|
|
13
|
+
1. form: one JSON object (as text, or already parsed) with exactly the keys use and show, strict JSON (a duplicate
|
|
14
|
+
key or a constant such as NaN fails), each a list of strings.
|
|
15
|
+
2. use: at least one id (``empty``), at most the ``use`` limit of the frames file (``limit``), no id twice
|
|
16
|
+
(``duplicate``), each id in the item's bank. A frame or catalogue sentence id the bank does not hold for this item
|
|
17
|
+
fails ``precondition`` (``is-met`` on a not met item, ``step-1`` on a met one, ``mandatory`` without a catalogue
|
|
18
|
+
Shall); any other id fails ``unknown``.
|
|
19
|
+
3. show: distinct reference ids (``v4``) of this item's values other than its check and verdict, which Auditex always
|
|
20
|
+
renders. Another item's id, an unknown id, a check or verdict id fails ``reference``; a repeat ``duplicate``.
|
|
21
|
+
Run summary checks: exactly the keys summary and highlight; summary 1 to the ``summary`` limit of distinct ids of
|
|
22
|
+
``run_bank`` (a run frame whose counts do not hold fails ``precondition``); highlight up to the ``highlight`` limit of
|
|
23
|
+
distinct item numbers, written as integers, of ``highlightable`` (an item of another verdict fails ``precondition``).
|
|
24
|
+
|
|
25
|
+
Rendering: the Check and Verdict frames; the selected sentences in the model's order, except that remediation steps
|
|
26
|
+
keep their baseline order across the places the model gave steps; then the values listed in show or shown by a
|
|
27
|
+
selected frame, in the item's value order, each quoted and escaped under its fixed label (``LABELS``). The summary
|
|
28
|
+
renders its frames in the model's order and the highlighted items in the rules' order. ``answer_form`` and
|
|
29
|
+
``summary_form`` give M10-T03's decoding grammar the JSON schema with the allowed id enums; every answer the schema
|
|
30
|
+
admits passes these checks. Pure and deterministic: no model, no network.
|
|
31
|
+
"""
|
|
32
|
+
from __future__ import annotations
|
|
33
|
+
|
|
34
|
+
import json
|
|
35
|
+
import re
|
|
36
|
+
from collections.abc import Mapping
|
|
37
|
+
from typing import Any
|
|
38
|
+
|
|
39
|
+
from .answer_digest import (
|
|
40
|
+
CATALOGUE,
|
|
41
|
+
CATALOGUE_ID,
|
|
42
|
+
VERDICT_TEXT,
|
|
43
|
+
frames,
|
|
44
|
+
highlightable,
|
|
45
|
+
item_bank,
|
|
46
|
+
quoted,
|
|
47
|
+
ref_of,
|
|
48
|
+
run_bank,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
ITEM_KEYS = ("use", "show")
|
|
52
|
+
SUMMARY_KEYS = ("summary", "highlight")
|
|
53
|
+
ALWAYS_SHOWN = ("check", "verdict")
|
|
54
|
+
LABELS = {"check": "Check", "severity": "Severity", "requirement": "Requirement", "reason": "Reason",
|
|
55
|
+
"field": "Field", "setting": "Setting"}
|
|
56
|
+
REF_ID = re.compile(r"v[1-9][0-9]*")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class AnswerCheckError(ValueError):
|
|
60
|
+
"""An answer that did not pass the checks was given to the renderer."""
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _parse(answer: Any, keys: tuple[str, str]) -> tuple[Mapping[str, Any] | None, str | None]:
|
|
64
|
+
from azure_tenant_audit.strict_json import reject_json_constant, strict_pairs
|
|
65
|
+
|
|
66
|
+
if isinstance(answer, str):
|
|
67
|
+
try:
|
|
68
|
+
answer = json.loads(answer, object_pairs_hook=strict_pairs, parse_constant=reject_json_constant)
|
|
69
|
+
except (ValueError, RecursionError):
|
|
70
|
+
return None, "the answer is not one JSON object"
|
|
71
|
+
if not isinstance(answer, Mapping):
|
|
72
|
+
return None, "the answer is not one JSON object"
|
|
73
|
+
if set(answer) != set(keys):
|
|
74
|
+
return None, f"the answer's keys are {sorted(map(str, answer))[:6]}, not {' and '.join(keys)}"
|
|
75
|
+
return answer, None
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _id_list(value: Any, kind: type) -> bool:
|
|
79
|
+
return isinstance(value, list) and all(type(entry) is kind for entry in value)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def showable(item: Mapping[str, Any]) -> list[str]:
|
|
83
|
+
"""The reference ids an answer may list in ``show``: the item's values other than its check and verdict."""
|
|
84
|
+
return [value["ref"] for value in item["values"] if value["name"] not in ALWAYS_SHOWN]
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def answer_form(item: Mapping[str, Any], digest: Mapping[str, Any] | None = None) -> dict[str, Any]:
|
|
88
|
+
"""What a decoding grammar may produce for this item (M10-T03): the JSON schema with the allowed id enums, the
|
|
89
|
+
bank's sentences by id and the reference ids for ``show``. ``digest`` is accepted for symmetry with
|
|
90
|
+
``check_answer``; an item's form depends on the item alone."""
|
|
91
|
+
bank, ids = item_bank(item), showable(item)
|
|
92
|
+
limit = frames()["limits"]["use"]
|
|
93
|
+
schema = {"type": "object", "additionalProperties": False, "required": list(ITEM_KEYS),
|
|
94
|
+
"properties": {"use": {"type": "array", "minItems": 1, "maxItems": min(limit, len(bank)),
|
|
95
|
+
"uniqueItems": True, "items": {"type": "string", "enum": list(bank)}},
|
|
96
|
+
"show": {"type": "array", "maxItems": len(ids), "uniqueItems": True,
|
|
97
|
+
"items": {"type": "string", "enum": ids}}}}
|
|
98
|
+
return {"schema": schema, "sentences": {sid: entry["text"] for sid, entry in bank.items()}, "show": ids,
|
|
99
|
+
"limits": {"use": limit}}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def summary_form(digest: Mapping[str, Any]) -> dict[str, Any]:
|
|
103
|
+
"""What a decoding grammar may produce for the run summary: the JSON schema with the run frame and item number
|
|
104
|
+
enums, and the run frames' texts with Auditex's counts."""
|
|
105
|
+
bank, items, limits = run_bank(digest), highlightable(digest), frames()["limits"]
|
|
106
|
+
schema = {"type": "object", "additionalProperties": False, "required": list(SUMMARY_KEYS),
|
|
107
|
+
"properties": {"summary": {"type": "array", "minItems": 1, "maxItems": min(limits["summary"], len(bank)),
|
|
108
|
+
"uniqueItems": True, "items": {"type": "string", "enum": list(bank)}},
|
|
109
|
+
"highlight": {"type": "array", "maxItems": min(limits["highlight"], len(items)),
|
|
110
|
+
"uniqueItems": True, "items": {"type": "integer", "enum": items}}}}
|
|
111
|
+
return {"schema": schema, "sentences": bank, "highlight": items,
|
|
112
|
+
"limits": {"summary": limits["summary"], "highlight": limits["highlight"]}}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _check_use(use: Any, item: Mapping[str, Any], fail) -> None:
|
|
116
|
+
if not _id_list(use, str):
|
|
117
|
+
fail("form", "use is not a list of sentence ids")
|
|
118
|
+
return
|
|
119
|
+
limit, bank = frames()["limits"]["use"], item_bank(item)
|
|
120
|
+
if not use:
|
|
121
|
+
fail("empty", "use selects no sentence")
|
|
122
|
+
if len(use) > limit:
|
|
123
|
+
fail("limit", f"use selects {len(use)} sentences, more than {limit}")
|
|
124
|
+
seen: set[str] = set()
|
|
125
|
+
for sid in use:
|
|
126
|
+
if sid in seen:
|
|
127
|
+
fail("duplicate", f"use lists {sid} twice")
|
|
128
|
+
elif sid not in bank:
|
|
129
|
+
if sid in frames()["item"] or CATALOGUE_ID.fullmatch(sid):
|
|
130
|
+
fail("precondition", f"{sid} is not in this item's bank (verdict {VERDICT_TEXT[item['verdict']]})")
|
|
131
|
+
else:
|
|
132
|
+
fail("unknown", f"use holds {json.dumps(sid)[:40]}, not a sentence id of this item")
|
|
133
|
+
seen.add(sid)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def _check_show(show: Any, item: Mapping[str, Any], digest: Mapping[str, Any] | None, fail) -> None:
|
|
137
|
+
if not _id_list(show, str):
|
|
138
|
+
fail("form", "show is not a list of reference ids")
|
|
139
|
+
return
|
|
140
|
+
own = {value["ref"]: value["name"] for value in item["values"]}
|
|
141
|
+
others = {value["ref"] for entry in (digest["items"] if digest is not None else []) for value in entry["values"]}
|
|
142
|
+
seen: set[str] = set()
|
|
143
|
+
for ref in show:
|
|
144
|
+
if ref in seen:
|
|
145
|
+
fail("duplicate", f"show lists {json.dumps(ref)[:40]} twice")
|
|
146
|
+
elif ref not in own:
|
|
147
|
+
where = ("another item's value" if ref in others else
|
|
148
|
+
"no value of the digest" if REF_ID.fullmatch(ref) else "not a reference id such as v4")
|
|
149
|
+
fail("reference", f"{json.dumps(ref)[:40]} is {where}, not a value of this item")
|
|
150
|
+
elif own[ref] in ALWAYS_SHOWN:
|
|
151
|
+
fail("reference", f"{ref} is the item's {own[ref]}, which Auditex always shows")
|
|
152
|
+
seen.add(ref)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def check_answer(answer: Any, item: Mapping[str, Any], digest: Mapping[str, Any] | None = None) -> dict[str, Any]:
|
|
156
|
+
"""{"pass": bool, "failures": [{"check", "detail"}]} for the model's answer for one digest item.
|
|
157
|
+
|
|
158
|
+
Checks: form, empty, limit, duplicate, precondition, unknown (use) and reference (show). Pass the whole digest so
|
|
159
|
+
another item's reference ids are named as such.
|
|
160
|
+
"""
|
|
161
|
+
failures: list[dict[str, str]] = []
|
|
162
|
+
|
|
163
|
+
def fail(check: str, detail: str) -> None:
|
|
164
|
+
failures.append({"check": check, "detail": detail[:160]})
|
|
165
|
+
|
|
166
|
+
parsed, problem = _parse(answer, ITEM_KEYS)
|
|
167
|
+
if parsed is None:
|
|
168
|
+
fail("form", problem or "the answer is not one JSON object")
|
|
169
|
+
else:
|
|
170
|
+
_check_use(parsed["use"], item, fail)
|
|
171
|
+
_check_show(parsed["show"], item, digest, fail)
|
|
172
|
+
return {"pass": not failures, "failures": failures}
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def _check_name(item: Mapping[str, Any]) -> str:
|
|
176
|
+
return next(value["text"] for value in item["values"] if value["name"] == "check")
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _render(item: Mapping[str, Any], use: list[str], show: list[str]) -> str:
|
|
180
|
+
bank = item_bank(item)
|
|
181
|
+
lines = [f"Check: {quoted(_check_name(item))}", f"Verdict: {VERDICT_TEXT[item['verdict']]}."]
|
|
182
|
+
steps = iter(sorted((sid for sid in use if bank[sid]["kind"] == "step"), key=lambda sid: int(sid[5:])))
|
|
183
|
+
lines.extend(bank[next(steps) if bank[sid]["kind"] == "step" else sid]["text"] for sid in use)
|
|
184
|
+
shown = set(show) | {ref_of(item, name) for sid in use for name in bank[sid]["shows"]}
|
|
185
|
+
lines.extend(f"{LABELS[value['name']]}: {quoted(value['text'])}" for value in item["values"]
|
|
186
|
+
if value["ref"] in shown and value["name"] not in ALWAYS_SHOWN)
|
|
187
|
+
return "\n".join(lines)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def render_answer(answer: Any, item: Mapping[str, Any], digest: Mapping[str, Any] | None = None) -> str:
|
|
191
|
+
"""The item as Auditex shows it with the model's answer; AnswerCheckError when the answer does not pass."""
|
|
192
|
+
result = check_answer(answer, item, digest)
|
|
193
|
+
if not result["pass"]:
|
|
194
|
+
raise AnswerCheckError("; ".join(f"{f['check']}: {f['detail']}" for f in result["failures"]))
|
|
195
|
+
parsed, _ = _parse(answer, ITEM_KEYS)
|
|
196
|
+
return _render(item, parsed["use"], parsed["show"])
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def fallback_text(item: Mapping[str, Any]) -> str:
|
|
200
|
+
"""The fixed text an item shows when the model's answer fails the checks: the check and verdict frames, then the
|
|
201
|
+
severity and the reason only when the digest marks them as shipped catalogue text, so tenant data never changes
|
|
202
|
+
it."""
|
|
203
|
+
show = [value["ref"] for value in item["values"]
|
|
204
|
+
if value["name"] in ("severity", "reason") and value.get("source") == CATALOGUE]
|
|
205
|
+
return _render(item, [], show)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def answer_item(answer: Any, item: Mapping[str, Any], digest: Mapping[str, Any] | None = None) -> dict[str, Any]:
|
|
209
|
+
"""{"text", "fallback", "failures"}: the item rendered with the model's answer when it passes, else the fixed
|
|
210
|
+
text."""
|
|
211
|
+
result = check_answer(answer, item, digest)
|
|
212
|
+
if result["pass"]:
|
|
213
|
+
parsed, _ = _parse(answer, ITEM_KEYS)
|
|
214
|
+
return {"text": _render(item, parsed["use"], parsed["show"]), "fallback": False, "failures": []}
|
|
215
|
+
return {"text": fallback_text(item), "fallback": True, "failures": result["failures"]}
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def check_summary(answer: Any, digest: Mapping[str, Any]) -> dict[str, Any]:
|
|
219
|
+
"""{"pass": bool, "failures": [{"check", "detail"}]} for the model's run summary."""
|
|
220
|
+
failures: list[dict[str, str]] = []
|
|
221
|
+
|
|
222
|
+
def fail(check: str, detail: str) -> None:
|
|
223
|
+
failures.append({"check": check, "detail": detail[:160]})
|
|
224
|
+
|
|
225
|
+
parsed, problem = _parse(answer, SUMMARY_KEYS)
|
|
226
|
+
if parsed is None:
|
|
227
|
+
fail("form", problem or "the answer is not one JSON object")
|
|
228
|
+
return {"pass": False, "failures": failures}
|
|
229
|
+
limits, summary, highlight = frames()["limits"], parsed["summary"], parsed["highlight"]
|
|
230
|
+
if not _id_list(summary, str):
|
|
231
|
+
fail("form", "summary is not a list of run frame ids")
|
|
232
|
+
else:
|
|
233
|
+
bank = run_bank(digest)
|
|
234
|
+
if not summary:
|
|
235
|
+
fail("empty", "summary selects no frame")
|
|
236
|
+
if len(summary) > limits["summary"]:
|
|
237
|
+
fail("limit", f"summary selects {len(summary)} frames, more than {limits['summary']}")
|
|
238
|
+
for index, fid in enumerate(summary):
|
|
239
|
+
if fid in summary[:index]:
|
|
240
|
+
fail("duplicate", f"summary lists {fid} twice")
|
|
241
|
+
elif fid not in bank:
|
|
242
|
+
fail("precondition" if fid in frames()["run"] else "unknown",
|
|
243
|
+
f"{json.dumps(fid)[:40]} is not a run frame whose counts hold for this run")
|
|
244
|
+
if not _id_list(highlight, int):
|
|
245
|
+
fail("form", "highlight is not a list of item numbers")
|
|
246
|
+
else:
|
|
247
|
+
allowed, numbers = highlightable(digest), {item["item"] for item in digest["items"]}
|
|
248
|
+
if len(highlight) > limits["highlight"]:
|
|
249
|
+
fail("limit", f"highlight lists {len(highlight)} items, more than {limits['highlight']}")
|
|
250
|
+
for index, number in enumerate(highlight):
|
|
251
|
+
if number in highlight[:index]:
|
|
252
|
+
fail("duplicate", f"highlight lists item {number} twice")
|
|
253
|
+
elif number not in allowed:
|
|
254
|
+
fail("precondition" if number in numbers else "unknown",
|
|
255
|
+
f"item {number} is not an item the summary may highlight")
|
|
256
|
+
return {"pass": not failures, "failures": failures}
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def _render_summary(digest: Mapping[str, Any], summary: list[str], highlight: list[int]) -> str:
|
|
260
|
+
bank = run_bank(digest)
|
|
261
|
+
lines = [bank[fid] for fid in summary]
|
|
262
|
+
chosen = [item for item in digest["items"] if item["item"] in set(highlight)]
|
|
263
|
+
if chosen:
|
|
264
|
+
lines.append(frames()["highlight"]["heading"])
|
|
265
|
+
lines.extend(f"Check: {quoted(_check_name(item))}. Verdict: {VERDICT_TEXT[item['verdict']]}."
|
|
266
|
+
for item in chosen)
|
|
267
|
+
return "\n".join(lines)
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def fallback_summary(digest: Mapping[str, Any]) -> str:
|
|
271
|
+
"""The fixed run summary: every run frame without a precondition, in the frames file's order."""
|
|
272
|
+
unconditional = [fid for fid, frame in frames()["run"].items() if not frame["min"] and not frame["max"]]
|
|
273
|
+
return _render_summary(digest, unconditional, [])
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def render_summary(answer: Any, digest: Mapping[str, Any]) -> str:
|
|
277
|
+
"""The run summary as Auditex shows it with the model's answer; AnswerCheckError when it does not pass."""
|
|
278
|
+
result = check_summary(answer, digest)
|
|
279
|
+
if not result["pass"]:
|
|
280
|
+
raise AnswerCheckError("; ".join(f"{f['check']}: {f['detail']}" for f in result["failures"]))
|
|
281
|
+
parsed, _ = _parse(answer, SUMMARY_KEYS)
|
|
282
|
+
return _render_summary(digest, parsed["summary"], parsed["highlight"])
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def answer_summary(answer: Any, digest: Mapping[str, Any]) -> dict[str, Any]:
|
|
286
|
+
"""{"text", "fallback", "failures"}: the run summary with the model's answer when it passes, else the fixed one."""
|
|
287
|
+
result = check_summary(answer, digest)
|
|
288
|
+
if result["pass"]:
|
|
289
|
+
parsed, _ = _parse(answer, SUMMARY_KEYS)
|
|
290
|
+
return {"text": _render_summary(digest, parsed["summary"], parsed["highlight"]), "fallback": False,
|
|
291
|
+
"failures": []}
|
|
292
|
+
return {"text": fallback_summary(digest), "fallback": True, "failures": result["failures"]}
|