Skip to content
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

service/s3: presigned PutObject with Tagging set does not add tagging to object in S3 bucket. #1016

Closed
3 tasks done
jasdel opened this issue Jan 5, 2021 · 2 comments · Fixed by #1017
Closed
3 tasks done
Labels
bug This issue is a bug.

Comments

@jasdel
Copy link
Contributor

jasdel commented Jan 5, 2021

Confirm by changing [ ] to [x] below to ensure that it's a bug:

Describe the bug
Objects uploaded to S3 ith presign Put Object URL withTagging parameter set, do not have the tagging metadata. The SDK hoists the x-amz-tagging header to the query string, which is ignored by S3. S3 requires the x-amz-tagging to be a signed header.

Version of AWS SDK for Go?
v0.31.0`

Version of Go (go version)?
v1.15.x

To Reproduce (observed behavior)

package main

import (
	"context"
	"fmt"
	"log"
	"os"
	"strings"

	"github.com/aws/aws-sdk-go-v2/aws"
	v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/service/s3"
)

func main() {
	bucket := os.Args[1]
	key := os.Args[2]
	fileToPut := os.Args[3]

	presigned, err := getPresignedPut(context.TODO(), bucket, key)
	if err != nil {
		log.Fatalf("failed to get presigned URL, %v", err)
	}

	var headerStr strings.Builder
	for k, vs := range presigned.SignedHeader {
		for _, v := range vs {
			fmt.Fprintf(&headerStr, "-H \"%s: %s\" \\\n", k, v)
		}
	}
	fmt.Printf("curl -X %s \\\n%s-d @%s \\\n%q\n",
		presigned.Method, headerStr.String(), fileToPut, presigned.URL)
}

func getPresignedPut(ctx context.Context, bucket, key string) (*v4.PresignedHTTPRequest, error) {
	cfg, err := config.LoadDefaultConfig(ctx)
	if err != nil {
		return nil, fmt.Errorf("failed to load config, %w", err)
	}

	client := s3.NewPresignClient(s3.NewFromConfig(cfg))

	presigned, err := client.PresignPutObject(ctx, &s3.PutObjectInput{
		Bucket:  &bucket,
		Key:     &key,
		Tagging: aws.String("mytagname=mytagvalue"),
	})
	if err != nil {
		return nil, fmt.Errorf("failed to get PutObject presigned URL, %w", err)
	}

	return presigned, nil
}

Expected behavior
To be able to put the object to S3 with the tagged header.

Additional context
Add any other context about the problem here.

@github-actions
Copy link

github-actions bot commented Jan 5, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@jasdel
Copy link
Contributor Author

jasdel commented Jan 5, 2021

Workaround for this issue until tagged released is published is to go get the specific commit instead of a tagged version.

go get github.com/aws/aws-sdk-go-v2@58b543144e2a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant