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

Repeated region in STS Regional Endpoints for TokenFileWebIdentity #45

Closed
hartmanCodes opened this issue Feb 2, 2023 · 1 comment · Fixed by #46
Closed

Repeated region in STS Regional Endpoints for TokenFileWebIdentity #45

hartmanCodes opened this issue Feb 2, 2023 · 1 comment · Fixed by #46

Comments

@hartmanCodes
Copy link

Summary

When using the TokenFileWebIdentity, the data plane will successfully initialize with a token, but when a request is sent to refresh the token, an additional region is added to the hostname (Ex: sts.us-west-2.us-west-2.amazonaws.com). Rapid succession requests will continue to add regions to the host name as well (Ex: sts.us-west-2.us-west-2.us-west-2.us-west-2.us-west-2.amazonaws.com). This causes a DNS resolution error and the data plane is no longer authenticated with AWS.

The generate_service_methods will add additional regions if the region currently exists in the hostname, but I'm not certain that is causing the issue given that the function is called in init.lua and the class is only initialized once with no config passed as an argument.

Steps to Reproduce

  1. Initialize plugin with TokenFileWebIdentity
  2. Wait for token to expire (about an hour)
  3. Send requests to routes using the AWS SDK
  4. DNS Resolution error will appear with the additional regions in the hostname
@hartmanCodes
Copy link
Author

hartmanCodes commented Feb 9, 2023

After some testing, it was found that lines 325-327 of init.lua are the cause of the issue. This code is executed each time the token needs to be refreshed which is why the region is added each time.

Adding the snippet below resolves the issue,

        local function ends_with(str, ending)
           return ending == "" or str:sub(-#ending) == ending
        end

        local pre, post = service.config.endpoint:match("^(.+)(%.amazonaws%.com)$")
        if not ends_with(pre, service.config.region) then
           service.config.endpoint = pre .. "." .. service.config.region .. post
        end

        service.config.signingRegion = service.config.region

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 a pull request may close this issue.

1 participant