Skip to content

Commit 4755174

Browse files
committed
Support assuming intermediate roles
1 parent 0d44843 commit 4755174

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

cmd/topicctl/subcmd/get.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func getPreRun(cmd *cobra.Command, args []string) error {
6161

6262
func getRun(cmd *cobra.Command, args []string) error {
6363
ctx := context.Background()
64-
sess := session.Must(session.NewSession())
64+
sess, _ := session.NewSession()
6565

6666
adminClient, err := getConfig.shared.getAdminClient(ctx, sess, true)
6767
if err != nil {

cmd/topicctl/subcmd/repl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func replPreRun(cmd *cobra.Command, args []string) error {
3232

3333
func replRun(cmd *cobra.Command, args []string) error {
3434
ctx := context.Background()
35-
sess := session.Must(session.NewSession())
35+
sess, _ := session.NewSession()
3636

3737
adminClient, err := replConfig.shared.getAdminClient(ctx, sess, true)
3838
if err != nil {

pkg/admin/connector.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"time"
1010

1111
"github.com/aws/aws-sdk-go/aws"
12+
"github.com/aws/aws-sdk-go/aws/credentials"
13+
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
1214
"github.com/aws/aws-sdk-go/aws/session"
1315
sigv4 "github.com/aws/aws-sdk-go/aws/signer/v4"
1416
"github.com/segmentio/kafka-go"
@@ -76,7 +78,14 @@ func NewConnector(config ConnectorConfig) (*Connector, error) {
7678
switch config.SASL.Mechanism {
7779
case SASLMechanismAWSMSKIAM:
7880
sess := session.Must(session.NewSession())
79-
signer := sigv4.NewSigner(sess.Config.Credentials)
81+
var creds *credentials.Credentials
82+
if config.SASL.AssumeRole != "" {
83+
creds = stscreds.NewCredentials(sess, config.SASL.AssumeRole)
84+
} else {
85+
creds = sess.Config.Credentials
86+
}
87+
88+
signer := sigv4.NewSigner(creds)
8089
region := aws.StringValue(sess.Config.Region)
8190

8291
mechanismClient = &aws_msk_iam.Mechanism{

0 commit comments

Comments
 (0)