Coder Social home page Coder Social logo

configure-aws-credentials's Introduction

Configure AWS Credentials for GitHub Actions

Configure your AWS credentials and region environment variables for use in other GitHub Actions.

This action implements the AWS JavaScript SDK credential resolution chain and exports session environment variables for your other Actions to use. Environment variable exports are detected by both the AWS SDKs and the AWS CLI for AWS API calls.

Overview

API calls to AWS need to be signed with credential information, so when you use one of the AWS SDKs or an AWS tool, you must provide it with AWS credentials and and AWS region. One way to do that in GitHub Actions is to use a repository secret with IAM credentials, but this doesn't follow AWS security guidelines on using long term credentials. Instead, we recommend that you use a long term credential or JWT to fetch a temporary credential, and use that with your tools instead. This GitHub Action facilitates just that.

AWS SDKs and Tools look for your credentials in standardized environment variables. In essence, this Action runs through the standard credential resolution flow, and at the end, exports environment variables for you to use later.

We support five methods for fetching credentials from AWS, but we recommend that you use GitHub's OIDC provider in conjunction with a configured AWS IAM Identity Provider endpoint.

For more information on how to do that, read on.

Note about GHES

Some of this documentation may be inaccurate if you are using GHES (GitHub Enterprise Server), please take note to review the GitHub documentation when relevant.

For example, the URL that the OIDC JWT is issued from is different than the usual token.actions.githubusercontent.com, and will be unique to your enterprise server. As a result, you will need to configure this differently when you create the Identity Provider.

We do not presently have a GHES testing environment to validate this action. If you are running in GHES and encounter problems, please let us know.

Security recommendations

We recommend following Amazon IAM best practices for the AWS credentials used in GitHub Actions workflows, including:

  • Do not store credentials in your repository's code.
  • Grant least privilege to the credentials used in GitHub Actions workflows. Grant only the permissions required to perform the actions in your GitHub Actions workflows. Do not assume overly permissive roles, even for testing.
  • Monitor the activity of the credentials used in GitHub Actions workflows.
  • Use temporary credentials when possible.
  • Periodically rotate any long-term credentials you use.

Using this action

There are five different supported ways to retrieve credentials:

  • Using GitHub's OIDC provider (AssumeRoleWithWebIdentity)
  • Proceeding as an IAM user (No STS call is made)
  • Using access keys as action input (AssumeRole)
  • Using a WebIdentity Token File (AssumeRoleWithWebIdentity)
  • Using existing credentials in your runner (AssumeRole)

Because we use the AWS JavaScript SDK, we always will use the credential resolution flow for Node.js. Depending on your inputs, the action might override parts of this flow.

We recommend using the first option above: GitHub's OIDC provider. This method uses OIDC to get short-lived credentials needed for your actions. See OIDC for more information on how to setup your AWS account to assume a role with OIDC.

The following table describes which method we'll use to get your credentials based on which values are supplied to the Action:

Identity Used aws-access-key-id role-to-assume web-identity-token-file role-chaining id-token permission
[✅ Recommended] Assume Role directly using GitHub OIDC provider
IAM User
Assume Role using IAM User credentials
Assume Role using WebIdentity Token File credentials
Assume Role using existing credentials

Note: role-chaining is not always necessary to use existing credentials. If you're getting a "Credentials loaded by the SDK do not match" error, try enabling this option.

Options

See action.yml for more detail.

Option Description Required
aws-region Which AWS region to use Yes
role-to-assume Role for which to fetch credentials. Only required for some authentication types. No
aws-access-key-id AWS access key to use. Only required for some authentication types. No
aws-secret-access-key AWS secret key to use. Only required for some authentication types. No
aws-session-token AWS session token to use. Used in uncommon authentication scenarios. No
role-chaining Use existing credentials from the environment to assume a new role. No
audience The JWT audience when using OIDC. Used in non-default AWS partitions, like China regions. No
http-proxy An HTTP proxy to use for API calls. No
mask-aws-account-id AWS account IDs are not considered secret. Setting this will hide account IDs from output anyway. No
role-duration-seconds The assumed role duration in seconds, if assuming a role. Defaults to 1 hour. No
role-external-id The external ID of the role to assume. Only needed if your role requires it. No
role-session-name Defaults to "GitHubActions", but may be changed if required. No
role-skip-session-tagging Skips session tagging if set. No
inline-session-policy You may further restrict the assumed role policy by defining an inline policy here. No
managed-session-policies You may further restrict the assumed role policy by specifying a managed policy here. No
output-credentials When set, outputs fetched credentials as action step output. Defaults to false. No
unset-current-credentials When set, attempts to unset any existing credentials in your action runner. No
disable-retry Disabled retry/backoff logic for assume role calls. By default, retries are enabled. No
retry-max-attempts Limits the number of retry attempts before giving up. Defaults to 12. No
special-characters-workaround Uncommonly, some environments cannot tolerate special characters in a secret key. This option will retry fetching credentials until the secret access key does not contain special characters. This option overrides disable-retry and retry-max-attempts. No

Credential Lifetime

The default session duration is 1 hour.

If you would like to adjust this you can pass a duration to role-duration-seconds, but the duration cannot exceed the maximum that was defined when the IAM Role was created.

External ID

If your role requires an external ID to assume, you can provide the external ID with the role-external-id input

Session tagging and name

The default session name is "GitHubActions", and you can modify it by specifying the desired name in role-session-name. The session will be tagged with the following tags: (Refer to GitHub's documentation for GITHUB_ environment variable definitions)

Key Value
GitHub "Actions"
Repository GITHUB_REPOSITORY
Workflow GITHUB_WORKFLOW
Action GITHUB_ACTION
Actor GITHUB_ACTOR
Branch GITHUB_REF
Commit GITHUB_SHA

Note: all tag values must conform to the tag requirements. Particularly, GITHUB_WORKFLOW will be truncated if it's too long. If GITHUB_ACTOR or GITHUB_WORKFLOW contain invalid characters, the characters will be replaced with an '*'.

The action will use session tagging by default during role assumption, unless you follow our recommendation and are assuming a role with a WebIdentity. For WebIdentity role assumption, the session tags have to be included in the encoded WebIdentity token. This means that tags can only be supplied by the OIDC provider, and they cannot set during the AssumeRoleWithWebIdentity API call within the Action. See #419 for more information.

You can skip this session tagging by providing role-skip-session-tagging as true in the action's inputs:

      uses: aws-actions/configure-aws-credentials@v4
      with:
        role-skip-session-tagging: true

Session policies

Session policies are not required, but they allow you to limit the scope of the fetched credentials without making changes to IAM roles. You can specify inline session policies right in your workflow file, or refer to an existing managed session policy by its ARN.

Inline session policies

An IAM policy in stringified JSON format that you want to use as an inline session policy. Depending on preferences, the JSON could be written on a single line like this:

      uses: aws-actions/configure-aws-credentials@v4
      with:
         inline-session-policy: '{"Version":"2012-10-17","Statement":[{"Sid":"Stmt1","Effect":"Allow","Action":"s3:List*","Resource":"*"}]}'

Or we can have a nicely formatted JSON as well:

      uses: aws-actions/configure-aws-credentials@v4
      with:
         inline-session-policy: >-
          {
           "Version": "2012-10-17",
           "Statement": [
            {
             "Sid":"Stmt1",
             "Effect":"Allow",
             "Action":"s3:List*",
             "Resource":"*"
            }
           ]
          }

Managed session policies

The Amazon Resource Names (ARNs) of the IAM managed policies that you want to use as managed session policies. The policies must exist in the same account as the role. You can pass a single managed policy like this:

      uses: aws-actions/configure-aws-credentials@v4
      with:
         managed-session-policies: arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess

And we can pass multiple managed policies likes this:

      uses: aws-actions/configure-aws-credentials@v4
      with:
         managed-session-policies: |
          arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
          arn:aws:iam::aws:policy/AmazonS3OutpostsReadOnlyAccess

Misc

Adjust the retry mechanism

You can now configure retry settings for when the STS call fails. By default, we retry with exponential backoff 12 times. You can disable this behavior altogether by setting the disable-retry input to true, or you can configure the number of times it retries with the retry-max-attempts input.

Mask account ID

Your account ID is not masked by default in workflow logs since it's not considered sensitive information. However, you can set the mask-aws-account-id input to true to mask your account ID in workflow logs if desired.

Unset current credentials

Sometimes, existing credentials in your runner can get in the way of the intended outcome. You can set the unset-current-credentials input to true to work around this issue.

Special characters in AWS_SECRET_ACCESS_KEY

Some edge cases are unable to properly parse an AWS_SECRET_ACCESS_KEY if it contains special characters. For more information, please see the AWS CLI documentation. If you set the special-characters-workaround option, this action will continually retry fetching credentials until we get one that does not have special characters. This option overrides the disable-retry and retry-max-attempts options. We recommend that you do not enable this option unless required, because retrying APIs infinitely until they succeed is not best practice.

OIDC

We recommend using GitHub's OIDC provider to get short-lived AWS credentials needed for your actions. When using OIDC, you configure IAM to accept JWTs from GitHub's OIDC endpoint. This action will then create a JWT unique to the workflow run using the OIDC endpoint, and it will use the JWT to assume the specified role with short-term credentials.

To get this to work

  1. Configure your workflow to use the id-token: write permission.

  2. Configure your audience, if required.

  3. In your AWS account, configure IAM to trust GitHub's OIDC identity provider.

  4. Configure an IAM role with appropriate claim limits and permission scope.

    Note: Naming your role "GitHubActions" has been reported to not work. See #953.

  5. Specify that role's ARN when setting up this action.

First, in order for this action to create the JWT, your workflow file must have the id-token: write permission:

    permissions:
      id-token: write
      contents: read

OIDC Audience

When the JWT is created, an audience needs to be specified. Normally, you would use sts.amazonaws.com, and this action uses this by default if you don't specify one. This will work for most cases. Changing the default audience may be necessary when using non-default AWS partitions, such as China regions. You can specify the audience through the audience input:

    - name: Configure AWS Credentials for China region audience
      uses: aws-actions/configure-aws-credentials@v4
      with:
        audience: sts.amazonaws.com.cn
        aws-region: us-east-3
        role-to-assume: arn:aws-cn:iam::123456789100:role/my-github-actions-role

Configuring IAM to trust GitHub

To use GitHub's OIDC provider, you must first set up federation with the provider as an IAM IdP. The GitHub OIDC provider only needs to be created once per account (i.e. multiple IAM Roles that can be assumed by the GitHub's OIDC can share a single OIDC Provider). Here is a sample CloudFormation template that will configure this trust for you.

Note that the thumbprint below has been set to all F's because the thumbprint is not used when authenticating token.actions.githubusercontent.com. This is a special case used only when GitHub's OIDC is authenticating to IAM. IAM uses its library of trusted CAs to authenticate. The value is still the API, so it must be specified.

You can copy the template below, or load it from here: https://d38mtn6aq9zhn6.cloudfront.net/configure-aws-credentials-latest.yml

Parameters:
  GitHubOrg:
    Description: Name of GitHub organization/user (case sensitive)
    Type: String
  RepositoryName:
    Description: Name of GitHub repository (case sensitive)
    Type: String
  OIDCProviderArn:
    Description: Arn for the GitHub OIDC Provider.
    Default: ""
    Type: String
  OIDCAudience:
    Description: Audience supplied to configure-aws-credentials.
    Default: "sts.amazonaws.com"
    Type: String

Conditions:
  CreateOIDCProvider: !Equals 
    - !Ref OIDCProviderArn
    - ""

Resources:
  Role:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Effect: Allow
            Action: sts:AssumeRoleWithWebIdentity
            Principal:
              Federated: !If 
                - CreateOIDCProvider
                - !Ref GithubOidc
                - !Ref OIDCProviderArn
            Condition:
              StringEquals:
                token.actions.githubusercontent.com:aud: !Ref OIDCAudience
              StringLike:
                token.actions.githubusercontent.com:sub: !Sub repo:${GitHubOrg}/${RepositoryName}:*

  GithubOidc:
    Type: AWS::IAM::OIDCProvider
    Condition: CreateOIDCProvider
    Properties:
      Url: https://token.actions.githubusercontent.com
      ClientIdList: 
        - sts.amazonaws.com
      ThumbprintList:
        - ffffffffffffffffffffffffffffffffffffffff

Outputs:
  Role:
    Value: !GetAtt Role.Arn 

Claims and scoping permissions

To align with the Amazon IAM best practice of granting least privilege, the assume role policy document should contain a Condition that specifies a subject (sub) allowed to assume the role. GitHub also recommends filtering for the correct audience (aud). See AWS IAM documentation on which claims you can filter for in your trust policies.

Without a subject (sub) condition, any GitHub user or repository could potentially assume the role. The subject can be scoped to a GitHub organization and repository as shown in the CloudFormation template. However, scoping it down to your org and repo may cause the role assumption to fail in some cases. See Example subject claims for specific details on what the subject value will be depending on your workflow. You can also customize your subject claim if you want full control over the information you can filter for in your trust policy. If you aren't sure what your subject (sub) key is, you can add the actions-oidc-debugger action to your workflow to see the value of the subject (sub) key, as well as other claims.

Additional claim conditions can be added for higher specificity as explained in the GitHub documentation. Due to implementation details, not every OIDC claim is presently supported by IAM.

Further information about OIDC

For further information on OIDC and GitHub Actions, please see:

Self-Hosted Runners

If you run your GitHub Actions in a self-hosted runner that already has access to AWS credentials, such as an EC2 instance, then you do not need to provide IAM user access key credentials to this action. We will use the standard AWS JavaScript SDK credential resolution methods to find your credentials, so if the AWS JS SDK can authenticate on your runner, this Action will as well.

If no access key credentials are given in the action inputs, this action will use credentials from the runner environment using the default methods for the AWS SDK for Javascript.

You can use this action to simply configure the region and account ID in the environment, and then use the runner's credentials for all AWS API calls made by your Actions workflow:

uses: aws-actions/configure-aws-credentials@v4
with:
  aws-region: us-east-2

In this case, your runner's credentials must have permissions to call any AWS APIs called by your Actions workflow.

Or, you can use this action to assume a role, and then use the role credentials for all AWS API calls made by your Actions workflow:

uses: aws-actions/configure-aws-credentials@v4
with:
  aws-region: us-east-2
  role-to-assume: my-github-actions-role

In this case, your runner's credentials must have permissions to assume the role.

You can also assume a role using a web identity token file, such as if using Amazon EKS IRSA. Pods running in EKS worker nodes that do not run as root can use this file to assume a role with a web identity.

Proxy Configuration

If need use a HTTP proxy you can set it in the action manually.

Additionally this action will always consider the HTTP_PROXY environment variable.

Manually configured proxy:

uses: aws-actions/configure-aws-credentials@v4
with:
  aws-region: us-east-2
  role-to-assume: my-github-actions-role
  http-proxy: "http://companydomain.com:3128"

Proxy configured in the environment variable:

# Your environment configuration
HTTP_PROXY="http://companydomain.com:3128"

Use with the AWS CLI

This workflow does not install the AWS CLI into your environment. Self-hosted runners that intend to run this action prior to executing aws commands need to have the AWS CLI installed if it's not already present. Most GitHub hosted runner environments should include the AWS CLI by default.

Examples

AssumeRoleWithWebIdentity (recommended)

    - name: Configure AWS Credentials
      uses: aws-actions/configure-aws-credentials@v4
      with:
        aws-region: us-east-2
        role-to-assume: arn:aws:iam::123456789100:role/my-github-actions-role
        role-session-name: MySessionName

In this example, the Action will load the OIDC token from the GitHub-provided environment variable and use it to assume the role arn:aws:iam::123456789100:role/my-github-actions-role with the session name MySessionName.

AssumeRole with role previously assumed by action in same workflow

    - name: Configure AWS Credentials
      uses: aws-actions/configure-aws-credentials@v4
      with:
        aws-region: us-east-2
        role-to-assume: arn:aws:iam::123456789100:role/my-github-actions-role
        role-session-name: MySessionName
    - name: Configure other AWS Credentials
      uses: aws-actions/configure-aws-credentials@v4
      with:
        aws-region: us-east-2
        role-to-assume: arn:aws:iam::987654321000:role/my-second-role
        role-session-name: MySessionName
        role-chaining: true

In this two-step example, the first step will use OIDC to assume the role arn:aws:iam::123456789100:role/my-github-actions-role just as in the prior example. Following that, a second step will use this role to assume a different role, arn:aws:iam::987654321000:role/my-second-role.

AssumeRole with static IAM credentials in repository secrets

    - name: Configure AWS Credentials
      uses: aws-actions/configure-aws-credentials@v4
      with:
        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws-region: us-east-2
        role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
        role-external-id: ${{ secrets.AWS_ROLE_EXTERNAL_ID }}
        role-duration-seconds: 1200
        role-session-name: MySessionName

In this example, the secret AWS_ROLE_TO_ASSUME contains a string like arn:aws:iam::123456789100:role/my-github-actions-role. To assume a role in the same account as the static credentials, you can simply specify the role name, like role-to-assume: my-github-actions-role.

Retrieving credentials from step output, AssumeRole with temporary credentials

    - name: Configure AWS Credentials 1
      id: creds
      uses: aws-actions/configure-aws-credentials@v4
      with:
        aws-region: us-east-2
        role-to-assume: arn:aws:iam::123456789100:role/my-github-actions-role
        output-credentials: true
    - name: get caller identity 1
      run: |
        aws sts get-caller-identity
    - name: Configure AWS Credentials 2
      uses: aws-actions/configure-aws-credentials@v4
      with:
        aws-region: us-east-2
        aws-access-key-id: ${{ steps.creds.outputs.aws-access-key-id }}
        aws-secret-access-key: ${{ steps.creds.outputs.aws-secret-access-key }}
        aws-session-token: ${{ steps.creds.outputs.aws-session-token }}
        role-to-assume: arn:aws:iam::123456789100:role/my-other-github-actions-role
    - name: get caller identity2
      run: |
        aws sts get-caller-identity

This example shows that you can reference the fetched credentials as outputs if output-credentials is set to true. This example also shows that you can use the aws-session-token input in a situation where session tokens are fetched and passed to this action.

License Summary

This code is made available under the MIT license.

Security Disclosures

If you would like to report a potential security issue in this project, please do not create a GitHub issue. Instead, please follow the instructions here or email AWS security directly.

configure-aws-credentials's People

Contributors

alblue avatar allisaurus avatar aws-sdk-osds avatar clareliguori avatar dependabot-preview[bot] avatar dependabot[bot] avatar escudero89 avatar grahamcampbell avatar gulskr avatar ikana avatar jamesiri avatar kellertk avatar khushail avatar laurencega avatar massongit avatar mattsb42-aws avatar maxrabin avatar mhausenblas avatar mhemani-reach avatar morihaya avatar nesta219 avatar paragbhingre avatar peterwoodworth avatar piradeepk avatar purekrome avatar richardhboyd avatar siggimoo avatar swinton avatar tim-finnigan avatar yasminetalby avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

configure-aws-credentials's Issues

Suggested approach for multi-account deployments

Hello,

What would be the suggested approach for multi-account deployments?
Let's say I have "stage" and "live" accounts. Should I have one workflow that covers deployment to all environments in stage and live, or should I have separate workflows, one for stage one for live?

Also, in the scenario of workflow-per-account I would have fairly large duplicate yaml codebase, and in the case of one workflow, there is an issue with passing STAGE and LIVE creds.

Please advise. thank you

Assuming Role in different AWS Account

We have keys , secret access key for iAM user (deployer) in one account, want to assume role in another account (devops).

Got this error

##[error]User: arn:aws:iam:::user/deployer is not authorized to perform: sts:TagSession on resource: arn:aws:iam:::role/devops

Could not load credentials from any providers

We use Github Workflows for several projects. Some of them won't work with the configure-aws-credentials action. The workflow gets triggered and fails during the configure-aws-credentials action with the following error message: Credentials could not be loaded, please check your action inputs: Could not load credentials from any providers. It works if I restart the workflow manually.

Most of the Github workflows are triggered due to a Dependabot created PR. What drives me nuts is that it works for some Github Workflows but for other it never works (just by manually rerunning the workflow).

An example workflow looks like this

name: Pull Request

on:
  pull_request:
    branches: 
      - master
    types: [opened, synchronize, reopened]

jobs:        
  build:
    name: My Fancy Build Job

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.MY_AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.MY_AWS_SECRET_ACCESS_KEY }}
          aws-region: us-east-1

      - name: Use Node.js 12
        uses: actions/setup-node@v2
        with:
          node-version: '12'

      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"

      - name: Cache yarn cache
        uses: actions/cache@v2
        id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-
      - name: Install
        run: yarn install --prefer-offline --frozen-lockfile
      
      - name: ESLint
        run: yarn lint

      - name: Test
        run: yarn test

The corresponding dependabot.yml could look like this

version: 2
updates:
  - package-ecosystem: "npm"
    directory: "/"
    schedule:
      interval: "daily"
    labels:
      - "dependencies"
    ignore:
      - dependency-name: "aws-cdk"
      - dependency-name: "@aws-cdk/*"
    reviewers:
      - "steffen"

Assuming two roles in the same region in the same account fails

If I use this action to assume a role in a given region in a given account, perform some actions, and then try to assume a different role in the same region and the same account, it looks like the action defaults to using the first role to assume the second role.

In this case, I'm trying to use the first role (source role) to copy from a source S3 bucket to a local store, assuming the second role (target role), and using that second role to copy to a target S3 bucket.

My action looks generally like this:

---
name: Deploy

on:
  workflow_dispatch:

env:
  MY_AWS_REGION: us-west-2
  MY_TARGET_S3_BUCKET: foo-target
  MY_AWS_ACCOUNT_ID: ${{ secrets.MY_AWS_ACCOUNT_ID }}
  MY_SRC_S3_BUCKET: foo-src

jobs:
  build_and_deploy:
    runs-on: [self-hosted, linux, small]
    name: Deploy to S3
    timeout-minutes: 10
    steps:
      - name: Get AWS credentials for source S3 bucket 
        id: get-src-creds
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-region: ${{ env.MY_AWS_REGION }}
          role-to-assume: arn:aws:iam::${{ env.MY_AWS_ACCOUNT_ID }}:role/foo-src
          role-duration-seconds: 1800

      - name: Copy from source S3 bucket
        id: copy-from-s3
        shell: bash
        run: |
          aws s3 sync --only-show-errors --no-progress --delete  "s3://${MY_SRC_S3_BUCKET}" ${GITHUB_WORKSPACE}

      - name: Get AWS credentials for target S3 bucket
        id: get-target-creds
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-region: ${{ env.MY_AWS_REGION }}
          role-to-assume: arn:aws:iam::${{ env.MY_AWS_ACCOUNT_ID }}:role/foo-target
          role-duration-seconds: 1800

      - name: Copy to target S3 bucket
        id: copy-to-s3
        shell: bash
        run: |
          aws s3 sync --only-show-errors --no-progress --delete  ${GITHUB_WORKSPACE} "s3://${MY_TARGET_S3_BUCKET}" 

When running that action, the source role assumption succeeds and I'm able to copy files from the source S3 bucket.

The target role assumption fails with the following error:

Error: User: arn:aws:sts::***:assumed-role/foo-src/GitHubActions is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::***:role/foo-target

That error is true; the source role is not authorized to assume the target role.

My assumption was that the action would use the self-hosted runner's instance profile and associated role to assume the second role (which is how it assumed the first role), rather than using the first role to assume the second role.

Is there a workaround to assume a second role in the same region and account where a first role was assumed? Should I instead be passing some sort of flag to tell the action unset all the environment variables it previously set before it tries to assume a new role?

Error performing any action on GitHub Actions: "The security token included in the request is invalid"

Hi there, apologise for such a basic issue - been banging my head against the desk for far too long on this 😬

Attempting to get this working with GitHub Actions (GitHub-hosted runner) and I can't seem to get this to work at all:

name: CICD
on:
  - push
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: eu-west-2

Always results in:

> Run aws-actions/configure-aws-credentials@v1
##[error]The security token included in the request is invalid.
(node:2546) UnhandledPromiseRejectionWarning: InvalidClientTokenId: The security token included in the request is invalid.
    at Request.extractError (/home/runner/work/_actions/aws-actions/configure-aws-credentials/v1/dist/index.js:2473:29)
    at Request.callListeners (/home/runner/work/_actions/aws-actions/configure-aws-credentials/v1/dist/index.js:30526:20)
    at Request.emit (/home/runner/work/_actions/aws-actions/configure-aws-credentials/v1/dist/index.js:30498:10)
    at Request.emit (/home/runner/work/_actions/aws-actions/configure-aws-credentials/v1/dist/index.js:8502:14)
    at Request.transition (/home/runner/work/_actions/aws-actions/configure-aws-credentials/v1/dist/index.js:7836:10)
    at AcceptorStateMachine.runTo (/home/runner/work/_actions/aws-actions/configure-aws-credentials/v1/dist/index.js:15674:12)
    at /home/runner/work/_actions/aws-actions/configure-aws-credentials/v1/dist/index.js:15686:10
    at Request.<anonymous> (/home/runner/work/_actions/aws-actions/configure-aws-credentials/v1/dist/index.js:7852:9)
    at Request.<anonymous> (/home/runner/work/_actions/aws-actions/configure-aws-credentials/v1/dist/index.js:8504:12)
    at Request.callListeners (/home/runner/work/_actions/aws-actions/configure-aws-credentials/v1/dist/index.js:30536:18)
(node:2546) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2546) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

So, for sanity's sake I added this in just before configure-aws-credentials:

steps:
  - run: aws sts get-caller-identity
    env:
      AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
      AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
      AWS_REGION: eu-west-2

Which always returns:

> Run aws sts get-caller-identity

An error occurred (InvalidClientTokenId) when calling the GetCallerIdentity operation: The security token included in the request is invalid.
##[error]Process completed with exit code 255.

I can confirm the credentials work on my Mac - aws sts get-caller-identity returns a JSON block with the UserId, Account & user's Arn. These are user credentials with the following permissions:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor1",
            "Effect": "Allow",
            "Action": "sts:GetCallerIdentity",
            "Resource": "*"
        }
    ]
}

(I also temporarily gave it Administrator permissions yesterday to confirm it wasn't a permissions issue, to no effect)

The secrets are organisation-wide & I am certain are being pulled through - another secret I have is a SLACK_WEBHOOK_URL which is used to report that the builds fail (because of the error mentioned above!).

Is there any additional setup required with GitHub Actions to get this to work out-of-the-box that I'm missing?

Thanks,

When running on EC2 not picking up credentials

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

MFA/2fa support.

Is there any way to use the new workflow input features to request for a 2fa code when getting temporary credentials and put them in during the steps?

##[error]The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.The request signature we calculated does not match the signature you provided

I am receiving:

Configure AWS Credentials
Run aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ***
aws-secret-access-key: ***
aws-region: ***

##[error]The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

  • The first run with this access-key-id & aws-secret-access-key worked. Every consecutive run is failing.
  • This same access-key-id & aws-secret-access-key works consistently in circleci
  • Tried with aws-actions/[email protected] and received the same results

Config:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

Looks like a problem with: AWS Signature Version 4 Key Signing Errors
https://docs.aws.amazon.com/general/latest/gr/signature-v4-troubleshooting.html

Any suggestions?

AWS_* credentials are persisted throughout the job steps

Hello!

I can see that other actions in other steps are able to access AWS_* credentials set by aws-actions/configure-aws-credentials@v1:

image

Is there any flag like persist-credentials: false that i can use to unset those envars at the end of the step (like one in actions/checkout)?

Here is the workflow snips i use in my yaml file:

jobs:
  myjob:
    runs-on: windows-2016
    steps:

      # Do some stuff

      # Setup AWS CLI credentials
    - name: 'Configure AWS creds'
       uses: aws-actions/configure-aws-credentials@v1
       with:
         aws-access-key-id: ${{ secrets.MY_AWS_ACCESS_KEY_ID }}
         aws-secret-access-key: ${{ secrets.MY_AWS_SECRET_ACCESS_KEY }}
         aws-region: us-east-1

      # Publish to S3 
    - name: 'Copy to S3 bucket'
       run: |
         aws s3 cp ${{ github.workspace }}\foo\  s3://my-s3-bucket/bar/ --recursive --exclude "*" --include "*.baz"
       shell: pwsh

      # Send Slack notification
    - name: 'Slack channel notification'
       uses: 8398a7/action-slack@v3
       env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
       # other slack action config

Thanks in advance!

Need for sts:TagSession Permission

We are using the AWS Deploy CloudFormation Stack Github Action to configure AWS accounts that are created via AWS Organizations.

Of course, we are first using this action for credential configuration and assuming a role. However, this credential action does session tagging which requires the sts:TagSession permission. This need for tagging is of course documented in the readme of this action. However, in our case, the tag is needed in the trust policy of the OrganizationAccountAccessRole in the member account that is created by AWS Organizations.

This results in manual effort/intervention to our automated process. We have to configure the root user for the member account created by AWS Organizations to add the permission to the trust policy.

Would it be possible to make the session tagging optional?

Branch name validation too strict

We name our branches with a specific pattern that starts with a # followed by digits and other chars like #2-bit-ref-r.

But when executing the configure-aws-credentials action it fails since the name does not match the required regex pattern.

1 validation error detected: Value 'refs/heads/#2-bit-ref-r' at 'tags.7.member.value' failed to satisfy constraint: Member must satisfy regular expression pattern: [\p{L}\p{Z}\p{N}_.:/=+\-@]*

Since for github it's a valid branch name it should also be accepted by this action.

Pass custom tags

Hello!

It'd be nice to be able to pass custom tags in the session tagging, especially if the values can be GitHub Secrets.
We have some concerns around the power of the user that is required to make changes within our environments using GitHub Actions. Being able to pass custom tags, would enable us to create alarms, or possibly create restrictions based on missing tags in requests. You can't do this currently as all the tags are known and in plain text.

Cheers,

Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1

Thanks for making this available!

Following the instructions in the README, I have added this block in my action config

    - name: Configure AWS Credentials
      uses: aws-actions/configure-aws-credentials@v1
      with:
        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws-region: us-east-1

And I am getting the error in the title of the issue (see here). Am I missing something?

Thanks again!

Using Instance Profile to Assume Role

Hi, I am trying to assume a role with an instance profile but it keeps saying that the token request is invalid. The instance is a Self-Hosted GitHub Runner that has the ability to assume a role (dev_terraform) within the AWS console but does not have full access to AWS.

Below is the permissions policy for the instance profile to assume the role (dev_terraform):

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "sts:AssumeRole",
                "sts:TagSession",
                "sts:GetFederationToken"
            ],
            "Resource": "dev_terraform"
        },
        {
            "Sid": "VisualEditor1",
            "Effect": "Allow",
            "Action": [
                "sts:GetSessionToken",
                "sts:GetAccessKeyInfo",
                "sts:GetCallerIdentity",
                "sts:GetServiceBearerToken"
            ],
            "Resource": "*"
        },
        {
            "Sid": "VisualEditor2",
            "Effect": "Allow",
            "Action": "cloudformation:*",
            "Resource": "*"
        }
    ]
}

The permissions policy for the role that is being assumed (dev_terraform) has full admin access to the AWS environment. Below is the trust policy for the role that is being assumed (dev_terraform):

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "dev_github_runner"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}

Lastly, here is the github workflow I am trying to run:

name: Deploys CF from GH Runner

on:
  push:
    paths:
    - '.github/workflows/deployAwsCf.yml'

jobs:
  build:
    env:
      NODE_TLS_REJECT_UNAUTHORIZED: 0
      GIT_SSL_NO_VERIFY: true
    runs-on: [aws-ubuntu-runner]
    steps:
    - uses: actions/checkout@v2
    - uses: actions/configure-aws-credentials@v1
      with:
        aws-region: us-east-1
        role-to-assume: dev_terraform
#        role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
#        role-duration-seconds: 3600
#        role-session-name: CloudFormationSession

I have tried both this method and the role-to-assume method but neither of them work. I would like to know if I am missing anything else. I have tested the aws cli command on the virtual machine itself and it has worked successfully. Attached is the log file for the GitHub action.

log_553.txt

Multiple profiles

Is it possible to also setup multiple profiles which can be used?

Replacement options for actions/aws deprecation for S3 CLI usage

Hi 👋 I just noticed the deprecation warning for actions/aws/cli ("This actions has been deprecated in favor of https://github.com/aws-actions. This repo has been archived and will be made private on 12/31/2019") and wanted to ask about replacement steps.

Currently I have a workflow defined as:

- name: Upload S3
  uses: actions/aws/cli@master
  env:
    AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
    AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  with:
    args: s3 cp ./results/ s3://reports/results/ --recursive

I didn't see any other aws/cli Action within the aws-actions organization. Is there a way to call the s3 CLI from Actions now?

Sorry if I didn't see the proper migration steps and thanks for the Action/project 🙏

Optional AWS_ACCESS_KEY_ID and AWS_SECRET_ACCES_KEY when relying on IAM Roles

I'm using my own self-hosted runner which runs in AWS. The runner instance has IAM Role which takes care of the all the credentials and policies so I don't need to store any AWS credentials outside AWS.

The IAM role allows the runner to do a 'aws sts assume-role' but doesn't need any credentials (uses IAM role).
I would like to use this Github Action to do the assume-role, instead of scripting it myself and set the credential output as environment variable so I can use them in all the following steps, but currently AWS_ACCESS_KEY_ID and AWS_SECRET_ACCES_KEY are required. I would like to them to be optional so it fits the use case when using IAM roles which is a best-practice.

Consider lowering the role-duration default to 1 hour for role chaining

Currently the default for role-duration default is 6 hours:

role-duration-seconds:
description: "Role duration in seconds (default: 6 hours)"
required: false

documented here:

The default session duration is 6 hours, but if you would like to adjust this you can pass a duration to `role-duration-seconds`.

The rationale behind this is described in the code here:

// The max time that a GitHub action is allowed to run is 6 hours.
// That seems like a reasonable default to use if no role duration is defined.
const MAX_ACTION_RUNTIME = 6 * 3600;

That's a sensible default. I'd like to propose lowering the default to one hour to make the experience nicer for role-chaining. See [the footnote on this page]:

Using the credentials for one role to assume a different role is called role chaining. When you use role chaining, your new credentials are limited to a maximum duration of one hour. When you use roles to grant permissions to applications that run on EC2 instances, those applications are not subject to this limitation.

How does this come up for us? We have an automation that rotates IAM tokens in our GitHub repos. It uses temporary role tokens (with a 12 hour lifetime, rotated every 6 hours). For repos that need multiple roles we generate a "hub role" restricted to assuming that repos different roles (with an explicit deny for everything else). We install tokens for this "hub role" into the repos secrets. The error message that happens is easy to understand:

##[error]The requested DurationSeconds exceeds the 1 hour session limit for roles assumed by role chaining.

If we could pick a default from the start, I think 1 hour would make a bit more sense, just so that this case was smooth. I think it's not a very niche case but I'm not sure. One hour is still a reasonably long time for a build, and setting role-session-duration to 6 hours explicitly would still work.

If you're uncomfortable lowering the default, I understand. If you want a PR I'd be happy to do that.

At the very least, posting this so it shows up if someone searches for the error.

Invalid tag when assuming role

Hi 👋
I've just been trying to use the new role-assuming feature in master, but I've run into an issues with the session tagging.

I'm getting the following error:

##[error]1 validation error detected: Value 'dependabot-preview[bot]' at 'tags.5.member.value' failed to satisfy constraint: Member must satisfy regular expression pattern: [\p{L}\p{Z}\p{N}_.:/=+\-@]*
##[error]Node run failed with exit code 1

My theory is that this is caused by tagging the session with the GITHUB_ACTOR environment variable.
In this line, the session is tagged with GITHUB_ACTOR.

The actor of the run (and so GITHUB_ACTOR) was dependabot-preview[bot].
It seems that [ and ] are not valid characters in AWS session tags, and so this is crashing the program.

Seems like the tag must be removed or the variable sanitised.

Provide a way to allow multiple accounts?

I'm wonder if there might be a way to allow access to multiple AWS accounts. I've built an action that packages my code with all of my dependencies and installs the package as a lambda layer. What I'd like to be able to do is have the layer installed in the sandbox account (I'm using Organizations) so that the branch gets installed into their account.

So something like (not exactly sure what the YAML syntax would be):

       - name: Configure AWS credentials                                         
          uses: aws-actions/configure-aws-credentials@v1                          
          with:                                                                   
            aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_github.actor}}                                            
            aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_github.actor }}           
            aws-region: us-east-2    

and then specify all of the accounts in github secrets with user names appended - for example AWS_ACCESS_KEY_ID_wyllie. The idea would be that a developer would get a new version of the layer to test with their lambda functions whenever they push their code.

I guess a work around would be to have all the layers in one account and have them accessible to the sandbox accounts - I'm not sure if that would be an easy thing to configure though

feat: Add cli install option

It would be handy if the action could also have a flag install_cli: true|false, default false in order to install the latest cli on self-hosted runners.
Related #113

Your .dependabot/config.yml contained invalid details

Dependabot encountered the following error when parsing your .dependabot/config.yml:

Automerging is not enabled for this account. You can enable it from the [account settings](https://app.dependabot.com/accounts/aws-actions/settings) screen in your Dependabot dashboard.

Please update the config file to conform with Dependabot's specification using our docs and online validator.

Use incorrect sts endpoint when using China regions

Use aws credential like below,

    - name: Configure AWS credentials
      uses: aws-actions/configure-aws-credentials@v1
      with:
        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws-session-token: ${{secrets.AWS_SESSION_TOKEN}}
        aws-region: cn-northwest-1

Got below error,

Run aws-actions/configure-aws-credentials@v1
##[error]Inaccessible host: `sts.cn-northwest-1.amazonaws.com'. This service may not be available in the `cn-northwest-1' region.

According to the doc of AWS China region, the correct endpoint of STS in China region is sts.cn-northwest-1.amazonaws.com.cn. Of course, cn-northwest-1 will be replaced as cn-north-1 in BJS region.

[Error at /MyStack] Need to perform AWS calls for account ***, but no credentials have been configured

Hi everyone! Thanks for this amazing GH action. I have been using it almost over the past 2 years and it's being great!

I have a repository that was inactive for almost one year. Last weekend I tried to upgrade some dependencies and after merging to the main branch, I got an error in the deploy step with AWS CDK:

[Error at /MyStack] Need to perform AWS calls for account ***, but no credentials have been configured

Here's my GitHub Action file:

name: Server Deploy on staging

on:
  push:
    branches:
      - main

jobs:
  # DEPLOY SERVER STAGING
  server-deploy-staging:
    name: Deploy Server on Staging
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: '14.17'
      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_STAGING }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_STAGING }}
          aws-region: us-east-1
      - name: Cache yarn.lock
        id: yarn-cache
        uses: actions/cache@master
        with:
          path: |
            node_modules
            */*/node_modules
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-
      - name: Install
        if: steps.yarn-cache.outputs.cache-hit != 'true'
        run: |
          yarn install --frozen-lockfile --production=false --non-interactive
      - name: Deploy Server on Staging
        run: |
          cdk deploy MyStack \
            -c mode=staging \
            -c account='123' \
            --require-approval=never \
            --profile=my-profile

Any thoughts on why am I seeing this error?

The step Configure AWS Credentials is running successfully
Screen Shot 2021-06-28 at 15 27 18

Feature request: inline session policies for assuming role

Request

It would be great if this action could support session policies (the Policy parameter for AssumeRole operation) for assumed roles.

Problem being solved

Inline policies help IAM users apply permission boundaries to roles being assumed. This may help prevent accidents in a job or otherwise limit the scope in which the assumed role can be used thus improving security posture.

Use cases

Limiting permissions of a role based on action being taken

For example, a role may be specified as an organization secret with access to update many CloudFormation stacks. An inline policy might be used to reduce the permissions to a subset of resources, such as denying access to RDS resources or denying access when tags do not match expected tags for the project.

An example inline policy denying CloudFormation actions to resources with unexpected tags:

{
   "Version":"2012-10-17",
   "Statement":[
      {
         "Effect":"Deny",
         "Action":"CloudFormation:*",
         "Resource":"*",
         "Condition": {"StringNotLikeIfExists": {"aws:ResourceTag/CUSTOM_TAG": "my-tag-value"}}
      }
   ]
}

Limiting source IP for assumed role dynamically

One might use a session policy to ensure the temporary credentials generated by this action are limited to the source IP address of the GitHub action runner. Thus, if the temporary credentials are exfiltrated, they won't be (as) useful to an attacker.

For example, an inline policy may be generated dynamically by resolving the public IP of the GitHub runner, only allowing AWS actions to be taken from the current IP address (could be used with haythem/public-ip action)

Ref: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_examples_aws_deny-ip.html

Proposed usage

Usage might look like this:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - name Configure Inline Policy
      id: inline-policy
      uses: FICTIONAL_EXAMPLE@example
      with:
        some-param: value
      # outputs JSON policy string as `.policy`


    - name: Configure AWS Credentials
      uses: aws-actions/configure-aws-credentials@v1
      with:        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }}
        aws-region: us-east-2
        role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
        assume-role-policy:  ${{ steps.inline-policy.outputs.policy }}

How to update the secert while running the actions?

I am using this action to upload to s3, but my AWS_SECRET_ACCESS_KEY will expire after 30mins. I have a case where sometimes my script will take more than 30mins to execute and meanwhile this AWS_SECRET_ACCESS_KEY will expire. How to handle this kind of case?
For example:

steps:
      - uses: actions/checkout@master
      - run: bash script-run-more-time.sh # This might take more than 30mins
      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }}
          aws-region: us-east-2

Organization secrets don't work

Github recently released the feature to setup secrets at organization level.
I tried setting up AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY there and tried to use them with the action like:

    - name: Configure AWS Credentials
      uses: aws-actions/configure-aws-credentials@v1
      with:
        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws-region: us-east-1

But the actions fails:

Run aws-actions/configure-aws-credentials@v1
  with:
    aws-region: us-east-1
  env:
    PATH: /home/runner/.rubies/ruby-2.7.0/bin:/usr/share/rust/.cargo/bin:/home/runner/.config/composer/vendor/bin:/home/runner/.dotnet/tools:/snap/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin
##[error]Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1

I tried setting the same secrets at repo level and it works.

Proxy Support

Hello there,

it would be really nice to set a HTTP or HTTPS proxy server in the step configuration, or to just pass through the already set environmental settings of the runner.

If it is already possible and I just missed it where to set it, let me know.

web-identity-token-file is not in v1, but readme says it is

The readme indicates that web-identity-token-file is present in @v1

You can configure your workflow as follows in order to use this file:

uses: aws-actions/configure-aws-credentials@v1
with:
  aws-region: us-east-2
  role-to-assume: my-github-actions-role
  web-identity-token-file: /var/run/secrets/eks.amazonaws.com/serviceaccount/token

However it appears this functionality was added 4th August and the module has not been released since then. Hence you cannot use this feature as it is documented.

I have worked around this by

uses: aws-actions/configure-aws-credentials@master

But I cannot recommend this to others, as it does not pin the module to a stable (or released) version. However this may be worth either documenting, or removing the documentation until it has been released.

Ability to log out?

I have a scenario where I would like to have the capability to re-run the "configure-aws-credentials" action again using the same account but different roles inside the same job.

Is there a way to log out/reset/forget the credentials of the first run? My current option is to revert to bash and that is pretty verbose.

Thank you

Action overrides AWS env vars for subsequent running action

Hi.

I am using aws-actions/configure-aws-credentials@v1 and doing some ECR steps, after which i run a custom action similar to the below code, in which i set some env vars for awscli with different AWS credentials (key_id+secret) than those used with this action.

runs:
  ...
  inputs:
    aws_region:
      required: true
    aws_key:
      required: true
    aws_secret:
      required: true
  env:
    AWS_DEFAULT_REGION: ${{ inputs.aws_region }}
    AWS_ACCESS_KEY_ID: ${{ inputs.aws_key }}
    AWS_SECRET_ACCESS_KEY: ${{ inputs.aws_secret }}
  using: 'docker'
  image: 'docker://example/toolkit:latest'
  args:
    - 'bash'
    - '-c'
    - 'printenv | grep -i aws && aws configure list && aws sts get-caller-identity --output json | jq'

The vars are present both as standalone and those prefixed with INPUT_, but after seeing the output of aws configure list and aws sts get-caller-identity i find out that the credentials are not those i set manually, but those populated by configure-aws-credentials from previous steps.

So my questions are:

  • Why do they propagate and take precedence over the ones i set specifically in my custom action?
  • How can we reset credentials and vars or do a cleanup after using configure-aws-credentials action?

Comas on workflow name causes error

When the workflow name has a comma, the action fails with this error:

##[error]1 validation error detected: Value 'Build, Test and Deploy API' at 'tags.3.member.value' failed to satisfy constraint: Member must satisfy regular expression pattern: [\p{L}\p{Z}\p{N}_.:/=+\-@]*

Signature calculation fails

Hi.

I have a github workflow in which i use 2 sets of credentials coming from secrets. Both are just key, secret and region, no assume roles etc.

I run aws-actions/configure-aws-credentials@v1 with the first set of access_key_id+secret_key, then do a ECR login, docker build and push and then ECR logout all being successful.

After that i run aws-actions/configure-aws-credentials@v1 with the second set of access_key_id+secret_key which runs successfully also and then try to do a sts get-calller-identity or s3 ls but get the same error on both:

An error occurred (SignatureDoesNotMatch) when calling the GetCallerIdentity operation: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

So to debug i removed everything except the call with the second set of credentials, and now i get the error on the action level, which used to go through without error when i was doing the ECR stuff first.

Run aws-actions/configure-aws-credentials@v1

##[error]The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

P.S. I tested the second pair of credentials locally on my pc with the same python and awscli versions and i was able to run sts get-calller-identity without any problems.

Could not load credentials from any providers

I have already checked related issues #202 #188 , but in my case I am not using Dependabot.

This is my pipeline.yaml truncated till this action:

name: My Deployment
on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Setup node
        uses: actions/setup-node@v2
        with:
          node-version: '14'
      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-region: ap-southeast-1
          role-to-assume:arn:aws:iam::000000000000:role/github-actions-matteogioioso-saml-proxy
          role-session-name: GitHubActions
      
        ....

This is my trust relationship for that role:

{
  "Version": "2008-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Federated": "arn:aws:iam::000000000:oidc-provider/vstoken.actions.githubusercontent.com"
      },
      "Action": "sts:AssumeRoleWithWebIdentity",
      "Condition": {
        "StringLike": {
          "vstoken.actions.githubusercontent.com:sub": "repo:MatteoGioioso/saml-proxy:*"
        }
      }
    }
  ]
}

This is my OICD provider setup in IAM

image

And this is the error:

Run aws-actions/configure-aws-credentials@v1
  with:
    aws-region: ap-southeast-1
    role-to-assume: arn:aws:iam::000000000000:role/github-actions-matteogioioso-saml-proxy
    role-session-name: GitHubActions
Error: Credentials could not be loaded, please check your action inputs: Could not load credentials from any providers

I am not using a self-hosted runner

What am I doing wrong? Maybe the audience?

Thanks

UPDATE:

it seems like this method return false, because you do not validate credentials in the assumeRole method:

    const useGitHubOIDCProvider = () => {
        // The assumption here is that self-hosted runners won't be populating the `ACTIONS_ID_TOKEN_REQUEST_TOKEN`
        // environment variable and they won't be providing a web idenity token file or access key either.
        // V2 of the action might relax this a bit and create an explicit precedence for these so that customers
        // can provide as much info as they want and we will follow the established credential loading precedence.
        return roleToAssume && process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN && !accessKeyId && !webIdentityTokenFile
    }

honestly I cannot find a way to echo this variable ACTIONS_ID_TOKEN_REQUEST_TOKEN

UPDATE 2:

ok, this variable ACTIONS_ID_TOKEN_REQUEST_TOKEN is not set, I am not sure why is not there and also I cannot find much information about it.

I am willing to submit a PR if needed.

Getting aws command not found on MacOS self-hosted runner

Generally, this action appears to expose the aws cli to subsequent actions, however, on a self-hosted MacOS runner I get the following error:

/Users/runner/actions-runner/_work/_temp/***.sh: line 1: aws: command not found

With config:

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: us-east-2
      
      - name: Upload Artifacts to Primitive S3 Artifacts Manager
        run: |
          aws configure set default.s3.multipart_threshold 300MB

Exact same logic passes on ubuntu-latest github-hosted runner. Looking at documentation, it is suggested that self-hosted runners do not actually require any additional setup, docs only mention the convenience of not passing around secrets. However, this does not actually appear to be the case.

Installing AWS CLI manually on runner had no affect. Installed with sudo, and it worked.

README.md should be updated to reflect this requirement.

Trying to use `webIdentityTokenFile` results in `Credentials could not be loaded` error

https://docs.aws.amazon.com/cli/latest/reference/sts/assume-role-with-web-identity.html

I have a setup where I need to assume a role using a web identity token, AWS CLI commands below:

aws sts assume-role-with-web-identity \
 --role-arn $AWS_ROLE_ARN \
 --role-session-name mysession \
 --web-identity-token file:///var/run/secrets/eks.amazonaws.com/serviceaccount/token \
 --duration-seconds 1000 > /tmp/irp-cred.txt

export AWS_ACCESS_KEY_ID="$(cat /tmp/irp-cred.txt | jq -r ".Credentials.AccessKeyId")"
export AWS_SECRET_ACCESS_KEY="$(cat /tmp/irp-cred.txt | jq -r ".Credentials.SecretAccessKey")"
export AWS_SESSION_TOKEN="$(cat /tmp/irp-cred.txt | jq -r ".Credentials.SessionToken")"

Expected Action YAML:

    steps:
      - uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-region: eu-west-1
          role-to-assume: arn:aws:iam::xxxxxxxxx:role/role_name_to_assume
          web-identity-token: /var/run/secrets/eks.amazonaws.com/serviceaccount/token

The context to this is I have a pod running on a EKS cluster and EKS IRSA is not an option.

`role-skip-session-tagging: false` skips session tagging

getInput always returns a string, and this action doesn't convert the return value to a boolean. So if you specify role-skip-session-tagging: false, you won't get session tagging.

const roleSkipSessionTagging = core.getInput('role-skip-session-tagging', { required: false });

const roleSessionTags = roleSkipSessionTagging ? undefined : tagArray;

The obvious workaround is to just remove the role-skip-session-tagging option instead of specifying role-skip-session-tagging: false, but it's definitely confusing that role-skip-session-tagging: false doesn't work as expected.

error when using role-to-assume

As of 8/3/2020, we are seeing below error when using

##[error]Missing required environment value. Are you running in GitHub Actions?

- name: Configure AWS Credentials
  uses: aws-actions/configure-aws-credentials@v1
  with:
    aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
    aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
    aws-region: ${{ env.G_AWS_REGION }}
    role-to-assume: arn:aws:iam::${{ env.G_AWS_ACCOUNT_ID }}:${{ env.G_ROLE_ASSUME }}
    role-duration-seconds: 1200

to debug further, when we printed all the env variables ( GITHUB_REPOSITORY, GITHUB_WORKFLOW, GITHUB_ACTION, GITHUB_ACTOR, GITHUB_REF, GITHUB_SHA ) , we noticed GITHUB_ACTION to be empty.

Appreciate any help to get this fixed.

Fail if AWS_SDK_LOAD_CONFIG: true but no ~/.aws/config file

The current version of amazon-ecr-credential-helper, v0.4.0, requires:

    AWS_EC2_METADATA_DISABLED: true
    AWS_SDK_LOAD_CONFIG: true

in order to load the IAM Role for Service Account (IRSA) when run under Kubernetes.

Fortunately, configure-aws-credentials does not require those settings to work with IRSA, but unfortunately they do cause configure-aws-credentials to fail when there is no ~/.aws/credentials file:

Stack Trace
internal/fs/utils.js:220
    throw err;
    ^

Error: ENOENT: no such file or directory, open '/home/runner/.aws/credentials'
    at Object.openSync (fs.js:440:3)
    at Object.readFileSync (fs.js:342:35)
    at Object.readFileSync (/runner/_work/_actions/aws-actions/configure-aws-credentials/v1/dist/index.js:598:38)
    at IniLoader.parseFile (/runner/_work/_actions/aws-actions/configure-aws-credentials/v1/dist/index.js:6500:47)
    at IniLoader.loadFrom (/runner/_work/_actions/aws-actions/configure-aws-credentials/v1/dist/index.js:6550:30)
    at Config.region (/runner/_work/_actions/aws-actions/configure-aws-credentials/v1/dist/index.js:13483:36)
    at Config.set (/runner/_work/_actions/aws-actions/configure-aws-credentials/v1/dist/index.js:13150:39)
    at Config.<anonymous> (/runner/_work/_actions/aws-actions/configure-aws-credentials/v1/dist/index.js:12985:12)
    at Config.each (/runner/_work/_actions/aws-actions/configure-aws-credentials/v1/dist/index.js:1010:32)
    at new Config (/runner/_work/_actions/aws-actions/configure-aws-credentials/v1/dist/index.js:12984:19) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/home/runner/.aws/credentials'
}

This is using the current @v1 which points to commit 32d908a.

I would like/expect this situation to be handled, since in this case credentials come not from EC2 metadata or ~/.aws/credentials but instead from $AWS_WEB_IDENTITY_TOKEN_FILE, and everything works fine without those settings that amazon-ecr-credential-helper needs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.