SNOW-3869839: Treat S3 HEAD 403 as file-not-found in preflight upload check - #2987
Draft
sfc-gh-turbaszek wants to merge 3 commits into
Draft
SNOW-3869839: Treat S3 HEAD 403 as file-not-found in preflight upload check#2987sfc-gh-turbaszek wants to merge 3 commits into
sfc-gh-turbaszek wants to merge 3 commits into
Conversation
… check S3 returns 403 (instead of 404) for a HEAD request on a non-existent key when the caller's credentials lack s3:ListBucket on the bucket. The scoped credentials Snowflake issues for internal-stage PUTs grant PutObject/ GetObject on the prefix but not bucket-level ListBucket, so the connector's pre-flight existence check was raising a hard 403 error even though the subsequent PUT would succeed. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The preflight HEAD result is only consulted when meta.overwrite is False,
so treating an ambiguous 403 as "file absent" in that case would upload
over a file the user asked us to keep, silently breaking
PUT ... OVERWRITE = FALSE. Restrict the 403 tolerance to the case where
the file is going to be overwritten anyway - where the answer cannot
change what happens next - and keep raising otherwise. This also leaves
the download preflight, where overwrite is False, reporting genuine
permission failures instead of "not found".
When the 403 is raised, log a warning naming the likely cause (missing
s3:ListBucket) and both remedies, since a bare "403 Client Error:
Forbidden" is what made this hard to diagnose in the first place. Also
include the status code in the not-found debug line so 404 ("absent") is
distinguishable from 403 ("assuming absent") in logs.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2987 +/- ##
==========================================
+ Coverage 65.04% 65.13% +0.09%
==========================================
Files 123 123
Lines 17413 17438 +25
Branches 2387 2394 +7
==========================================
+ Hits 11326 11359 +33
+ Misses 5648 5639 -9
- Partials 439 440 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
PUTuploads to S3-backed internal stages could fail with403 Client Error: Forbiddenon the pre-flight existence check (get_file_header()→HEAD), even though the underlyingPUTwould have succeeded.403(not404) forHeadObjecton a non-existent key when the caller lackss3:ListBucketon the bucket — which is the case for the scoped STS credentials Snowflake issues for stage uploads (they grantPutObject/GetObjecton the prefix but not bucket-levelListBucket).get_file_header()(sync and async S3 storage clients) now treats403the same as404— i.e. "cannot confirm the file exists, proceed to upload" — instead of raising.Test plan
test_get_header_403_treated_as_not_foundtotest/unit/test_s3_util.pyandtest/unit/aio/test_s3_util_async.pytest/unit/test_s3_util.pyandtest/unit/aio/test_s3_util_async.pysuites — all passingDESCRIPTION.mdchangelogFixes SNOW-3869839.
🤖 Generated with Claude Code