Skip to content
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 support to use KMS for signing EIF files when building them #20

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

eugkoira
Copy link

@eugkoira eugkoira commented Apr 12, 2024

Issue #, if available:
aws/aws-nitro-enclaves-cli#204

Description of changes:

This is a reworked version of #6 because it was abandoned

We extend EIF building functionality with additional option of signing EIF files with KMS.
sign_info parameter of EifBuilder now turned to a structure that contains enum for the signing key.
This enum can be represented as local private key (previous functionality)
or KMS signing key (implemented in COSE library).

Also a couple of wrappers and helper methods are introduced
to store initial information about signing keys and transform it to the keys itself.

The information about KMS signing key is represented as unique KMS key id string and optional
region string. In case region is missed it will be read from AWS_REGION environment variable
as a standard way for SDK configuration.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@eugkoira eugkoira mentioned this pull request Apr 12, 2024
Cargo.toml Outdated Show resolved Hide resolved
examples/eif_build.rs Outdated Show resolved Hide resolved
We extend EIF building functionality with additional option of signing EIF files with KMS.
sign_info parameter of EifBuilder now turned to a structure that contains enum for the signing key.
This enum can be represented as local private key (previous functionality)
or KMS signing key (implemented in COSE library).

Also a couple of wrappers and helper methods are introduced
to store initial information about signing keys and transform it to the keys itself.

The information about KMS signing key is represented as unique KMS key id string and optional
region string. In case region is missed it will be read from AWS_REGION environment variable
as a standard way for SDK configuration.

Signed-off-by: Eugene Koira <eugkoira@amazon.com>
Small part of reading and initializing key and certficate data is covered with tests.

Signed-off-by: Eugene Koira <eugkoira@amazon.com>
Signed-off-by: Eugene Koira <eugkoira@amazon.com>
Update minimum supported rust version (MSRV) to 1.68.2.

Signed-off-by: Eugene Koira <eugkoira@amazon.com>
@eugkoira eugkoira marked this pull request as ready for review April 18, 2024 16:10
Comment on lines +27 to +30
aws-sdk-kms = "<=1.20"
aws-config = "<=1.1"
aws-types = "<=1.1"
aws-smithy-runtime = { version = "<=1.2" }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for enforcing a maximal version? Consider adding it as a comment or in the commit message.

};

let sign_key_data = sign_key_info.map(|key_info| {
SignKeyData::new(&SignKeyDataInfo {
cert_path: signing_certificate.unwrap().to_string(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unwrap -> sign_key_info.zip(signing_certificate).map(|(key_info, certificate)| ...)

(None, Some(key_path)) => Some(SignKeyInfo::LocalPrivateKeyInfo {
path: key_path.to_string(),
}),
_ => panic!("kms-key-id and private-key parameters are mutually exclusive"),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: panic! -> unreachable!

pub private_key: Vec<u8>,
pub struct SignKeyDataInfo {
// Path to the certificate file
pub cert_path: String,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We should consider to use std::path::Path for all the paths

.await
.unwrap()
};
let runtime = Runtime::new().unwrap();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consider to map the unwrap to an Err(String) and use ?

signing_certificate,
signature,
signing_certificate: sign_info.cert.clone(),
signature: cose_sign.unwrap().as_bytes(false).unwrap(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use expect and explain why it is safe to unwrap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants