AWS code-library documentation change
Summary
Updated IAM client initialization to use fromEnvironment() method and improved policy document formatting with Kotlin multiline strings
Security assessment
The change demonstrates using environment-based credential providers (fromEnvironment) which is a security best practice, but doesn't address a specific vulnerability. The policy content remains permissive ('s3:*' on all resources) but this is part of the example rather than a security fix.
Diff
diff --git a/code-library/latest/ug/kotlin_1_iam_code_examples.md b/code-library/latest/ug/kotlin_1_iam_code_examples.md index 0b70a7e90..1e414f585 100644 --- a//code-library/latest/ug/kotlin_1_iam_code_examples.md +++ b//code-library/latest/ug/kotlin_1_iam_code_examples.md @@ -116,13 +116,14 @@ Create functions that wrap IAM user actions. - val policyDocumentValue: String = - "{" + - " \"Version\": \"2012-10-17\"," + - " \"Statement\": [" + - " {" + - " \"Effect\": \"Allow\"," + - " \"Action\": [" + - " \"s3:*\"" + - " ]," + - " \"Resource\": \"*\"" + - " }" + - " ]" + - "}" + val policyDocumentValue = """ + { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "s3:*" + ], + "Resource": "*" + } + ] + } + """.trimIndent() @@ -136 +137 @@ Create functions that wrap IAM user actions. - IamClient { region = "AWS_GLOBAL" }.use { iamClient -> + IamClient.fromEnvironment { region = "AWS_GLOBAL" }.use { iamClient -> @@ -170 +171 @@ Create functions that wrap IAM user actions. - IamClient { region = "AWS_GLOBAL" }.use { iamClient -> + IamClient.fromEnvironment { region = "AWS_GLOBAL" }.use { iamClient -> @@ -213,5 +214 @@ Create functions that wrap IAM user actions. - val stsClient = - StsClient { - region = "us-east-1" - } - + val stsClient = StsClient.fromEnvironment { region = "us-east-1" } @@ -230,2 +227 @@ Create functions that wrap IAM user actions. - val staticCredentials = - StaticCredentialsProvider { + val staticCredentials = StaticCredentialsProvider { @@ -238,3 +234 @@ Create functions that wrap IAM user actions. - val s3 = - S3Client { - credentialsProvider = staticCredentials + val s3 = S3Client.fromEnvironment { @@ -241,0 +236 @@ Create functions that wrap IAM user actions. + credentialsProvider = staticCredentials @@ -263 +258 @@ Create functions that wrap IAM user actions. - val iam = IamClient { region = "AWS_GLOBAL" } + val iam = IamClient.fromEnvironment { region = "AWS_GLOBAL" } @@ -294 +289 @@ Create functions that wrap IAM user actions. - val iam = IamClient { region = "AWS_GLOBAL" } + val iam = IamClient.fromEnvironment { region = "AWS_GLOBAL" } @@ -363 +358 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - IamClient { region = "AWS_GLOBAL" }.use { iamClient -> + IamClient.fromEnvironment { region = "AWS_GLOBAL" }.use { iamClient -> @@ -424 +419 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - IamClient { region = "AWS_GLOBAL" }.use { iamClient -> + IamClient.fromEnvironment { region = "AWS_GLOBAL" }.use { iamClient -> @@ -453 +448 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - IamClient { region = "AWS_GLOBAL" }.use { iamClient -> + IamClient.fromEnvironment { region = "AWS_GLOBAL" }.use { iamClient -> @@ -477,17 +472,18 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - val policyDocumentVal = - "{" + - " \"Version\": \"2012-10-17\"," + - " \"Statement\": [" + - " {" + - " \"Effect\": \"Allow\"," + - " \"Action\": [" + - " \"dynamodb:DeleteItem\"," + - " \"dynamodb:GetItem\"," + - " \"dynamodb:PutItem\"," + - " \"dynamodb:Scan\"," + - " \"dynamodb:UpdateItem\"" + - " ]," + - " \"Resource\": \"*\"" + - " }" + - " ]" + - "}" + val policyDocumentVal = """ + { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "dynamodb:DeleteItem", + "dynamodb:GetItem", + "dynamodb:PutItem", + "dynamodb:Scan", + "dynamodb:UpdateItem" + ], + "Resource": "*" + } + ] + } + """.trimIndent() @@ -501 +497 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - IamClient { region = "AWS_GLOBAL" }.use { iamClient -> + IamClient.fromEnvironment { region = "AWS_GLOBAL" }.use { iamClient -> @@ -530 +526 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - IamClient { region = "AWS_GLOBAL" }.use { iamClient -> + IamClient.fromEnvironment { region = "AWS_GLOBAL" }.use { iamClient -> @@ -563 +559 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - IamClient { region = "AWS_GLOBAL" }.use { iamClient -> + IamClient.fromEnvironment { region = "AWS_GLOBAL" }.use { iamClient -> @@ -592 +588 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - IamClient { region = "AWS_GLOBAL" }.use { iamClient -> + IamClient.fromEnvironment { region = "AWS_GLOBAL" }.use { iamClient -> @@ -621 +617 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - IamClient { region = "AWS_GLOBAL" }.use { iamClient -> + IamClient.fromEnvironment { region = "AWS_GLOBAL" }.use { iamClient -> @@ -651 +647 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - IamClient { region = "AWS_GLOBAL" }.use { iamClient -> + IamClient.fromEnvironment { region = "AWS_GLOBAL" }.use { iamClient -> @@ -684 +680 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - IamClient { region = "AWS_GLOBAL" }.use { iamClient -> + IamClient.fromEnvironment { region = "AWS_GLOBAL" }.use { iamClient -> @@ -713 +709 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - IamClient { region = "AWS_GLOBAL" }.use { iamClient -> + IamClient.fromEnvironment { region = "AWS_GLOBAL" }.use { iamClient -> @@ -741 +737 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - IamClient { region = "AWS_GLOBAL" }.use { iamClient -> + IamClient.fromEnvironment { region = "AWS_GLOBAL" }.use { iamClient -> @@ -767 +763 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - IamClient { region = "AWS_GLOBAL" }.use { iamClient -> + IamClient.fromEnvironment { region = "AWS_GLOBAL" }.use { iamClient -> @@ -793 +789 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - IamClient { region = "AWS_GLOBAL" }.use { iamClient -> + IamClient.fromEnvironment { region = "AWS_GLOBAL" }.use { iamClient -> @@ -832 +828 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - IamClient { region = "AWS_GLOBAL" }.use { iamClient -> + IamClient.fromEnvironment { region = "AWS_GLOBAL" }.use { iamClient ->