carlspring / s3fs-nio

A Java (NIO2) FileSystem Provider for Amazon AWS S3.
https://s3fs-nio.carlspring.org/
66 stars 23 forks source link

403 STS #768

Open jeronimonunes opened 1 year ago

jeronimonunes commented 1 year ago

Bug Description

Using STS library all requests turns out as 403

Steps To Reproduce

  1. Create a project using this library
  2. Implement a basic put request
  3. Place the STS library into you classpath or pom.xml
  4. Deploy the application in an environment that provide the STS authentication

Expected Behavior

Requests are successfully authenticated

Environment

steve-todorov commented 1 year ago

Hey,

Apologies for the delayed reply, but we've been busy the past weeks.

It sounds to me like you have not properly configured the environment for the new filesystem:

import static org.carlspring.cloud.storage.s3fs.S3Factory.ACCESS_KEY;
import static org.carlspring.cloud.storage.s3fs.S3Factory.SECRET_KEY;

Map<String, ?> env = ImmutableMap.<String, Object> builder().put(ACCESS_KEY, "access key")
                                                            .put(SECRET_KEY, "secret key")
                                                            .build();

FileSystems.newFileSystem(URI.create("s3:///"), env, Thread.currentThread().getContextClassLoader());

We currently do not support picking up the AWS environment variables so if you've deployed this in an EC2 instance with STS then that would not work out of the box unfortunately. You could probably use this:

Map<String, ?> env = ImmutableMap.<String, Object> builder().put(ACCESS_KEY, System.getEnv('AWS_ACCESS_KEY_ID'))
                                                            .put(SECRET_KEY, System.getEnv('AWS_SECRET_ACCESS_KEY'))
                                                            .build();

It is in our TODO list to have this automatically picked up, but we simply don't have that much time to dig into it right now. We are open for PRs if you are interested in working on this feature. :)