Skip to content

Commit

Permalink
aa: fix kbs_host_addr extraction from agent config
Browse files Browse the repository at this point in the history
Signed-off-by: Magnus Kulke <[email protected]>
  • Loading branch information
mkulke authored and fitzthum committed Oct 4, 2023
1 parent f4f89da commit ebceb0c
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions attestation-agent/lib/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ pub(crate) async fn get_kbs_token() -> Result<Vec<u8>> {

// Check for /peerpod/daemon.json to see if we are in a peer pod
// If so we need to read from the agent-config file, not /proc/cmdline
let kbs_host_addr = match Path::new(PEER_POD_CONFIG_PATH).exists() {
true => get_kbs_host_from_config_file().await?,
false => get_kbs_host_from_cmdline().await?,
let kbc_params = match Path::new(PEER_POD_CONFIG_PATH).exists() {
true => get_kbc_params_from_config_file().await?,
false => get_kbc_params_from_cmdline().await?,
};

let kbs_host_url = extract_kbs_host_url(&kbc_params)?;

let mut client =
KbsClientBuilder::with_evidence_provider(evidence_provider, &kbs_host_addr).build()?;
KbsClientBuilder::with_evidence_provider(evidence_provider, &kbs_host_url).build()?;

let (token, tee_keypair) = client.get_token().await?;
let message = Message {
Expand All @@ -40,25 +42,31 @@ pub(crate) async fn get_kbs_token() -> Result<Vec<u8>> {
Ok(res)
}

pub(crate) async fn get_kbs_host_from_cmdline() -> Result<String> {
fn extract_kbs_host_url(kbc_params: &str) -> Result<String> {
let kbs_host = kbc_params
.split("::")
.last()
.ok_or(anyhow!("illegal input `agent.aa_kbc_params` format",))?
.to_string();

Ok(kbs_host)
}

pub(crate) async fn get_kbc_params_from_cmdline() -> Result<String> {
let cmdline = fs::read_to_string("/proc/cmdline").await?;
let kbs_host = cmdline
let kbc_params = cmdline
.split_ascii_whitespace()
.find(|para| para.starts_with("agent.aa_kbc_params="))
.ok_or(anyhow!(
"no `agent.aa_kbc_params` provided in kernel commandline!",
))?
.strip_prefix("agent.aa_kbc_params=")
.expect("must have one")
.split("::")
.last()
.ok_or(anyhow!("illegal input `agent.aa_kbc_params` format",))?
.to_string();

Ok(kbs_host)
Ok(kbc_params)
}

pub(crate) async fn get_kbs_host_from_config_file() -> Result<String> {
pub(crate) async fn get_kbc_params_from_config_file() -> Result<String> {
// We only care about the aa_kbc_params value at the moment
#[derive(Debug, Deserialize)]
struct AgentConfig {
Expand Down

0 comments on commit ebceb0c

Please sign in to comment.