Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug-1881575: only require objectUser permissions for GCS #1001

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions antenna/ext/gcs/crashstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _save_file(self, path, data):
:arg bytes data: the data to save

"""
bucket = self.client.get_bucket(self.bucket)
bucket = self.client.bucket(self.bucket)
blob = bucket.blob(path)
blob.upload_from_string(data)

Expand All @@ -115,7 +115,7 @@ def _load_file(self, path):
:returns: data as bytes

"""
bucket = self.client.get_bucket(self.bucket)
bucket = self.client.bucket(self.bucket)
blob = bucket.blob(path)
return blob.download_as_bytes()

Expand All @@ -126,8 +126,9 @@ def verify_write_to_bucket(self):
def check_health(self, state):
"""Check GCS connection health."""
try:
# get the bucket to verify GCS is up and we can connect to it.
self.client.get_bucket(self.bucket)
# check if a blob exists to verify GCS is up and we can connect to it,
# without exceeding the permissions granted by roles/storage.objectUser
self.client.bucket(self.bucket).blob(generate_test_filepath()).exists()
Copy link
Contributor

Choose a reason for hiding this comment

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

Will the test file always exist? I'm not sure I understand this test and what will happen in this try/except block that catches Exception.

Copy link
Member Author

Choose a reason for hiding this comment

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

the test file won't exist, but that's fine because the exists function returns a boolean unless it lacks permissions

except Exception as exc:
state.add_error("GcsCrashStorage", repr(exc))

Expand Down
2 changes: 1 addition & 1 deletion tests/unittest/test_gcs_crashstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_missing_bucket_halts_startup(self, client, gcs_helper):
@patch("google.cloud.storage.Client")
def test_write_error(self, MockStorageClient, client):
mock_client = MockStorageClient.return_value
bucket = mock_client.get_bucket.return_value
bucket = mock_client.bucket.return_value
good_blob = Mock()
bad_blob = Mock()
bad_blob.upload_from_string.side_effect = Unauthorized("not authorized")
Expand Down