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

Correct instantiation of AWS session object #421

Merged
merged 1 commit into from
May 7, 2021

Conversation

bodgit
Copy link
Contributor

@bodgit bodgit commented Apr 28, 2021

The region needs to be set on the config object before creating the
session so that things like setting AWS_STS_REGIONAL_ENDPOINTS can
take effect.

Also, if credentials cannot be acquired, die at that point instead of
carrying on.

Fixes #420

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

haugenj
haugenj previously approved these changes Apr 29, 2021
Copy link
Contributor

@haugenj haugenj left a comment

Choose a reason for hiding this comment

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

👍 LGTM, thanks!

@bwagner5
Copy link
Contributor

bwagner5 commented May 5, 2021

I'm good with your changes, but rather than making users specify: export AWS_STS_REGIONAL_ENDPOINTS regional we can just hard code the config to use regional endpoints. I don't think there's a reason to use the global endpoint w/ NTH. If there's something I'm missing with that assumption, then a second option would be to add the AWS_STS_REGIONAL_ENDPOINTS var in the helm chart's values.yaml and default it to regional.

cfg := aws.NewConfig().
			WithRegion(nthConfig.AWSRegion).
			WithEndpoint(nthConfig.AWSEndpoint).
			WithSTSRegionalEndpoint(endpoints.RegionalSTSEndpoint)
		sess := session.Must(session.NewSessionWithOptions(session.Options{
			Config:            *cfg,
			SharedConfigState: session.SharedConfigEnable,
		}))

@bodgit
Copy link
Contributor Author

bodgit commented May 6, 2021

It was purely a case of not changing existing behaviour. You can do exactly as you describe and force the regional endpoint when creating the session object; I've seen some controllers/drivers do that. If you're happy to have that slight change in behaviour then I can tweak the PR. That would be one less Kustomization patch I have to have 😉

@bwagner5
Copy link
Contributor

bwagner5 commented May 6, 2021

Cool, I’m good with hard coding it in the session! Mind adding to this pr?

The region needs to be set on the config object before creating the
session so that things like setting `AWS_STS_REGIONAL_ENDPOINTS` can
take effect.

Also, if credentials cannot be acquired, die at that point instead of
carrying on.
@bodgit
Copy link
Contributor Author

bodgit commented May 6, 2021

Done

Copy link
Contributor

@bwagner5 bwagner5 left a comment

Choose a reason for hiding this comment

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

nice! Thank you! LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to use STS regional endpoint
3 participants