Skip to content

Commit b5935a8

Browse files
committed
Use private-key parameter for KMS keys
This commit allows to pass KMS key ARN via the `--private-key` parameter. The underlying crate `aws-nitro-enclaves-image-format` will parse the given value and decide if a KMS key or a local key is given. Parameters `--kms-key-id` and `--kms-key-region` have been removed. Signed-off-by: Mark Kirichenko <[email protected]>
1 parent 0d405e8 commit b5935a8

File tree

11 files changed

+33
-260
lines changed

11 files changed

+33
-260
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ page_size = "0.6"
2020
signal-hook = "0.3"
2121
ciborium = "0.2"
2222
driver-bindings = { path = "./driver-bindings" }
23-
aws-nitro-enclaves-image-format = "0.4"
23+
aws-nitro-enclaves-image-format = "0.5"
2424
eif_loader = { path = "./eif_loader" }
2525
enclave_build = { path = "./enclave_build" }
2626
openssl = "0.10.66"

eif_loader/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ rust-version = "1.68"
88
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99

1010
[dependencies]
11-
aws-nitro-enclaves-image-format = "0.4"
11+
aws-nitro-enclaves-image-format = "0.5"
1212
nix = "0.26"
1313
libc = "0.2"
1414
vsock = "0.3"

enclave_build/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ url = "2.4"
2121
sha2 = "0.9.5"
2222
futures = "0.3.28"
2323

24-
aws-nitro-enclaves-image-format = "0.4"
24+
aws-nitro-enclaves-image-format = "0.5"
2525
tar = "0.4.40"
2626
flate2 = "1.0.28"

enclave_build/src/lib.rs

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ mod yaml_generator;
1212

1313
use aws_nitro_enclaves_image_format::defs::{EifBuildInfo, EifIdentityInfo, EIF_HDR_ARCH_ARM64};
1414
use aws_nitro_enclaves_image_format::utils::identity::parse_custom_metadata;
15-
use aws_nitro_enclaves_image_format::utils::{
16-
EifBuilder, SignKeyData, SignKeyDataInfo, SignKeyInfo,
17-
};
15+
use aws_nitro_enclaves_image_format::utils::{EifBuilder, SignKeyData};
1816
use docker::DockerUtil;
1917
use serde_json::json;
2018
use sha2::Digest;
@@ -71,9 +69,7 @@ impl<'a> Docker2Eif<'a> {
7169
output: &'a mut File,
7270
artifacts_prefix: String,
7371
certificate_path: &Option<String>,
74-
key_path: &Option<String>,
75-
kms_key_id: &Option<String>,
76-
kms_key_region: &Option<String>,
72+
private_key: &Option<String>,
7773
img_name: Option<String>,
7874
img_version: Option<String>,
7975
metadata_path: Option<String>,
@@ -102,31 +98,17 @@ impl<'a> Docker2Eif<'a> {
10298
}
10399
}
104100

105-
let sign_key_info = match (kms_key_id, key_path) {
106-
(None, None) => None,
107-
(Some(kms_id), None) => Some(SignKeyInfo::KmsKeyInfo {
108-
id: kms_id.into(),
109-
region: kms_key_region.clone(),
110-
}),
111-
(None, Some(key_path)) => Some(SignKeyInfo::LocalPrivateKeyInfo {
112-
path: key_path.into(),
113-
}),
114-
_ => return Err(Docker2EifError::SignArgsError),
101+
let sign_info = match (private_key, certificate_path) {
102+
(Some(key), Some(cert)) => SignKeyData::new(key, Path::new(&cert)).map_or_else(
103+
|e| {
104+
eprintln!("Could not read signing info: {:?}", e);
105+
None
106+
},
107+
Some,
108+
),
109+
_ => None,
115110
};
116111

117-
let sign_info = sign_key_info
118-
.map(|key_info| {
119-
SignKeyData::new(&SignKeyDataInfo {
120-
cert_path: certificate_path
121-
.as_ref()
122-
.ok_or(Docker2EifError::SignArgsError)?
123-
.into(),
124-
key_info,
125-
})
126-
.map_err(|_| Docker2EifError::SignArgsError)
127-
})
128-
.transpose()?;
129-
130112
Ok(Docker2Eif {
131113
docker_image,
132114
docker,

enclave_build/src/main.rs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use clap::{Arg, ArgAction, ArgGroup, Command};
4+
use clap::{Arg, ArgAction, Command};
55
use std::fs::OpenOptions;
66

77
use aws_nitro_enclaves_image_format::generate_build_info;
@@ -68,29 +68,14 @@ fn main() {
6868
.arg(
6969
Arg::new("signing-certificate")
7070
.long("signing-certificate")
71-
.help("Specify the path to the signing certificate"),
71+
.help("Specify the path to the signing certificate")
72+
.requires("private-key"),
7273
)
7374
.arg(
7475
Arg::new("private-key")
7576
.long("private-key")
76-
.help("Specify the path to the private-key"),
77-
)
78-
.arg(
79-
Arg::new("kms-key-id")
80-
.long("kms-key-id")
81-
.help("Specify unique id of the KMS key")
82-
)
83-
.arg(
84-
Arg::new("kms-key-region")
85-
.long("kms-key-region")
86-
.help("Specify region in which the KMS key resides")
87-
.requires("kms-key-id")
88-
)
89-
.group(
90-
ArgGroup::new("signing-key")
91-
.args(["kms-key-id", "private-key"])
92-
.multiple(false)
93-
.requires("signing-certificate")
77+
.help("Specify KMS key ARN or the path to the private key file")
78+
.requires("signing-certificate"),
9479
)
9580
.arg(
9681
Arg::new("build")
@@ -139,10 +124,6 @@ fn main() {
139124
let img_name = matches.get_one::<String>("image_name").map(String::from);
140125
let img_version = matches.get_one::<String>("image_version").map(String::from);
141126
let metadata = matches.get_one::<String>("metadata").map(String::from);
142-
let kms_key_id = matches.get_one::<String>("kms-key-id").map(String::from);
143-
let kms_key_region = matches
144-
.get_one::<String>("kms-key-region")
145-
.map(String::from);
146127

147128
let mut output = OpenOptions::new()
148129
.read(true)
@@ -163,8 +144,6 @@ fn main() {
163144
".".to_string(),
164145
&signing_certificate,
165146
&private_key,
166-
&kms_key_id,
167-
&kms_key_region,
168147
img_name,
169148
img_version,
170149
metadata,

src/common/commands_parser.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,8 @@ pub struct BuildEnclavesArgs {
106106
pub output: String,
107107
/// The path to the signing certificate for signed enclaves.
108108
pub signing_certificate: Option<String>,
109-
/// The path to the private key for signed enclaves.
109+
/// KMS key ARN or path to the private key for signed enclaves.
110110
pub private_key: Option<String>,
111-
/// ID of the KMS key for signed enclaves.
112-
pub kms_key_id: Option<String>,
113-
/// Region of the KMS key for signed enclaves.
114-
pub kms_key_region: Option<String>,
115111
/// The name of the enclave image.
116112
pub img_name: Option<String>,
117113
/// The version of the enclave image.
@@ -141,8 +137,6 @@ impl BuildEnclavesArgs {
141137
})?,
142138
signing_certificate: parse_signing_certificate(args),
143139
private_key: parse_private_key(args),
144-
kms_key_id: parse_kms_key_id(args),
145-
kms_key_region: parse_kms_key_region(args),
146140
img_name: parse_image_name(args),
147141
img_version: parse_image_version(args),
148142
metadata: parse_metadata(args),
@@ -528,14 +522,6 @@ fn parse_private_key(args: &ArgMatches) -> Option<String> {
528522
args.get_one::<String>("private-key").map(String::from)
529523
}
530524

531-
fn parse_kms_key_id(args: &ArgMatches) -> Option<String> {
532-
args.get_one::<String>("kms-key-id").map(String::from)
533-
}
534-
535-
fn parse_kms_key_region(args: &ArgMatches) -> Option<String> {
536-
args.get_one::<String>("kms-key-region").map(String::from)
537-
}
538-
539525
fn parse_image_name(args: &ArgMatches) -> Option<String> {
540526
args.get_one::<String>("image_name").map(String::from)
541527
}
@@ -565,7 +551,7 @@ mod tests {
565551
use crate::common::construct_error_message;
566552
use crate::create_app;
567553

568-
use clap::{Arg, ArgGroup, Command};
554+
use clap::{Arg, Command};
569555

570556
/// Parse the path of the JSON config file
571557
fn parse_config_file(args: &ArgMatches) -> NitroCliResult<String> {

src/lib.rs

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ pub fn build_enclaves(args: BuildEnclavesArgs) -> NitroCliResult<()> {
5858
&args.output,
5959
&args.signing_certificate,
6060
&args.private_key,
61-
&args.kms_key_id,
62-
&args.kms_key_region,
6361
&args.img_name,
6462
&args.img_version,
6563
&args.metadata,
@@ -75,8 +73,6 @@ pub fn build_from_docker(
7573
output_path: &str,
7674
signing_certificate: &Option<String>,
7775
private_key: &Option<String>,
78-
kms_key_id: &Option<String>,
79-
kms_key_region: &Option<String>,
8076
img_name: &Option<String>,
8177
img_version: &Option<String>,
8278
metadata_path: &Option<String>,
@@ -140,8 +136,6 @@ pub fn build_from_docker(
140136
artifacts_path()?,
141137
signing_certificate,
142138
private_key,
143-
kms_key_id,
144-
kms_key_region,
145139
img_name.clone(),
146140
img_version.clone(),
147141
metadata_path.clone(),
@@ -713,29 +707,14 @@ macro_rules! create_app {
713707
.arg(
714708
Arg::new("signing-certificate")
715709
.long("signing-certificate")
716-
.help("Local path to developer's X509 signing certificate."),
710+
.help("Local path to developer's X509 signing certificate.")
711+
.requires("private-key"),
717712
)
718713
.arg(
719714
Arg::new("private-key")
720715
.long("private-key")
721-
.help("Local path to developer's Eliptic Curve private key."),
722-
)
723-
.arg(
724-
Arg::new("kms-key-id")
725-
.long("kms-key-id")
726-
.help("Specify unique id of the KMS key")
727-
)
728-
.arg(
729-
Arg::new("kms-key-region")
730-
.long("kms-key-region")
731-
.help("Specify region in which the KMS key resides")
732-
.requires("kms-key-id")
733-
)
734-
.group(
735-
ArgGroup::new("signing-key")
736-
.args(&["kms-key-id", "private-key"])
737-
.multiple(false)
738-
.requires("signing-certificate")
716+
.help("KMS key ARN or local path to developer's Eliptic Curve private key.")
717+
.requires("signing-certificate"),
739718
)
740719
.arg(
741720
Arg::new("image_name")

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
extern crate lazy_static;
1010

11-
use clap::{Arg, ArgGroup, Command};
11+
use clap::{Arg, Command};
1212
use log::info;
1313
use std::os::unix::net::UnixStream;
1414

0 commit comments

Comments
 (0)