@@ -17,6 +17,7 @@ import (
1717 "github.com/aws/aws-sdk-go-v2/feature/s3/manager"
1818 "github.com/aws/aws-sdk-go-v2/service/s3"
1919 s3types "github.com/aws/aws-sdk-go-v2/service/s3/types"
20+ "github.com/aws/smithy-go/middleware"
2021 "github.com/containerd/containerd/v2/core/content"
2122 "github.com/containerd/containerd/v2/pkg/labels"
2223 "github.com/moby/buildkit/cache/remotecache"
@@ -34,36 +35,38 @@ import (
3435)
3536
3637const (
37- attrBucket = "bucket"
38- attrRegion = "region"
39- attrPrefix = "prefix"
40- attrManifestsPrefix = "manifests_prefix"
41- attrBlobsPrefix = "blobs_prefix"
42- attrName = "name"
43- attrTouchRefresh = "touch_refresh"
44- attrEndpointURL = "endpoint_url"
45- attrAccessKeyID = "access_key_id"
46- attrSecretAccessKey = "secret_access_key"
47- attrSessionToken = "session_token"
48- attrUsePathStyle = "use_path_style"
49- attrUploadParallelism = "upload_parallelism"
50- maxCopyObjectSize = 5 * 1024 * 1024 * 1024
38+ attrBucket = "bucket"
39+ attrRegion = "region"
40+ attrPrefix = "prefix"
41+ attrManifestsPrefix = "manifests_prefix"
42+ attrBlobsPrefix = "blobs_prefix"
43+ attrName = "name"
44+ attrTouchRefresh = "touch_refresh"
45+ attrEndpointURL = "endpoint_url"
46+ attrAccessKeyID = "access_key_id"
47+ attrSecretAccessKey = "secret_access_key"
48+ attrSessionToken = "session_token"
49+ attrUsePathStyle = "use_path_style"
50+ attrUploadParallelism = "upload_parallelism"
51+ attrDisableAcceptEncoding = "disable_accept_encoding"
52+ maxCopyObjectSize = 5 * 1024 * 1024 * 1024
5153)
5254
5355type Config struct {
54- Bucket string
55- Region string
56- Prefix string
57- ManifestsPrefix string
58- BlobsPrefix string
59- Names []string
60- TouchRefresh time.Duration
61- EndpointURL string
62- AccessKeyID string
63- SecretAccessKey string
64- SessionToken string
65- UsePathStyle bool
66- UploadParallelism int
56+ Bucket string
57+ Region string
58+ Prefix string
59+ ManifestsPrefix string
60+ BlobsPrefix string
61+ Names []string
62+ TouchRefresh time.Duration
63+ EndpointURL string
64+ AccessKeyID string
65+ SecretAccessKey string
66+ SessionToken string
67+ UsePathStyle bool
68+ UploadParallelism int
69+ DisableAcceptEncoding bool
6770}
6871
6972func getConfig (attrs map [string ]string ) (Config , error ) {
@@ -141,20 +144,30 @@ func getConfig(attrs map[string]string) (Config, error) {
141144 uploadParallelism = uploadParallelismInt
142145 }
143146
147+ disableAcceptEncoding := false
148+ disableAcceptEncodingStr , ok := attrs [attrDisableAcceptEncoding ]
149+ if ok {
150+ disableAcceptEncodingUser , err := strconv .ParseBool (disableAcceptEncodingStr )
151+ if err == nil {
152+ disableAcceptEncoding = disableAcceptEncodingUser
153+ }
154+ }
155+
144156 return Config {
145- Bucket : bucket ,
146- Region : region ,
147- Prefix : prefix ,
148- ManifestsPrefix : manifestsPrefix ,
149- BlobsPrefix : blobsPrefix ,
150- Names : names ,
151- TouchRefresh : touchRefresh ,
152- EndpointURL : endpointURL ,
153- AccessKeyID : accessKeyID ,
154- SecretAccessKey : secretAccessKey ,
155- SessionToken : sessionToken ,
156- UsePathStyle : usePathStyle ,
157- UploadParallelism : uploadParallelism ,
157+ Bucket : bucket ,
158+ Region : region ,
159+ Prefix : prefix ,
160+ ManifestsPrefix : manifestsPrefix ,
161+ BlobsPrefix : blobsPrefix ,
162+ Names : names ,
163+ TouchRefresh : touchRefresh ,
164+ EndpointURL : endpointURL ,
165+ AccessKeyID : accessKeyID ,
166+ SecretAccessKey : secretAccessKey ,
167+ SessionToken : sessionToken ,
168+ UsePathStyle : usePathStyle ,
169+ UploadParallelism : uploadParallelism ,
170+ DisableAcceptEncoding : disableAcceptEncoding ,
158171 }, nil
159172}
160173
@@ -419,6 +432,17 @@ func newS3Client(ctx context.Context, config Config) (*s3Client, error) {
419432 options .UsePathStyle = config .UsePathStyle
420433 options .BaseEndpoint = aws .String (config .EndpointURL )
421434 }
435+ if config .DisableAcceptEncoding {
436+ // GCS's GFE appends "gzip(gfe)" to the Accept-Encoding header after the
437+ // AWS SDK has signed it as "identity", causing SignatureDoesNotMatch (403).
438+ // Removing the DisableAcceptEncodingGzip middleware prevents the header
439+ // from being added to the request and included in the signature at all.
440+ // See: https://github.com/moby/buildkit/issues/3749
441+ options .APIOptions = append (options .APIOptions , func (stack * middleware.Stack ) error {
442+ stack .Finalize .Remove ("DisableAcceptEncodingGzip" )
443+ return nil
444+ })
445+ }
422446 })
423447
424448 return & s3Client {
0 commit comments