minio-java icon indicating copy to clipboard operation
minio-java copied to clipboard

ChainProvider breaks on AwsEnvironmentProvider

Open lespea opened this issue 9 months ago • 2 comments

I'm trying to use a ChainedProvider such that it tries both the aws env variables and the aws config file. If I have the provider setup like this,

        ChainedProvider(
          new AwsConfigProvider(null, null),
          new AwsEnvironmentProvider(),
        ),

It works just fine (i.e. if I have a config file it reads that otherwise picks up the env secrets). However if I swap the order then I get an exception because it doesn't fall back to the config file...

        ChainedProvider(
          new AwsEnvironmentProvider(),
          new AwsConfigProvider(null, null),
        ),

throws

[error] java.lang.RuntimeException: java.lang.NullPointerException: AccessKey must not be null
[error] 	at io.minio.S3Base.throwEncapsulatedException(S3Base.java:308)
[error] 	at io.minio.MinioClient.listBuckets(MinioClient.java:782)

[error] Caused by: java.lang.NullPointerException: AccessKey must not be null
[error] 	at java.base/java.util.Objects.requireNonNull(Objects.java:259)
[error] 	at io.minio.credentials.Credentials.<init>(Credentials.java:55)
[error] 	at io.minio.credentials.AwsEnvironmentProvider.fetch(AwsEnvironmentProvider.java:35)
[error] 	at io.minio.credentials.ChainedProvider.fetch(ChainedProvider.java:51)
[error] 	at io.minio.S3Base.executeAsync(S3Base.java:586)
[error] 	at io.minio.S3Base.lambda$executeAsync$1(S3Base.java:828)
[error] 	at java.base/java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:1187)
[error] 	at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2341)
[error] 	at io.minio.S3Base.executeAsync(S3Base.java:825)
[error] 	at io.minio.S3Base.executeGetAsync(S3Base.java:988)
[error] 	at io.minio.MinioAsyncClient.listBuckets(MinioAsyncClient.java:1355)
[error] 	at io.minio.MinioAsyncClient.listBuckets(MinioAsyncClient.java:1333)
[error] 	at io.minio.MinioClient.listBuckets(MinioClient.java:778)

Not sure if I'm just using something incorrectly or if it's a bug. I haven't tested any other providers FYI.

lespea avatar Mar 03 '25 19:03 lespea

@lespea Feel free to send a PR to AwsEnvironmentProvider.java

balamurugana avatar Mar 04 '25 01:03 balamurugana

I started looking at this, and it seems the solution to catch this and future/other problems would be to modify the Credentials constructor so that itseld throws a ProviderException if the access/secret key are null/empty. However that would change the signature of the exception which I'm not sure you want to do? I could also modify the ChainedProvider so that it just tries each provider for any exception type but I'm not 100% sure if that's desired either? Otherwise just modifying the individual Providers to throw the correct exception type is probably the least invasive.

lespea avatar Mar 04 '25 05:03 lespea

Fixed by https://github.com/minio/minio-java/pull/1621

balamurugana avatar Jul 21 '25 13:07 balamurugana