sec(ci): verify golang-migrate tarball sha256 before install#537
sec(ci): verify golang-migrate tarball sha256 before install#537cristim wants to merge 1 commit into
Conversation
Replace the unverified `curl | tar` pipe with a two-step download + sha256 verification before extraction. The official sha256sum.txt published with the v4.17.0 release is used as the source of truth. `set -euo pipefail` ensures the step aborts immediately if the checksum check fails. Closes #434
📝 WalkthroughWalkthroughThe workflow file Changesgolang-migrate Download Security Hardening
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
.github/workflows/database-migration.yml (1)
147-157: ⚖️ Poor tradeoffConsider extracting the golang-migrate installation into a composite action or using
go installfor better maintainability.The installation logic is duplicated identically across all three cloud provider jobs (AWS, GCP, Azure). While the current approach significantly improves security, the duplication creates a maintenance burden—any version bump or checksum update must be applied in three places.
Two alternatives to consider:
Extract to a composite action: Create
.github/actions/install-golang-migrate/action.ymlthat accepts version and SHA256 as inputs, reducing duplication and centralizing the installation logic.Use
go install(preferred): As suggested in issue#434, install via a pinned Go module eliminates tarball/checksum management entirely:- name: Install golang-migrate run: | go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@v4.17.0This leverages Go's module checksums (go.sum) for integrity verification and is already used elsewhere in your CI.
Also applies to: 226-236, 295-305
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.github/workflows/database-migration.yml around lines 147 - 157, The golang-migrate install block (env MIGRATE_VERSION / MIGRATE_SHA256 and the run: curl|sha256sum|tar|sudo install sequence) is duplicated across provider jobs; replace it by either (A) extracting that logic into a composite action (e.g., .github/actions/install-golang-migrate/action.yml) that accepts MIGRATE_VERSION and MIGRATE_SHA256 inputs and performs the curl/verify/install steps, then call that action from each job; or (B, preferred) remove the tarball steps and replace the run block with a go install invocation that pins the module (e.g., go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@${MIGRATE_VERSION}) so CI relies on Go module checksums instead of manual tarball download; update the three occurrences (the run blocks referenced) accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In @.github/workflows/database-migration.yml:
- Around line 147-157: The golang-migrate install block (env MIGRATE_VERSION /
MIGRATE_SHA256 and the run: curl|sha256sum|tar|sudo install sequence) is
duplicated across provider jobs; replace it by either (A) extracting that logic
into a composite action (e.g.,
.github/actions/install-golang-migrate/action.yml) that accepts MIGRATE_VERSION
and MIGRATE_SHA256 inputs and performs the curl/verify/install steps, then call
that action from each job; or (B, preferred) remove the tarball steps and
replace the run block with a go install invocation that pins the module (e.g.,
go install -tags 'postgres'
github.com/golang-migrate/migrate/v4/cmd/migrate@${MIGRATE_VERSION}) so CI
relies on Go module checksums instead of manual tarball download; update the
three occurrences (the run blocks referenced) accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3e514ebd-e240-411f-9558-8512c96a3c66
📒 Files selected for processing (1)
.github/workflows/database-migration.yml
Summary
curl -L ... | tar xvzpipe in all threeInstall golang-migratesteps (AWS, GCP, Azure jobs) with a two-step download + sha256 checksum verification before extraction.26c53c9...) is sourced from the officialsha256sum.txtpublished alongside the golang-migrate v4.17.0 GitHub Release.set -euo pipefail+sha256sum --check --strictensures the step aborts immediately on a mismatch; a tampered tarball cannot silently execute.Closes #434
Test plan
sha256sum --check --strictworks on ubuntu-latest (it ships with coreutils)migrate.linux-amd64.tar.gzfrom the v4.17.0 release:curl -fsSL https://github.com/golang-migrate/migrate/releases/download/v4.17.0/sha256sum.txt | grep linux-amd64.tar.gzmigrateto/usr/local/binand it is executableSummary by CodeRabbit