Conversation
| def _getIdHash(id): | ||
| """Return md5 prefix based on id value""" | ||
| m = hashlib.new("md5") | ||
| m.update(id.encode("utf8")) |
Check failure
Code scanning / CodeQL
Use of a broken or weak cryptographic hashing algorithm on sensitive data
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI over 1 year ago
To fix the issue, replace the use of the MD5 hashing algorithm in _getIdHash with a stronger algorithm, such as SHA-256. This ensures that the hash function is resistant to pre-image and collision attacks. The change involves:
- Updating the
_getIdHashfunction to usehashlib.sha256instead ofhashlib.new("md5"). - Ensuring that the rest of the code remains functional by keeping the truncation to the first 5 characters of the hash.
No additional imports are required since hashlib already supports SHA-256.
| @@ -25,4 +25,4 @@ | ||
| def _getIdHash(id): | ||
| """Return md5 prefix based on id value""" | ||
| m = hashlib.new("md5") | ||
| """Return sha256 prefix based on id value""" | ||
| m = hashlib.sha256() | ||
| m.update(id.encode("utf8")) |
There was a problem hiding this comment.
Since we now depend on hdf5-json to do this testing, it might be a good idea to include hdf5-json's tests as a step in the CI
mattjala
left a comment
There was a problem hiding this comment.
Besides a few minor comments and questions, this is good to go in. I'll try to get the outstanding PRs on hdf5-json reviewed this week so that we can avoid having HSDS depend on a specific branch.
| created = link_item["created"] | ||
| # allow "pre-dated" attributes if recent enough | ||
| predate_max_time = config.get("predate_max_time", default=10.0) | ||
| if now - created > predate_max_time: |
There was a problem hiding this comment.
This comparison seems backwards. If I understand correctly, the difference between current time and creation time should need to be under the max time, not above it
| azure-storage-blob | ||
| cryptography | ||
| h5py>=3.6.0 | ||
| git+https://github.com/HDFGroup/hdf5-json.git@abstract#egg=h5json |
There was a problem hiding this comment.
It's fine to leave this as a git ref during development, but it needs to be changed to a real version after merge/release
| "bitshuffle >=0.5.2", | ||
| "cryptography", | ||
| "h5py >= 3.6.0", | ||
| "h5json@git+https://github.com/HDFGroup/hdf5-json@abstract", |
There was a problem hiding this comment.
It's fine to leave this as a git ref during development, but it needs to be changed to a real version after merge/release
| from h5json.array_util import bytesToArray, squeezeArray, getBroadcastShape | ||
| from h5json.objid import isValidUuid | ||
| from h5json.shape_util import isNullSpace, isScalar, getShapeDims, getMaxDims, getRank | ||
| from h5json.dset_util import getChunkDims, isExtensible |
There was a problem hiding this comment.
isExtensible is defined in h5json's shape_util, and then imported into h5json's dset_util. HSDS should import it directly from shape_util.
| from h5json.hdf5dtype import getBaseTypeJson, validateTypeItem, createDataType, getItemSize | ||
| from h5json.shape_util import getShapeDims, getShapeClass, getShapeJson | ||
| from h5json.dset_util import getChunkSize, generateLayout | ||
| from h5json.dset_util import getDataSize, validateDatasetCreationProps |
There was a problem hiding this comment.
getDataSize is defined in h5json's shape_util, and then h5json imports it into dset_util. HSDS should import getDataSize directly from h5json.shape_util.
| uses: actions/checkout@v4 | ||
| with: | ||
| repository: HDFGroup/h5pyd | ||
| path: ${{github.workspace}}/h5pyd |
There was a problem hiding this comment.
Between the merging of hdf5-json's new branch into master and the associated/follow-up HSDS and h5pyd release, this should be changed to point at h5pyd's h5json branch.
| ] | ||
| requires-python = ">=3.8" | ||
| requires-python = ">=3.10" | ||
| version = "0.9.2" |
There was a problem hiding this comment.
Should be bumped to 1.0.0 for consistency
| @@ -1,2 +1,2 @@ | |||
| aiohttp==3.9.4 | |||
| aiobotocore==2.13.0 | |||
There was a problem hiding this comment.
The requirements.txt in this branch should be updated to reflect all the dependency updates that have gone into master
| @@ -0,0 +1,2973 @@ | |||
| openapi: 3.1.0 | |||
There was a problem hiding this comment.
The README points at HDFGroup/hdf5-rest-api as an authoritative description of the API, but it's now out of date. We should remove any references to it and flag it as out of date.
| # link related functions | ||
| # | ||
| from h5json.time_util import getNow | ||
| from h5json.link_util import validateLinkName, getLinkClass, getLinkPath, getLinkFilePath |
There was a problem hiding this comment.
validateLinkName and isEqualLink moved to h5json.link_util, but their analogues for attributes (validateAttributeName and isEqualAttr) stayed behind in hsds/util/attrUtil.py. Is there a reason the two are split differently?
| max_rangeget_gap: 1024 # max gap in byte for intelligent range get requests | ||
| predate_maxtime: 10.0 # max delta between object created timestamp in request and actual time | ||
| posix_delay: 0.0 # delay for POSIX IO operations for simulating cloud storage latencies | ||
| max_compact_dset_size: 65536 # size in bytes for maximum compact storage size |
There was a problem hiding this comment.
It seems that nothing ever uses this field.
| allow_any_bucket_write: true # enable writes to buckets other than default bucket | ||
| bit_shuffle_default_blocksize: 2048 # default blocksize for bitshuffle filter | ||
| max_rangeget_gap: 1024 # max gap in byte for intelligent range get requests | ||
| predate_maxtime: 10.0 # max delta between object created timestamp in request and actual time |
There was a problem hiding this comment.
All the places that try to use this field (servicenode_lib.py:1059, servicenode_lib.py:1347 and link_sn.py:301 spell it as predate_max_time instead of the correct predate_maxtime, find a missing key, and always get the default value.
| """ create dataset objects based on parameters in items list """ | ||
|
|
||
| if not root_id: | ||
| msg = "no root_id given for createDatatypeObjs" |
There was a problem hiding this comment.
Incorrect function name in error msg - should be createDatasets
| post_crawler = PostCrawler(app, root_id=root_id, bucket=bucket, items=items) | ||
| await post_crawler.crawl() | ||
| if post_crawler.get_status() > 201: | ||
| msg = f"createGroups returning status from crawler: {post_crawler.get_status()}" |
There was a problem hiding this comment.
Incorrect function name in error msg - should say _createObjects returning status...
|
|
||
| obj_list = post_crawler.get_rsp_objs() | ||
| if not isinstance(obj_list, list): | ||
| msg = f"createGroups expected list but got: {type(obj_list)}" |
There was a problem hiding this comment.
Incorrect function name in error msg - should be _createObjects expected...
| requires-python = ">=3.10" | ||
| version = "0.9.2" | ||
|
|
||
| dependencies = [ |
There was a problem hiding this comment.
pyproject/requirements.txt is missing openapi_spec_validator, so CI skips the openapi spec validation step
| multiple groups in one request. `type` is not permitted in the body | ||
| (groups have no datatype). | ||
|
|
||
| **Bug:** `implicit` is only forwarded to argument construction for |
There was a problem hiding this comment.
Should be moved to a GH issue instead of a note in openapi
| (multi-item list) create; it is not restricted to non-batch | ||
| creates. | ||
|
|
||
| **Bug:** for a batch create (list with more than one item), |
There was a problem hiding this comment.
Should be moved to a GH issue instead of being in the openapi spec
| schema: { type: boolean, default: false } | ||
| description: | | ||
| Include an `alias` list of h5paths that resolve to this | ||
| dataset. Bug: on this specific route, the flag that gates |
There was a problem hiding this comment.
Bug desc should be moved to a GH issue
| properties: | ||
| bytes_sent: | ||
| type: integer | ||
| description: "Note: a source-level bug (hsds/basenode.py) assigns bytes_recv over this key immediately after setting it, so this actually reports received bytes, and sent-byte count is not exposed." |
There was a problem hiding this comment.
Bug desc should be moved to a GH issue
| description: | | ||
| Include an `alias` list of h5paths that resolve to this group. | ||
| Note: parsed with a raw truthiness check rather than real | ||
| boolean parsing, so `?getalias=0` is truthy and turns this on. |
There was a problem hiding this comment.
Truthiness issue seems like a bug and should be moved from here to a GH issue
| description: | | ||
| Include an `alias` list of h5paths that resolve to this | ||
| datatype. Note: parsed with a raw truthiness check, so | ||
| `?getalias=0` is truthy and turns this on. |
There was a problem hiding this comment.
Truthiness issue seems like a bug and should be moved from here to a GH issue
| unit_tests = ('array_util_test', 'chunk_util_test', 'compression_test', 'domain_util_test', | ||
| 'dset_util_test', 'hdf5_dtype_test', 'id_util_test', 'lru_cache_test', | ||
| unit_tests = ('chunk_util_test', 'compression_test', 'domain_util_test', | ||
| 'dset_util_test', 'lru_cache_test', 'openapi_test', |
There was a problem hiding this comment.
glob_parser_test and _stor_util_test` are omitted from this list.
| # in use and block its removal) actually gets torn down. | ||
| DOWN_COMPOSE_FILES="${COMPOSE_FILES}" | ||
| if [[ -z ${SWAGGER} ]]; then | ||
| DOWN_COMPOSE_FILES="${DOWN_COMPOSE_FILES} -f admin/docker/docker-compose.swagger.yml" |
There was a problem hiding this comment.
The referenced swagger file doesn't seem to exist, which will break teardown
Use h5json package for typing and objids
Important
Migrated HSDS to use the h5json library for core utilities, restructured utility modules, added support for client-provided object IDs and timestamps, and updated dependencies to require Python 3.10+ with h5json 1.0.0+.
Library Migration and Utility Restructuring
hsds/util/idUtil.py,hsds/util/timeUtil.py,hsds/util/hdf5dtype.py, andhsds/util/arrayUtil.pyas their functionality is now provided by h5json.hsds/util/nodeUtil.pywith node ID generation, partitioning, and datanode URL resolution functions.util.idUtil�h5json.objid,util.timeUtil�h5json.time_util).Object ID and Timestamp Handling
POST_Dataset,POST_Group,POST_Datatype, and related functions indset_dn.py,group_dn.py,ctype_dn.py, anddset_sn.py.max_timestamp_driftconfiguration parameter to validate client-provided timestamps inattr_dn.py,link_dn.py, and related modules, with fallback to server-generated timestamps when skew exceeds threshold.deleted_idsset when creating new objects with the same ID.Configuration and Dependencies
default_vlen_type_size,predate_maxtime,posix_delay,max_compact_dset_size, andmax_timestamp_drifttoadmin/config/config.yml.pyproject.tomlto require Python 3.10+, add h5json 1.0.0+, update numpy to 2.0.0+, and constrain numcodecs to �0.15.1..github/workflows/python-package.yml.API and Function Refactoring
POST_Dataset,POST_Group, andPOST_Datatypehandlers to support batch creation of multiple objects using new helper functions (createDatasets,createGroups,createDatatypeObjs) andDomainCrawlerfor writing initial data.getChunkLayoutcalls togetChunkDimsthroughout codebase; moved layout from top-level response to nested undercreationProperties.h5domaintofileinlink_dn.py,link_sn.py, andservicenode_lib.py; added per-link timestamp validation inPUT_Links.POST_Dataset,POST_Group, andPOST_Datatypeinstead of always creating empty objects.New Functionality
hsds/post_crawl.pywithPostCrawlerclass for asynchronously creating multiple HDF5 objects with configurable worker count and error handling.getConsolidatedMetaDatafunction inasync_lib.pyto create consolidated metadata summaries for all objects in a domain.put_datamethod toDomainCrawlerfor writing one-chunk dataset values; addeddoPointWriteanddoHyperslabWritefunctions indset_lib.pyfor writing point and hyperslab selections.getobjsparameter togetDomainResponsefunction to optionally return domain objects from S3 summary file.Bug Fixes and Improvements
HTTPInternalServerErrortoHTTPBadRequestfor duplicate object IDs and invalid configurations inctype_dn.py,dset_dn.py, andgroup_dn.py.posix_delayconfiguration support tofileClient.pyfor simulating cloud storage latencies inget_object,put_object, andlist_keysmethods.HSDS_VERSIONfrom 0.9.2 to 1.0.0 inbasenode.py.Test Updates
testPostDatasetWithId,testPostTypeWithId,testPostWithId), attribute initialization (testPostDatasetWithAttributes,testPostWithAttributes), timestamp handling (testUseTimestamp), and batch creation (testPostMulti,testDatasetPostMulti).creationPropertiesinstead of top-level; removedCHUNK_MIN/CHUNK_MAXconstants and moved them to local scope; updated external link tests to usefilefield instead ofh5domain.array_util_test.py,hdf5_dtype_test.py, andid_util_test.pyas their functionality is now tested through h5json library.createObjId,getFilterItem) instead of local utilities.This description was created by
for 2bafb51. You can customize this summary. It will automatically update as commits are pushed.