nimakaviani / s3-copy-controller

Experimental data plane controller to copy data from a Kubernetes cluster to cloud object stores
2 stars 2 forks source link

EKS IRSA support #2

Open nabuskey opened 2 years ago

nabuskey commented 2 years ago

Need to use something like this to fallback to w/e is available in credentials chain:

// UseProviderSecret - AWS configuration which can be used to issue requests against AWS API
func useProviderSecret(ctx context.Context, data []byte, region, profile string) (*aws.Config, error) {
    creds, err := credentialsIDSecret(data, profile)
    if err != nil {
        return nil, errors.Wrap(err, "cannot parse credentials secret")
    }
    if creds.AccessKeyID == "" && creds.SecretAccessKey == "" {
        conf, err := config.LoadDefaultConfig(ctx, config.WithRegion(region))
        if err != nil {
            return nil, errors.Wrap(err, "cannot obtain credentials from temporary credentials chain")
        }
        _, err = conf.Credentials.Retrieve(ctx)
        if err != nil {
            return nil, errors.Wrap(err, "failed to retrieve credentials")
        }
        return &conf, nil
    }
    conf, err := config.LoadDefaultConfig(ctx, config.WithRegion(region), config.WithCredentialsProvider(credentials.StaticCredentialsProvider{
        Value: creds,
    }))
    return &conf, err
}

This is working in my setup. I'll make a PR later.

nimakaviani commented 2 years ago

sounds good, thanks!