Repository navigation
feat(Sources): Fallback to anonymous client for s3 and gs on auth failure - #671
Conversation
Release 0.4.56
Release 0.4.57
Release 0.4.58
|
The fix for issue #566 has been successfully implemented and tested locally and via GitHub Actions. All CI checks have passed! Ready for review and merge. |
There was a problem hiding this comment.
Pull request overview
Adds anonymous-access fallback for cloud object downloads so public s3:// and gs:// resources can be read even when local credentials are missing or auth fails.
Changes:
- S3 loader now lazily creates an authenticated boto3 client, and retries once with an
UNSIGNEDclient when an auth-like failure is detected. - GS loader now retries once with
storage.Client.create_anonymous_client()when an auth-like failure is detected. - Improves GS retry logging to use an f-string and includes exception details via
exc_info=True.
Comments suppressed due to low confidence (2)
aperturedb/Sources.py:89
- The fallback condition includes matching the message "'NoneType' object has no attribute 'get_object'", which isn’t an auth/credentials error and should be prevented by the
if self.s3 is None: ...initialization above. Treating this as a trigger for anonymous mode can mask unrelated programming/configuration mistakes; it would be better to remove this branch or handle the underlying None-client case explicitly.
if not tried_anonymous and ("NoCredentialsError" in str(type(e)) or "403" in str(e) or "401" in str(e) or "'NoneType' object has no attribute 'get_object'" in str(e)):
import boto3
aperturedb/Sources.py:132
- As with S3, the anonymous fallback decision relies on substring checks against
str(type(e))andstr(e)("DefaultCredentialsError"/"401"/"403"). This is fragile and may trigger on unrelated errors. Prefer catching the specific Google auth/storage exception types (e.g.,google.auth.exceptions.DefaultCredentialsErrorand the storage Forbidden/Unauthorized exceptions) and using their structured status/code to decide when anonymous retry is appropriate.
except Exception as e:
if not tried_anonymous and ("DefaultCredentialsError" in str(type(e)) or "403" in str(e) or "401" in str(e)):
client = storage.Client.create_anonymous_client()
tried_anonymous = True
continue
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
faec966 to
69935e2
Compare
|
Addressed feedback from copilot: Refactored exception handling to use specific botocore exceptions, and ensured custom injected s3 clients are not overridden. Updated in latest commit. |
Addresses review feedback from Copilot
…ove NoneType check
e621ff8 to
3ea9f02
Compare
ad-claw000
left a comment
There was a problem hiding this comment.
Addressed the remaining feedback. Removed the NoneType branch.
ad-claw000
left a comment
There was a problem hiding this comment.
Applied autopep8 formatting to the new log messages to fix the pre-commit CI failure.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 18 out of 20 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
test/test_Sources.py:53
- Same issue as above:
botocore.UNSIGNEDis used without importingbotocore(onlybotocore.exceptions). This will fail at runtime; importbotocoreorUNSIGNEDbefore using it.
self.assertTrue(success)
self.assertEqual(mock_client_factory.call_count, 2)
_, kwargs = mock_client_factory.call_args_list[1]
self.assertEqual(kwargs['config'].signature_version, botocore.UNSIGNED)
ad-claw000
left a comment
There was a problem hiding this comment.
Addressed the remaining feedback on unused boto3 imports and run_test_container TAG match.
|
Addressed all remaining review comments in commit 0b01821:
|
Closes #566
This PR introduces fallback anonymous access for reading objects from Amazon S3 and Google Cloud Storage (GS) buckets when the initial authenticated request fails due to
NoCredentialsError(or similar authorization/access errors).When a user doesn't have specific cloud credentials configured locally but wants to load public objects via
s3://orgs://URLs, the loader now catches the auth-related exception and seamlessly recreates a client withUNSIGNEDsignature (S3) orcreate_anonymous_client()(GS).