Skip to content

Commit be7eda5

Browse files
committed
attestation_policy: unify the PCR path across platforms
Previously, attestation policies had to handle different PCR path formats: - Azure SNP: input.azsnpvtpm.tpm.pcr01 - Azure TDX: input.aztdxvtpm.tpm.pcr01 - Local TPM: input.tpm.pcr[1] This change introduces a generic `get_by_path()` helper and rewrites PCR validation rules to dynamically traverse nested objects based on a platform-specific path array. As a result, the same set of rules can now be reused for multiple platforms without duplicating policy logic. Benefits: - Removes platform-specific hardcoding from rules - Simplifies maintenance and extension to future platforms - Makes PCR verification more consistent and extensible Signed-off-by: Fangge Jin <[email protected]>
1 parent 6266e84 commit be7eda5

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

policy/attestation-policy.rego

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ default configuration := 36
2929

3030
##### Azure vTPM SNP
3131
executables := 3 if {
32+
platform := detect_platform
3233
input.azsnpvtpm.measurement in data.reference.measurement
33-
input.azsnpvtpm.tpm.pcr4 in data.reference.snp_pcr04
34-
input.azsnpvtpm.tpm.pcr7 in data.reference.snp_pcr07
35-
input.azsnpvtpm.tpm.pcr11 in data.reference.snp_pcr11
34+
pcr_match(platform, "pcr04", data.reference.pcr04)
35+
pcr_match(platform, "pcr07", data.reference.pcr07)
3636
}
3737

3838
hardware := 2 if {
@@ -52,3 +52,35 @@ configuration := 2 if {
5252
input.azsnpvtpm.policy_smt_allowed in data.reference.smt_allowed
5353
}
5454

55+
##### PCRs check for any platform
56+
platform_paths := {
57+
"azure-snp": ["azsnpvtpm", "tpm"],
58+
"azure-tdx": ["aztdxvtpm", "tpm"],
59+
"raw": ["tpm"]
60+
}
61+
62+
detect_platform := "azure-snp" if {
63+
input.azsnpvtpm
64+
} else := "azure-tdx" if {
65+
input.aztdxvtpm
66+
} else := "raw"
67+
68+
get_by_path(obj, path) = result if {
69+
result := object.get(obj, path, false)
70+
}
71+
72+
get_pcr_value(platform, pcr_name) = value if {
73+
platform != "raw"
74+
tpm := get_by_path(input, platform_paths[platform])
75+
value := tpm[pcr_name]
76+
}
77+
78+
get_pcr_value("raw", pcr_name) = value if {
79+
tpm := get_by_path(input, platform_paths["raw"])
80+
idx := to_number(trim_prefix(pcr_name, "pcr"))
81+
value := tpm.pcr[idx]
82+
}
83+
84+
pcr_match(platform, pcr_name, expected_values) if {
85+
lower(get_pcr_value(platform, pcr_name)) in expected_values
86+
}

0 commit comments

Comments
 (0)