Skip to content

Commit eb0fca1

Browse files
RUST-1699 / RUST-1718 AWS authentication fixes (#926)
1 parent 6cdffa5 commit eb0fca1

File tree

3 files changed

+44
-16
lines changed

3 files changed

+44
-16
lines changed

.evergreen/config.yml

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,18 @@ functions:
859859
${PREPARE_SHELL}
860860
${DRIVERS_TOOLS}/.evergreen/run-load-balancer.sh stop
861861
862+
"tear down aws":
863+
- command: shell.exec
864+
params:
865+
shell: "bash"
866+
script: |
867+
${PREPARE_SHELL}
868+
cd "${DRIVERS_TOOLS}/.evergreen/auth_aws"
869+
if [ -f "./aws_e2e_setup.json" ]; then
870+
. ./activate-authawsvenv.sh
871+
python ./lib/aws_assign_instance_profile.py
872+
fi
873+
862874
"upload test results":
863875
- command: attach.xunit_results
864876
params:
@@ -878,6 +890,7 @@ pre:
878890
post:
879891
- func: "stop load balancer"
880892
- func: "stop mongo orchestration"
893+
- func: "tear down aws"
881894
- func: "upload test results"
882895
- func: "upload-mo-artifacts"
883896
- func: "cleanup"
@@ -1019,8 +1032,8 @@ tasks:
10191032
- func: "run aws auth test with assume role credentials"
10201033
- func: "run aws auth test with aws credentials as environment variables"
10211034
- func: "run aws auth test with aws credentials and session token as environment variables"
1022-
# - func: "run aws auth test with aws EC2 credentials"
1023-
# - func: "run aws ECS auth test"
1035+
- func: "run aws auth test with aws EC2 credentials"
1036+
- func: "run aws ECS auth test"
10241037
- func: "run aws assume role with web identity test"
10251038

10261039
- name: "test-5.0-standalone"
@@ -1081,8 +1094,8 @@ tasks:
10811094
- func: "run aws auth test with assume role credentials"
10821095
- func: "run aws auth test with aws credentials as environment variables"
10831096
- func: "run aws auth test with aws credentials and session token as environment variables"
1084-
# - func: "run aws auth test with aws EC2 credentials"
1085-
# - func: "run aws ECS auth test"
1097+
- func: "run aws auth test with aws EC2 credentials"
1098+
- func: "run aws ECS auth test"
10861099
- func: "run aws assume role with web identity test"
10871100

10881101
- name: "test-6.0-standalone"
@@ -1143,8 +1156,8 @@ tasks:
11431156
- func: "run aws auth test with assume role credentials"
11441157
- func: "run aws auth test with aws credentials as environment variables"
11451158
- func: "run aws auth test with aws credentials and session token as environment variables"
1146-
# - func: "run aws auth test with aws EC2 credentials"
1147-
# - func: "run aws ECS auth test"
1159+
- func: "run aws auth test with aws EC2 credentials"
1160+
- func: "run aws ECS auth test"
11481161
- func: "run aws assume role with web identity test"
11491162

11501163
- name: "test-7.0-standalone"
@@ -1205,8 +1218,8 @@ tasks:
12051218
- func: "run aws auth test with assume role credentials"
12061219
- func: "run aws auth test with aws credentials as environment variables"
12071220
- func: "run aws auth test with aws credentials and session token as environment variables"
1208-
# - func: "run aws auth test with aws EC2 credentials"
1209-
# - func: "run aws ECS auth test"
1221+
- func: "run aws auth test with aws EC2 credentials"
1222+
- func: "run aws ECS auth test"
12101223
- func: "run aws assume role with web identity test"
12111224

12121225
- name: "test-rapid-standalone"
@@ -1267,8 +1280,8 @@ tasks:
12671280
- func: "run aws auth test with assume role credentials"
12681281
- func: "run aws auth test with aws credentials as environment variables"
12691282
- func: "run aws auth test with aws credentials and session token as environment variables"
1270-
# - func: "run aws auth test with aws EC2 credentials"
1271-
# - func: "run aws ECS auth test"
1283+
- func: "run aws auth test with aws EC2 credentials"
1284+
- func: "run aws ECS auth test"
12721285
- func: "run aws assume role with web identity test"
12731286

12741287
- name: "test-latest-standalone"
@@ -1330,8 +1343,8 @@ tasks:
13301343
- func: "run aws auth test with assume role credentials"
13311344
- func: "run aws auth test with aws credentials as environment variables"
13321345
- func: "run aws auth test with aws credentials and session token as environment variables"
1333-
# - func: "run aws auth test with aws EC2 credentials"
1334-
# - func: "run aws ECS auth test"
1346+
- func: "run aws auth test with aws EC2 credentials"
1347+
- func: "run aws ECS auth test"
13351348
- func: "run aws assume role with web identity test"
13361349

13371350
- name: "test-connection-string"

src/client/auth/aws.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub(crate) struct AwsCredential {
167167

168168
#[serde(
169169
default,
170-
deserialize_with = "serde_util::deserialize_datetime_option_from_double"
170+
deserialize_with = "serde_util::deserialize_datetime_option_from_double_or_string"
171171
)]
172172
expiration: Option<bson::DateTime>,
173173
}

src/serde_util.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,29 @@ pub(crate) fn serialize_true<S: Serializer>(s: S) -> std::result::Result<S::Ok,
129129
}
130130

131131
#[cfg(feature = "aws-auth")]
132-
pub(crate) fn deserialize_datetime_option_from_double<'de, D>(
132+
pub(crate) fn deserialize_datetime_option_from_double_or_string<'de, D>(
133133
deserializer: D,
134134
) -> std::result::Result<Option<bson::DateTime>, D::Error>
135135
where
136136
D: Deserializer<'de>,
137137
{
138-
let millis = f64::deserialize(deserializer)? * 1000.0;
139-
Ok(Some(bson::DateTime::from_millis(millis as i64)))
138+
#[derive(Deserialize)]
139+
#[serde(untagged)]
140+
enum AwsDateTime {
141+
Double(f64),
142+
String(String),
143+
}
144+
145+
let date_time = match AwsDateTime::deserialize(deserializer)? {
146+
AwsDateTime::Double(seconds) => {
147+
let millis = seconds * 1000.0;
148+
bson::DateTime::from_millis(millis as i64)
149+
}
150+
AwsDateTime::String(string) => bson::DateTime::parse_rfc3339_str(string)
151+
.map_err(|e| serde::de::Error::custom(format!("invalid RFC 3339 string: {}", e)))?,
152+
};
153+
154+
Ok(Some(date_time))
140155
}
141156

142157
#[cfg(test)]

0 commit comments

Comments
 (0)