Skip to content

Commit 0d44843

Browse files
committed
Add assumeRole option
1 parent 4961de2 commit 0d44843

File tree

3 files changed

+47
-26
lines changed

3 files changed

+47
-26
lines changed

cmd/topicctl/subcmd/shared.go

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@ import (
1414
)
1515

1616
type sharedOptions struct {
17-
brokerAddr string
18-
clusterConfig string
19-
expandEnv bool
20-
saslMechanism string
21-
saslPassword string
22-
saslUsername string
23-
tlsCACert string
24-
tlsCert string
25-
tlsEnabled bool
26-
tlsKey string
27-
tlsSkipVerify bool
28-
tlsServerName string
29-
zkAddr string
30-
zkPrefix string
17+
brokerAddr string
18+
clusterConfig string
19+
expandEnv bool
20+
saslMechanism string
21+
saslPassword string
22+
saslUsername string
23+
saslAssumeRole string
24+
tlsCACert string
25+
tlsCert string
26+
tlsEnabled bool
27+
tlsKey string
28+
tlsSkipVerify bool
29+
tlsServerName string
30+
zkAddr string
31+
zkPrefix string
3132
}
3233

3334
func (s sharedOptions) validate() error {
@@ -95,6 +96,10 @@ func (s sharedOptions) validate() error {
9596
(s.saslUsername != "" || s.saslPassword != "") {
9697
log.Warn("Username and password are ignored if using SASL AWS-MSK-IAM")
9798
}
99+
100+
if saslMechanism != admin.SASLMechanismAWSMSKIAM && s.saslAssumeRole != "" {
101+
log.Warn("AssumeRole is ignored unless using SASL AWS-MSK-IAM")
102+
}
98103
}
99104

100105
return err
@@ -150,10 +155,11 @@ func (s sharedOptions) getAdminClient(
150155
SkipVerify: s.tlsSkipVerify,
151156
},
152157
SASL: admin.SASLConfig{
153-
Enabled: saslEnabled,
154-
Mechanism: saslMechanism,
155-
Password: s.saslPassword,
156-
Username: s.saslUsername,
158+
Enabled: saslEnabled,
159+
Mechanism: saslMechanism,
160+
Password: s.saslPassword,
161+
Username: s.saslUsername,
162+
AssumeRole: s.saslAssumeRole,
157163
},
158164
},
159165
ReadOnly: readOnly,
@@ -211,6 +217,12 @@ func addSharedFlags(cmd *cobra.Command, options *sharedOptions) {
211217
os.Getenv("TOPICCTL_SASL_USERNAME"),
212218
"SASL username if using SASL; will override value set in cluster config",
213219
)
220+
cmd.Flags().StringVar(
221+
&options.saslAssumeRole,
222+
"sasl-assume-role",
223+
"",
224+
"Intermediate role to assume if using SASL AWS-MSK-IAM",
225+
)
214226
cmd.Flags().StringVar(
215227
&options.tlsCACert,
216228
"tls-ca-cert",

pkg/admin/connector.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ type TLSConfig struct {
4848

4949
// SASLConfig stores the SASL-related configuration for a connection.
5050
type SASLConfig struct {
51-
Enabled bool
52-
Mechanism SASLMechanism
53-
Username string
54-
Password string
51+
Enabled bool
52+
Mechanism SASLMechanism
53+
Username string
54+
Password string
55+
AssumeRole string
5556
}
5657

5758
// Connector is a wrapper around the low-level, kafka-go dialer and client.

pkg/config/cluster.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ type SASLConfig struct {
111111

112112
// Password is the SASL password. Ignored if mechanism is AWS-MSK-IAM.
113113
Password string `json:"password"`
114+
115+
// Intermediate role ARN to assume. Only used if mechanism is AWS-MSK-IAM.
116+
AssumeRole string `json:"assumeRole"`
114117
}
115118

116119
// Validate evaluates whether the cluster config is valid.
@@ -165,6 +168,10 @@ func (c ClusterConfig) Validate() error {
165168
(c.Spec.SASL.Username != "" || c.Spec.SASL.Password != "") {
166169
log.Warn("Username and password are ignored if using SASL AWS-MSK-IAM")
167170
}
171+
172+
if saslMechanism != admin.SASLMechanismAWSMSKIAM && c.Spec.SASL.AssumeRole != "" {
173+
log.Warn("AssumeRole is ignored unless using SASL AWS-MSK-IAM")
174+
}
168175
}
169176

170177
return err
@@ -231,10 +238,11 @@ func (c ClusterConfig) NewAdminClient(
231238
SkipVerify: c.Spec.TLS.SkipVerify,
232239
},
233240
SASL: admin.SASLConfig{
234-
Enabled: c.Spec.SASL.Enabled,
235-
Mechanism: saslMechanism,
236-
Username: saslUsername,
237-
Password: saslPassword,
241+
Enabled: c.Spec.SASL.Enabled,
242+
Mechanism: saslMechanism,
243+
Username: saslUsername,
244+
Password: saslPassword,
245+
AssumeRole: c.Spec.SASL.AssumeRole,
238246
},
239247
},
240248
ExpectedClusterID: c.Spec.ClusterID,

0 commit comments

Comments
 (0)