Unverified Commit 6e3e010e authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Relax behavior of profile parser (#1458)

- Fixes aws-sdk-rust#547

Previously, if no default profile was defined and no explicit profile was selected, the profile file provider would return an error. This relaxes that behavior to allow provider chains to move onto the next provider when that is the case.
parent c78c67e3
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -10,3 +10,9 @@
# references = ["smithy-rs#920"]
# meta = { "breaking" = false, "tada" = false, "bug" = false }
# author = "rcoh"

[[aws-sdk-rust]]
message = "Fix bug in profile file credential provider where a missing `default` profile lead to an unintended error."
references = ["aws-sdk-rust#547", "smithy-rs#1458"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "rcoh"
+1 −0
Original line number Diff line number Diff line
@@ -333,6 +333,7 @@ mod test {

    make_test!(ecs_assume_role);
    make_test!(ecs_credentials);
    make_test!(ecs_credentials_invalid_profile);

    make_test!(sso_assume_role);
    make_test!(sso_no_token_file);
+18 −2
Original line number Diff line number Diff line
@@ -112,9 +112,24 @@ pub(super) fn resolve_chain<'a>(
    profile_set: &'a ProfileSet,
    profile_override: Option<&str>,
) -> Result<ProfileChain<'a>, ProfileFileError> {
    // If there are no profiles, allow flowing into the next provider
    if profile_set.is_empty() {
        return Err(ProfileFileError::NoProfilesDefined);
    }

    // If:
    // - There is no explicit profile override
    // - We're looking for the default profile (no configuration)
    // - There is not default profile
    // Then:
    // - Treat this situation as if no profiles were defined
    if profile_override == None
        && profile_set.selected_profile() == "default"
        && profile_set.get_profile("default") == None
    {
        tracing::debug!("No default profile defined");
        return Err(ProfileFileError::NoProfilesDefined);
    }
    let mut source_profile_name =
        profile_override.unwrap_or_else(|| profile_set.selected_profile());
    let mut visited_profiles = vec![];
@@ -221,6 +236,7 @@ mod static_credentials {
mod credential_process {
    pub const CREDENTIAL_PROCESS: &str = "credential_process";
}

const PROVIDER_NAME: &str = "ProfileFile";

fn base_provider(profile: &Profile) -> Result<BaseProvider, ProfileFileError> {
+5 −0
Original line number Diff line number Diff line
{
  "HOME": "/home",
  "AWS_REGION": "us-east-1",
  "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI": "/v2/credentials/52b19262-e7aa-4f56-a1cd-b958dcde8f3b"
}
+3 −0
Original line number Diff line number Diff line
# a profile that isn't the `default` profile
[profile notdefault]
a = b
Loading