forked from cloudflare/goflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SASL/SCAM support to Kafka transport. (cloudflare#121)
This pull request adds the optional -transport.kafka.scram flag, which tells the Kafka transport to use SASL/SCRAM for authentication. This allows goflow2 to work with AWS Managed Service for Kafka (MSK) which does not support SASL/PLAIN. Co-authored-by: Brian Landers <[email protected]> Co-authored-by: lspgn <[email protected]>
- Loading branch information
1 parent
3734d83
commit e0d30b7
Showing
4 changed files
with
110 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package kafka | ||
|
||
// From https://github.com/Shopify/sarama/blob/main/examples/sasl_scram_client/scram_client.go | ||
|
||
import ( | ||
"crypto/sha256" | ||
"crypto/sha512" | ||
|
||
"github.com/xdg-go/scram" | ||
) | ||
|
||
var ( | ||
SHA256 scram.HashGeneratorFcn = sha256.New | ||
SHA512 scram.HashGeneratorFcn = sha512.New | ||
) | ||
|
||
type XDGSCRAMClient struct { | ||
*scram.Client | ||
*scram.ClientConversation | ||
scram.HashGeneratorFcn | ||
} | ||
|
||
func (x *XDGSCRAMClient) Begin(userName, password, authzID string) (err error) { | ||
x.Client, err = x.HashGeneratorFcn.NewClient(userName, password, authzID) | ||
if err != nil { | ||
return err | ||
} | ||
x.ClientConversation = x.Client.NewConversation() | ||
return nil | ||
} | ||
|
||
func (x *XDGSCRAMClient) Step(challenge string) (response string, err error) { | ||
response, err = x.ClientConversation.Step(challenge) | ||
return | ||
} | ||
|
||
func (x *XDGSCRAMClient) Done() bool { | ||
return x.ClientConversation.Done() | ||
} |