datahub icon indicating copy to clipboard operation
datahub copied to clipboard

chore(vulnerability): MD5 to SHA256 - Addressing High Vulnerability

Open pinakipb2 opened this issue 9 months ago • 2 comments

Vulnerability was introduced because of using MD5. So now the hasing algorithm comes from an env variable.

And can be replaced with SHA-256 followed by migrations.

pinakipb2 avatar May 03 '24 13:05 pinakipb2

Once I can get the tests run and it looks good, then we'll get it merged.

david-leifker avatar Jun 26 '24 19:06 david-leifker

Walkthrough

This change introduces a configurable hashing algorithm for generating document IDs in the DataHub system. By implementing the environment variable ELASTIC_ID_HASH_ALGO with a default value of MD5, the system can now dynamically select the hash algorithm based on this configuration. This enhancement improves flexibility, adaptability to various environments, and potential security.

Changes

Files Change Summary
docker/datahub-gms/env/docker-*.env, docker/quickstart/docker-compose-*.yml Added environment variable ELASTIC_ID_HASH_ALGO set to MD5
entity-registry/src/main/java/com/linkedin/metadata/aspect/models/graph/Edge.java Dynamic hash algorithm selection in toDocId method using ELASTIC_ID_HASH_ALGO environment variable
metadata-io/src/main/java/com/linkedin/metadata/systemmetadata/ElasticSearchSystemMetadataService.java Introduced property injection for hashAlgo and a method to set the hash algorithm for testing
metadata-io/src/main/java/com/linkedin/metadata/timeseries/transformer/TimeseriesAspectTransformer.java Added hashAlgo field, setter method, and modified getDocId method to handle dynamic hashing
metadata-io/src/test/java/com/linkedin/metadata/systemmetadata/SystemMetadataServiceTestBase.java Configured _client to set and use idHashAlgo in the test setup() method
metadata-io/src/test/java/com/linkedin/metadata/timeseries/search/TimeseriesAspectServiceTestBase.java Created TimeseriesAspectTransformer instance with idHashAlgo in upsertDocument method
metadata-io/src/main/resources/application.yaml Added idHashAlgo property under elasticsearch section with a default value of MD5
smoke-test/cypress-dev.sh Added environment variable ELASTIC_ID_HASH_ALGO set to MD5 in testing script
metadata-io/build.gradle, smoke-test/build.gradle Configured environment variable ELASTIC_ID_HASH_ALGO to MD5 during test execution in multiple tasks

In fields of code where data flows,
A choice of hash now beauty shows.
From MD5 to what you choose,
Our paths of data freely cruise.
Transform with ease, switch, and see,
The digital world in harmony!
🌐🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Jun 28 '24 21:06 coderabbitai[bot]

This is not a vulnerability and should only be changed on brand new deployments that have never had any ingests and in general with caution. I don't really think this is something we should support. Changing this configuration on a deployed instance will result in orphaning all currently created edges without an appropriate migration script. The usage of MD5 here is in line with its recommended use cases, all we care about here is hash collisions which MD5 is sufficiently low in probability.

RyanHolstien avatar Jul 29 '24 19:07 RyanHolstien

Updating branch to run CI again, checking for test failures again.

david-leifker avatar Jul 31 '24 14:07 david-leifker

There are currently CI test failures on this branch which prevents merging into master at this time. Missing import most likely here for example. cc: @pinakipb2

david-leifker avatar Jul 31 '24 14:07 david-leifker

There are currently CI test failures on this branch which prevents merging into master at this time. Missing import most likely here for example. cc: @pinakipb2

@david-leifker Have fixed the missing import.

pinakipb2 avatar Jul 31 '24 15:07 pinakipb2

Seeing some failures in CI with regard to the algorithm being null, i.e. https://github.com/datahub-project/datahub/actions/runs/10187240058/job/28182260173?pr=10423#step:6:13305

This should be reproduce-able locally by ./gradlew :metadata-io:test

david-leifker avatar Jul 31 '24 22:07 david-leifker

Seeing some failures in CI with regard to the algorithm being null, i.e. https://github.com/datahub-project/datahub/actions/runs/10187240058/job/28182260173?pr=10423#step:6:13305

This should be reproduce-able locally by ./gradlew :metadata-io:test

Updated the PR and the build is not failing on that.

pinakipb2 avatar Aug 03 '24 16:08 pinakipb2

I think there are likely missing changes to the quickstart docker compose. This is likely breaking the smoke tests. Please run this command from the logs here. It will likely update some files in the docker/quickstart directory and fix the failing smoke tests.

david-leifker avatar Aug 06 '24 01:08 david-leifker

@david-leifker - All checks passed. Thanks a lot for the help !!

pinakipb2 avatar Aug 06 '24 13:08 pinakipb2

Nice! Thank you!

david-leifker avatar Aug 06 '24 18:08 david-leifker