unbroken-dome / gradle-aws-codeartifact-plugin

Gradle Plugin for AWS CodeArtifact
MIT License
6 stars 6 forks source link

Does not work with AWS SSO Credentials #1

Open Spareo opened 2 years ago

Spareo commented 2 years ago

I would really like to integrate this with some projects but I am unable to get it to work with our AWS SSO credentials. I get the following error

Caused by: software.amazon.awssdk.core.exception.SdkClientException: Unable to load credentials from any of the providers in the chain AwsCredentialsProviderChain(credentialsProviders=[org.unbrokendome.gradle.plugins.aws.codeartifact.internal.aws.GradleProviderCredentialsProvider@87399638, ProfileCredentialsProvider(), ContainerCredentialsProvider(), InstanceProfileCredentialsProvider()]) : [org.unbrokendome.gradle.plugins.aws.codeartifact.internal.aws.GradleProviderCredentialsProvider@87399638: No value for access key ID, ProfileCredentialsProvider(): To use Sso related properties in the 'default' profile, the 'sso' service module must be on the class path., ContainerCredentialsProvider(): Cannot fetch credentials from container - neither AWS_CONTAINER_CREDENTIALS_FULL_URI or AWS_CONTAINER_CREDENTIALS_RELATIVE_URI environment variables are set., InstanceProfileCredentialsProvider(): Unable to load credentials from service endpoint.]

SSO credential support for the AWS Java SDK was added in version 2.15.33 per this PR . Would it be possible to get this plugin working with SSO credentials out of the box without any additional config?

cherrydev commented 2 years ago

I've created a PR for the upstream unbroken-dome/aws-codeartifact-maven-proxy repo that adds sso support, which only required the AWS SSO SDK library to be added to the build, and required no code changes. I'm also going to see if this can be worked around by just adding the same library to the buildscript dependencies of the project using the plugin. The author, @tkrullmann does appear to be active, so hopefully he'll see this, resolve the PR, then update the plugin to use the updated proxy version.

agrabovskis commented 1 month ago

To get your build scripts working with SSO add the AWS SSO library to classpath of plugins/buildscript (I'm using Kotlin synthax):

buildscript {
    dependencies {
        // required for AWS SSO authentication to work
        classpath("software.amazon.awssdk:sso:2.16.90")
    }
}

Then the plugin will see the "sso" module and you can set up AWS SSO configuration in ~/.aws/. It worked for me with the following keys configured:

One interesting detail is that you have to add aws_access_key_id= to ~/.aws/credentials (yes, it can be empty or any other value). Looks like some logic still checks that the Access Key is configured even though it is later superseded by SSO token.

Then you can aws sso login && ./gradlew ...