bojanbass / nx-aws

NX monorepo with AWS S3 caching
147 stars 29 forks source link

Does this package support Github's recommended method of Configuring AWS Credentials (OIDC)? #649

Open avakil3 opened 3 months ago

avakil3 commented 3 months ago

Github recommends using GitHub's OIDC provider (AssumeRoleWithWebIdentity) to set up AWS credentials: see here.

When setting up AWS credentials this way in Github Actions, I am successfully able to upload a dummy test file to my S3 bucket using a aws s3 sync command. However, the nx affected test command doesn't upload any cache to the designated bucket and I get the error Error checking cache file existence - 403: UnknownError. However, I was successfully able to get it to work when I added the AWS access key and secret to my Github account as an ENV variable.

I was wondering if this package supports this method of AWS credentials setup in Github Actions.

Here is part of the github actions workflow yml that sets the AWS access key and secret:

`

steps:
  - name: Checkout
    uses: actions/checkout@v3
    with:
      fetch-depth: 0

  - name: Configure AWS Credentials
    id: creds
    uses: aws-actions/configure-aws-credentials@v4
    with:
      aws-region: us-east-1
      role-to-assume: [INSERT ROLE HERE]
      output-credentials: true

  - name: get caller identity 1
    run: aws sts get-caller-identity

  - name: Set AWS credentials as environment variables
    run: |
      echo "NXCACHE_AWS_ACCESS_KEY_ID=${{ steps.creds.outputs.aws-access-key-id }}" >> "$GITHUB_ENV"
      echo "NXCACHE_AWS_SECRET_ACCESS_KEY=${{ steps.creds.outputs.aws-secret-access-key }}" >> "$GITHUB_ENV"

`

HarryNiotis commented 2 months ago

@avakil3 I have made this work properly using OIDC flow. I just add a step in my actions before running any build command

- name: Configure AWS Credentials
    id: creds
    uses: aws-actions/configure-aws-credentials@v4
    with:
      aws-region: us-east-1
      role-to-assume: [INSERT ROLE HERE]

And I dont specify any AWS credentials for the nx-aws-cache package. I only specify the following on my workflows

 NXCACHE_AWS_BUCKET
 NXCACHE_AWS_ENCRYPTION_KEY (if you want to encrypt)

It then picks up the AWS credentials and runs properly. It uses the AWS sdk under the hood that works with cached credentials