Skip to content

Commit a707e1b

Browse files
authored
feat: add support for account ID in IMDS credentials (#1573)
1 parent 8c23dad commit a707e1b

File tree

22 files changed

+1091
-811
lines changed

22 files changed

+1091
-811
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"id": "525a1637-f0f1-4cbd-97dd-5e9c6bcd182e",
3+
"type": "feature",
4+
"description": "Add support for fetching account ID from IMDS credentials on EC2"
5+
}

aws-runtime/aws-config/api/aws-config.api

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public final class aws/sdk/kotlin/runtime/auth/credentials/EnvironmentCredential
7777

7878
public final class aws/sdk/kotlin/runtime/auth/credentials/ImdsCredentialsProvider : aws/smithy/kotlin/runtime/auth/awscredentials/CloseableCredentialsProvider {
7979
public fun <init> ()V
80+
public fun <init> (Ljava/lang/String;Laws/sdk/kotlin/runtime/config/imds/InstanceMetadataProvider;Laws/smithy/kotlin/runtime/util/PlatformProvider;)V
81+
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
8082
public fun <init> (Ljava/lang/String;Lkotlin/Lazy;Laws/smithy/kotlin/runtime/util/PlatformEnvironProvider;Laws/smithy/kotlin/runtime/time/Clock;)V
8183
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
8284
public fun close ()V
@@ -256,6 +258,7 @@ public final class aws/sdk/kotlin/runtime/config/AwsSdkSetting {
256258
public final fun getAwsContainerCredentialsFullUri ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
257259
public final fun getAwsContainerCredentialsRelativeUri ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
258260
public final fun getAwsDisableRequestCompression ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
261+
public final fun getAwsEc2InstanceProfileName ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
259262
public final fun getAwsEc2MetadataDisabled ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
260263
public final fun getAwsEc2MetadataServiceEndpoint ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
261264
public final fun getAwsEc2MetadataServiceEndpointMode ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
@@ -325,6 +328,8 @@ public final class aws/sdk/kotlin/runtime/config/endpoints/ResolversKt {
325328

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

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

402+
public final class aws/sdk/kotlin/runtime/config/imds/ImdsResolversKt {
403+
public static final fun resolveDisableEc2Metadata (Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
404+
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;
405+
public static final fun resolveEc2InstanceProfileName (Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
406+
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;
407+
}
408+
397409
public abstract interface class aws/sdk/kotlin/runtime/config/imds/InstanceMetadataProvider : java/io/Closeable {
398410
public abstract fun get (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
399411
}
@@ -494,6 +506,8 @@ public final class aws/sdk/kotlin/runtime/config/profile/AwsProfileKt {
494506
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;
495507
public static final fun getCredentialProcess (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/String;
496508
public static final fun getDisableRequestCompression (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/Boolean;
509+
public static final fun getEc2InstanceProfileName (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/String;
510+
public static final fun getEc2MetadataDisabled (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/Boolean;
497511
public static final fun getEndpointUrl (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Laws/smithy/kotlin/runtime/net/url/Url;
498512
public static final fun getIgnoreEndpointUrls (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/Boolean;
499513
public static final fun getIntOrNull (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Integer;

aws-runtime/aws-config/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.jetbrains.dokka.gradle.DokkaTaskPartial
99

1010
plugins {
1111
alias(libs.plugins.aws.kotlin.repo.tools.smithybuild)
12+
alias(libs.plugins.kotlinx.serialization)
1213
}
1314

1415
description = "Support for AWS configuration"
@@ -53,6 +54,7 @@ kotlin {
5354
implementation(libs.kotlinx.coroutines.test)
5455
implementation(libs.smithy.kotlin.http.test)
5556
implementation(libs.kotlinx.serialization.json)
57+
implementation(libs.kotest.framework.datatest)
5658
}
5759
}
5860
jvmTest {

aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/DefaultChainCredentialsProvider.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import aws.smithy.kotlin.runtime.util.PlatformProvider
4141
* @param region the region to make credentials requests to.
4242
* @return the newly-constructed credentials provider
4343
*/
44-
public class DefaultChainCredentialsProvider constructor(
44+
public class DefaultChainCredentialsProvider(
4545
public val profileName: String? = null,
4646
public val platformProvider: PlatformProvider = PlatformProvider.System,
4747
httpClient: HttpClientEngine? = null,
@@ -51,6 +51,11 @@ public class DefaultChainCredentialsProvider constructor(
5151
private val manageEngine = httpClient == null
5252
private val engine = httpClient ?: DefaultHttpEngine()
5353

54+
private val imdsClient = ImdsClient {
55+
platformProvider = this@DefaultChainCredentialsProvider.platformProvider
56+
engine = this@DefaultChainCredentialsProvider.engine
57+
}
58+
5459
private val chain = CredentialsProviderChain(
5560
SystemPropertyCredentialsProvider(platformProvider::getProperty),
5661
EnvironmentCredentialsProvider(platformProvider::getenv),
@@ -59,12 +64,7 @@ public class DefaultChainCredentialsProvider constructor(
5964
ProfileCredentialsProvider(profileName = profileName, platformProvider = platformProvider, httpClient = engine, region = region),
6065
EcsCredentialsProvider(platformProvider, engine),
6166
ImdsCredentialsProvider(
62-
client = lazy {
63-
ImdsClient {
64-
platformProvider = this@DefaultChainCredentialsProvider.platformProvider
65-
engine = this@DefaultChainCredentialsProvider.engine
66-
}
67-
},
67+
client = imdsClient,
6868
platformProvider = platformProvider,
6969
),
7070
)
@@ -75,6 +75,7 @@ public class DefaultChainCredentialsProvider constructor(
7575

7676
override fun close() {
7777
provider.close()
78+
imdsClient.close()
7879
if (manageEngine) {
7980
engine.closeIfCloseable()
8081
}

0 commit comments

Comments
 (0)