Skip to content

Commit 55fdddb

Browse files
committed
feat: warn if default ingress_settings is used in remote_functions
1 parent 650a190 commit 55fdddb

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

bigframes/functions/_function_session.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ def remote_function(
120120
cloud_function_max_instances: Optional[int] = None,
121121
cloud_function_vpc_connector: Optional[str] = None,
122122
cloud_function_memory_mib: Optional[int] = 1024,
123-
cloud_function_ingress_settings: Literal[
124-
"all", "internal-only", "internal-and-gclb"
125-
] = "all",
123+
cloud_function_ingress_settings: Optional[
124+
Literal["all", "internal-only", "internal-and-gclb"]
125+
] = None,
126126
):
127127
"""Decorator to turn a user defined function into a BigQuery remote function.
128128
@@ -302,8 +302,9 @@ def remote_function(
302302
https://cloud.google.com/functions/docs/configuring/memory.
303303
cloud_function_ingress_settings (str, Optional):
304304
Ingress settings controls dictating what traffic can reach the
305-
function. By default `all` will be used. It must be one of:
306-
`all`, `internal-only`, `internal-and-gclb`. See for more details
305+
function. Options are: `all`, `internal-only`, or `internal-and-gclb`.
306+
If no setting is provided, `all` will be used by default and a warning
307+
will be issued. See for more details
307308
https://cloud.google.com/functions/docs/networking/network-settings#ingress_settings.
308309
"""
309310
# Some defaults may be used from the session if not provided otherwise
@@ -400,6 +401,15 @@ def remote_function(
400401
" For more details see https://cloud.google.com/functions/docs/securing/cmek#before_you_begin"
401402
)
402403

404+
if cloud_function_ingress_settings is None:
405+
cloud_function_ingress_settings = "all"
406+
msg = (
407+
"The `cloud_function_ingress_settings` are set to 'all' by default, "
408+
"which may change. Consider using 'internal-only' for enhanced security. "
409+
"See https://cloud.google.com/functions/docs/networking/network-settings#ingress_settings for details."
410+
)
411+
warnings.warn(msg, category=UserWarning)
412+
403413
bq_connection_manager = session.bqconnectionmanager
404414

405415
def wrapper(func):

bigframes/pandas/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ def remote_function(
8080
cloud_function_max_instances: Optional[int] = None,
8181
cloud_function_vpc_connector: Optional[str] = None,
8282
cloud_function_memory_mib: Optional[int] = 1024,
83-
cloud_function_ingress_settings: Literal[
84-
"all", "internal-only", "internal-and-gclb"
85-
] = "all",
83+
cloud_function_ingress_settings: Optional[
84+
Literal["all", "internal-only", "internal-and-gclb"]
85+
] = None,
8686
):
8787
return global_session.with_default_session(
8888
bigframes.session.Session.remote_function,

bigframes/session/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,9 +1203,9 @@ def remote_function(
12031203
cloud_function_max_instances: Optional[int] = None,
12041204
cloud_function_vpc_connector: Optional[str] = None,
12051205
cloud_function_memory_mib: Optional[int] = 1024,
1206-
cloud_function_ingress_settings: Literal[
1207-
"all", "internal-only", "internal-and-gclb"
1208-
] = "all",
1206+
cloud_function_ingress_settings: Optional[
1207+
Literal["all", "internal-only", "internal-and-gclb"]
1208+
] = None,
12091209
):
12101210
"""Decorator to turn a user defined function into a BigQuery remote function. Check out
12111211
the code samples at: https://cloud.google.com/bigquery/docs/remote-functions#bigquery-dataframes.
@@ -1369,8 +1369,9 @@ def remote_function(
13691369
https://cloud.google.com/functions/docs/configuring/memory.
13701370
cloud_function_ingress_settings (str, Optional):
13711371
Ingress settings controls dictating what traffic can reach the
1372-
function. By default `all` will be used. It must be one of:
1373-
`all`, `internal-only`, `internal-and-gclb`. See for more details
1372+
function. Options are: `all`, `internal-only`, or `internal-and-gclb`.
1373+
If no setting is provided, `all` will be used by default and a warning
1374+
will be issued. See for more details
13741375
https://cloud.google.com/functions/docs/networking/network-settings#ingress_settings.
13751376
Returns:
13761377
collections.abc.Callable:

tests/system/large/functions/test_remote_function.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,6 +2354,11 @@ def generate_stats(row: pandas.Series) -> list[int]:
23542354
pytest.param(
23552355
{}, functions_v2.ServiceConfig.IngressSettings.ALLOW_ALL, id="no-set"
23562356
),
2357+
pytest.param(
2358+
{"cloud_function_ingress_settings": None},
2359+
functions_v2.ServiceConfig.IngressSettings.ALLOW_ALL,
2360+
id="set-none",
2361+
),
23572362
pytest.param(
23582363
{"cloud_function_ingress_settings": "all"},
23592364
functions_v2.ServiceConfig.IngressSettings.ALLOW_ALL,

0 commit comments

Comments
 (0)