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

When running on EC2 not picking up credentials #245

Closed
nitrocode opened this issue Aug 3, 2021 · 8 comments
Closed

When running on EC2 not picking up credentials #245

nitrocode opened this issue Aug 3, 2021 · 8 comments
Labels
bug Something isn't working closed-for-staleness p2 response-requested Waiting on additional info and feedback. Will move to 'closing-soon' in 5 days.

Comments

@nitrocode
Copy link

nitrocode commented Aug 3, 2021

context

I noticed that from a previous issue and subsequent pull request that this feature should be supported. I'm using the following yaml but it's not working as expected.

I'm on Amazon Linux 2 self-hosted EC2 instances.

I tried this

      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1

which returns Error: Input required and not supplied: aws-region

I tried this

      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-region: us-east-2

which returns

Error: Credentials could not be loaded, please check your action inputs: Could not load credentials from any providers

references

similar issues in other projects

@AmaniEzz
Copy link

I'm facing the same problem, have you found solutions?

@nitrocode
Copy link
Author

@AmaniEzz @paragbhingre it looks like my issue was with setting the following input variables.

    env:
      AWS_EC2_METADATA_DISABLED: true
      AWS_SDK_LOAD_CONFIG: true

My originaly issue was with using docker/build-push-action which would throw errors because it couldn't read from the IAM role so I experiemented with running this action prior to the docker one and I ran into the same issue. I ended up not needing this action once I omitted the above env variables.

I have not re-tested the aws-actions/configure-aws-credentials after omitting the above env variables.

@AmaniEzz
Copy link

AmaniEzz commented Aug 16, 2021 via email

@rogerscuall
Copy link

rogerscuall commented Jul 28, 2022

Any update regarding this issue? I'm having the same problem. I tried multiple values for the envar listed here with no luck.
In my case, the runner is on an EC2 instance with a profile with the required permissions.

@peterwoodworth peterwoodworth added needs-triage This issue still needs to be triaged bug Something isn't working p2 and removed investigating labels Sep 30, 2022
@peterwoodworth peterwoodworth changed the title Request: example of using self-hosted EC2 using IAM role When running on EC2 not picking up credentials Oct 7, 2022
@peterwoodworth
Copy link
Contributor

I'll try to investigate this at some point in the next week

@kellertk
Copy link
Contributor

Hi there! You're getting this error because the JavaScript SDK is unable to load credentials from any of the credential providers. One of the first things the action does it attempt to get the SDK to refresh the running credentials with a call to loadCredentails. If that throws an exception, you'll see the error above.

Could not load credentials from any providers is a standard error message from the JavaScript SDK (this action uses version 2). The credential provider load order is documented here: https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-credentials-node.html. Depending on your runner's environment, this could be coming from a couple of things, but if you're running in EC2 and trying to use an IAM role, you do need to have the metadata service enabled (which is number 6 in the above documented precedence order).

There are some environment variables that control the behavior of the JS SDK, one of which is AWS_EC2_METADATA_DISABLED - if that env variable is set to a truthy value, the SDK will not communicate with the IMDS and will not be able to run under IAM role credentials.

Of course, if you're trying to do some other method of authentication other than IAM roles on your runner, you'll need to make sure that's working on your runner with the JS SDK as well. One easy way is to use a simple "hello world" app written against the JavaScript v2 SDK and run that on your runner: https://docs.aws.amazon.com/code-samples/latest/catalog/javascript-nodegetstarted-sample.js.html. If that works, you know the SDK should be able to authenticate.

@kellertk kellertk added response-requested Waiting on additional info and feedback. Will move to 'closing-soon' in 5 days. and removed needs-triage This issue still needs to be triaged labels Oct 12, 2022
@github-actions
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 2 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 2 days unless further comments are made. labels Oct 18, 2022
@dsagroads
Copy link

I get the same error

│ Error: configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found.
│ 
│ Please see https://registry.terraform.io/providers/hashicorp/aws
│ for more information about providing credentials.
│ 
│ AWS Error: failed to refresh cached credentials, no EC2 IMDS role found, operation error ec2imds: GetMetadata, request canceled, context deadline exceeded
│ 
│ 
│   with provider["registry.terraform.io/hashicorp/aws"],
│   on main.tf line 19, in provider "aws":
│   19: provider "aws" {```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working closed-for-staleness p2 response-requested Waiting on additional info and feedback. Will move to 'closing-soon' in 5 days.
Projects
None yet
Development

No branches or pull requests

7 participants