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

Send md5 of customer key #217

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/unreleased/217-robertstrache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix sending the MD5 of the customer provided encryption key https://github.com/vmware-tanzu/velero/issues/7693
16 changes: 16 additions & 0 deletions velero-plugin-for-aws/object_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package main

import (
"context"
"crypto/md5"
"encoding/base64"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -74,6 +76,7 @@ type ObjectStore struct {
s3Uploader *manager.Uploader
kmsKeyID string
sseCustomerKey string
sseCustomerKeyMd5 string
signatureVersion string
serverSideEncryption string
tagging string
Expand Down Expand Up @@ -213,6 +216,18 @@ func (o *ObjectStore) Init(config map[string]string) error {
} else {
o.checksumAlg = string(types.ChecksumAlgorithmCrc32)
}

if customerKeyEncryptionFile != "" {
customerKey, err := readCustomerKey(customerKeyEncryptionFile)
if err != nil {
return err
}
sseCustomerKey := base64.StdEncoding.EncodeToString([]byte(customerKey))
o.sseCustomerKey = sseCustomerKey
hash := md5.Sum([]byte(customerKey))
sseCustomerKeyMd5 := base64.StdEncoding.EncodeToString(hash[:])
o.sseCustomerKeyMd5 = sseCustomerKeyMd5
}
return nil
}

Expand Down Expand Up @@ -267,6 +282,7 @@ func (o *ObjectStore) PutObject(bucket, key string, body io.Reader) error {
case o.sseCustomerKey != "":
input.SSECustomerAlgorithm = aws.String("AES256")
input.SSECustomerKey = &o.sseCustomerKey
input.SSECustomerKeyMD5 = &o.sseCustomerKeyMd5
Copy link
Contributor

@reasonerjt reasonerjt Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the func "GetObject" and "ObjectExists" also need this change?

// otherwise, use the SSE algorithm specified, if any
case o.serverSideEncryption != "":
input.ServerSideEncryption = types.ServerSideEncryption(o.serverSideEncryption)
Expand Down
Loading