|
1 | 1 | use std::time::Duration; |
2 | 2 |
|
3 | 3 | use aws_config::timeout::TimeoutConfig; |
4 | | -use aws_credential_types::provider::future; |
5 | | -use aws_credential_types::provider::ProvideCredentials; |
| 4 | +use aws_credential_types::Credentials; |
6 | 5 | use aws_sdk_kms::types::SigningAlgorithmSpec; |
7 | 6 | use aws_sdk_kms::{ |
8 | | - config::{Credentials, Region}, |
| 7 | + config::Region, |
9 | 8 | primitives::Blob, |
10 | 9 | Client, |
11 | 10 | }; |
@@ -39,9 +38,9 @@ pub struct KmsKeyDefinition { |
39 | 38 | #[derive(Clone, Debug, Deserialize)] |
40 | 39 | pub struct Config { |
41 | 40 | /// The AWS access key that can access the KMS keys |
42 | | - aws_access_key_id: String, |
| 41 | + aws_access_key_id: Option<String>, |
43 | 42 | /// The secret corresponding to the AWS access key |
44 | | - aws_secret_access_key: String, |
| 43 | + aws_secret_access_key: Option<String>, |
45 | 44 | /// The region to be used |
46 | 45 | aws_region: String, |
47 | 46 |
|
@@ -91,21 +90,6 @@ pub struct AmazonKMSSigner { |
91 | 90 | client: Client, |
92 | 91 | } |
93 | 92 |
|
94 | | -impl ProvideCredentials for Config { |
95 | | - fn provide_credentials<'a>(&'a self) -> future::ProvideCredentials<'a> |
96 | | - where |
97 | | - Self: 'a, |
98 | | - { |
99 | | - future::ProvideCredentials::ready(Ok(Credentials::new( |
100 | | - self.aws_access_key_id.clone(), |
101 | | - self.aws_secret_access_key.clone(), |
102 | | - None, |
103 | | - None, |
104 | | - "AmazonKMSSigner", |
105 | | - ))) |
106 | | - } |
107 | | -} |
108 | | - |
109 | 93 | pub struct KmsRcgenRemoteSigner { |
110 | 94 | x509_public_key: Vec<u8>, |
111 | 95 | /// The id to lookup the private portion of the X509 key in Amazon KMS |
@@ -275,12 +259,28 @@ impl SignerConfig for Config { |
275 | 259 | .operation_attempt_timeout(Duration::from_secs(10)) |
276 | 260 | .operation_timeout(Duration::from_secs(10)) |
277 | 261 | .build(); |
278 | | - let aws_config = aws_config::from_env() |
279 | | - .timeout_config(timeout_config) |
280 | | - .region(Region::new(self.aws_region.clone())) |
281 | | - .credentials_provider(self.clone()) |
282 | | - .load() |
283 | | - .await; |
| 262 | + let aws_config = match (self.aws_access_key_id, self.aws_secret_access_key) { |
| 263 | + (Some(_), None) => return Err( |
| 264 | + SigningError::InvalidAwsConfig("aws_access_key_id is defined but aws_secret_access_key is not defined".to_string()) |
| 265 | + ), |
| 266 | + (None, Some(_)) => return Err( |
| 267 | + SigningError::InvalidAwsConfig("aws_secret_access_key is defined but aws_access_key_id is not defined".to_string()) |
| 268 | + ), |
| 269 | + (Some(access_key_id), Some(secret_access_key)) => aws_config::from_env() |
| 270 | + .region(Region::new(self.aws_region.clone())) |
| 271 | + .credentials_provider( |
| 272 | + Credentials::new(access_key_id, secret_access_key, None, None, "AmazonKMSSigner") |
| 273 | + ) |
| 274 | + .load() |
| 275 | + .await, |
| 276 | + // If access key is not defined, use the default config |
| 277 | + (None, None) => aws_config::from_env() |
| 278 | + .timeout_config(timeout_config) |
| 279 | + .region(Region::new(self.aws_region.clone())) |
| 280 | + .load() |
| 281 | + .await, |
| 282 | + }; |
| 283 | + |
284 | 284 | let client = Client::new(&aws_config); |
285 | 285 |
|
286 | 286 | let ssh_keys = match (self.user_key, self.host_key) { |
|
0 commit comments