Skip to content
This repository has been archived by the owner on Nov 21, 2023. It is now read-only.

Commit

Permalink
Include the policy evaluation report in the Attestation Results Token
Browse files Browse the repository at this point in the history
Signed-off-by: Jiale Zhang <[email protected]>
  • Loading branch information
jialez0 committed Aug 11, 2023
1 parent 3300eab commit 08d2ca4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
14 changes: 6 additions & 8 deletions attestation-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub mod verifier;

use crate::token::AttestationTokenBroker;

use anyhow::{anyhow, bail, Context, Result};
use anyhow::{anyhow, Context, Result};
use as_types::SetPolicyInput;
use config::Config;
pub use kbs_types::{Attestation, Tee};
Expand Down Expand Up @@ -129,18 +129,16 @@ impl AttestationService {
.map_err(|e| anyhow!("Generate reference data failed{:?}", e))?;

// Now only support using default policy to evaluate
let (result, policy_engine_output) = self
let evaluation_report = self
.policy_engine
.evaluate(reference_data_map, tcb.clone(), None)
.await?;

if !result {
bail!("Policy Engine verification failed: {policy_engine_output}");
}
.await
.map_err(|e| anyhow!("Policy Engine evaluation failed: {e}"))?;

let token_claims = json!({
"tee-pubkey": attestation.tee_pubkey.clone(),
"tcb-status": flattened_claims
"tcb-status": flattened_claims,
"evaluation-report": evaluation_report,
});
let attestation_results_token = self.token_broker.issue(token_claims)?;

Expand Down
2 changes: 1 addition & 1 deletion attestation-service/src/policy_engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub trait PolicyEngine {
reference_data_map: HashMap<String, Vec<String>>,
input: String,
policy_id: Option<String>,
) -> Result<(bool, String)>;
) -> Result<String>;

async fn set_policy(&mut self, input: SetPolicyInput) -> Result<()>;
}
11 changes: 9 additions & 2 deletions attestation-service/src/policy_engine/opa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl PolicyEngine for OPA {
reference_data_map: HashMap<String, Vec<String>>,
input: String,
policy_id: Option<String>,
) -> Result<(bool, String)> {
) -> Result<String> {
let policy_file_path = format!(
"{}/{}.rego",
self.policy_dir_path
Expand Down Expand Up @@ -100,9 +100,16 @@ impl PolicyEngine for OPA {
return Err(anyhow!(res));
}

// If a clear approval opinion is given in the evaluation report,
// the rejection information will be reflected in the evaluation failure return value.
let res_kv: Value = serde_json::from_str(&res)?;
if let Some(allow) = res_kv["allow"].as_bool() {
if !allow {
bail!("Untrusted TEE evidence")
}
}

Ok((res_kv["allow"].as_bool().unwrap_or(false), res))
Ok(res)
}

async fn set_policy(&mut self, input: SetPolicyInput) -> Result<()> {
Expand Down

0 comments on commit 08d2ca4

Please sign in to comment.