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

Pass server-side encryption option to minio.StatObject call #142

Open
wants to merge 7 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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#145](https://github.com/thanos-io/objstore/pull/145) Include content length in the response of Get and GetRange.

### Fixed
- [#141](https://github.com/thanos-io/objstore/pull/142) S3: Fix missing encryption configuration for `Bucket.Exists()` and `Bucket.Attributes()` calls.
- [#153](https://github.com/thanos-io/objstore/pull/153) Metrics: Fix `objstore_bucket_operation_duration_seconds_*` for `get` and `get_range` operations.
- [#117](https://github.com/thanos-io/objstore/pull/117) Metrics: Fix `objstore_bucket_operation_failures_total` incorrectly incremented if context is cancelled while reading object contents.
- [#115](https://github.com/thanos-io/objstore/pull/115) GCS: Fix creation of bucket with GRPC connections. Also update storage client to `v1.40.0`.
Expand Down
18 changes: 16 additions & 2 deletions providers/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,14 @@ func (b *Bucket) GetRange(ctx context.Context, name string, off, length int64) (

// Exists checks if the given object exists.
func (b *Bucket) Exists(ctx context.Context, name string) (bool, error) {
_, err := b.client.StatObject(ctx, b.name, name, minio.StatObjectOptions{})
sse, err := b.getServerSideEncryption(ctx)
if err != nil {
return false, err
}

_, err = b.client.StatObject(ctx, b.name, name, minio.StatObjectOptions{
ServerSideEncryption: sse,
})
if err != nil {
if b.IsObjNotFoundErr(err) {
return false, nil
Expand Down Expand Up @@ -574,7 +581,14 @@ func (b *Bucket) Upload(ctx context.Context, name string, r io.Reader) error {

// Attributes returns information about the specified object.
func (b *Bucket) Attributes(ctx context.Context, name string) (objstore.ObjectAttributes, error) {
objInfo, err := b.client.StatObject(ctx, b.name, name, minio.StatObjectOptions{})
sse, err := b.getServerSideEncryption(ctx)
if err != nil {
return objstore.ObjectAttributes{}, err
}

objInfo, err := b.client.StatObject(ctx, b.name, name, minio.StatObjectOptions{
ServerSideEncryption: sse,
})
if err != nil {
return objstore.ObjectAttributes{}, err
}
Expand Down
59 changes: 59 additions & 0 deletions providers/s3/s3_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ package s3_test
import (
"bytes"
"context"
"io"
"path/filepath"
"strings"
"testing"

"github.com/efficientgo/core/testutil"
"github.com/efficientgo/e2e"
e2edb "github.com/efficientgo/e2e/db"
"github.com/go-kit/log"
"github.com/minio/minio-go/v7/pkg/encrypt"

"github.com/thanos-io/objstore/exthttp"
"github.com/thanos-io/objstore/providers/s3"
"github.com/thanos-io/objstore/test/e2e/e2ethanos"
)
Expand Down Expand Up @@ -54,3 +59,57 @@ func BenchmarkUpload(b *testing.B) {
testutil.Ok(b, bkt.Upload(ctx, "test", strings.NewReader(str)))
}
}

func TestSSECencryption(t *testing.T) {
ctx := context.Background()
e, err := e2e.NewDockerEnvironment("e2e-ssec", e2e.WithLogger(log.NewNopLogger()))
testutil.Ok(t, err)
t.Cleanup(e2ethanos.CleanScenario(t, e))

const bucket = "sse-c-encryption"
m := e2ethanos.NewMinio(e, "sse-c-encryption", bucket)
testutil.Ok(t, e2e.StartAndWaitReady(m))

cfg := s3.Config{
Bucket: bucket,
AccessKey: e2edb.MinioAccessKey,
SecretKey: e2edb.MinioSecretKey,
Endpoint: m.Endpoint("https"),
Insecure: false,
HTTPConfig: exthttp.HTTPConfig{
TLSConfig: exthttp.TLSConfig{
CAFile: filepath.Join(m.Dir(), "certs", "CAs", "ca.crt"),
CertFile: filepath.Join(m.Dir(), "certs", "public.crt"),
KeyFile: filepath.Join(m.Dir(), "certs", "private.key"),
},
},
SSEConfig: s3.SSEConfig{
Type: string(encrypt.SSEC),
EncryptionKey: "testdata/encryption_key",
},
BucketLookupType: s3.AutoLookup,
}

bkt, err := s3.NewBucketWithConfig(
log.NewNopLogger(),
cfg,
"test-ssec",
nil,
)
testutil.Ok(t, err)

upload := "secret content"
testutil.Ok(t, bkt.Upload(ctx, "encrypted", strings.NewReader(upload)))

exists, err := bkt.Exists(ctx, "encrypted")
testutil.Ok(t, err)
if !exists {
t.Fatalf("upload failed")
}

r, err := bkt.Get(ctx, "encrypted")
testutil.Ok(t, err)
b, err := io.ReadAll(r)
testutil.Ok(t, err)
testutil.Equals(t, upload, string(b))
}
1 change: 1 addition & 0 deletions providers/s3/testdata/encryption_key
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
suchSecretVeryCryptographicKeyZ
Loading