-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add trustee-agent - a simple tool to fetch secrets from Trustee #791
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
33 changes: 33 additions & 0 deletions
33
attestation-agent/kbs_protocol/src/bin/trustee-attester/README.md
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,33 @@ | ||
# Trustee attester # | ||
|
||
A tool to attest and fetch secrets from Trustee | ||
|
||
Trustee attester is a part of [confidential-containers](https://github.com/confidential-containers) | ||
[guest-components](https://github.com/confidential-containers/guest-components) | ||
project but can be used for confidential VMs as well. | ||
|
||
Trustee attester is using attestation-agent's kbs_protocol client and | ||
attesters to gather hardware-based confidential-computing evidence | ||
and send it over to Trustee. | ||
|
||
A resource with exact same path must be uploaded to Trustee before trustee-attester runs. | ||
|
||
|
||
## Build: ## | ||
|
||
```bash | ||
cargo build -p kbs_protocol --bin trustee-attester --no-default-features | ||
--features "background_check,passport,<openssl|rust-crypto>,bin,<attesters-list>" | ||
``` | ||
|
||
## Run: ## | ||
|
||
```bash | ||
$ trustee-attester --url <Trustee-URL> [--cert-file <path>] get-resource --path <resource-path> | ||
``` | ||
|
||
## Example: ## | ||
|
||
```bash | ||
$ trustee-attester --url http://localhost:50000 get-resource --path default/keys/dummy | ||
``` |
90 changes: 90 additions & 0 deletions
90
attestation-agent/kbs_protocol/src/bin/trustee-attester/main.rs
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,90 @@ | ||
// Copyright (c) 2023 by Alibaba. | ||
// Copyright (c) 2024 Red Hat, Inc | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//! Attest and fetch confidential resources from Trustee | ||
|
||
use anyhow::Result; | ||
use base64::engine::general_purpose::STANDARD; | ||
use base64::Engine; | ||
use clap::{Parser, Subcommand}; | ||
use log::debug; | ||
use std::fs; | ||
use std::path::PathBuf; | ||
|
||
use kbs_protocol::evidence_provider::NativeEvidenceProvider; | ||
use kbs_protocol::KbsClientBuilder; | ||
use kbs_protocol::KbsClientCapabilities; | ||
use kbs_protocol::ResourceUri; | ||
|
||
#[derive(Parser)] | ||
struct Cli { | ||
/// Trustee URL of format <protocol>://<host>:<port> | ||
#[clap(long, value_parser)] | ||
url: String, | ||
|
||
/// Trustee https certificate file path (PEM format) | ||
#[clap(long, value_parser)] | ||
cert_file: Option<PathBuf>, | ||
|
||
#[clap(subcommand)] | ||
command: Commands, | ||
} | ||
|
||
#[derive(Subcommand)] | ||
enum Commands { | ||
/// Get confidential resource | ||
#[clap(arg_required_else_help = true)] | ||
GetResource { | ||
/// KBS Resource path of format <repository>/<type>/<tag> | ||
/// Document: https://github.com/confidential-containers/guest-components/blob/main/attestation-agent/docs/KBS_URI.md | ||
#[clap(long, value_parser)] | ||
path: String, | ||
}, | ||
} | ||
|
||
#[tokio::main(flavor = "current_thread")] | ||
async fn main() -> Result<()> { | ||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); | ||
|
||
let cli = Cli::parse(); | ||
|
||
let url = cli.url; | ||
let cert_file = cli.cert_file; | ||
|
||
debug!("url {}", url); | ||
debug!("cert_file {:?}", cert_file); | ||
|
||
// Native evidence provider | ||
let evidence_provider = Box::new(NativeEvidenceProvider::new()?); | ||
|
||
// a kbs_protocol client with evidence_provider | ||
let mut client_builder = KbsClientBuilder::with_evidence_provider(evidence_provider, &url); | ||
|
||
// if a certificate is given, use it | ||
if let Some(cf) = cert_file { | ||
debug!("Reading certificate from cert_file {}", cf.display()); | ||
let cert = fs::read_to_string(cf)?; | ||
client_builder = client_builder.add_kbs_cert(&cert) | ||
} | ||
|
||
// Build the client. This client is used throughout the program | ||
let mut client = client_builder.build()?; | ||
|
||
match cli.command { | ||
Commands::GetResource { path } => { | ||
// resource_path should start with '/' but not with '//' | ||
let resource_path = match path.starts_with('/') { | ||
false => format!("/{}", path), | ||
true => path, | ||
}; | ||
let resource = ResourceUri::new("", &resource_path)?; | ||
let resource_bytes = client.get_resource(resource).await?; | ||
|
||
println!("{}", STANDARD.encode(resource_bytes)); | ||
} | ||
}; | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The preview looks good, while we do not need the
#
in the end of the line when making headings. https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#headings