Skip to content

feat(Sources): Fallback to anonymous client for s3 and gs on auth failure - #671

Merged
luisremis merged 18 commits into
developfrom
feat/566-anonymous-storage-access
May 21, 2026
Merged

luisremis merged 18 commits into
developfrom
feat/566-anonymous-storage-access

Conversation

@ad-claw000

Copy link
Copy Markdown
Contributor

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:// or gs:// URLs, the loader now catches the auth-related exception and seamlessly recreates a client with UNSIGNED signature (S3) or create_anonymous_client() (GS).

@ad-claw000

Copy link
Copy Markdown
Contributor Author

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 UNSIGNED client 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)) and str(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.DefaultCredentialsError and 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.

Comment thread aperturedb/Sources.py Resolved
Comment thread aperturedb/Sources.py Resolved
@ad-claw000
ad-claw000 force-pushed the feat/566-anonymous-storage-access branch from faec966 to 69935e2 Compare May 19, 2026 02:34
@ad-claw000
ad-claw000 requested a review from luisremis May 19, 2026 04:08
@ad-claw000

Copy link
Copy Markdown
Contributor Author

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.

@luisremis
luisremis requested a review from Copilot May 19, 2026 21:18
luisremis
luisremis previously approved these changes May 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread aperturedb/Sources.py Resolved
Comment thread aperturedb/Sources.py Resolved
Copilot AI review requested due to automatic review settings May 20, 2026 00:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread aperturedb/Sources.py Resolved
Comment thread aperturedb/Sources.py Resolved
@ad-claw000
ad-claw000 force-pushed the feat/566-anonymous-storage-access branch from e621ff8 to 3ea9f02 Compare May 20, 2026 01:06

@ad-claw000 ad-claw000 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed the remaining feedback. Removed the NoneType branch.

@ad-claw000 ad-claw000 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied autopep8 formatting to the new log messages to fix the pre-commit CI failure.

Copilot AI review requested due to automatic review settings May 20, 2026 08:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.UNSIGNED is used without importing botocore (only botocore.exceptions). This will fail at runtime; import botocore or UNSIGNED before 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)

Comment thread test/test_Sources.py Resolved
Copilot AI review requested due to automatic review settings May 20, 2026 08:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 20 changed files in this pull request and generated 3 comments.

Comment thread test/run_test_container.sh Resolved
Comment thread test/test_Sources.py Resolved
Comment thread aperturedb/Sources.py Resolved
Copilot AI review requested due to automatic review settings May 20, 2026 23:22

@ad-claw000 ad-claw000 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed the remaining feedback on unused boto3 imports and run_test_container TAG match.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread test/run_test_container.sh Resolved
Comment thread test/test_Sources.py Resolved
Copilot AI review requested due to automatic review settings May 21, 2026 07:03
@ad-claw000

Copy link
Copy Markdown
Contributor Author

Addressed all remaining review comments in commit 0b01821:

  • Fixed exact glob match for _non_http in test/run_test_container.sh.
  • Added support and test for botocore.exceptions.PartialCredentialsError in aperturedb/Sources.py and test/test_Sources.py.
  • Patched time.sleep to skip delays during test/test_Sources.py execution.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread aperturedb/Sources.py Resolved
Comment thread aperturedb/Sources.py Resolved
@luisremis
luisremis merged commit de009c7 into develop May 21, 2026
2 checks passed
@luisremis
luisremis deleted the feat/566-anonymous-storage-access branch May 21, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Access files from gs and s3 buckets anonymously.

3 participants