aws / aws-sdk-java-v2

The official AWS SDK for Java - Version 2
Apache License 2.0
2.16k stars 833 forks source link

STS not supported with native builds due to missing reflect-config #2985

Open elrob opened 2 years ago

elrob commented 2 years ago

Describe the bug

With STS service included as a dependency, the default credentials provider skips STS in the chain as StsWebIdentityCredentialsProviderFactory.class needs to be included in reflect-config.json

Including it manually fixes it. But other clients like S3 have reflect-config.json so STS should too.

Expected behavior

Within a native build, the STS credentials provider should be included as part of the default credentials provider chain if it is included as a dependency.

Current behavior

Even with STS service included as a dependency, the default credentials provider skips STS in the chain as StsWebIdentityCredentialsProviderFactory.class needs to be included in reflect-config.json

Steps to Reproduce

It occurs here: https://github.com/aws/aws-sdk-java-v2/blob/584ccb59e770177aeaa4c3b6bda4e24015b8ece9/core/auth/src/main/java/software/amazon/awssdk/auth/credentials/internal/WebIdentityCredentialsUtils.java#L46

This use of reflection means the software.amazon.awssdk.services.sts.internal.StsWebIdentityCredentialsProviderFactory is not picked up in a native build unless it is explicitly included in reflect-config.json.

Possible Solution

Create reflect-config.json for STS client package (like S3 etc) and include software.amazon.awssdk.services.sts.internal.StsWebIdentityCredentialsProviderFactory in it.

Context

No response

AWS Java SDK version used

latest

JDK version used

11

Operating System and version

linux

elrob commented 2 years ago

Original native image compilation support was added here: https://github.com/aws/aws-sdk-java-v2/commit/b9d26ef42fe5dd8a366eefca1844f2071547f2d2 (sts was left out)

debora-ito commented 2 years ago

Hi @elrob thank you for calling our attention to this. Marking as a bug.

nicolas-vivot commented 2 years ago

Is it possible to get this fixed ?

eduanb commented 1 year ago

This is still an issue, here is how you can add the hint in Spring Boot 3 and Kotlin:

@Configuration
@ImportRuntimeHints(StsRuntineHints::class)
class AwsStsRuntimeHints

class StsRuntineHints : RuntimeHintsRegistrar {
    override fun registerHints(hints: RuntimeHints, classLoader: ClassLoader?) {
        hints.reflection().registerType(StsWebIdentityCredentialsProviderFactory::class.java)
    }
}