@@ -44,6 +44,11 @@ pub(crate) type KmsProviderList = Vec<KmsInfo>;
44
44
static CSFLE_LOCAL_KEY : Lazy < String > = Lazy :: new ( || get_env_var ( "CSFLE_LOCAL_KEY" ) ) ;
45
45
static FLE_AWS_KEY : Lazy < String > = Lazy :: new ( || get_env_var ( "FLE_AWS_KEY" ) ) ;
46
46
static FLE_AWS_SECRET : Lazy < String > = Lazy :: new ( || get_env_var ( "FLE_AWS_SECRET" ) ) ;
47
+ static FLE_AWS_TEMP_KEY : Lazy < String > = Lazy :: new ( || get_env_var ( "CSFLE_AWS_TEMP_ACCESS_KEY_ID" ) ) ;
48
+ static FLE_AWS_TEMP_SECRET : Lazy < String > =
49
+ Lazy :: new ( || get_env_var ( "CSFLE_AWS_TEMP_SECRET_ACCESS_KEY" ) ) ;
50
+ static FLE_AWS_TEMP_SESSION_TOKEN : Lazy < String > =
51
+ Lazy :: new ( || get_env_var ( "CSFLE_AWS_TEMP_SESSION_TOKEN" ) ) ;
47
52
static FLE_AZURE_TENANTID : Lazy < String > = Lazy :: new ( || get_env_var ( "FLE_AZURE_TENANTID" ) ) ;
48
53
static FLE_AZURE_CLIENTID : Lazy < String > = Lazy :: new ( || get_env_var ( "FLE_AZURE_CLIENTID" ) ) ;
49
54
static FLE_AZURE_CLIENTSECRET : Lazy < String > = Lazy :: new ( || get_env_var ( "FLE_AZURE_CLIENTSECRET" ) ) ;
@@ -61,13 +66,16 @@ static CSFLE_TLS_CERT_DIR: Lazy<String> = Lazy::new(|| get_env_var("CSFLE_TLS_CE
61
66
static CRYPT_SHARED_LIB_PATH : Lazy < String > = Lazy :: new ( || get_env_var ( "CRYPT_SHARED_LIB_PATH" ) ) ;
62
67
63
68
fn get_env_var ( name : & str ) -> String {
64
- std:: env:: var ( name) . unwrap_or_else ( |_| {
65
- panic ! (
66
- "Missing environment variable for {}. See src/test/csfle.rs for the list of required \
67
- variables and instructions for retrieving them.",
68
- name
69
- )
70
- } )
69
+ match std:: env:: var ( name) {
70
+ Ok ( v) if !v. is_empty ( ) => v,
71
+ _ => {
72
+ panic ! (
73
+ "Missing environment variable for {}. See src/test/csfle.rs for the list of \
74
+ required variables and instructions for retrieving them.",
75
+ name
76
+ )
77
+ }
78
+ }
71
79
}
72
80
73
81
pub ( crate ) static AWS_KMS : Lazy < KmsInfo > = Lazy :: new ( || {
@@ -80,6 +88,17 @@ pub(crate) static AWS_KMS: Lazy<KmsInfo> = Lazy::new(|| {
80
88
None ,
81
89
)
82
90
} ) ;
91
+ static AWS_TEMP_KMS : Lazy < KmsInfo > = Lazy :: new ( || {
92
+ (
93
+ KmsProvider :: aws ( ) ,
94
+ doc ! {
95
+ "accessKeyId" : & * FLE_AWS_TEMP_KEY ,
96
+ "secretAccessKey" : & * FLE_AWS_TEMP_SECRET ,
97
+ "sessionToken" : & * FLE_AWS_TEMP_SESSION_TOKEN ,
98
+ } ,
99
+ None ,
100
+ )
101
+ } ) ;
83
102
pub ( crate ) static AWS_KMS_NAME1 : Lazy < KmsInfo > = Lazy :: new ( || {
84
103
let aws_info = AWS_KMS . clone ( ) ;
85
104
( aws_info. 0 . with_name ( "name1" ) , aws_info. 1 , aws_info. 2 )
@@ -310,3 +329,39 @@ async fn fle2v2_ok(name: &str) -> bool {
310
329
}
311
330
true
312
331
}
332
+
333
+ pub ( crate ) fn fill_kms_placeholders (
334
+ kms_provider_map : std:: collections:: HashMap < mongocrypt:: ctx:: KmsProvider , Document > ,
335
+ ) -> KmsProviderList {
336
+ use mongocrypt:: ctx:: KmsProviderType ;
337
+
338
+ let placeholder = doc ! { "$$placeholder" : 1 } ;
339
+
340
+ let mut kms_providers = Vec :: new ( ) ;
341
+ for ( provider, mut config) in kms_provider_map {
342
+ // AWS uses temp creds if the "sessionToken" key is present in the config
343
+ let test_kms_provider = if * provider. provider_type ( ) == KmsProviderType :: Aws
344
+ && config. contains_key ( "sessionToken" )
345
+ {
346
+ Some ( & * AWS_TEMP_KMS )
347
+ } else {
348
+ ( * ALL_KMS_PROVIDERS ) . iter ( ) . find ( |( p, ..) | p == & provider)
349
+ } ;
350
+
351
+ for ( key, value) in config. iter_mut ( ) {
352
+ if value. as_document ( ) == Some ( & placeholder) {
353
+ let test_kms_provider = test_kms_provider
354
+ . unwrap_or_else ( || panic ! ( "missing config for {:?}" , provider) ) ;
355
+ let placeholder_value = test_kms_provider. 1 . get ( key) . unwrap_or_else ( || {
356
+ panic ! ( "provider config {:?} missing key {:?}" , provider, key)
357
+ } ) ;
358
+ * value = placeholder_value. clone ( ) ;
359
+ }
360
+ }
361
+
362
+ let tls_options = test_kms_provider. and_then ( |( _, _, tls_options) | tls_options. clone ( ) ) ;
363
+ kms_providers. push ( ( provider, config, tls_options) ) ;
364
+ }
365
+
366
+ kms_providers
367
+ }
0 commit comments