fix(s3): handle 301 redirect in bucket region detection#2000
Merged
frewilhelm merged 4 commits intoJun 12, 2026
Merged
Conversation
AWS SDK v2 does not follow 301 redirects (only 307/308). S3 returns 301 on HeadBucket when the bucket is in a different region, signaling the correct region via the X-Amz-Bucket-Region response header. The SDK's GetBucketRegion middleware only reads that header on non-error responses, so the 301 was propagated as a fatal error. After GetBucketRegion returns an error, inspect it as a *smithyhttp.ResponseError. If it is a 301 with the X-Amz-Bucket-Region header present, extract the region and continue instead of failing. Fixes: unable to read access: failed to find bucket region: operation error S3: HeadBucket, StatusCode: 301, MovedPermanently Signed-off-by: Jakob Möller <contact@jakob-moeller.com>
6b582b6 to
bb06642
Compare
Signed-off-by: Frederic Wilhelm <frederic.wilhelm@sap.com>
Signed-off-by: Frederic Wilhelm <frederic.wilhelm@sap.com>
frewilhelm
approved these changes
Jun 12, 2026
matthiasbruns
approved these changes
Jun 12, 2026
frewilhelm
added a commit
that referenced
this pull request
Jun 12, 2026
<!-- markdownlint-disable MD041 --> #### What this PR does / why we need it Cherry-pick of #1994 and #2000 from main to releases/0.44 --------- Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Jakob Möller <contact@jakob-moeller.com> Signed-off-by: Frederic Wilhelm <frederic.wilhelm@sap.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jakob Möller <jakob.moeller@sap.com>
matthiasbruns
pushed a commit
to knp-sap/ocm
that referenced
this pull request
Jun 15, 2026
…nt-model#2000) ## Summary - `ocm download resources` fails when an S3 bucket lives in a different region than the default hint (`us-west-1`) - AWS S3 returns HTTP 301 on `HeadBucket` to signal the correct region via `X-Amz-Bucket-Region` response header - AWS SDK v2 does not follow 301 redirects (only 307/308); the 301 is surfaced as a `*smithyhttp.ResponseError` - `manager.GetBucketRegion`'s `deserializeBucketRegion` middleware only reads the header on non-error responses, so the 301 propagated as a fatal error **Error seen by users:** ``` failed to find bucket region: operation error S3: HeadBucket, https response error StatusCode: 301 ... api error MovedPermanently: Moved Permanently ``` **Fix:** after `GetBucketRegion` returns an error, inspect it as a `*smithyhttp.ResponseError`. If it is a 301 with `X-Amz-Bucket-Region` header present, extract the region and continue. Reported in: open-component-model#1999 ## Test plan - [ ] Unit tests cover: 301 with region header (extracts region), 301 without header (propagates error), 403 (ignored), plain network error (propagates) - [ ] `go test ./api/utils/accessio/downloader/s3/...` passes - [ ] `go build ./...` passes - [ ] Manual verification: `ocm --verbose download resources -r <component-with-s3-resource-in-non-default-region>` --------- Signed-off-by: Jakob Möller <contact@jakob-moeller.com> Signed-off-by: Frederic Wilhelm <frederic.wilhelm@sap.com> Co-authored-by: Frederic Wilhelm <frederic.wilhelm@sap.com> Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ocm download resourcesfails when an S3 bucket lives in a different region than the default hint (us-west-1)HeadBucketto signal the correct region viaX-Amz-Bucket-Regionresponse header*smithyhttp.ResponseErrormanager.GetBucketRegion'sdeserializeBucketRegionmiddleware only reads the header on non-error responses, so the 301 propagated as a fatal errorError seen by users:
Fix: after
GetBucketRegionreturns an error, inspect it as a*smithyhttp.ResponseError. If it is a 301 withX-Amz-Bucket-Regionheader present, extract the region and continue.Reported in: #1999
Test plan
go test ./api/utils/accessio/downloader/s3/...passesgo build ./...passesocm --verbose download resources -r <component-with-s3-resource-in-non-default-region>