Skip to content

Commit 5d699ee

Browse files
committed
SECURITY FIX: Prevent PRs from pushing to container registry
Critical security vulnerability fixed in dev container prebuild workflow. **Vulnerability:** - Workflow was set to `push: always` for ALL events including PRs - Any pull request (including from FORKS) could push to ghcr.io - Malicious contributors could push compromised dev container images - Could overwrite legitimate `latest` tag with malicious image **Fix:** - Changed push condition to: `github.event_name != 'pull_request'` - PRs now build/test ONLY (push: never) - Only these events can push: - Push to master branch - Manual workflow_dispatch - Scheduled weekly rebuilds - All require write access to repository **Behavior Now:** - ✅ PRs: Build and test image (validates Dockerfile changes) - ✅ Master: Build, test, and push to registry - ✅ Schedule: Build, test, and push to registry - ✅ Manual: Build, test, and push to registry **Additional Improvements:** - Updated summary output to clearly indicate push status - Added security warning for PR builds - Makes it obvious when image was/wasn't pushed This ensures only trusted maintainers with repository write access can publish dev container images to the registry. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 90e83d6 commit 5d699ee

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

.github/workflows/devcontainer-prebuild.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
with:
4747
imageName: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
4848
cacheFrom: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
49-
push: always
49+
push: ${{ github.event_name != 'pull_request' && 'always' || 'never' }}
5050
imageTag: latest
5151

5252
- name: Summary
@@ -58,7 +58,15 @@ jobs:
5858
echo "" >> $GITHUB_STEP_SUMMARY
5959
echo "**Trigger:** ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
6060
echo "" >> $GITHUB_STEP_SUMMARY
61-
echo "**Benefits:**" >> $GITHUB_STEP_SUMMARY
62-
echo "- 🚀 Faster dev container startup (cached layers)" >> $GITHUB_STEP_SUMMARY
63-
echo "- 📦 Consistent environment across all developers" >> $GITHUB_STEP_SUMMARY
64-
echo "- ⚡ Weekly rebuilds keep dependencies fresh" >> $GITHUB_STEP_SUMMARY
61+
if [ "${{ github.event_name }}" = "pull_request" ]; then
62+
echo "**Status:** ✅ Build tested successfully (not pushed to registry)" >> $GITHUB_STEP_SUMMARY
63+
echo "" >> $GITHUB_STEP_SUMMARY
64+
echo "⚠️ **Security Note:** PRs only build/test the image. Push to master to publish." >> $GITHUB_STEP_SUMMARY
65+
else
66+
echo "**Status:** ✅ Built and pushed to registry" >> $GITHUB_STEP_SUMMARY
67+
echo "" >> $GITHUB_STEP_SUMMARY
68+
echo "**Benefits:**" >> $GITHUB_STEP_SUMMARY
69+
echo "- 🚀 Faster dev container startup (cached layers)" >> $GITHUB_STEP_SUMMARY
70+
echo "- 📦 Consistent environment across all developers" >> $GITHUB_STEP_SUMMARY
71+
echo "- ⚡ Weekly rebuilds keep dependencies fresh" >> $GITHUB_STEP_SUMMARY
72+
fi

0 commit comments

Comments
 (0)