Skip to content

Commit 0d7afcf

Browse files
committed
fix S3 head object Server Side Encryption parameters, fix #709
1 parent 11eee29 commit 0d7afcf

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ BUG FIXES
1616
- fix `--rbac` behavior when /var/lib/clickhouse/access not exists
1717
- fix `skip_database_engines` behavior
1818
- fix `skip_databases` behavior during restore for corner case `db.prefix*` and corner cases when conflict with `--tables="*pattern.*"`, fix [663](https://github.com/Altinity/clickhouse-backup/issues/663)
19+
- fix S3 head object Server Side Encryption parameters, fix [709](https://github.com/Altinity/clickhouse-backup/issues/709)
1920

2021
# v2.3.2
2122
BUG FIXES

pkg/storage/s3.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,12 @@ func (s *S3) getObjectVersion(ctx context.Context, key string) (*string, error)
343343
}
344344

345345
func (s *S3) StatFile(ctx context.Context, key string) (RemoteFile, error) {
346-
head, err := s.client.HeadObject(ctx, &s3.HeadObjectInput{
346+
params := &s3.HeadObjectInput{
347347
Bucket: aws.String(s.Config.Bucket),
348348
Key: aws.String(path.Join(s.Config.Path, key)),
349-
})
349+
}
350+
s.enrichHeadParamsWithSSE(params)
351+
head, err := s.client.HeadObject(ctx, params)
350352
if err != nil {
351353
var opError *smithy.OperationError
352354
if errors.As(err, &opError) {
@@ -463,10 +465,12 @@ func (s *S3) CopyObject(ctx context.Context, srcBucket, srcKey, dstKey string) (
463465
if err != nil {
464466
return 0, err
465467
}
466-
dstObjResp, err := s.client.HeadObject(ctx, &s3.HeadObjectInput{
468+
dstHeadParams := &s3.HeadObjectInput{
467469
Bucket: aws.String(s.Config.Bucket),
468470
Key: aws.String(dstKey),
469-
})
471+
}
472+
s.enrichHeadParamsWithSSE(dstHeadParams)
473+
dstObjResp, err := s.client.HeadObject(ctx, dstHeadParams)
470474
if err != nil {
471475
return 0, err
472476
}
@@ -620,11 +624,12 @@ func (s *S3) restoreObject(ctx context.Context, key string) error {
620624
}
621625
i := 0
622626
for {
623-
headObjectRequest := &s3.HeadObjectInput{
627+
restoreHeadParams := &s3.HeadObjectInput{
624628
Bucket: aws.String(s.Config.Bucket),
625629
Key: aws.String(path.Join(s.Config.Path, key)),
626630
}
627-
res, err := s.client.HeadObject(ctx, headObjectRequest)
631+
s.enrichHeadParamsWithSSE(restoreHeadParams)
632+
res, err := s.client.HeadObject(ctx, restoreHeadParams)
628633
if err != nil {
629634
return fmt.Errorf("restoreObject: failed to head %s object metadata, %v", path.Join(s.Config.Path, key), err)
630635
}
@@ -639,6 +644,18 @@ func (s *S3) restoreObject(ctx context.Context, key string) error {
639644
}
640645
}
641646

647+
func (s *S3) enrichHeadParamsWithSSE(headParams *s3.HeadObjectInput) {
648+
if s.Config.SSECustomerAlgorithm != "" {
649+
headParams.SSECustomerAlgorithm = aws.String(s.Config.SSECustomerAlgorithm)
650+
}
651+
if s.Config.SSECustomerKey != "" {
652+
headParams.SSECustomerKey = aws.String(s.Config.SSECustomerKey)
653+
}
654+
if s.Config.SSECustomerKeyMD5 != "" {
655+
headParams.SSECustomerKeyMD5 = aws.String(s.Config.SSECustomerKeyMD5)
656+
}
657+
}
658+
642659
type s3File struct {
643660
size int64
644661
lastModified time.Time

0 commit comments

Comments
 (0)