Skip to content

IAM role credentials not working if EC2 IMDSv2 session tokens 'required' #215

@fred-vogt

Description

@fred-vogt

EC2 Instance Metadata V2 support needs a newer version of github.com/aws/aws-sdk-go.

Tested with release 0.4.0.

~/.ecr/log/ecr-login.log:

time="2020-06-01T02:09:39Z" level=debug msg="Calling ECR.GetAuthorizationToken" registry=...
time="2020-06-01T02:09:39Z" level=error msg="Error retrieving credentials" 
error="
ecr: Failed to get authorization token: 
  NoCredentialProviders: no valid providers in chain. 
  Deprecated.
      For verbose messaging see aws.Config.CredentialsChainVerboseErrors
"

Making IMDSv2 session tokens optional fixes it:

AWS_PROFILE=admin-dev aws ec2 modify-instance-metadata-options \
    --instance-id <instance-id> \
    --http-tokens optional
{
    "InstanceId": "i-...",
    "InstanceMetadataOptions": {
        "State": "pending",
        "HttpTokens": "optional",
        "HttpPutResponseHopLimit": 64,
        "HttpEndpoint": "enabled"
    }
}

Notice the hop limit is NOT the default of 1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions