Skip to content

"no EC2 instance role found" due to incorrect iamSecurityCredsPath #351

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

Closed
eriksw opened this issue Aug 8, 2019 · 4 comments · Fixed by #356 or #363
Closed

"no EC2 instance role found" due to incorrect iamSecurityCredsPath #351

eriksw opened this issue Aug 8, 2019 · 4 comments · Fixed by #356 or #363
Labels
bug This issue is a bug.

Comments

@eriksw
Copy link

eriksw commented Aug 8, 2019

Version of AWS SDK for Go?

# github.com/aws/aws-sdk-go-v2 v0.10.0

Version of Go (go version)?

go1.11.5

What issue did you see?

Attempting to run something equivalent to the README.md example:

panic: failed to describe table, EC2RoleRequestError: no EC2 instance role found
caused by: EC2MetadataError: failed to make Client request
caused by:

goroutine 1 [running]:
...

Steps to reproduce

Reproduction requires an EC2 instance where EC2ws returns a 301 for a GET of http://169.254.169.254/latest/meta-data/iam/security-credentials (without trailing slash) with a with-trailing-slash Location in the 301. On most instances I have checked, except this one particular t2.xlarge in us-west-2, that GET returns the listing of profiles instead of the 301 redirect.

There is no proxy in front of EC2ws on this instance. This is in-the-wild EC2ws behavior that aws-sdk-go-v2 needs to handle.

$ curl -vv http://169.254.169.254/latest/meta-data/iam/security-credentials
*   Trying 169.254.169.254...
* Connected to 169.254.169.254 (169.254.169.254) port 80 (#0)
> GET /latest/meta-data/iam/security-credentials HTTP/1.1
> Host: 169.254.169.254
> User-Agent: curl/7.47.0
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 301 Moved Permanently
< Location: http://169.254.169.254/latest/meta-data/iam/security-credentials/
< Content-Length: 0
< Connection: close
< Date: Thu, 08 Aug 2019 20:02:03 GMT
< Server: EC2ws
<
* Closing connection 0

Related papercuts

While debugging this, none of the obvious approaches to get logging from EC2RoleProvider worked:

  • Setting the LogLevel on the Config returned by LoadDefaultAWSConfig did not work.

    cfg, err := external.LoadDefaultAWSConfig()
    ...
    cfg.LogLevel = aws.LogDebugWithHTTPBody
    

    This produced no output.

  • Passing the log level to LoadDefaultAWSConfig did not work.

    cfg, err := external.LoadDefaultAWSConfig(aws.WithLogLevel(aws.LogDebugWithHTTPBody))
    

    This also produced no output.

At least one of the above approaches should have resulted in EC2RoleProvider logging its requests. I had to resort to editing a vendored aws-sdk-go-v2 (modifying aws.NewClient to always set the LogLevel, ignoring the config) in order to get debug logging from an EC2RoleProvider created by external.LoadDefaultAWSConfig—that's not reasonable.

@eriksw
Copy link
Author

eriksw commented Aug 8, 2019

This is related to #198 but at some point the redirect stopped getting followed, making this a showstopper issue.

@CannibalVox
Copy link

This is massive, it effectively makes aws-sdk-go-v2 unusable for anyone on kubernetes.

@jasdel
Copy link
Contributor

jasdel commented Aug 16, 2019

Thanks for reporting this issue. I created #355 to track the log option not being applied to the credential provider derived from LoadDefaultAWSConfig.

Reviewing the commit history, it looks like #315 would of disabled following the redirect behavior. I think a solution to this issue is to allow redirects for GET methods. EC2 Instance Metadata service is a special case where a redirect could be used. I don't think redirects are valid to follow for any other AWS service due to request signing. With that said the SDK's #198 needs to be fixed as well to prevent the redirect in the first case.

@jasdel jasdel added the bug This issue is a bug. label Aug 16, 2019
jasdel added a commit to jasdel/aws-sdk-go-v2 that referenced this issue Aug 16, 2019
Fixes the EC2 Instance Metadata Service client to no longer squash the
trailing slash when requesting instance metadata.

Related to aws#351
jasdel added a commit to jasdel/aws-sdk-go-v2 that referenced this issue Aug 16, 2019
Fixes the iamSecurityCredsPath var to include a trailing slash
preventing redirects when making requests to the EC2 Instance Metadata
service.

Fix aws#351
jasdel added a commit to jasdel/aws-sdk-go-v2 that referenced this issue Aug 16, 2019
Fixes the EC2 Instance Metadata Service client to no longer squash the
trailing slash when requesting instance metadata.

Related to aws#351
jasdel added a commit to jasdel/aws-sdk-go-v2 that referenced this issue Aug 16, 2019
Fixes the iamSecurityCredsPath var to include a trailing slash
preventing redirects when making requests to the EC2 Instance Metadata
service.

Fix aws#351
jasdel added a commit to jasdel/aws-sdk-go-v2 that referenced this issue Aug 16, 2019
Fixes the EC2 Instance Metadata Service client to no longer squash the
trailing slash when requesting instance metadata.

Related to aws#351
jasdel added a commit to jasdel/aws-sdk-go-v2 that referenced this issue Aug 16, 2019
Fixes the iamSecurityCredsPath var to include a trailing slash
preventing redirects when making requests to the EC2 Instance Metadata
service.

Fix aws#351
jasdel added a commit that referenced this issue Aug 20, 2019
…356)

Fixes the EC2 Instance Metadata Service client to no longer squash the trailing slash when requesting instance metadata. Also, fixes the iamSecurityCredsPath var to include a trailing slash preventing redirects when making requests to the EC2 Instance Metadata service.

Fix #351
Related to #351
jasdel added a commit to jasdel/aws-sdk-go-v2 that referenced this issue Aug 22, 2019
Services
===
* Synced the V2 SDK with latest AWS service API definitions.
  * Fixes [aws#359](aws#359)

SDK Features
===

SDK Enhancements
===
* `private/protocol`: Add support for TimestampFormat in protocols ([aws#358](aws#358))
  * Adds support for the timestampForamt API model trait to the V2 SDK. The SDK will now generate API client parameters with the correct time format for APIs modeled with custom time stamp formats specified.
  * Fixes [aws#202](aws#202)
  * Fixes [aws#286](aws#286)
* `aws`: Add example for custom HTTP client idle connection options ([aws#350](aws#350))
  * Adds example to the SDK for configuring custom HTTP client idle connection keep alive options.

SDK Bugs
===
* `private/model/api`: Fix API doc being generated with wrong value ([aws#359](aws#359))
  * Fixes the SDK's generated API documentation for structure member being generated with the wrong documentation value when the member was included multiple times in the model doc-2.json file, but under different types.
  * V2 port of to v1 [aws/aws-sdk-go#2748](aws/aws-sdk-go#2748)
* `aws/ec2rolecreds`: Fix security creds path to include trailing slash ([aws#356](aws#356))
  * Fixes the iamSecurityCredsPath var to include a trailing slash preventing redirects when making requests to the EC2 Instance Metadata service.
  * Fixes [aws#351](aws#351)
* `service/dynamodb/expression`: Improved reporting of bad key conditions ([aws#360](aws#360))
  * Improved error reporting when invalid key conditions are constructed using KeyConditionBuilder
jasdel added a commit that referenced this issue Aug 23, 2019
Services
===
* Synced the V2 SDK with latest AWS service API definitions.
  * Fixes [#359](#359)

SDK Features
===

SDK Enhancements
===
* `private/protocol`: Add support for TimestampFormat in protocols ([#358](#358))
  * Adds support for the timestampForamt API model trait to the V2 SDK. The SDK will now generate API client parameters with the correct time format for APIs modeled with custom time stamp formats specified.
  * Fixes [#202](#202)
  * Fixes [#286](#286)
* `aws`: Add example for custom HTTP client idle connection options ([#350](#350))
  * Adds example to the SDK for configuring custom HTTP client idle connection keep alive options.

SDK Bugs
===
* `private/model/api`: Fix API doc being generated with wrong value ([#359](#359))
  * Fixes the SDK's generated API documentation for structure member being generated with the wrong documentation value when the member was included multiple times in the model doc-2.json file, but under different types.
  * V2 port of to v1 [aws/aws-sdk-go#2748](aws/aws-sdk-go#2748)
* `aws/ec2rolecreds`: Fix security creds path to include trailing slash ([#356](#356))
  * Fixes the iamSecurityCredsPath var to include a trailing slash preventing redirects when making requests to the EC2 Instance Metadata service.
  * Fixes [#351](#351)
* `service/dynamodb/expression`: Improved reporting of bad key conditions ([#360](#360))
  * Improved error reporting when invalid key conditions are constructed using KeyConditionBuilder
@deanshelton913
Copy link

I concur with @CannibalVox. This is failing for my app operating from within an EKS node running on fargate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
4 participants