Skip to content

Commit 52291de

Browse files
committed
Do not return errors uploading to S3
1 parent c1036c6 commit 52291de

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

pkg/leeway/cache/remote/s3.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
1717
"github.com/aws/aws-sdk-go-v2/service/s3"
1818
"github.com/aws/aws-sdk-go-v2/service/s3/types"
19+
"github.com/aws/smithy-go"
1920
log "github.com/sirupsen/logrus"
2021

2122
"github.com/gitpod-io/leeway/pkg/leeway/cache"
@@ -480,7 +481,6 @@ func (s *S3Storage) UploadObject(ctx context.Context, key string, src string) er
480481
u.PartSize = defaultS3PartSize
481482
})
482483

483-
// For multipart uploads, we use a different approach with checksums
484484
input := &s3.PutObjectInput{
485485
Bucket: aws.String(s.bucketName),
486486
Key: aws.String(key),
@@ -489,6 +489,11 @@ func (s *S3Storage) UploadObject(ctx context.Context, key string, src string) er
489489

490490
_, err = uploader.Upload(ctx, input)
491491
if err != nil {
492+
var apiErr smithy.APIError
493+
if errors.As(err, &apiErr) && apiErr.ErrorCode() == "Forbidden" {
494+
log.WithError(err).Warnf("permission denied while uploading object %s to S3 - continuing", key)
495+
return nil
496+
}
492497
return fmt.Errorf("failed to upload object: %w", err)
493498
}
494499

pkg/leeway/cache/remote/s3_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/aws/aws-sdk-go-v2/aws"
1616
"github.com/aws/aws-sdk-go-v2/service/s3"
1717
"github.com/aws/aws-sdk-go-v2/service/s3/types"
18+
"github.com/aws/smithy-go"
1819
"github.com/gitpod-io/leeway/pkg/leeway/cache"
1920
"github.com/google/go-cmp/cmp"
2021
)
@@ -377,6 +378,24 @@ func TestS3Cache_Upload(t *testing.T) {
377378
},
378379
expectError: true,
379380
},
381+
{
382+
name: "403 forbidden error should not fail",
383+
packages: []cache.Package{
384+
&mockPackage{version: "v1"},
385+
},
386+
mockPutObject: func(key string) error {
387+
return &smithy.GenericAPIError{
388+
Code: "Forbidden",
389+
Message: "Access Denied",
390+
}
391+
},
392+
localCache: &mockLocalCache{
393+
locations: map[string]string{
394+
"v1": filepath.Join(tmpDir, "pkg1.tar.gz"),
395+
},
396+
},
397+
expectError: false,
398+
},
380399
}
381400

382401
for _, tt := range tests {

0 commit comments

Comments
 (0)