-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/md5 usedforsecurity (#17866)
## Summary & Motivation For FIPS enabled systems the MD5 function is disabled in `openssl`. Since Dagster is using `hashlib.md5` in various locations (`dagster`, `dagster-dbt`, and `dagster-k8s`), on a FIPS enabled environment the UI will deliver the following error when trying to load the code location: ``` ValueError: [digital envelope routines: EVP_DigestInit_ex] disabled for FIPS File "/opt/dagster/app/venv/lib/python3.11/site-packages/dagster/_grpc/server.py", line 609, in _get_serialized_external_repository_data external_repository_data_from_def( File "/opt/dagster/app/venv/lib/python3.11/site-packages/dagster/_core/host_representation/external_data.py", line 1341, in external_repository_data_from_def asset_graph = external_asset_graph_from_defs( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/dagster/app/venv/lib/python3.11/site-packages/dagster/_core/host_representation/external_data.py", line 1531, in external_asset_graph_from_defs atomic_execution_unit_id = assets_def.unique_id ^^^^^^^^^^^^^^^^^^^^ File "/opt/dagster/app/venv/lib/python3.11/site-packages/dagster/_core/definitions/assets.py", line 1254, in unique_id return hashlib.md5((json.dumps(sorted(self.keys))).encode("utf-8")).hexdigest() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` A web search [indicates](s3tools/s3cmd#1005) that flagging such `hashlib.md5` uses with the `usedforsecurity=False` parameter will resolve this error. As far as I can ascertain, each of the modified usages are indeed NOT used for the security of the md5 algorithm but instead used to determine the uniqueness of the item(s) being hashed. If this is not the case, my PR will need to be corrected. ## How I Tested These Changes I have deployed these changes on my own companies FIPS-enabled, k8s-based systems and seen the error resolved.
- Loading branch information
1 parent
9b0f031
commit 55f7522
Showing
5 changed files
with
21 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import hashlib | ||
import sys | ||
from typing import Union | ||
|
||
|
||
def non_secure_md5_hash_str(s: Union[bytes, bytearray, memoryview]) -> str: | ||
"""Drop in replacement md5 hash function marking it for a non-security purpose.""" | ||
# check python version, use usedforsecurity flag if possible. | ||
if sys.version_info[0] <= 3 and sys.version_info[1] <= 8: | ||
return hashlib.md5(s).hexdigest() | ||
else: | ||
return hashlib.md5(s, usedforsecurity=False).hexdigest() # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters