Skip to content

Allow the AWS SDK to get auth from the environment (fixes #28) #88

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

Merged
merged 8 commits into from
Apr 8, 2025

Conversation

Makeshift
Copy link
Contributor

@Makeshift Makeshift commented Jan 10, 2025

The AWS SDK can automatically gather auth from various sources in the environment, but this couldn't happen because the zod schema validation would throw if you didn't provide STORAGE_S3_ACCESS_KEY and STORAGE_S3_SECRET_KEY.

This PR makes several of the env vars optional, and deprecates them in favour of the env vars AWS SDK will infer by default.

I've tested these changes in my EKS cluster with IRSA set up for the pod to assume a role for S3 access, and it seems to work as expected.

Fixes #28, and should still be backwards compatible.


const s3 = new S3Client({
credentials: {
if (options.STORAGE_S3_ACCESS_KEY && options.STORAGE_S3_SECRET_KEY) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This being separate is required, because having secretAccessKey and accessKeyId keys set to undefined in a credential object will cause the AWS SDK to throw and not actually grab from the env

@axelfontaine
Copy link

This would also be very useful on EC2 for automatically using instance profiles.

Is there anything preventing this from being merged?

@LouisHaftmann LouisHaftmann requested a review from DrJume February 15, 2025 09:39
Copy link
Collaborator

@DrJume DrJume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your PR! As we don't have experience with AWS, we appreciate you helping to include this platform.
The changes proposed improve AWS usage, but it seems, a little bit at the cost of the manual configuration.
Not everyone using S3 is on AWS, so it would be nice to combine the two approaches equally.
A compromise would be to keep the current manual documentation and validation, but to add a new Auto-Config parameter, making it easier for people using AWS. This extra parameter would add your logic, instead of replacing the current manual way.

@Makeshift
Copy link
Contributor Author

Thank you for your PR! As we don't have experience with AWS, we appreciate you helping to include this platform. The changes proposed improve AWS usage, but it seems, a little bit at the cost of the manual configuration. Not everyone using S3 is on AWS, so it would be nice to combine the two approaches equally. A compromise would be to keep the current manual documentation and validation, but to add a new Auto-Config parameter, making it easier for people using AWS. This extra parameter would add your logic, instead of replacing the current manual way.

If you're using the AWS SDK, the AWS_ vars work for all S3 providers, irrelevant of the actual S3 backend in use. For example, if ran on my branch, this compose file sets all the needed config options via env var for AWS-SDK to communicate successfully with local minio:

services:
  postgres:
    image: postgres:15
    ports:
      - 5432:5432
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: postgres

  mysql:
    image: mysql:8
    ports:
      - 3306:3306
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: mysql

  minio:
    image: quay.io/minio/minio:latest
    entrypoint: sh
    command: -c 'mkdir -p /data/test && /usr/bin/minio server /data'
    ports:
      - 9000:9000
    environment:
      MINIO_ROOT_USER: access_key
      MINIO_ROOT_PASSWORD: secret_key

  cache-server:
    build:
      dockerfile: Dockerfile
      context: .
    ports:
      - '3000:3000'
    environment:
      API_BASE_URL: http://localhost:3000

      STORAGE_DRIVER: s3
      STORAGE_S3_BUCKET: test
###### vvvvv
      AWS_ACCESS_KEY_ID: access_key
      AWS_SECRET_ACCESS_KEY: secret_key
      AWS_ENDPOINT_URL: http://minio:9000

They're functionally identical to passing the vars in when invoking the SDK, like you are currently, so I wouldn't say it's an AWS-centric change - merely unlocking the rest of the functionality that AWS SDK exposes rather than just a limited sliver.

The SDK already has many different auth mechanisms whether you're using AWS or not, and promoting using them rather than adding a limited custom config setup on top reduces maintenance overhead for you and improves adoption by allowing for more advanced use-cases that would be non-feasible for you to support (Such as OIDC authentication with minio).

Would some better documentation, eg examples and links to the SDK environment variables list help? (this is actually the CLI variable list, but they're very intentionally identical to the SDK variable list)

@LouisHaftmann
Copy link
Collaborator

I would probably completely replace our custom env vars in favor of aws defaults and only validate vars which are always required. The basic env vars should also be mentioned in the docs so people don't have to look it up elsewhere.

@DrJume
Copy link
Collaborator

DrJume commented Feb 18, 2025

Thank you for your PR! As we don't have experience with AWS, we appreciate you helping to include this platform. The changes proposed improve AWS usage, but it seems, a little bit at the cost of the manual configuration. Not everyone using S3 is on AWS, so it would be nice to combine the two approaches equally. A compromise would be to keep the current manual documentation and validation, but to add a new Auto-Config parameter, making it easier for people using AWS. This extra parameter would add your logic, instead of replacing the current manual way.

If you're using the AWS SDK, the AWS_ vars work for all S3 providers, irrelevant of the actual S3 backend in use. For example, if ran on my branch, this compose file sets all the needed config options via env var for AWS-SDK to communicate successfully with local minio:

services:

  postgres:

    image: postgres:15

    ports:

      - 5432:5432

    environment:

      POSTGRES_USER: postgres

      POSTGRES_PASSWORD: postgres

      POSTGRES_DB: postgres



  mysql:

    image: mysql:8

    ports:

      - 3306:3306

    environment:

      MYSQL_ROOT_PASSWORD: root

      MYSQL_DATABASE: mysql



  minio:

    image: quay.io/minio/minio:latest

    entrypoint: sh

    command: -c 'mkdir -p /data/test && /usr/bin/minio server /data'

    ports:

      - 9000:9000

    environment:

      MINIO_ROOT_USER: access_key

      MINIO_ROOT_PASSWORD: secret_key



  cache-server:

    build:

      dockerfile: Dockerfile

      context: .

    ports:

      - '3000:3000'

    environment:

      API_BASE_URL: http://localhost:3000



      STORAGE_DRIVER: s3

      STORAGE_S3_BUCKET: test

###### vvvvv

      AWS_ACCESS_KEY_ID: access_key

      AWS_SECRET_ACCESS_KEY: secret_key

      AWS_ENDPOINT_URL: http://minio:9000

They're functionally identical to passing the vars in when invoking the SDK, like you are currently, so I wouldn't say it's an AWS-centric change - merely unlocking the rest of the functionality that AWS SDK exposes rather than just a limited sliver.

The SDK already has many different auth mechanisms whether you're using AWS or not, and promoting using them rather than adding a limited custom config setup on top reduces maintenance overhead for you and improves adoption by allowing for more advanced use-cases that would be non-feasible for you to support (Such as OIDC authentication with minio).

Would some better documentation, eg examples and links to the SDK environment variables list help? (this is actually the CLI variable list, but they're very intentionally identical to the SDK variable list)

You're right. I didn't know that the AWS SDK handles so many credentials environments cases.

@axelfontaine
Copy link

I just want to add that this isn't just nice to have, it's essential. When using EC2 instance profiles, the credentials in the instance metadata are temporary and refresh regularly. Passing them to the cache server doesn't help as they will fail as soon as the first refresh happens. The AWS SDK handles all this automatically. This PR is really essential for making things work.

@LouisHaftmann
Copy link
Collaborator

LouisHaftmann commented Mar 1, 2025

Alright, let's just remove our custom env var validation and just let the aws sdk handle configuration.

todos:

  • remove custom env validation logic
  • update docs with link to aws sdk docs
  • update examples in docs

@reegnz
Copy link

reegnz commented Mar 27, 2025

@Makeshift can you do what @LouisHaftmann asked? I think there's a couple of us that would be grateful if this awesome tool would work with the AWS SDK default credential chain out of the box.

* upstream/dev:
  chore(release): v7.0.1
  fix: execute delete query for pruning uploads (falcondev-oss#123)
  docs: use correct env var name for cache cleanup (falcondev-oss#125)
  ci(release): push also tag `dev`
  chore(release): v7.0.0
  docs: add `zstd` info
  feat: proxy unknown requests to default GitHub `ACTIONS_RESULTS_URL` & revive v1 support
  build(docker): use cluster size of 1 by default
  chore(helm): add proxy port 8000
  feat!: drop cache service v1 support
  fix(proxy): disable passthrough websockets
  feat(proxy): enable http2
  feat(proxy): only tls intercept required hostname
  feat: enable nitro `node-cluster` preset
  feat: enable proxy debug logs if debug enabled
  test: add random path prefix to `ACTIONS_CACHE_URL`
  chore(release): v6.0.1
  fix: handle random path prefix for cache service v1 routes
  chore(release): v6.0.0
  feat!: binary patching alternative (falcondev-oss#112)
@Makeshift
Copy link
Contributor Author

@LouisHaftmann I think that should do it, if you're willing to re-review.

@Makeshift Makeshift requested a review from DrJume March 30, 2025 11:00
@LouisHaftmann LouisHaftmann self-requested a review March 31, 2025 00:55
@LouisHaftmann
Copy link
Collaborator

Sorry for the delay, was on vacation for the last 3 weeks.

We just need to update the test env vars. Then we can merge. @Makeshift

.env.s3.storage

STORAGE_DRIVER=s3
STORAGE_S3_BUCKET=test
AWS_ENDPOINT_URL=http://localhost:9000
AWS_ACCESS_KEY_ID=minioadmin
AWS_SECRET_ACCESS_KEY=minioadmin

@Makeshift
Copy link
Contributor Author

Done - Also fixed .env in the root since I'd missed that before too.

@LouisHaftmann LouisHaftmann merged commit 41ed9d6 into falcondev-oss:dev Apr 8, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AWS IRSA support
5 participants