-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from veraison/policy
feat(keybroker-server): Use Rego to appraise EARs
- Loading branch information
Showing
10 changed files
with
239 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Reference Values | ||
|
||
## Arm CCA | ||
|
||
The Arm CCA appraisal policy requires the user to provide one or more RIM values corresponding to known and trusted Realm workloads. | ||
|
||
The reference values must be provided in a JSON file that conforms to the following CDDL grammar: | ||
|
||
```cddl | ||
start = { | ||
"reference-values": [ + b64-rim ] | ||
} | ||
b64-rim = text .b64c rim | ||
rim = bytes .size 32 | ||
``` | ||
|
||
Note that the RIM values are Base64-encoded and that there must be at least one. | ||
|
||
### Example | ||
|
||
The following contains reference values for three trusted workloads: | ||
|
||
```json | ||
{ | ||
"reference-values": [ | ||
"MRMUq3NiA1DPdYg0rlxl2ejC3H/r5ufZZUu+hk4wDUk=", | ||
"q3N/r5ufZZUu+iAg0rlxl2ejC3HMRMUhk4wDUk1DPdY=", | ||
"UvZTSVUJ6IZtdtK0GEa5nueYxDcEJDa2vNHYL6RhQbs=" | ||
] | ||
} | ||
``` | ||
|
||
### Mock mode | ||
|
||
In "mock" mode, the keybroker server must be started using the following command line: | ||
|
||
```sh | ||
keybroker-server \ | ||
--mock-challenge \ | ||
--verbose \ | ||
--reference-values <(echo '{ "reference-values": [ "MRMUq3NiA1DPdYg0rlxl2ejC3H/r5ufZZUu+hk4wDUk=" ] }') | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package arm_cca | ||
|
||
default allow := false | ||
|
||
allow if { | ||
input.eat_profile == "tag:github.com,2023:veraison/ear" | ||
|
||
# platform part | ||
prec := input.submods.CCA_SSD_PLATFORM | ||
prec["ear.status"] == "affirming" | ||
|
||
# realm part | ||
rrec := input.submods.CCA_REALM | ||
rrec["ear.status"] == "warning" | ||
|
||
rtv := rrec["ear.trustworthiness-vector"] | ||
rtv["instance-identity"] == 2 | ||
|
||
# check RIM value against known-good-values | ||
rclaims := rrec["ear.veraison.annotated-evidence"] | ||
rim := rclaims["cca-realm-initial-measurement"] | ||
rim in data["reference-values"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright 2024 Contributors to the Veraison project. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::error::Result; | ||
use phf::{phf_map, Map}; | ||
use regorus::{self, Value}; | ||
|
||
pub static MEDIATYPES_TO_POLICY: Map<&'static str, (&'static str, &'static str)> = phf_map! { | ||
r#"application/eat-collection; profile="http://arm.com/CCA-SSD/1.0.0""# => ( include_str!("arm-cca.rego"), "data.arm_cca.allow" ), | ||
// Other, future mappings | ||
}; | ||
|
||
// Evaluate an EAR claims-set against the appraisal policy and known-good RIM values | ||
pub(crate) fn rego_eval( | ||
policy: &str, | ||
policy_rule: &str, | ||
reference_values: &str, | ||
ear_claims: &str, | ||
) -> Result<Value> { | ||
// Create engine. | ||
let mut engine = regorus::Engine::new(); | ||
|
||
engine.set_rego_v1(true); | ||
engine.set_strict_builtin_errors(false); | ||
|
||
// Add the appraisal policy | ||
engine.add_policy(String::from("policy.rego"), String::from(policy))?; | ||
|
||
// Load the configured known good RIM values | ||
engine.add_data(Value::from_json_file(reference_values)?)?; | ||
|
||
// Set the EAR claims-set to be appraised | ||
engine.set_input(Value::from_json_str(ear_claims)?); | ||
|
||
let results = engine.eval_rule(policy_rule.to_string())?; | ||
|
||
Ok(results) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn rego_eval_ear_default_policy_ok() { | ||
let ear_claims = include_str!("../../../testdata/ear-claims-ok.json"); | ||
let reference_values = stringify_testdata_path("rims-matching.json"); | ||
|
||
let results = rego_eval( | ||
include_str!("arm-cca.rego"), | ||
"data.arm_cca.allow", | ||
&reference_values, | ||
ear_claims, | ||
) | ||
.expect("successful eval"); | ||
|
||
assert_eq!(results.to_string(), "true"); | ||
} | ||
|
||
#[test] | ||
fn rego_eval_default_policy_unmatched_rim() { | ||
let ear_claims = include_str!("../../../testdata/ear-claims-ok.json"); | ||
let reference_values = stringify_testdata_path("rims-not-matching.json"); | ||
|
||
let results = rego_eval( | ||
include_str!("arm-cca.rego"), | ||
"data.arm_cca.allow", | ||
&reference_values, | ||
ear_claims, | ||
) | ||
.expect("successful eval"); | ||
|
||
assert_eq!(results.to_string(), "false"); | ||
} | ||
|
||
fn stringify_testdata_path(s: &str) -> String { | ||
let mut test_data = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
|
||
test_data.push("../../testdata"); | ||
test_data.push(s); | ||
|
||
test_data.into_os_string().into_string().unwrap() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"eat_nonce": "bobW2XzHE7xt1D285JGmtAMRwCeov4WjnaY-nORMEyqKEZ0pb65qaZnpvz5EcbDOASRdiJQkwx6JeTs7HWsVBA==", | ||
"eat_profile": "tag:github.com,2023:veraison/ear", | ||
"submods": { | ||
"CCA_REALM": { | ||
"ear.status": "warning", | ||
"ear.trustworthiness-vector": { | ||
"configuration": 0, | ||
"executables": 33, | ||
"file-system": 0, | ||
"hardware": 0, | ||
"instance-identity": 2, | ||
"runtime-opaque": 0, | ||
"sourced-data": 0, | ||
"storage-opaque": 0 | ||
}, | ||
"ear.veraison.annotated-evidence": { | ||
"cca-realm-challenge": "bobW2XzHE7xt1D285JGmtAMRwCeov4WjnaY+nORMEyqKEZ0pb65qaZnpvz5EcbDOASRdiJQkwx6JeTs7HWsVBA==", | ||
"cca-realm-extensible-measurements": [ | ||
"JNWwopbMBcvYBoxQZ8W9Rzt3Ddpq4IL+O6MKvj+aarE=", | ||
"eI/AkL/GuO2QMVK6hBTnPa9bjHux55rVAqsGmbZZ7RY=", | ||
"2sRqWEFdw6ANenQYUgCOnK5k9S0DufdtdvSzZE/vxBY=", | ||
"MsavxiflVYXAMVU1nzMaDiJfaEDblH3Zbvq4G+JnGTk=" | ||
], | ||
"cca-realm-hash-algo-id": "sha-256", | ||
"cca-realm-initial-measurement": "MRMUq3NiA1DPdYg0rlxl2ejC3H/r5ufZZUu+hk4wDUk=", | ||
"cca-realm-personalization-value": "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIDEzIGxhenkgZG9ncy5UaGUgcXVpY2sgYnJvd24gZm94IA==", | ||
"cca-realm-public-key": "BHb5iAkb5YXtQYAa7Pq4WFSMYwV+FrDmdhILvQ0vnCngVsXUGgEw65whUXiZ3CMUayjhsGK9PqSzFf0hnxy7Uoy250ykm+Fnc3NPYaHKYQMbK789kY8vlP/EIo5QkZVErg==", | ||
"cca-realm-public-key-hash-algo-id": "sha-256" | ||
} | ||
}, | ||
"CCA_SSD_PLATFORM": { | ||
"ear.status": "affirming" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"reference-values": [ | ||
"MRMUq3NiA1DPdYg0rlxl2ejC3H/r5ufZZUu+hk4wDUk=", | ||
"q3N/r5ufZZUu+iAg0rlxl2ejC3HMRMUhk4wDUk1DPdY=" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"reference-values": [ | ||
"XRMUq3NiA1DPdYg0rlxl2ejC3H/r5ufZZUu+hk4wDUk=", | ||
"X3N/r5ufZZUu+iAg0rlxl2ejC3HMRMUhk4wDUk1DPdY=" | ||
] | ||
} |