Skip to content

Commit 7f0904d

Browse files
chore: relax adding objectUser role in blob creation (#1593)
Co-authored-by: Huan Chen <142538604+Genesis929@users.noreply.github.com>
1 parent 6e98a2c commit 7f0904d

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

bigframes/clients.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ def __init__(
8686
self._cloud_resource_manager_client = cloud_resource_manager_client
8787

8888
def create_bq_connection(
89-
self, project_id: str, location: str, connection_id: str, iam_role: str
89+
self,
90+
project_id: str,
91+
location: str,
92+
connection_id: str,
93+
iam_role: Optional[str] = None,
9094
):
9195
"""Create the BQ connection if not exist. In addition, try to add the IAM role to the connection to ensure required permissions.
9296
@@ -119,11 +123,12 @@ def create_bq_connection(
119123

120124
# Ensure IAM role on the BQ connection
121125
# https://cloud.google.com/bigquery/docs/reference/standard-sql/remote-functions#grant_permission_on_function
122-
try:
123-
self._ensure_iam_binding(project_id, service_account_id, iam_role)
124-
except google.api_core.exceptions.PermissionDenied as ex:
125-
ex.message = f"Failed ensuring IAM binding (role={iam_role}, service-account={service_account_id}). {ex.message}"
126-
raise
126+
if iam_role:
127+
try:
128+
self._ensure_iam_binding(project_id, service_account_id, iam_role)
129+
except google.api_core.exceptions.PermissionDenied as ex:
130+
ex.message = f"Failed ensuring IAM binding (role={iam_role}, service-account={service_account_id}). {ex.message}"
131+
raise
127132

128133
# Introduce retries to accommodate transient errors like:
129134
# (1) Etag mismatch,

bigframes/operations/strings.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,7 @@ def to_blob(self, connection: Optional[str] = None) -> series.Series:
305305
raise NotImplementedError()
306306

307307
session = self._block.session
308-
connection = session._create_bq_connection(
309-
connection=connection, iam_role="storage.objectUser"
310-
)
308+
connection = session._create_bq_connection(connection=connection)
311309
return self._apply_binary_op(connection, ops.obj_make_ref_op)
312310

313311

bigframes/session/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1833,7 +1833,10 @@ def from_glob_path(
18331833
return s.rename(name).to_frame()
18341834

18351835
def _create_bq_connection(
1836-
self, iam_role: str, *, connection: Optional[str] = None
1836+
self,
1837+
*,
1838+
connection: Optional[str] = None,
1839+
iam_role: Optional[str] = None,
18371840
) -> str:
18381841
"""Create the connection with the session settings and try to attach iam role to the connection SA.
18391842
If any of project, location or connection isn't specified, use the session defaults. Returns fully-qualified connection name."""

0 commit comments

Comments
 (0)