-
Notifications
You must be signed in to change notification settings - Fork 45
Add support for role chain assumption #132
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,11 +7,15 @@ import ( | |
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "net" | ||
| "os" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/aws/aws-sdk-go-v2/aws" | ||
| "github.com/aws/aws-sdk-go-v2/config" | ||
| "github.com/aws/aws-sdk-go-v2/credentials/stscreds" | ||
| "github.com/aws/aws-sdk-go-v2/service/sts" | ||
| "github.com/twmb/franz-go/pkg/kadm" | ||
| "github.com/twmb/franz-go/pkg/kgo" | ||
| "github.com/twmb/franz-go/pkg/sasl" | ||
|
|
@@ -123,7 +127,10 @@ func NewAdminClient(ctx context.Context, data []byte, kube client.Client) (*kadm | |
| Pass: kc.SASL.Password, | ||
| }.AsMechanism() | ||
| case "aws-msk-iam": | ||
| mechanism = kaws.ManagedStreamingIAM(authenticateAwsIam) | ||
| mechanism = kaws.ManagedStreamingIAM(func(ctx context.Context) (kaws.Auth, error) { | ||
| return authenticateAwsIam(ctx, kc.SASL.RoleArn) | ||
| }) | ||
| opts = append(opts, kgo.Dialer((&tls.Dialer{NetDialer: &net.Dialer{Timeout: 10 * time.Second}}).DialContext)) | ||
| case "scram-sha-512": | ||
| mechanism = scram.Auth{ | ||
| User: kc.SASL.Username, | ||
|
|
@@ -171,12 +178,20 @@ func NewAdminClient(ctx context.Context, data []byte, kube client.Client) (*kadm | |
| return kadm.NewClient(c), nil | ||
| } | ||
|
|
||
| func authenticateAwsIam(ctx context.Context) (a kaws.Auth, err error) { | ||
| func authenticateAwsIam(ctx context.Context, roleArn string) (a kaws.Auth, err error) { | ||
| s, err := config.LoadDefaultConfig(ctx) | ||
| if err != nil { | ||
| return kaws.Auth{}, err | ||
| } | ||
|
|
||
| if roleArn != "" { | ||
| stsClient := sts.NewFromConfig(s) | ||
| provider := stscreds.NewAssumeRoleProvider(stsClient, roleArn, func(o *stscreds.AssumeRoleOptions) { | ||
| o.RoleSessionName = "crossplane-provider-kafka" | ||
| }) | ||
| s.Credentials = aws.NewCredentialsCache(provider) | ||
| } | ||
|
Comment on lines
+187
to
+193
|
||
|
|
||
| v, err := s.Credentials.Retrieve(ctx) | ||
| if err != nil { | ||
| return kaws.Auth{}, err | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,8 +31,9 @@ type Config struct { | |
| // SASL is an sasl option | ||
| type SASL struct { | ||
| Mechanism string `json:"mechanism"` | ||
| Password string `json:"password"` //nolint:gosec | ||
| RoleArn string `json:"roleArn"` | ||
| Username string `json:"username"` | ||
| Password string `json:"password"` //nolint:gosec | ||
|
Comment on lines
32
to
36
|
||
| } | ||
|
|
||
| // TLS is an option for enabling encryption in transit. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.