Skip to content

Commit 07e1eeb

Browse files
committed
docs: added README for msk iam module
1 parent 9fc698c commit 07e1eeb

File tree

2 files changed

+126
-1
lines changed

2 files changed

+126
-1
lines changed

sasl/aws_msk_iam/README.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# AWS MSK IAM
2+
3+
This extension provides a capability to get authenticated with [AWS Managed Apache Kafka](https://aws.amazon.com/msk/)
4+
through AWS IAM.
5+
6+
You can use the `Mechanism` for SASL authentication, like below.
7+
8+
```go
9+
ctx := context.Background()
10+
11+
// using aws-sdk-go-v2
12+
creds, err := aws.NewConfig().Credentials.Retrieve(ctx)
13+
if err != nil {
14+
// NOTE: address error properly
15+
panic(err)
16+
}
17+
m := &Mechanism{
18+
GenericSigner: &AWSSignerV2{
19+
Signer: sigv2.NewSigner(),
20+
Credentials: creds,
21+
},
22+
Region: "us-east-1",
23+
SignTime: time.Now(),
24+
Expiry: time.Minute * 5,
25+
}
26+
config := kafka.ReaderConfig{
27+
Brokers: []string{"https://localhost"},
28+
GroupID: "some-consumer-group",
29+
GroupTopics: []string{"some-topic"},
30+
Dialer: &kafka.Dialer{
31+
Timeout: 10 * time.Second,
32+
DualStack: true,
33+
SASLMechanism: m,
34+
TLS: &tls.Config{},
35+
},
36+
}
37+
```
38+
39+
40+
## Examples
41+
42+
### aws-sdk-go-v2
43+
44+
If you use [aws-sdk-go-v2](https://github.com/aws/aws-sdk-go-v2), you can use `AWSSignerV2` to get authenticated with MSK.
45+
46+
```go
47+
package main
48+
49+
import (
50+
"context"
51+
"time"
52+
53+
"github.com/aws/aws-sdk-go-v2/aws"
54+
sigv2 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
55+
)
56+
57+
func main() {
58+
ctx := context.Background()
59+
creds, err := aws.NewConfig().Credentials.Retrieve(ctx)
60+
if err != nil {
61+
// NOTE: address error properly
62+
panic(err)
63+
}
64+
m := &Mechanism{
65+
GenericSigner: &AWSSignerV2{
66+
Signer: sigv2.NewSigner(),
67+
Credentials: creds,
68+
},
69+
Region: "us-east-1",
70+
SignTime: time.Now(),
71+
Expiry: time.Minute * 5,
72+
}
73+
}
74+
```
75+
76+
### aws-sdk-go
77+
78+
If you use [aws-sdk-go](https://github.com/aws/aws-sdk-go), which is a old version of SDK, you can use `AWSSignerV1` to get authenticated with MSK.
79+
80+
```go
81+
package main
82+
83+
import (
84+
"time"
85+
86+
"github.com/aws/aws-sdk-go/aws/defaults"
87+
sig "github.com/aws/aws-sdk-go/aws/signer/v4"
88+
)
89+
90+
func main() {
91+
m := &Mechanism{
92+
GenericSigner: &AWSSignerV1{
93+
Signer: sig.NewSigner(defaults.Config().Credentials),
94+
},
95+
Region: "us-east-1",
96+
SignTime: time.Now(),
97+
Expiry: time.Minute * 5,
98+
}
99+
}
100+
```
101+
102+
### Authentication method at Old Version of Kafka-Go
103+
104+
The old versions of `kafka-go` library was using [aws-sdk-go](https://github.com/aws/aws-sdk-go).
105+
We keep this functionality for backward compatibility.
106+
107+
```go
108+
package main
109+
110+
import (
111+
"time"
112+
113+
"github.com/aws/aws-sdk-go/aws/defaults"
114+
sig "github.com/aws/aws-sdk-go/aws/signer/v4"
115+
)
116+
117+
func main() {
118+
m := &Mechanism{
119+
Signer: sig.NewSigner(defaults.Config().Credentials),
120+
Region: "us-east-1",
121+
SignTime: time.Now(),
122+
Expiry: time.Minute * 5,
123+
}
124+
}
125+
```

sasl/aws_msk_iam/msk_iam.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type SignerIfc interface {
3535
// Mechanism implements sasl.Mechanism for the AWS_MSK_IAM mechanism, based on the official java implementation:
3636
// https://github.com/aws/aws-msk-iam-auth
3737
type Mechanism struct {
38-
// Deprecated, to support both of the aws-sdk-go-v1 and aws-sdk-go-v2, we implemented GenericSigner. The sig.Signer to use when signing the request.
38+
// \The sig.Signer to use when signing the request. To support both of the aws-sdk-go-v1 and aws-sdk-go-v2, we implemented GenericSigner too.
3939
Signer *sig.Signer
4040
// interface which supports both of the aws-sdk-go-v1 and aws-sdk-go-v2, use when signing the request.
4141
GenericSigner SignerIfc

0 commit comments

Comments
 (0)