Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/525a1637-f0f1-4cbd-97dd-5e9c6bcd182e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "525a1637-f0f1-4cbd-97dd-5e9c6bcd182e",
"type": "feature",
"description": "Add support for fetching account ID from IMDS credentials on EC2"
}
14 changes: 14 additions & 0 deletions aws-runtime/aws-config/api/aws-config.api
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public final class aws/sdk/kotlin/runtime/auth/credentials/EnvironmentCredential

public final class aws/sdk/kotlin/runtime/auth/credentials/ImdsCredentialsProvider : aws/smithy/kotlin/runtime/auth/awscredentials/CloseableCredentialsProvider {
public fun <init> ()V
public fun <init> (Ljava/lang/String;Laws/sdk/kotlin/runtime/config/imds/InstanceMetadataProvider;Laws/smithy/kotlin/runtime/util/PlatformProvider;)V
public synthetic fun <init> (Ljava/lang/String;Laws/sdk/kotlin/runtime/config/imds/InstanceMetadataProvider;Laws/smithy/kotlin/runtime/util/PlatformProvider;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Lkotlin/Lazy;Laws/smithy/kotlin/runtime/util/PlatformEnvironProvider;Laws/smithy/kotlin/runtime/time/Clock;)V
public synthetic fun <init> (Ljava/lang/String;Lkotlin/Lazy;Laws/smithy/kotlin/runtime/util/PlatformEnvironProvider;Laws/smithy/kotlin/runtime/time/Clock;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun close ()V
Expand Down Expand Up @@ -256,6 +258,7 @@ public final class aws/sdk/kotlin/runtime/config/AwsSdkSetting {
public final fun getAwsContainerCredentialsFullUri ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
public final fun getAwsContainerCredentialsRelativeUri ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
public final fun getAwsDisableRequestCompression ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
public final fun getAwsEc2InstanceProfileName ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
public final fun getAwsEc2MetadataDisabled ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
public final fun getAwsEc2MetadataServiceEndpoint ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
public final fun getAwsEc2MetadataServiceEndpointMode ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
Expand Down Expand Up @@ -325,6 +328,8 @@ public final class aws/sdk/kotlin/runtime/config/endpoints/ResolversKt {

public final class aws/sdk/kotlin/runtime/config/imds/EC2MetadataError : aws/sdk/kotlin/runtime/AwsServiceException {
public fun <init> (ILjava/lang/String;)V
public fun <init> (Laws/smithy/kotlin/runtime/http/HttpStatusCode;Ljava/lang/String;)V
public final fun getStatus ()Laws/smithy/kotlin/runtime/http/HttpStatusCode;
public final fun getStatusCode ()I
}

Expand Down Expand Up @@ -394,6 +399,13 @@ public final class aws/sdk/kotlin/runtime/config/imds/ImdsClient$Companion {
public final fun invoke (Lkotlin/jvm/functions/Function1;)Laws/sdk/kotlin/runtime/config/imds/ImdsClient;
}

public final class aws/sdk/kotlin/runtime/config/imds/ImdsResolversKt {
public static final fun resolveDisableEc2Metadata (Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun resolveDisableEc2Metadata$default (Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun resolveEc2InstanceProfileName (Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun resolveEc2InstanceProfileName$default (Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
}

public abstract interface class aws/sdk/kotlin/runtime/config/imds/InstanceMetadataProvider : java/io/Closeable {
public abstract fun get (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
Expand Down Expand Up @@ -494,6 +506,8 @@ public final class aws/sdk/kotlin/runtime/config/profile/AwsProfileKt {
public static synthetic fun getBooleanOrNull$default (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/Boolean;
public static final fun getCredentialProcess (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/String;
public static final fun getDisableRequestCompression (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/Boolean;
public static final fun getEc2InstanceProfileName (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/String;
public static final fun getEc2MetadataDisabled (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/Boolean;
public static final fun getEndpointUrl (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Laws/smithy/kotlin/runtime/net/url/Url;
public static final fun getIgnoreEndpointUrls (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/Boolean;
public static final fun getIntOrNull (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Integer;
Expand Down
2 changes: 2 additions & 0 deletions aws-runtime/aws-config/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.jetbrains.dokka.gradle.DokkaTaskPartial

plugins {
alias(libs.plugins.aws.kotlin.repo.tools.smithybuild)
alias(libs.plugins.kotlinx.serialization)
}

description = "Support for AWS configuration"
Expand Down Expand Up @@ -53,6 +54,7 @@ kotlin {
implementation(libs.kotlinx.coroutines.test)
implementation(libs.smithy.kotlin.http.test)
implementation(libs.kotlinx.serialization.json)
implementation(libs.kotest.framework.datatest)
}
}
jvmTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import aws.smithy.kotlin.runtime.util.PlatformProvider
* @param region the region to make credentials requests to.
* @return the newly-constructed credentials provider
*/
public class DefaultChainCredentialsProvider constructor(
public class DefaultChainCredentialsProvider(
public val profileName: String? = null,
public val platformProvider: PlatformProvider = PlatformProvider.System,
httpClient: HttpClientEngine? = null,
Expand All @@ -51,6 +51,11 @@ public class DefaultChainCredentialsProvider constructor(
private val manageEngine = httpClient == null
private val engine = httpClient ?: DefaultHttpEngine()

private val imdsClient = ImdsClient {
platformProvider = this@DefaultChainCredentialsProvider.platformProvider
engine = this@DefaultChainCredentialsProvider.engine
}

private val chain = CredentialsProviderChain(
SystemPropertyCredentialsProvider(platformProvider::getProperty),
EnvironmentCredentialsProvider(platformProvider::getenv),
Expand All @@ -59,12 +64,7 @@ public class DefaultChainCredentialsProvider constructor(
ProfileCredentialsProvider(profileName = profileName, platformProvider = platformProvider, httpClient = engine, region = region),
EcsCredentialsProvider(platformProvider, engine),
ImdsCredentialsProvider(
client = lazy {
ImdsClient {
platformProvider = this@DefaultChainCredentialsProvider.platformProvider
engine = this@DefaultChainCredentialsProvider.engine
}
},
client = imdsClient,
platformProvider = platformProvider,
),
)
Expand All @@ -75,6 +75,7 @@ public class DefaultChainCredentialsProvider constructor(

override fun close() {
provider.close()
imdsClient.close()
if (manageEngine) {
engine.closeIfCloseable()
}
Expand Down
Loading
Loading