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

Changing S3 metadata x-amz-meta-x-amz-key and x-amz-meta-x-amz-iv #342

Closed
davidsonff opened this issue Aug 8, 2015 · 4 comments
Closed

Comments

@davidsonff
Copy link

I am trying to do client-side encryption for S3 and then loading into Redshift. I have the following (partial) code:

input.Body = file
            input.Bucket = &bucket
            input.Key = &s3Key
            input.Metadata = map[string]*string{"x-amz-meta-x-amz-key": aws.String(encKeyStr), "x-amz-meta-x-amz-iv": aws.String(initVect)}

            log.Println("Uploading ", file.Name(), " to AWS S3 bucket ", bucket, ", key ", s3Key)

            output, err := uploader.Upload(&input)
            if err != nil {
                    if multierr, ok := err.(s3manager.MultiUploadFailure); ok {
                            // Process error and its associated uploadID
                            log.Fatal("Error:", multierr.Code(), multierr.Message(), multierr.UploadID())
                    } else {
                            // Process error generically
                            log.Fatal("Error:", err.Error())
                    }
            }

When I run it it fails with (after making some changes to unmarshal_error.go):

403 Forbidden
map[Date:[Fri, 07 Aug 2015 21:28:03 GMT] Server:[AmazonS3] X-Amz-Request-Id:[2495C9B900951A75] X-Amz-Id-2:[zHYa2qpTMKBxFhd5AwXFB1fq6dHNOOOoEnUwswUarCSWep8dCQ3XI8+mlsm9s9jL] Content-Type:[application/xml]]
map[]
ps_load.go:363: Error:SerializationError: failed to decode S3 XML error response

When I comment out the input.Metadata line of code, it runs just fine.

Am I doing something incorrectly? Why can I do everything else but add these metadata items? I think I have full authorization on the bucket...

Thanks,

Frank

@jasdel
Copy link
Contributor

jasdel commented Aug 11, 2015

Hi @davidsonff initially the header metadata key names should be x-amz-key and x-amz-iv. The x-amz-meta- prefix will automatically be added by the SDK when using S3 operations.

Using this example I was able to write an object into S3 with the x-amz-key and x-amz-iv with dummy data.

package main

import (
    "bytes"
    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/service/s3"
    "github.com/aws/aws-sdk-go/service/s3/s3manager"
    "log"
)

func main() {
    svc := s3.New(nil)

    uploader := s3manager.NewUploader(&s3manager.UploadOptions{
        S3: svc,
    })

    result, err := uploader.Upload(&s3manager.UploadInput{
        Bucket: aws.String("bucketName"),
        Key:    aws.String("keyName"),
        Body:   bytes.NewReader(make([]byte, 5*1024*1024)),
        Metadata: map[string]*string{
            "x-amz-key": aws.String("encKeyStr"),
            "x-amz-iv":  aws.String("initVect"),
        },
    })
    if err != nil {
        log.Fatalln(err)
    }

    log.Println(result)
}

@jasdel
Copy link
Contributor

jasdel commented Aug 11, 2015

In order to help debug your issue I suggest enabling debug logging with HTTP body. This will print the detailed response body before it is deserialized by the SDK.

svc := s3.New(aws.NewConfig().WithLogLevel(aws.LogDebugWithHTTPBody))

@davidsonff
Copy link
Author

Thanks!!! That fixed it! Also, I was not using base64 to encode the ciphers... Now I just need to figure out how the encryption actually works!!!

@jasdel
Copy link
Contributor

jasdel commented Aug 11, 2015

If you haven't already found it, take a look at this help doc it provides a few useful links at the bottom with examples how the Java AWS SDK handles client side encryption.

skotambkar pushed a commit to skotambkar/aws-sdk-go that referenced this issue May 20, 2021
Services
===
* Synced the V2 SDK with latest AWS service API definitions.
* Fixes [aws#341](aws/aws-sdk-go-v2#341)
* Fixes [aws#342](aws/aws-sdk-go-v2#342)

SDK Breaking Changes
===
* `aws`: Add default HTTP client instead of http.DefaultClient/Transport ([aws#315](aws/aws-sdk-go-v2#315))
  * Adds a new BuildableHTTPClient type to the SDK's aws package. The type uses the builder pattern with immutable changes. Modifications to the buildable client create copies of the client.  Adds a HTTPClient interface to the aws package that the SDK will use as an abstraction over the specific HTTP client implementation. The SDK will default to the BuildableHTTPClient, but a *http.Client can be also provided for custom configuration.  When the SDK's aws.Config.HTTPClient value is a BuildableHTTPClient the SDK will be able to use API client specific request timeout options.
  * Fixes [aws#279](aws/aws-sdk-go-v2#279)
  * Fixes [aws#269](aws/aws-sdk-go-v2#269)

SDK Enhancements
===
* `service/s3/s3manager`: Update S3 Upload Multipart location ([aws#324](aws/aws-sdk-go-v2#324))
  * Updates the Location returned value of S3 Upload's Multipart UploadOutput type to be consistent with single part upload URL. This update also brings the multipart upload Location inline with the S3 object URLs created by the SDK.
  * Fixes [aws#323](aws/aws-sdk-go-v2#323)
  * V2 Port [aws#2453](aws#2453)

SDK Bugs
===
* `private/model`: Handles empty map vs unset map behavior in send request ([aws#337](aws/aws-sdk-go-v2#337))
  * Updated shape marshal model to handle the empty map vs nil map behavior. Adding a test case to assert behavior when a user sends an empty map vs nil map.
  * Fix [aws#332](aws/aws-sdk-go-v2#332)
* `service/rds`: Fix presign URL for same region ([aws#331](aws/aws-sdk-go-v2#331))
  * Fixes RDS no-autopresign URL for same region issue for aws-sdk-go-v2. Solves the issue by making sure that the presigned URLs are not created, when the source and destination regions are the same. Added and updated the tests accordingly.
  * Fix [aws#271](aws/aws-sdk-go-v2#271)
* `private/protocola/json/jsonutil`: Fix Unmarshal map[string]bool ([aws#320](aws/aws-sdk-go-v2#320))
  * Fixes the JSON unmarshaling of maps of bools. The unmarshal case was missing the condition for bool value, in addition the bool pointer.
  * Fix [aws#319](aws/aws-sdk-go-v2#319)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants