Skip to content

RUST-1699 / RUST-1718 AWS authentication fixes #926

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

Merged
merged 3 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,18 @@ functions:
${PREPARE_SHELL}
${DRIVERS_TOOLS}/.evergreen/run-load-balancer.sh stop

"tear down aws":
- command: shell.exec
params:
shell: "bash"
script: |
${PREPARE_SHELL}
cd "${DRIVERS_TOOLS}/.evergreen/auth_aws"
if [ -f "./aws_e2e_setup.json" ]; then
. ./activate-authawsvenv.sh
python ./lib/aws_assign_instance_profile.py
fi

"upload test results":
- command: attach.xunit_results
params:
Expand All @@ -878,6 +890,7 @@ pre:
post:
- func: "stop load balancer"
- func: "stop mongo orchestration"
- func: "tear down aws"
- func: "upload test results"
- func: "upload-mo-artifacts"
- func: "cleanup"
Expand Down Expand Up @@ -1019,8 +1032,8 @@ tasks:
- func: "run aws auth test with assume role credentials"
- func: "run aws auth test with aws credentials as environment variables"
- func: "run aws auth test with aws credentials and session token as environment variables"
# - func: "run aws auth test with aws EC2 credentials"
# - func: "run aws ECS auth test"
- func: "run aws auth test with aws EC2 credentials"
- func: "run aws ECS auth test"
- func: "run aws assume role with web identity test"

- name: "test-5.0-standalone"
Expand Down Expand Up @@ -1081,8 +1094,8 @@ tasks:
- func: "run aws auth test with assume role credentials"
- func: "run aws auth test with aws credentials as environment variables"
- func: "run aws auth test with aws credentials and session token as environment variables"
# - func: "run aws auth test with aws EC2 credentials"
# - func: "run aws ECS auth test"
- func: "run aws auth test with aws EC2 credentials"
- func: "run aws ECS auth test"
- func: "run aws assume role with web identity test"

- name: "test-6.0-standalone"
Expand Down Expand Up @@ -1143,8 +1156,8 @@ tasks:
- func: "run aws auth test with assume role credentials"
- func: "run aws auth test with aws credentials as environment variables"
- func: "run aws auth test with aws credentials and session token as environment variables"
# - func: "run aws auth test with aws EC2 credentials"
# - func: "run aws ECS auth test"
- func: "run aws auth test with aws EC2 credentials"
- func: "run aws ECS auth test"
- func: "run aws assume role with web identity test"

- name: "test-7.0-standalone"
Expand Down Expand Up @@ -1205,8 +1218,8 @@ tasks:
- func: "run aws auth test with assume role credentials"
- func: "run aws auth test with aws credentials as environment variables"
- func: "run aws auth test with aws credentials and session token as environment variables"
# - func: "run aws auth test with aws EC2 credentials"
# - func: "run aws ECS auth test"
- func: "run aws auth test with aws EC2 credentials"
- func: "run aws ECS auth test"
- func: "run aws assume role with web identity test"

- name: "test-rapid-standalone"
Expand Down Expand Up @@ -1267,8 +1280,8 @@ tasks:
- func: "run aws auth test with assume role credentials"
- func: "run aws auth test with aws credentials as environment variables"
- func: "run aws auth test with aws credentials and session token as environment variables"
# - func: "run aws auth test with aws EC2 credentials"
# - func: "run aws ECS auth test"
- func: "run aws auth test with aws EC2 credentials"
- func: "run aws ECS auth test"
- func: "run aws assume role with web identity test"

- name: "test-latest-standalone"
Expand Down Expand Up @@ -1330,8 +1343,8 @@ tasks:
- func: "run aws auth test with assume role credentials"
- func: "run aws auth test with aws credentials as environment variables"
- func: "run aws auth test with aws credentials and session token as environment variables"
# - func: "run aws auth test with aws EC2 credentials"
# - func: "run aws ECS auth test"
- func: "run aws auth test with aws EC2 credentials"
- func: "run aws ECS auth test"
- func: "run aws assume role with web identity test"

- name: "test-connection-string"
Expand Down
2 changes: 1 addition & 1 deletion src/client/auth/aws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub(crate) struct AwsCredential {

#[serde(
default,
deserialize_with = "serde_util::deserialize_datetime_option_from_double"
deserialize_with = "serde_util::deserialize_datetime_option_from_double_or_string"
)]
expiration: Option<bson::DateTime>,
}
Expand Down
21 changes: 18 additions & 3 deletions src/serde_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,29 @@ pub(crate) fn serialize_true<S: Serializer>(s: S) -> std::result::Result<S::Ok,
}

#[cfg(feature = "aws-auth")]
pub(crate) fn deserialize_datetime_option_from_double<'de, D>(
pub(crate) fn deserialize_datetime_option_from_double_or_string<'de, D>(
deserializer: D,
) -> std::result::Result<Option<bson::DateTime>, D::Error>
where
D: Deserializer<'de>,
{
let millis = f64::deserialize(deserializer)? * 1000.0;
Ok(Some(bson::DateTime::from_millis(millis as i64)))
#[derive(Deserialize)]
#[serde(untagged)]
enum AwsDateTime {
Double(f64),
String(String),
}

let date_time = match AwsDateTime::deserialize(deserializer)? {
AwsDateTime::Double(seconds) => {
let millis = seconds * 1000.0;
bson::DateTime::from_millis(millis as i64)
}
AwsDateTime::String(string) => bson::DateTime::parse_rfc3339_str(string)
.map_err(|e| serde::de::Error::custom(format!("invalid RFC 3339 string: {}", e)))?,
};

Ok(Some(date_time))
}

#[cfg(test)]
Expand Down