Skip to content

Commit b7e204f

Browse files
committed
Enable unsigned s3 usage
1 parent 232de81 commit b7e204f

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

metaflow/metaflow_config.py

+6
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
###
8888
S3_ENDPOINT_URL = from_conf("S3_ENDPOINT_URL")
8989
S3_VERIFY_CERTIFICATE = from_conf("S3_VERIFY_CERTIFICATE")
90+
S3_SIGN_REQUEST = from_conf("S3_SIGN_REQUEST", True)
9091

9192
# Set ServerSideEncryption for S3 uploads
9293
S3_SERVER_SIDE_ENCRYPTION = from_conf("S3_SERVER_SIDE_ENCRYPTION")
@@ -130,6 +131,11 @@
130131
DATATOOLS_CLIENT_PARAMS["endpoint_url"] = S3_ENDPOINT_URL
131132
if S3_VERIFY_CERTIFICATE:
132133
DATATOOLS_CLIENT_PARAMS["verify"] = S3_VERIFY_CERTIFICATE
134+
if not S3_SIGN_REQUEST:
135+
# TODO: possible to achieve this without importing botocore?
136+
from botocore import UNSIGNED
137+
from botocore.config import Config
138+
DATATOOLS_CLIENT_PARAMS["config"] = Config(signature_version=UNSIGNED)
133139

134140
DATATOOLS_SESSION_VARS = from_conf("DATATOOLS_SESSION_VARS", {})
135141

metaflow/metaflow_environment.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,13 @@ def _get_download_code_package_cmd(self, code_package_url, datastore_type):
9696
# Boto3 does not play well with passing None or an empty string to endpoint_url
9797
return "{python} -c '{script}'".format(
9898
python=self._python(),
99-
script='import boto3, os; ep=os.getenv(\\"METAFLOW_S3_ENDPOINT_URL\\"); boto3.client(\\"s3\\", **({\\"endpoint_url\\":ep} if ep else {})).download_file(\\"%s\\", \\"%s\\", \\"job.tar\\")'
100-
% (bucket, s3_object),
99+
script='import boto3, os;'
100+
'from botocore import UNSIGNED; from botocore.config import Config;'
101+
'ep=os.getenv(\\"METAFLOW_S3_ENDPOINT_URL\\");'
102+
'no_sign=os.getenv(\\"METAFLOW_S3_SIGN_REQUEST\\") == "False";'
103+
'boto3.client(\\"s3\\", **({\\"endpoint_url\\":ep} if ep else {}),'
104+
'**({\\"config\\": Config(signature_version=UNSIGNED)} if no_sign else {}))'
105+
'.download_file(\\"%s\\", \\"%s\\", \\"job.tar\\")' % (bucket, s3_object),
101106
)
102107
elif datastore_type == "azure":
103108
from .plugins.azure.azure_utils import parse_azure_full_path

metaflow/plugins/argo/argo_workflows.py

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
KUBERNETES_SECRETS,
4444
S3_ENDPOINT_URL,
4545
S3_SERVER_SIDE_ENCRYPTION,
46+
S3_SIGN_REQUEST,
4647
SERVICE_HEADERS,
4748
SERVICE_INTERNAL_URL,
4849
UI_URL,
@@ -1765,6 +1766,9 @@ def _container_templates(self):
17651766
# add METAFLOW_S3_ENDPOINT_URL
17661767
env["METAFLOW_S3_ENDPOINT_URL"] = S3_ENDPOINT_URL
17671768

1769+
# support for unsigned s3 requests
1770+
env["METAFLOW_S3_SIGN_REQUEST"] = S3_SIGN_REQUEST
1771+
17681772
# support Metaflow sandboxes
17691773
env["METAFLOW_INIT_SCRIPT"] = KUBERNETES_SANDBOX_INIT_SCRIPT
17701774
env["METAFLOW_KUBERNETES_SANDBOX_INIT_SCRIPT"] = (

metaflow/plugins/kubernetes/kubernetes.py

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
OTEL_ENDPOINT,
3737
S3_ENDPOINT_URL,
3838
S3_SERVER_SIDE_ENCRYPTION,
39+
S3_SIGN_REQUEST,
3940
SERVICE_HEADERS,
4041
KUBERNETES_SECRETS,
4142
SERVICE_INTERNAL_URL,
@@ -271,6 +272,7 @@ def create_jobset(
271272
"METAFLOW_AZURE_STORAGE_BLOB_SERVICE_ENDPOINT",
272273
AZURE_STORAGE_BLOB_SERVICE_ENDPOINT,
273274
)
275+
.environment_variable("METAFLOW_S3_SIGN_REQUEST", S3_SIGN_REQUEST)
274276
.environment_variable(
275277
"METAFLOW_DATASTORE_SYSROOT_AZURE", DATASTORE_SYSROOT_AZURE
276278
)

0 commit comments

Comments
 (0)