feat: add rule AZ-CMP-005 Trusted Launch (Secure Boot + vTPM) check - #273
Conversation
AZ-CMP-005 collided with openshield-org#273 (Trusted Launch check), opened a day before this PR and already claiming that rule ID. Renumbered the rule file, playbook, tests, and all four compliance framework entries to AZ-CMP-006. Also fixes a false-positive gap flagged in review: the rule only checked for an NSG on the VMSS network interface configuration itself, missing the case where the NSG is attached at the subnet level instead. A VMSS whose NIC has no NSG but deploys into a subnet that does have one was being incorrectly flagged. Now resolves each network interface configuration's subnet (via the existing get_virtual_networks() collector, no new collector needed) and treats either a NIC-level or subnet-level NSG as compliant, matching how AZ-NET-010 already reads subnet.network_security_group. Added SOC2 to the rule's own FRAMEWORKS dict (was previously only in soc2.json, inconsistent with how several other rules, e.g. AZ-KV-006, already include it directly). Addresses review feedback from TFT444 and m-khan-97 on openshield-org#275. Signed-off-by: Dipesh Ray <dipesh.ray.g@gmail.com>
parthrohit22
left a comment
There was a problem hiding this comment.
nice work @shariqueahmad108-ship-it ,
Solid rule. I like that you didn't just flag every VM without Trusted Launch - you actually resolve Gen1 vs Gen2 via the OS disk and treat "can't determine" as NOT_APPLICABLE instead of guessing, which keeps this from throwing false positives on VMs that physically can't support it. Confidential VM carve-out is a nice touch too. Verified the SDK fields (security_type, uefi_settings, secure_boot_enabled, v_tpm_enabled, hyper_v_generation) against the real azure-mgmt-compute models, all match. 562 passed, clean lint. No conflict with #275's AZ-CMP-006. LGTM, approving.
Vishnu2707
left a comment
There was a problem hiding this comment.
One thing before merge though, the playbook uses RG=$1 and VM=$2 directly, with set -u that'll just crash instead of showing the usage message if someone runs it with no args. Same issue @TFT444 flagged on KV-006 before, just needs ${1:-} and ${2:-} like fix_az_net_016.sh already does. That should be a quick fix though.
| # Note: only supported on Gen2 VM sizes/images; the update requires a restart to take effect. | ||
|
|
||
| set -euo pipefail | ||
|
|
There was a problem hiding this comment.
please use ${1:-} and ${2:-} like how it is present in fix_az_net_016.sh to avoid further bugs
Use ${1:-}/${2:-} so running the playbook with missing arguments prints the
usage message and exits 1, instead of crashing on an unbound variable under
`set -euo pipefail`. Matches the convention in fix_az_net_016.sh.
Addresses review feedback from @Vishnu2707 on openshield-org#273.
Signed-off-by: shariqueahmad108-ship-it <shariqueahmad108@gmail.com>
|
Good catch @Vishnu2707 — fixed in 3415de1. Switched to |
TFT444
left a comment
There was a problem hiding this comment.
Single blocking issue: fix_az_cmp_005.sh uses RG=\ and VM=\ with set -u at the top. Running the script without arguments crashes before the usage message is printed. Change both to \ and , matching the pattern in fix_az_net_016.sh. Everything else looks good.
|
Thanks @TFT444 — that one's already handled: |
|
@shariqueahmad108-ship-it branch have conflict solve it please |
Adds a Compute scan rule that flags Generation 2 VMs which do not have Trusted Launch fully enabled (security type TrustedLaunch with both Secure Boot and vTPM on). Without them, unsigned or malicious code can run during boot and persist beneath the OS, evading OS-level antimalware and EDR. Generation 1 VMs cannot use Trusted Launch and are treated as NOT_APPLICABLE: a VM's list_all() representation does not carry its Hyper-V generation, so the rule resolves the OS disk's hyper_v_generation to confirm a VM is Gen2 before flagging, and never raises a false finding against Gen1 hardware. A security type already declared as TrustedLaunch is itself Gen2-only, so a Secure-Boot/vTPM-off VM there is flagged without a disk lookup. Confidential VMs (which provide Secure Boot and vTPM by construction) are out of scope, and a VM whose generation cannot be confirmed is left unflagged rather than risking a Gen1 false positive. Includes the remediation playbook (playbooks/cli/fix_az_cmp_005.sh) and maps the rule across the four compliance frameworks: NIST CSF PR.DS-6, ISO 27001 A.12.5.1, and SOC 2 CC6.8. CIS uses the repository's existing N/A convention (as in AZ-KV-001) because CIS Azure Foundations 2.0.0 has no dedicated Trusted Launch recommendation. Adds six unit tests covering the compliant, non-compliant Gen2, TrustedLaunch-declared-but-vTPM-off, Gen1 NOT_APPLICABLE, unknown-generation, and Confidential-VM cases. Closes openshield-org#269 Signed-off-by: shariqueahmad108-ship-it <shariqueahmad108@gmail.com>
Use ${1:-}/${2:-} so running the playbook with missing arguments prints the
usage message and exits 1, instead of crashing on an unbound variable under
`set -euo pipefail`. Matches the convention in fix_az_net_016.sh.
Addresses review feedback from @Vishnu2707 on openshield-org#273.
Signed-off-by: shariqueahmad108-ship-it <shariqueahmad108@gmail.com>
3415de1 to
67d21d7
Compare
What
Implements Rule 1 of #269 —
AZ-CMP-005, flagging Generation 2 VMs that don't have Trusted Launch (Secure Boot and vTPM) fully enabled. (Per the issue's Coordination note, the Managed Identity rule was descoped, so this PR is the sole remaining scope.)Follows the
scanner/rules/one-file-per-rule template, with the matching remediation playbook and compliance-framework mappings.Detection logic
security_type == "TrustedLaunch"and bothuefi_settings.secure_boot_enabledandv_tpm_enabledareTrue.list_all()representation doesn't carry its Hyper-V generation, so the rule resolves the OS disk'shyper_v_generation(viaazure_client.get_disk(), the same patternAZ-CMP-002uses) to confirm a VM is Gen2 before flagging. A readable Gen1 disk reportsV1and is skipped — no false finding against hardware that can't run Trusted Launch.security_type == "TrustedLaunch"but Secure Boot / vTPM off is Gen2-only by definition, so it's flagged without needing a disk lookup.AZ-CMP-002). Trade-off: a Gen2 VM whose disk generation can't be read is a possible false negative; I erred toward zero Gen1 false positives, but happy to switch to surfacing it as a distinct low-severity/unknown result if you'd prefer theAZ-CMP-002treatment.Compliance mappings (all four framework JSONs)
PR.DS-6A.12.5.1CC6.8N/A-CMP-005AZ-KV-001) rather than a fabricated control id — glad to renumber if there's a preferred mapping.Tests
Six unit tests added to
tests/test_rules_compute.py(mock-based, no network):V2) without a security profile → one MEDIUM findingTrustedLaunchdeclared but vTPM off → flagged without a disk lookupV1) → NOT_APPLICABLE, no findingHonest testing note
I don't have an Azure subscription, so I could not run the issue's "tested against a real Azure free-trial subscription" step — the live checkboxes below are left unchecked for a maintainer/reviewer to confirm. The rule is fully covered by the unit tests above (compliant / non-compliant / Gen1 / unknown / confidential) and the fixtures mirror the real SDK attribute shapes (
SecurityProfile.security_type,UefiSettings.secure_boot_enabled/v_tpm_enabled,Disk.hyper_v_generation).Test plan (from the issue)
fix_az_cmp_005.sh)Closes #269