-
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.
feat(keybroker-server): Use Rego to appraise EARs
Use Rego to implement the appraisal policy for attestation results. A default policy is hardcoded (see keybroker-server/src/policy.rego). The user may provide their own policy to override the default using the `--policy` command line switch. The user must provide a JSON file containing one or more RIM reference values. Fix #13 Signed-off-by: Thomas Fossati <thomas.fossati@linaro.org>
- Loading branch information
1 parent
f8bc788
commit 3d66ee0
Showing
9 changed files
with
183 additions
and
10 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
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,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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2024 Contributors to the Veraison project. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use regorus::{self, Value}; | ||
|
||
use crate::error::Result; | ||
|
||
// Evaluate an EAR claims-set against the appraisal policy and known-good RIM values | ||
pub(crate) fn rego_eval( | ||
custom_policy: Option<String>, | ||
rims: &str, | ||
ear_claims: &str, | ||
) -> Result<Value> { | ||
const POLICY: &str = include_str!("policy.rego"); | ||
|
||
// Create engine. | ||
let mut engine = regorus::Engine::new(); | ||
|
||
engine.set_rego_v1(true); | ||
engine.set_strict_builtin_errors(false); | ||
|
||
// Add the appraisal policy | ||
match custom_policy { | ||
None => { | ||
engine.add_policy(String::from("policy.rego"), String::from(POLICY))?; | ||
} | ||
Some(file) => { | ||
engine.add_policy_from_file(file)?; | ||
} | ||
} | ||
|
||
// Load the configured known good RIM values | ||
engine.add_data(Value::from_json_file(rims)?)?; | ||
|
||
// Set the EAR claims-set to be appraised | ||
engine.set_input(Value::from_json_str(ear_claims)?); | ||
|
||
let results = engine.eval_rule("data.arm_cca.allow".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 rims = stringify_testdata_path("rims-matching.json"); | ||
|
||
let results = rego_eval(None, &rims, 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 rims = stringify_testdata_path("rims-not-matching.json"); | ||
|
||
let results = rego_eval(None, &rims, 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=" | ||
] | ||
} |