Skip to content
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

auth/aws: fix panic in IAM-based login when client config doesn't exist #23366

Merged
merged 8 commits into from
Sep 30, 2023

Conversation

austingebauer
Copy link
Contributor

@austingebauer austingebauer commented Sep 28, 2023

This PR fixes a panic in AWS auth method for IAM-based login when the client config doesn't exist. The panic exists in Vault 1.15 by way of #21960. I've added a test that would cause the panic without these changes.

Steps taken to reproduce:

  1. Enable auth method with AWS env vars providing credentials (do not write client config)
  2. Write role
  3. Login with the auth method

Fixes: #23361

@austingebauer austingebauer added this to the 1.15.1 milestone Sep 28, 2023
@austingebauer austingebauer requested a review from a team as a code owner September 28, 2023 03:12
@github-actions github-actions bot added the hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed label Sep 28, 2023
return "", nil, nil, logical.ErrorResponse("error getting configuration"), nil
return "", nil, nil, nil, fmt.Errorf("error getting configuration: %w", err)
}
if config == nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a behavior change to not allow IAM-based login when the client configuration does not exist. This was permitted prior to the change that introduced the panic (for example, in 1.14.x).

I could use thoughts on whether this is a change we want to make.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change make sense. I am not sure what credentials are used to make API calls if the client config does not exist.

Copy link

@protochron protochron Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have to look at the code, but without allowing an empty client configuration you're effectively disallowing instance profiles from being used to provide AWS credentials, right? The AWS Go SDK will fall back to using them if you aren't overriding how the default credentials chain is managed. The Vault docs also suggest that not providing a client configuration is supported:

If static credentials are not provided using this endpoint, then the credentials will be retrieved from the environment variables AWS_ACCESS_KEY, AWS_SECRET_KEY and AWS_REGION respectively. If the credentials are still not found and if the method is configured on an EC2 instance with metadata querying capabilities, the credentials are fetched automatically.

Copy link
Contributor Author

@austingebauer austingebauer Sep 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the details, @protochron! I'm looking a little closer at how the client is configured in the case where the client config hasn't been written. I don't want to fix this panic and break more users with the behavior change of requiring it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@protochron is right that the default credential chain will be used if the client configuration isn't written. This means the credentials will be source from env vars, instance profiles, etc.

I think it would be less disruptive to maintain the behavior which doesn't require the client config to be written. If we changed the behavior, users would need to write an empty config similar to the workaround in the known issue included in this PR.

I'm going to change this so that the panic is fixed and the behavior of not requiring the client config is maintained.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@austingebauer that sounds perfect. It wouldn't necessarily be the worst thing to write an empty config if there was any other precedent in Vault for it, but I think people would be surprised by that being necessary. I certainly was!

Thanks again for deep diving on this issue.

Copy link
Contributor Author

@austingebauer austingebauer Sep 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I'd rather avoid telling users that they need to write an empty config after upgrading to 1.15.0+ for their logins to continue working. We will maintain the current behavior and fix the panic. I've made those changes in 34d8673.

No problem, sorry for any trouble this caused!

@github-actions
Copy link

Build Results:
All builds succeeded! ✅

@github-actions
Copy link

github-actions bot commented Sep 28, 2023

CI Results:
All Go tests succeeded! ✅

@austingebauer austingebauer merged commit 80e1912 into main Sep 30, 2023
@austingebauer austingebauer deleted the fix-aws-auth-panic branch September 30, 2023 02:25
robmonte added a commit that referenced this pull request Oct 3, 2023
robmonte added a commit that referenced this pull request Oct 3, 2023
robmonte pushed a commit that referenced this pull request Oct 6, 2023
…st (#23366)

* auth/aws: fix panic in IAM-based login when client config doesn't exist

* add changelog

* adds known issue for 1.15.0

* fixes up known issue with workaround

* fix link

* maintain behavior of client config not needing to exist for IAM login

* update changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic when using the AWS authentication backend and a static role
3 participants