Skip to content

Switch use of md5 hashing to sha256 - #9165

Merged
taylorsilva merged 3 commits into
concourse:masterfrom
IvanChalukov:sha256-switch
May 10, 2025
Merged

taylorsilva merged 3 commits into
concourse:masterfrom
IvanChalukov:sha256-switch

Conversation

@IvanChalukov

@IvanChalukov IvanChalukov commented Mar 27, 2025 •

Copy link
Copy Markdown
Contributor

Changes proposed by this PR

Related to #9021 and #9133

closes #9122

FIPS-compliant PostgreSQL instances restrict the use of md5 hashing, requiring a transition to sha256. To accommodate this, a migration has been implemented to convert all existing md5 hashes in the affected tables to sha256. For large databases, this process may take some time to complete.

  • Replace MD5 with SHA-256 in all relevant areas
  • Update test cases accordingly
  • Perform manual testing to ensure UI functionality remains intact, including features like disabling resources and pinning specific resource versions

Notes to reviewer

Results from tests on highly loaded database:

Setup

Component Details
Database Instance PostgreSQL on AWS
Instance Class db.t4g.xlarge
vCPU 4
RAM 16 GB
Engine Version 16.8
Storage 250 GiB

Data

Tables Rows
resource_config_versions 10 337 812
build_resource_config_version_inputs 18 626 661
build_resource_config_version_outputs 2 745 473
next_build_inputs 41 482
resource_caches 531
resource_disabled_versions 46
builds 9 804 696
jobs 40 006

Migration was done in ~19 mins.

Release Note

  • Must be executed during a scheduled downtime window. Depending on the size of your database the migration could take ten's of minutes or even a few hours. Plan accordingly.
  • Replaces MD5 with SHA-256 across the codebase
  • Migrates all existing MD5-hashed data to SHA-256 in the database

@IvanChalukov
IvanChalukov requested a review from a team March 27, 2025 15:52
@taylorsilva taylorsilva added this to the v8.0.0 milestone Mar 27, 2025

@Kump3r Kump3r left a comment

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.

Tested with a local Concourse and a similar external Postgres database to what @IvanChalukov described. In my case the migration took around ~20min., but in the end I was able to confirm the previous regressions are no longer applicable.

  • No new builds were rescheduled with the same versions ✅
  • Disabled versions and pinned versions were not duplicated and re-executed. ✅

@taylorsilva taylorsilva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for doing the timing tests guys. I'm going to do some local upgrade/downgrade testing just to see if I can find any other breaking scenarios before approving.

@taylorsilva taylorsilva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This LGTM. I was trying to think of versions that might cause key ordering to differ between Go and Postgres again. I made the mock resource output a custom version with this value:

{
  "version_one": "first",
  "version_two": "second",
  "version_three": "third",
  "versionOne": "one",
  "versionTwo": "two",
  "versionThree": "three",
  "version-one": "once",
  "version-two": "twice",
  "version-three": "thrice"
}

Go ordered it like this:

version-one	once
version-three	thrice
version-two	twice
versionOne	one
versionThree	three
versionTwo	two
version_one	first
version_three	third
version_two	second

And Postgresql ordered it like this:

{
  "versionOne": "one",
  "versionTwo": "two",
  "version-one": "once",
  "version-two": "twice",
  "version_one": "first",
  "version_two": "second",
  "versionThree": "three",
  "version-three": "thrice",
  "version_three": "third"
}

I made a simple pipeline that would trigger on any new versions found.

I docker compose'd what's currently on master, set the pipeline, let the job trigger once with the custom version.
I then switched over to this PR branch, docker compose'd to upgrade my dev instance. No new version was created and the job didn't trigger a second time.

image (ignore the errors, they're happening because I'm forcing the mock resource to output a version it doesn't know how to read) image (second row is the relevant version to track. First row is the custom mock resource type I made).

I'm going to leave this PR open for one more week just in case someone can think of something else related to the resource versions that might cause issues. I think the one I thought of is unlike anything the majority of resources would ever output as a version. Hopefully it is edge-case-y enough to give us confidence that this does work now and won't cause a bunch of versions to be recreated.

Thanks for the hard work @IvanChalukov!

@taylorsilva
taylorsilva merged commit 2eb97bf into concourse:master May 10, 2025
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Pull Requests May 10, 2025
taylorsilva added a commit that referenced this pull request Jul 28, 2025
This reverts commit 2eb97bf, reversing
changes made to c17cb83.

This is a breaking change that will be introduced in v8 of Concourse.
taylorsilva added a commit that referenced this pull request Jul 30, 2025
This reverts commit 2eb97bf, reversing
changes made to c17cb83.

This is a breaking change that will be introduced in v8 of Concourse.
taylorsilva added a commit that referenced this pull request Jul 30, 2025
This reverts commit 2eb97bf, reversing
changes made to c17cb83.

This is a breaking change that will be introduced in v8 of Concourse.
taylorsilva added a commit that referenced this pull request Jul 31, 2025
This reverts commit 2eb97bf, reversing
changes made to c17cb83.

This is a breaking change that will be introduced in v8 of Concourse.
taylorsilva added a commit that referenced this pull request Jul 31, 2025
This reverts commit 2eb97bf, reversing
changes made to c17cb83.

This is a breaking change that will be introduced in v8 of Concourse.
taylorsilva added a commit that referenced this pull request Jul 31, 2025
This reverts commit 2eb97bf, reversing
changes made to c17cb83.

This is a breaking change that will be introduced in v8 of Concourse.
taylorsilva added a commit that referenced this pull request Jul 31, 2025
This reverts commit 2eb97bf, reversing
changes made to c17cb83.

This is a breaking change that will be introduced in v8 of Concourse.
taylorsilva added a commit that referenced this pull request Aug 6, 2025
This reverts commit 2eb97bf, reversing
changes made to c17cb83.

This is a breaking change that will be introduced in v8 of Concourse.
taylorsilva added a commit that referenced this pull request Aug 7, 2025
This reverts commit 2eb97bf, reversing
changes made to c17cb83.

This is a breaking change that will be introduced in v8 of Concourse.
taylorsilva added a commit that referenced this pull request Aug 8, 2025
This reverts commit 2eb97bf, reversing
changes made to c17cb83.

This is a breaking change that will be introduced in v8 of Concourse.
taylorsilva added a commit that referenced this pull request Aug 8, 2025
This reverts commit 2eb97bf, reversing
changes made to c17cb83.

This is a breaking change that will be introduced in v8 of Concourse.
@taylorsilva

Copy link
Copy Markdown
Member

Following up on the previous conversation in this PR currently marked as resolved: I locally ran a copy of the ci.concourse-ci.org database, looking for any {} or NULL versions in resource_config_versions and resource_caches tables. I did not find any in there. I used this query:

select count("version") from resource_config_versions where "version" = '{}'::jsonb or "version" IS NULL;
select count("version") from resource_caches rc where "version" = '{}'::jsonb or "version" is NULL;

I'm going to make a call out to the community to run the above query to see if this is also the case for others or if Pix4D's case is more common.


Since I had a local copy of our prod db, I ran the migration just to get a sense of how long it might take to run in prod and got a 6min runtime. This is on an M1 macbook pro with 32GB ram, running Postgres 17 natively (not in docker).

@taylorsilva

Copy link
Copy Markdown
Member

@IvanChalukov Based on the data so far from https://github.com/orgs/concourse/discussions/9265 it looks like empty versions {} are present in people's databases.

I think these empty versions must come from custom resources. I modified the mock resource type to return an empty version. You can use that image here: https://hub.docker.com/r/concourseteam/mock-resource/tags

image
resource_types:
  - name: mock-empty
    type: registry-image
    source:
      repository: concourseteam/mock-resource
      tag: empty-version

resources:
  - name: mock
    type: mock-empty

jobs:
  - name: job
    plan:
      - get: mock
image

This is probably something we shouldn't allow. I'll open a separate issue for that.

Anyways, what happens when we upgrade a db running Concourse 7.14 to master?
I setup a local Concourse running 7.14 and set the above pipeline. Db looks like this:
image

Then I upgraded it the latest code on master. Db looked like this after:
image

Empty versions are not recalculated, as previously stated in prior comments.

I've also just discovered another issue related to 7.14. The latest migration number comes after the one in this PR:
image

Which currently causes upgrades to fail.

Action Items

Based on the above, the following work needs to be done:

  • Migration number needs to be updated so it's the latest migration. I'll go ahead and fix this myself.
  • The migration needs to be updated to handle {} empty json versions. I'd like to assign this to you @IvanChalukov
  • Open new issue to potentially filter out or error when resources return empty versions.

@aliculPix4D

aliculPix4D commented Sep 5, 2025 •

Copy link
Copy Markdown
Contributor

I've also just discovered another issue related to 7.14. The latest migration number comes after the one in this PR:

@taylorsilva does this mean that people who deployed v7.14.X all have this issue with migration history and that you will have to release v7.14.2? or that happened only in your experiment because you first deployed the master?

@Kump3r

Kump3r commented Sep 5, 2025

Copy link
Copy Markdown
Contributor

I've also just discovered another issue related to 7.14. The latest migration number comes after the one in this PR:

@taylorsilva does this mean that people who deployed v7.14.X all have this issue with migration history and that you will have to release v7.14.2? or that happened only in your experiment because you first deployed the master?

No it means that in master the md5_sha256 migration needs to come after the other, since it uses timestamp names to schedule the order of migrations, but due to the older migration still not being released it needs to be renamed.

@taylorsilva

Copy link
Copy Markdown
Member

What Kalin said! There will be no issue for users, this was only an issue present on master and doesn't affect any released version of Concourse.

@ragaskar

Copy link
Copy Markdown

👋

Hi folks -- not following all of this, but I see that in this thread there was possibly some concern that these changes could cause builds to be incorrectly re-run, I thought I'd add some anecdotal data:

we just upgraded to 8.0.0 and it looks like we had re-runs for jobs that triggered off of the gcs-resource. That is, it looks like after our deployment we had two jobs get triggered by inputs that we had already processed. I'm not really up-to-speed on how version-ing etc works with resources so my statement might appear nonsensical, apologies.

I see two jobs where this has happened (both related to gcs-resource). Those two jobs do not have a "version" (maybe?? I'm not sure if the "version" returned as part of the resource in is the same thing as the concourse version for the resource) because we don't set a regex for them -- they just have a "generation". Curiously previous builds never show this resource appearing as "changed" -- even when the generation ticks up.

There are another few jobs that use the gcs-resource that didn't re-trigger and they did have a regex set and thus had a version value. If this is the same version as a concourse version it sounds like that explains our problem ...

After reading more of the gcs-resource README I think the "why didn't it change previously" makes more sense to me:

"Objects will be found via the pattern configured by regexp or versioned_file. The versions will be used to order them (using semver). Each object's filename is the resulting version."

The filename would never have changed in this case. Doesn't necessarily explain why it triggered now, but maybe that comes down to the hash approach changing? I dunno. It's not that big of a deal for us, but maybe I'll come back if we see future triggering fail for some reason.

No request for action, just noting this in case someone else shows up having observed similar behavior looking for anecdotes.

@taylorsilva

Copy link
Copy Markdown
Member

We did find issues related to jobs re-running or not running at all with versions they previously ran with. Thanks for trying to explain your situation. It sounds like there may have been a bug of some kind but there's not enough info for me to speculate. As you said, you don't fully get how the resource versioning stuff works, so maybe things are behaving as expected?

@ragaskar
If you want to share the job history of the version that triggered the re-run, that would be help. This page specifically when you click on a resource in a pipeline:
image

And highlight the jobs that got re-run. Then on the build logs for that job, if you could show the get steps, like this:
image

If the get step has the text highlighted yellow, that means it was the cause of the trigger. I'm curious if that's the case for your gcs resource's version.

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

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Upgrading after switching md5 to sha256 creates duplicate versions

5 participants