Repository navigation
RHINENG-33319: hash package strings with SHA-512 - #2401
MichaelMraka wants to merge 2 commits into
Conversation
Reviewer's GuideSchema and migrationsAdd an idempotent SQL backfill that creates SHA-512 string IDs, updates package references, and removes the old SHA-256 IDs.
ImplementationSwitch package summary and description hashing to SHA-512, and run SQL jobs with the admin database connection needed for the backfill.
ConfigurationRemove the hard-coded sync-role database user so the SQL job can use the configured admin credentials.
DocumentationUpdate the SQL-job documentation to describe its admin database role.
TestsTest SHA-512 hashing and nil or empty input handling, and verify SQL jobs connect as the admin role.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2401 +/- ##
==========================================
+ Coverage 66.83% 66.96% +0.13%
==========================================
Files 157 157
Lines 9021 9022 +1
==========================================
+ Hits 6029 6042 +13
+ Misses 2990 2978 -12
Partials 2 2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tasks/sql_job/sql/002_update_strings_sha512.sql" line_range="15" />
<code_context>
+-- WHERE octet_length(description_hash) = 32
+-- OR octet_length(summary_hash) = 32;
+
+CREATE INDEX IF NOT EXISTS package_description_hash_idx ON package (description_hash);
+CREATE INDEX IF NOT EXISTS package_summary_hash_idx ON package (summary_hash);
+
</code_context>
<issue_to_address>
**Backfill stops at index creation**
When the SQL job runs as `vmaas_sync`, `vmaas_sync` is not the owner of `package`, so PostgreSQL rejects the `CREATE INDEX` statements and rolls back the transaction before the backfill runs.
Run the index creation as the owner of `package`.
Also at `tasks/sql_job/sql/002_update_strings_sha512.sql:16-17`, `tasks/sql_job/sql/002_update_strings_sha512.sql:38-40`.
</issue_to_address>
### Comment 2
<location path="tasks/sql_job/sql/002_update_strings_sha512.sql" line_range="31" />
<code_context>
+ON CONFLICT (id) DO NOTHING;
+
+UPDATE package p
+SET description_hash = sha512(convert_to(s.value, 'UTF8'))
+WHERE octet_length(description_hash) = 32;
+
</code_context>
<issue_to_address>
**SHA-512 backfill rolls back**
When execution reaches either package `UPDATE`, both `UPDATE` statements reference `s.value` without declaring `s` in a `FROM` clause, so PostgreSQL rejects them and the SQL job rolls back, leaving the package hashes unchanged.
Add `strings s` to each `UPDATE` statement’s `FROM` clause.
Also at `tasks/sql_job/sql/002_update_strings_sha512.sql:34-36`.
</issue_to_address>
### Comment 3
<location path="tasks/sql_job/sql/002_update_strings_sha512.sql" line_range="38-39" />
<code_context>
+SET summary_hash = sha512(convert_to(s.value, 'UTF8'))
+WHERE octet_length(summary_hash) = 32;
+
+DELETE FROM strings
+WHERE octet_length(id) = 32;
+
+DROP INDEX IF EXISTS package_description_hash_idx;
</code_context>
<issue_to_address>
**Package evaluation fails after migration**
When an evaluator retains a pre-migration cache and lazy-saves a missing EVRA for a known package after the migration deletes the 32-byte string IDs, `getMissingPackage` reuses the cached hashes, so inserting the package violates the foreign key to `strings` and evaluation fails.
Keep the old string IDs available until evaluators no longer reuse hashes from pre-migration caches.
</issue_to_address>
### Comment 4
<location path="tasks/sql_job/sql/002_update_strings_sha512.sql" line_range="16-17" />
<code_context>
+-- OR octet_length(summary_hash) = 32;
+
+CREATE INDEX IF NOT EXISTS package_description_hash_idx ON package (description_hash);
+CREATE INDEX IF NOT EXISTS package_summary_hash_idx ON package (summary_hash);
+
+INSERT INTO strings (id, value)
+SELECT sha512(convert_to(s.value, 'UTF8')), s.value
</code_context>
<issue_to_address>
**Package writes stall during backfill**
When the backfill runs while package writers are active, the non-concurrent index builds take locks on `package` that conflict with writes, and the SQL job holds them until its transaction commits. Package writers therefore wait or fail for the duration of the backfill.
Avoid holding ordinary index-build locks across the backfill, for example by using a migration approach that builds indexes concurrently outside this transaction or by removing the temporary indexes.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 4 findings to address first, and the migration deletes every 32-byte strings row, but copies only rows referenced by package records; any unreferenced string values are lost. Reverting the code or rerunning the migration would not restore those deleted values.
Blocking findings: tasks/sql_job/sql/002_update_strings_sha512.sql:15, tasks/sql_job/sql/002_update_strings_sha512.sql:31, tasks/sql_job/sql/002_update_strings_sha512.sql:39, tasks/sql_job/sql/002_update_strings_sha512.sql:17
New summary and description ids are SHA-512 so later backfill can replace the SHA-256 values in strings.id. Existing rows are left unchanged.
The vmaas_sync role cannot rewrite strings.id and the package foreign keys. Connect with the Clowder admin role instead.
New summary and description ids are SHA-512 so later backfill can replace the SHA-256 values in strings.id. Existing rows are left unchanged.
Secure Coding Practices Checklist GitHub Link
Secure Coding Checklist
Summary by Sourcery
Migrate package string hashing to SHA-512 and provide an administrator-run backfill for existing package references.
New Features:
Enhancements:
Deployment:
Documentation:
Tests: