Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: role assumption in production #1194

Merged
merged 1 commit into from
Jan 22, 2025
Merged
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
43 changes: 20 additions & 23 deletions hq/app/aws/AWS.scala
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
package aws

import com.amazonaws.ClientConfiguration
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration
import config.Config
import model.{AwsAccount, DEV, PROD, Stage}
import model.AwsAccount
import play.api.Configuration
import utils.attempt.{Attempt, Failure}

import software.amazon.awssdk.core.client.builder.SdkClientBuilder
import software.amazon.awssdk.awscore.client.builder.AwsClientBuilder
import software.amazon.awssdk.awscore.client.builder.AwsAsyncClientBuilder
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider
import software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain
import software.amazon.awssdk.auth.credentials.{AwsCredentialsProviderChain, ProfileCredentialsProvider}
import software.amazon.awssdk.awscore.client.builder.{AwsAsyncClientBuilder, AwsClientBuilder}
import software.amazon.awssdk.core.client.config.SdkAdvancedAsyncClientOption
import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.services.cloudformation.CloudFormationAsyncClient
import software.amazon.awssdk.services.ec2.Ec2AsyncClient
import software.amazon.awssdk.services.efs.EfsAsyncClient
import software.amazon.awssdk.services.iam.IamAsyncClient
import software.amazon.awssdk.services.s3.S3Client
import software.amazon.awssdk.services.sts.StsClient
import software.amazon.awssdk.services.sts.auth.StsAssumeRoleCredentialsProvider
import software.amazon.awssdk.services.sts.model.AssumeRoleRequest
import software.amazon.awssdk.services.cloudformation.CloudFormationAsyncClient
import software.amazon.awssdk.services.dynamodb.DynamoDbClient
import software.amazon.awssdk.services.s3.S3Client
import software.amazon.awssdk.services.ec2.Ec2AsyncClient
import software.amazon.awssdk.services.efs.EfsAsyncClient
import software.amazon.awssdk.services.support.SupportAsyncClient


import utils.attempt.{Attempt, Failure}

import java.util.concurrent.Executors.newCachedThreadPool

Expand All @@ -38,15 +29,21 @@ object AWS {
)
}

private def stsClientForRoleAssumption(account: AwsAccount): StsClient = {
StsClient.builder.region(Config.region).credentialsProvider(ProfileCredentialsProvider.create(account.id)).build()
}

private def credentialsProvider(account: AwsAccount): AwsCredentialsProviderChain = {
AwsCredentialsProviderChain.of(
StsAssumeRoleCredentialsProvider.builder()
.stsClient(stsClientForRoleAssumption(account))
.refreshRequest(AssumeRoleRequest.builder.roleArn(account.roleArn).roleSessionName("security-hq").build()).build(),
.stsClient(
StsClient.builder
.region(Config.region)
.build()
)
.refreshRequest(
AssumeRoleRequest.builder
.roleArn(account.roleArn)
.roleSessionName("security-hq")
.build()
)
.build(),
ProfileCredentialsProvider.create(account.id)
)
}
Expand Down
Loading