Skip to content

sync-diff: replace hardcoded use of MD5 with configurable option to support FIPS-compliant environments.#12622

Open
maxz-db wants to merge 1 commit into
pingcap:masterfrom
maxz-db:sync-diff-inspector-fips
Open

sync-diff: replace hardcoded use of MD5 with configurable option to support FIPS-compliant environments.#12622
maxz-db wants to merge 1 commit into
pingcap:masterfrom
maxz-db:sync-diff-inspector-fips

Conversation

@maxz-db
Copy link
Copy Markdown

@maxz-db maxz-db commented Apr 24, 2026

What problem does this PR solve?

Issue Number: close #12627

What is changed and how it works?

Added a new checksum-algorithm configuration flag to sync-diff-inspector:
Supported options: md5" and "sha256" hash functions for checksumming
Default: md5 for backwards compatibility.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
    Manual test on dev environment.
  • No code

Questions

Will it cause performance regression or break compatibility?

No. This only reuses the existing binlog value normalization path in validator.

Do you need to update user documentation, design documentation or monitoring documentation?

No.

Release note

sync-diff: replace hardcoded use of MD5 with configurable option to support FIPS-compliant environments.

@ti-chi-bot ti-chi-bot Bot added do-not-merge/needs-linked-issue do-not-merge/needs-triage-completed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Apr 24, 2026
@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot Bot commented Apr 24, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign 5kbpers for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added contribution This PR is from a community contributor. first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. labels Apr 24, 2026
@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot Bot commented Apr 24, 2026

Hi @maxz-db. Thanks for your PR.

I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot Bot commented Apr 24, 2026

Welcome @maxz-db!

It looks like this is your first PR to pingcap/tiflow 🎉.

I'm the bot to help you request reviewers, add labels and more, See available commands.

We want to make sure your contribution gets all the attention it needs!



Thank you, and welcome to pingcap/tiflow. 😃

@pingcap-cla-assistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@ti-chi-bot ti-chi-bot Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 24, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for SHA256 checksumming alongside the existing MD5 implementation to facilitate FIPS compliance. Key changes include the addition of a ChecksumAlgorithm configuration type, updates to the Config and DataSource structs, and the modification of the core checksum utility to dynamically generate SQL using either MD5 or SHA2. Review feedback recommends making the new --checksum-algorithm flag visible to users and reverting the args parameter type from []interface{} to []any to maintain consistency with modern Go standards.

Comment thread sync_diff_inspector/config/config.go Outdated
Comment thread sync_diff_inspector/utils/utils.go Outdated
Comment thread sync_diff_inspector/utils/utils_test.go Outdated
Comment thread sync_diff_inspector/utils/utils_test.go Outdated
… option to support FIPS-compliant environments. (pingcap#6)

Context:
TiDB FIPS build mode introduced in 7.6.0: pingcap/tidb#47949.
TiDB binaries built with FIPS 140-3 compliance mode disable MD5 hashing in OpenSSL library used by TiKV.

Problem:
sync-diff-inspector relies on hardcoded MD5() for chunk checksumming.
For performance reasons, TiDB may push expression evaluation down to TiKV coprocessor (tidb_query_expr), which uses OpenSSL for cryptographic functions.
In FIPS mode, TiKV's OpenSSL inner_evp_generic_fetch() tries to load MD5 algorithm and fails with error code 50856204 (EVP_R_UNSUPPORTED).
As a result, sync-diff-inspector fails because TiDB rejected all MD5-based checksum queries due to OpenSSL security policy restrictions.

Changes:
- Added a new `checksum-algorithm` configuration flag:
  - Supported options: md5" and "sha256" hash functions for checksumming
  - Default: md5 for backwards compatibility.
@maxz-db maxz-db force-pushed the sync-diff-inspector-fips branch from 3a17fe4 to 98099ee Compare May 5, 2026 01:05
Copy link
Copy Markdown
Contributor

@joechenrh joechenrh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And please update the PR description.

Comment on lines +413 to +415
if len(ds) > 0 {
checksumAlgorithm = ds[0].ChecksumAlgorithm
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len(ds) is validated to be positive before entering this function.

Conn *sql.DB
SessionConfig SessionConfig `toml:"session" json:"session"`

ChecksumAlgorithm ChecksumAlgorithm `toml:"checksum-algorithm" json:"checksum-algorithm"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about passing Config to buildSourceFromCfg, so we don't need store ChecksumAlgorithm in the DataSource.

@D3Hunter D3Hunter changed the title Replace hardcoded use of MD5 in sync-diff-inspector with configurable option to support FIPS-compliant environments. sync-diff: replace hardcoded use of MD5 with configurable option to support FIPS-compliant environments. May 6, 2026
@ti-chi-bot ti-chi-bot Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/needs-linked-issue do-not-merge/needs-triage-completed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels May 6, 2026
db *sql.DB, schemaName, tableName string,
tbInfo *model.TableInfo, limitRange string, indexHint string, args []any,
tbInfo *model.TableInfo, limitRange string, indexHint string,
args []any, checksumAlgorithm string,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we pass the param as ChecksumAlgorithm instead of string

@D3Hunter
Copy link
Copy Markdown
Contributor

D3Hunter commented May 6, 2026

/ok-to-test

@ti-chi-bot ti-chi-bot Bot added ok-to-test Indicates a PR is ready to be tested. and removed needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. labels May 6, 2026
@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot Bot commented May 6, 2026

@maxz-db: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-check 98099ee link true /test pull-check
pull-dm-integration-test-next-gen 98099ee link false /test pull-dm-integration-test-next-gen
pull-dm-integration-test 98099ee link true /test pull-dm-integration-test

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution This PR is from a community contributor. first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. ok-to-test Indicates a PR is ready to be tested. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sync-diff-inspector fails on TiDB cluster v8.5.4 with FIPS enabled

3 participants