diff --git a/CHANGELOG.md b/CHANGELOG.md index 0aa6d7cb..a28981bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ - Soft-deprecated `Record.GetUploadedFiles` in favour of `Record.GetUnsavedFiles` to minimize the ambiguities what the method do ([#6269](https://github.com/pocketbase/pocketbase/discussions/6269)). (@todo update docs to reflect the `:unsaved` getter change) +- Enforced `when_required` for the new AWS SDK request and response checksum validations to allow other non-AWS vendors to catch up with new AWS SDK changes (see [#6313](https://github.com/pocketbase/pocketbase/discussions/6313) and [aws/aws-sdk-go-v2#2960](https://github.com/aws/aws-sdk-go-v2/discussions/2960)). + _You can set the environment variables `AWS_REQUEST_CHECKSUM_CALCULATION` and `AWS_RESPONSE_CHECKSUM_VALIDATION` to `when_supported` if your S3 vendor supports the new [new default integrity protections](https://docs.aws.amazon.com/sdkref/latest/guide/feature-dataintegrity.html)._ + ## v0.24.4 diff --git a/tools/filesystem/filesystem.go b/tools/filesystem/filesystem.go index be2473e8..f64579e4 100644 --- a/tools/filesystem/filesystem.go +++ b/tools/filesystem/filesystem.go @@ -36,6 +36,27 @@ type System struct { bucket *blob.Bucket } +// ------------------------------------------------------------------- + +var requestChecksumCalculation = aws.RequestChecksumCalculationWhenRequired +var responseChecksumValidation = aws.ResponseChecksumValidationWhenRequired + +// @todo consider removing after the other non-AWS vendors catched up with the new changes +// (https://github.com/aws/aws-sdk-go-v2/discussions/2960) +func init() { + reqEnv := os.Getenv("AWS_REQUEST_CHECKSUM_CALCULATION") + if reqEnv != "" && strings.EqualFold(reqEnv, "when_supported") { + requestChecksumCalculation = aws.RequestChecksumCalculationWhenSupported + } + + resEnv := os.Getenv("AWS_RESPONSE_CHECKSUM_VALIDATION") + if resEnv != "" && strings.EqualFold(resEnv, "when_supported") { + responseChecksumValidation = aws.ResponseChecksumValidationWhenSupported + } +} + +// ------------------------------------------------------------------- + // NewS3 initializes an S3 filesystem instance. // // NB! Make sure to call `Close()` after you are done working with it. @@ -60,6 +81,9 @@ func NewS3( return nil, err } + cfg.RequestChecksumCalculation = requestChecksumCalculation + cfg.ResponseChecksumValidation = responseChecksumValidation + client := s3.NewFromConfig(cfg, func(o *s3.Options) { // ensure that the endpoint has url scheme for // backward compatibility with v1 of the aws sdk