adds support for S3 SSE with KMS

Signed-off-by: Mathias Merscher <Mathias.Merscher@dg-i.net>
This commit is contained in:
Mathias Merscher
2017-08-14 18:18:19 +02:00
parent e966eb9ab0
commit df320d7bf3
5 changed files with 17 additions and 4 deletions
+1
View File
@@ -98,6 +98,7 @@ type AWSConfig struct {
DisableSSL bool `json:"disableSSL"`
S3ForcePathStyle bool `json:"s3ForcePathStyle"`
S3Url string `json:"s3Url"`
KMSKeyID string `json:"kmsKeyId"`
}
// GCPConfig is configuration information for connecting to GCP.
@@ -19,6 +19,7 @@ package aws
import (
"io"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/heptio/ark/pkg/cloudprovider"
@@ -27,7 +28,8 @@ import (
var _ cloudprovider.ObjectStorageAdapter = &objectStorageAdapter{}
type objectStorageAdapter struct {
s3 *s3.S3
s3 *s3.S3
kmsKeyID string
}
func (op *objectStorageAdapter) PutObject(bucket string, key string, body io.ReadSeeker) error {
@@ -37,6 +39,12 @@ func (op *objectStorageAdapter) PutObject(bucket string, key string, body io.Rea
Body: body,
}
// if kmsKeyID is not empty, enable "aws:kms" encryption
if op.kmsKeyID != "" {
req.ServerSideEncryption = aws.String("aws:kms")
req.SSEKMSKeyId = &op.kmsKeyID
}
_, err := op.s3.PutObject(req)
return err
+3 -2
View File
@@ -32,7 +32,7 @@ type storageAdapter struct {
var _ cloudprovider.StorageAdapter = &storageAdapter{}
func NewStorageAdapter(config *aws.Config, availabilityZone string) (cloudprovider.StorageAdapter, error) {
func NewStorageAdapter(config *aws.Config, availabilityZone string, kmsKeyID string) (cloudprovider.StorageAdapter, error) {
sess, err := session.NewSession(config)
if err != nil {
return nil, err
@@ -48,7 +48,8 @@ func NewStorageAdapter(config *aws.Config, availabilityZone string) (cloudprovid
az: availabilityZone,
},
objectStorage: &objectStorageAdapter{
s3: s3.New(sess),
s3: s3.New(sess),
kmsKeyID: kmsKeyID,
},
}, nil
}
+1 -1
View File
@@ -324,7 +324,7 @@ func getAWSCloudProvider(cloudConfig api.CloudProviderConfig) (cloudprovider.Sto
)
}
return arkaws.NewStorageAdapter(awsConfig, cloudConfig.AWS.AvailabilityZone)
return arkaws.NewStorageAdapter(awsConfig, cloudConfig.AWS.AvailabilityZone, cloudConfig.AWS.KMSKeyID)
}
func getGCPCloudProvider(cloudConfig api.CloudProviderConfig) (cloudprovider.StorageAdapter, error) {