Skip to content

Commit

Permalink
Add support for AWS S3 anonymous credentials
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
  • Loading branch information
pditommaso committed Apr 23, 2022
1 parent 720a84d commit ae7ba35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Advanced client configuration options can be set by using the ``client`` attribu
=========================== ================
Name Description
=========================== ================
anonymous Allow the access of public S3 buckets without the need to provide AWS credentials. Any service that does not accept unsigned requests will return a service access error.
s3Acl Allow the setting of a predefined bucket permissions also known as *canned ACL*. Permitted values are ``Private``, ``PublicRead``, ``PublicReadWrite``, ``AuthenticatedRead``, ``LogDeliveryWrite``, ``BucketOwnerRead``, ``BucketOwnerFullControl`` and ``AwsExecRead``. See `Amazon docs <https://docs.aws.amazon.com/AmazonS3/latest/userguide/acl-overview.html#canned-acl>`_ for details.
connectionTimeout The amount of time to wait (in milliseconds) when initially establishing a connection before giving up and timing out.
endpoint The AWS S3 API entry point e.g. `s3-us-west-1.amazonaws.com`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
import com.amazonaws.ClientConfiguration;
import com.amazonaws.Protocol;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AnonymousAWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.BasicSessionCredentials;
import com.amazonaws.services.s3.S3ClientOptions;
Expand Down Expand Up @@ -863,7 +864,12 @@ protected S3FileSystem createFileSystem0(URI uri, Object accessKey, Object secre
AmazonS3Client client;
ClientConfiguration config = createClientConfig(props);

if (accessKey == null && secretKey == null) {
final boolean anonymous = "true".equals(props.getProperty("anonymous"));
if( anonymous ) {
log.debug("Creating AWS S3 client with anonymous credentials");
client = new AmazonS3Client(new com.amazonaws.services.s3.AmazonS3Client(new AnonymousAWSCredentials(), config));
}
else if (accessKey == null && secretKey == null) {
client = new AmazonS3Client(new com.amazonaws.services.s3.AmazonS3Client(config));
}
else {
Expand Down

0 comments on commit ae7ba35

Please sign in to comment.