-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
provider/aws: Support KMS encryption of S3 objects #5453
Changes from all commits
db91aeb
74de653
76b3c74
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 |
---|---|---|
|
@@ -74,6 +74,11 @@ func resourceAwsS3BucketObject() *schema.Resource { | |
ConflictsWith: []string{"source"}, | ||
}, | ||
|
||
"kms_key_id": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
|
||
"etag": &schema.Schema{ | ||
Type: schema.TypeString, | ||
// This will conflict with SSE-C and SSE-KMS encryption and multi-part upload | ||
|
@@ -117,6 +122,12 @@ func resourceAwsS3BucketObjectPut(d *schema.ResourceData, meta interface{}) erro | |
return fmt.Errorf("Must specify \"source\" or \"content\" field") | ||
} | ||
|
||
if _, ok := d.GetOk("kms_key_id"); ok { | ||
if _, ok := d.GetOk("etag"); ok { | ||
return fmt.Errorf("Unable to specify 'kms_key_id' and 'etag' together because 'etag' wouldn't equal the MD5 digest of the raw object data") | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @radeksimko Does this suffice for the parameter conflict? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd try improving the message for the user, so they also understand why. e.g. |
||
putInput := &s3.PutObjectInput{ | ||
Bucket: aws.String(bucket), | ||
Key: aws.String(key), | ||
|
@@ -143,6 +154,11 @@ func resourceAwsS3BucketObjectPut(d *schema.ResourceData, meta interface{}) erro | |
putInput.ContentDisposition = aws.String(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("kms_key_id"); ok { | ||
putInput.SSEKMSKeyId = aws.String(v.(string)) | ||
putInput.ServerSideEncryption = aws.String("aws:kms") | ||
} | ||
|
||
resp, err := s3conn.PutObject(putInput) | ||
if err != nil { | ||
return fmt.Errorf("Error putting object in S3 bucket (%s): %s", bucket, err) | ||
|
@@ -186,6 +202,7 @@ func resourceAwsS3BucketObjectRead(d *schema.ResourceData, meta interface{}) err | |
d.Set("content_language", resp.ContentLanguage) | ||
d.Set("content_type", resp.ContentType) | ||
d.Set("version_id", resp.VersionId) | ||
d.Set("kms_key_id", resp.SSEKMSKeyId) | ||
|
||
log.Printf("[DEBUG] Reading S3 Bucket Object meta: %s", resp) | ||
return nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we cannot use
ValidateFunc
to guard against this (until #4348 is finished/merged), I think we'll have to add some conditionals intoCreate
andUpdate
.Essentially we want to prevent the user from specifying
etag
when they specifiedkms_key_id
, because there's no way they can calculate that (unless they know how AWS encrypts the data via KMS).It would be great if we could also somehow prevent them from using the calculated value, as that's useless too, but I'm not quite sure how to approach that.It actually may be useful for at least knowing that object has changed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
ConflictsWith
sufficient to express this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I'm wrong but AFAIK it cannot be used with
Computed
fields as it would always be conflicting.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooooh you're right - I had forgotten!
Okay so we have to fall back to docs or checks within Create/Update like you said.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got that covered in the next few lines. Is this ready to roll?
Sent from my iPhone
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh great! Sorry I missed that. Yep this looks good. Merging now!