Skip to content
Merged
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
7 changes: 0 additions & 7 deletions .govulncheck-ignore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,3 @@
# "No fix available". When upstream ships a fix, the scanner stops
# reporting the ID and the wrapper flags this entry as stale,
# failing `make vuln` until it is removed.

- id: GO-2026-4887
module: github.com/docker/docker
reason: "No fix available — Moby AuthZ plugin bypass on oversized request bodies. Pulled in only via testcontainers-go from test/env/components.go (test infra); not linked into product binaries."
- id: GO-2026-4883
module: github.com/docker/docker
reason: "No fix available — Moby off-by-one error in plugin privilege validation. Pulled in only via testcontainers-go from test/env/components.go (test infra); not linked into product binaries."
2 changes: 1 addition & 1 deletion docker-compose/FakeS3Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ ARG GIT_COMMIT='not set'
ENV PATH=$PATH:$GOPATH/bin
ENV GO111MODULE=on

RUN go install github.com/johannesboyne/gofakes3/cmd/...@1.0.0
RUN go install github.com/johannesboyne/gofakes3/cmd/...@v1.2.0

CMD ["gofakes3", "-backend", "memory"]
255 changes: 132 additions & 123 deletions go.mod

Large diffs are not rendered by default.

624 changes: 309 additions & 315 deletions go.sum

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion pkg/entity/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ func NewDiffID(locations ...DiffLocation) DiffID {

type DiffObjectID struct {
Storage string
Bucket string
Prefix string
DiffID DiffID
}

func NewDiffObjectID(diffID DiffID, storage string, prefix string) DiffObjectID {
func NewDiffObjectID(diffID DiffID, storage string, bucket string, prefix string) DiffObjectID {
return DiffObjectID{
DiffID: diffID,
Storage: storage,
Bucket: bucket,
Prefix: prefix,
}
}
Expand Down
56 changes: 11 additions & 45 deletions pkg/objstore/s3_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,20 @@ import (
"io"
"iter"
"slices"
"strings"

"github.com/minio/minio-go/v7"

"github.com/clyso/chorus/pkg/s3"
"github.com/clyso/chorus/pkg/s3client"
)

func WrapS3common(client s3client.Client, provider s3.Provider) Common {
func WrapS3common(client s3client.Client) Common {
return &s3CommonClient{
client: client,
provider: provider,
client: client,
}
}

type s3CommonClient struct {
client s3client.Client
provider s3.Provider
client s3client.Client
}

func (s *s3CommonClient) BucketExists(ctx context.Context, bucket string) (bool, error) {
Expand Down Expand Up @@ -100,7 +96,6 @@ func (s *s3CommonClient) ListObjects(ctx context.Context, bucket string, opts ..

minioOpts := commonOpts.toMinioListOptions()
minioOpts.Recursive = true
minioOpts.Prefix = s.normalizeInputName(minioOpts.Prefix)

objects := s.client.S3().ListObjects(ctx, bucket, minioOpts)
return func(yield func(CommonObjectInfo, error) bool) {
Expand All @@ -122,7 +117,7 @@ func (s *s3CommonClient) ListObjects(ctx context.Context, bucket string, opts ..
return
}
info := CommonObjectInfo{
Key: s.normalizeOutputName(object.Key),
Key: object.Key,
VersionID: object.VersionID,
LastModified: object.LastModified,
Etag: object.ETag,
Expand Down Expand Up @@ -151,8 +146,13 @@ func (s *s3CommonClient) GetObject(ctx context.Context, bucket string, name stri
return object, nil
}

func (s *s3CommonClient) PutObject(ctx context.Context, bucket string, name string, reader io.Reader, len uint64) error {
if _, err := s.client.S3().PutObject(ctx, bucket, name, reader, int64(len), minio.PutObjectOptions{}); err != nil {
func (s *s3CommonClient) PutObject(ctx context.Context, bucket string, name string, reader io.Reader, len uint64, opts ...PutObjectOption) error {
putOpts := &commonPutOptions{}
for _, opt := range opts {
opt(putOpts)
}

if _, err := s.client.S3().PutObject(ctx, bucket, name, reader, int64(len), putOpts.toMinioPutOptions()); err != nil {
return fmt.Errorf("unable to upload object: %w", err)
}
return nil
Expand Down Expand Up @@ -261,37 +261,3 @@ func (s *s3CommonClient) ObjectInfo(ctx context.Context, bucket string, name str
Size: uint64(stat.Size),
}, nil
}

// https://github.com/minio/minio/issues/17356
// While working with lists, minio will output object keys as a/b/c, i.e, without leading slash.
// It will also consider a/b as a valid value for prefix search parameter.
// Prefix value /a/b will be considered invalid, search will return no results.
// At the same time, other implementations, e.g. Ceph, will act the other way.
// Meaning object keys will be listed as /a/b/c, with leading slash.
// List operation with prefix /a/b will give results, with prefix a/b won't.
// Therefore, in order to allow interoperability between providers, we should brind prefix parameter
// and object keys in list to the expected format.
func (s *s3CommonClient) normalizeInputName(name string) string {
if name == "" {
return name
}
isMinio := s.provider == s3.ProviderMinIO
hasLeadingSlash := strings.HasPrefix(name, "/")
if isMinio && hasLeadingSlash {
return strings.TrimPrefix(name, "/")
}
if !isMinio && !hasLeadingSlash {
return "/" + name
}
return name
}

func (s *s3CommonClient) normalizeOutputName(name string) string {
if name == "" {
return name
}
if !strings.HasPrefix(name, "/") {
return "/" + name
}
return name
}
26 changes: 20 additions & 6 deletions pkg/objstore/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,24 @@ func WithVersionID(versionID string) func(o *commonObjectOptions) {
}
}

type commonPutOptions struct {
unsignedPayload bool
}

func (r *commonPutOptions) toMinioPutOptions() minio.PutObjectOptions {
return minio.PutObjectOptions{
DisableContentSha256: r.unsignedPayload,
}
}

type PutObjectOption func(o *commonPutOptions)

func WithUnsignedPayload() PutObjectOption {
return func(o *commonPutOptions) {
o.unsignedPayload = true
}
}

type Clients interface {
AsS3(ctx context.Context, storage, user string) (s3client.Client, error)
AsSwift(ctx context.Context, storage, user string) (*gophercloud.ServiceClient, error)
Expand All @@ -132,7 +150,7 @@ type Common interface {
RemoveBucket(ctx context.Context, bucket string) error
EnableBucketVersioning(ctx context.Context, bucket string) error
GetObject(ctx context.Context, bucket string, name string, opts ...func(o *commonObjectOptions)) (io.Reader, error)
PutObject(ctx context.Context, bucket string, name string, reader io.Reader, len uint64) error
PutObject(ctx context.Context, bucket string, name string, reader io.Reader, len uint64, opts ...PutObjectOption) error
ObjectInfo(ctx context.Context, bucket string, name string, opts ...func(o *commonObjectOptions)) (*CommonObjectInfo, error)
ObjectExists(ctx context.Context, bucket string, name string, opts ...func(o *commonObjectOptions)) (bool, error)
RemoveObject(ctx context.Context, bucket string, name string, opts ...func(o *commonObjectOptions)) error
Expand Down Expand Up @@ -301,11 +319,7 @@ func (r *clients) AsCommon(ctx context.Context, storage string, user string) (Co
if err != nil {
return nil, err
}
storageAddress, err := r.credsSvc.GetS3Address(storage)
if err != nil {
return nil, err
}
return WrapS3common(client, storageAddress.Provider), nil
return WrapS3common(client), nil
case dom.Swift:
client, err := r.AsSwift(ctx, storage, user)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/objstore/swift_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (s *swiftCommonClient) GetObject(ctx context.Context, bucket string, name s
return response.Body, nil
}

func (s *swiftCommonClient) PutObject(ctx context.Context, bucket string, name string, reader io.Reader, len uint64) error {
func (s *swiftCommonClient) PutObject(ctx context.Context, bucket string, name string, reader io.Reader, len uint64, _ ...PutObjectOption) error {
if _, err := objects.Create(ctx, s.client, bucket, name, objects.CreateOpts{
Content: reader,
ContentLength: int64(len),
Expand Down
5 changes: 3 additions & 2 deletions pkg/store/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ func TokensToDiffObjectIDConverter(tokens []string) (entity.DiffObjectID, error)
return entity.DiffObjectID{
DiffID: diffID,
Storage: tokens[1],
Prefix: tokens[2],
Bucket: tokens[2],
Prefix: tokens[3],
}, nil
}

Expand All @@ -140,7 +141,7 @@ func DiffObjectIDToTokensConverter(id entity.DiffObjectID) ([]string, error) {
if err != nil {
return nil, fmt.Errorf("unable to get diff id tokens: %w", err)
}
return []string{tokens[0], id.Storage, id.Prefix}, nil
return []string{tokens[0], id.Storage, id.Bucket, id.Prefix}, nil
}

type DiffListStateStore struct {
Expand Down
45 changes: 45 additions & 0 deletions pkg/store/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,51 @@ var _ = Describe("Diff stores", func() {
})
})

func TestDiffObjectIDToTokensConverter(t *testing.T) {
tests := []struct {
name string
id entity.DiffObjectID
}{
{
name: "same storage different buckets",
id: entity.NewDiffObjectID(entity.NewDiffID(
entity.NewDiffLocation("main", "src-cb-test"),
entity.NewDiffLocation("main", "dst-cb-test"),
), "main", "src-cb-test", ""),
},
{
name: "prefix set",
id: entity.NewDiffObjectID(entity.NewDiffID(
entity.NewDiffLocation("f1", "restart1"),
entity.NewDiffLocation("main", "restart1"),
), "main", "restart1", "photo/"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r := require.New(t)
got, err := DiffObjectIDToTokensConverter(tt.id)
r.NoError(err)
gotID, err := TokensToDiffObjectIDConverter(got)
r.NoError(err)
r.EqualValues(tt.id, gotID)
})
}
}

func TestDiffObjectIDDistinguishesBucketsOnSameStorage(t *testing.T) {
r := require.New(t)
diffID := entity.NewDiffID(
entity.NewDiffLocation("main", "src-cb-test"),
entity.NewDiffLocation("main", "dst-cb-test"),
)
src, err := DiffObjectIDToTokensConverter(entity.NewDiffObjectID(diffID, "main", "src-cb-test", ""))
r.NoError(err)
dst, err := DiffObjectIDToTokensConverter(entity.NewDiffObjectID(diffID, "main", "dst-cb-test", ""))
r.NoError(err)
r.NotEqual(src, dst, "locations on the same storage must not share a listing cursor")
}

func TestDiffIDToTokensConverter(t *testing.T) {
type args struct {
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/store/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ func makeRedisFieldMap(value any) map[string]any {
result[redisTag] = nil
continue
}
if field.Type.Kind() == reflect.Ptr && fieldValue.IsNil() {
if field.Type.Kind() == reflect.Pointer && fieldValue.IsNil() {
result[redisTag] = nil
continue
}
if field.Type.Kind() == reflect.Ptr {
if field.Type.Kind() == reflect.Pointer {
result[redisTag] = fieldValue.Elem().Interface()
} else {
result[redisTag] = fieldValue.Interface()
Expand Down
1 change: 1 addition & 0 deletions pkg/swift/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func NewClient(ctx context.Context, addr StorageAddress, user Credentials) (*gop
Password: user.Password,
TenantName: user.TenantName,
DomainName: user.DomainName,
AllowReauth: true,
})
if err != nil {
return nil, fmt.Errorf("swift client: failed to authenticate for tenant %q: %w", user.TenantName, err)
Expand Down
2 changes: 1 addition & 1 deletion proto/gen/go/chorus/chorus.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/gen/go/chorus/diff.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/gen/go/chorus/policy.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/gen/go/chorus/webhook.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions proto/gen/go/chorus/webhook.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions proto/gen/openapi/chorus/chorus.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
"name": "Diff"
},
{
"name": "Policy"
"name": "Policy",
"description": "Manages chorus routing/replication policies"
},
{
"name": "Webhook"
"name": "Webhook",
"description": "Webhook service receives storage events and enqueues replication tasks.\nReturns non-200 only on transient errors (context cancelled, Redis\nunavailable) where a retry may succeed. Permanent errors (unknown storage,\ninvalid events, no replication policy) are logged server-side and return 200."
}
],
"consumes": [
Expand Down
Loading
Loading