Skip to content

[CI]: Harden GitHub Actions #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 16, 2024
Merged

Conversation

reactive-firewall
Copy link
Collaborator

@reactive-firewall reactive-firewall commented Dec 16, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced error reporting and control flow in the Makefile linting workflow.
    • Improved security through explicit permissions in the markdown linting workflow.
  • Updates

    • Updated action versions across multiple workflows for better stability and control.
    • Specified commit hashes for actions to ensure reproducibility.
  • Bug Fixes

    • Corrected a typographical error in the MATS workflow step name.

Co-authored-by: reactive-firewall <[email protected]>
Signed-off-by: StepSecurity Bot <[email protected]>
Copy link
Contributor

coderabbitai bot commented Dec 16, 2024

Walkthrough

This pull request focuses on updating GitHub Actions workflow files across the repository. The primary changes involve pinning specific commit hashes for various GitHub Actions instead of using version tags. These updates span multiple workflow files including CI-BUILD, CI-DOCS, CI-MATs, Labeler, Tests, Bandit, CodeQL Analysis, Markdown Lint, and YAML Lint workflows. The modifications ensure consistent and precise action versions, potentially improving workflow stability and reproducibility.

Changes

File Changes
.github/workflows/CI-BUILD.yml Updated actions/checkout and actions/setup-python to specific commit hashes
.github/workflows/CI-DOCS.yml Updated actions/checkout, actions/setup-python, and actions/upload-artifact to specific commit hashes
.github/workflows/CI-MATs.yml Updated action versions and corrected a typo in step name from "Summerize" to "Summarize"
.github/workflows/Labeler.yml Updated actions/labeler to a specific commit hash
.github/workflows/Tests.yml Updated multiple actions including actions/checkout, actions/setup-python, codecov/codecov-action, actions/upload-artifact, and codecov/test-results-action
.github/workflows/bandit.yml Updated actions/checkout and reactive-firewall/python-bandit-scan to specific commit hashes
.github/workflows/codeql-analysis.yml Updated actions/checkout and GitHub CodeQL actions to specific commit hashes
.github/workflows/yaml-lint.yml Updated actions/checkout and ibiqlik/action-yamllint to specific commit hashes

Possibly related PRs

Poem

🐰 Workflows dance with precision's might,
Commit hashes locked in, shining bright
Actions updated, version by version
Our CI pipeline, a rabbit's conversion
Stability reigns, errors take flight! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

deepsource-io bot commented Dec 16, 2024

Here's the code health analysis summary for commits 8041341..46cbfa8. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource Python LogoPython✅ SuccessView Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

@github-actions github-actions bot added Testing Something can be verified CI Continuous Integration Tooling GitHub Anything Meta labels Dec 16, 2024
@reactive-firewall reactive-firewall self-assigned this Dec 16, 2024
@reactive-firewall reactive-firewall marked this pull request as ready for review December 16, 2024 01:41
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
.github/workflows/makefile-lint.yml (1)

Security concern: Commit hash does not match any tagged release

The commit hash bd26d7905e47713ff0bf3b0e5e7b9c55f0d24e53 is currently the HEAD of the main branch but does not correspond to any tagged release. The latest release is v0.2.2 (commit: 48ab7819837d1bdfcbac58e301478a06efebf4a8), and there's no evidence of a v0.2.2+8 version. Using an untagged commit from the main branch could introduce unexpected changes or security risks.

  • Consider pinning to the latest stable release v0.2.2 using commit hash 48ab7819837d1bdfcbac58e301478a06efebf4a8
  • If specific features from main branch are needed, document the reason for using this specific commit
🔗 Analysis chain

Line range hint 75-83: Verify the checkmake repository hash.

The SHA verification is a good security practice, but let's verify the hash corresponds to the claimed version.


Let me verify if this commit hash corresponds to the claimed version v0.2.2+8.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the checkmake repository hash matches v0.2.2+8

# Fetch the repository and verify the commit
git ls-remote https://github.com/mrtazz/checkmake.git | grep "bd26d7905e47713ff0bf3b0e5e7b9c55f0d24e53"

Length of output: 206


Script:

#!/bin/bash
# Check git tags and releases to verify version
git ls-remote --tags https://github.com/mrtazz/checkmake.git

# Also check the latest release information
gh api repos/mrtazz/checkmake/releases/latest

Length of output: 10324

🧹 Nitpick comments (2)
.github/workflows/markdown-lint.yml (1)

Line range hint 26-39: Excellent error handling improvements

The enhanced error handling with detailed messages and proper exit codes improves debugging and maintainability.

Consider using POSIX built-ins as per your preferences:

-          printf "::error file=%s,line=%s,endLine=%s,title=VALIDATION_ERROR::ERROR %s\n" \
+          /usr/bin/printf "::error file=%s,line=%s,endLine=%s,title=VALIDATION_ERROR::ERROR %s\n" \
.github/workflows/CI-DOCS.yml (1)

Line range hint 57-58: Consider pinning pip package versions

While you're hardening the CI process, consider pinning the versions of pip packages in requirements.txt files for complete reproducibility.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8041341 and 46cbfa8.

📒 Files selected for processing (10)
  • .github/workflows/CI-BUILD.yml (2 hunks)
  • .github/workflows/CI-DOCS.yml (2 hunks)
  • .github/workflows/CI-MATs.yml (1 hunks)
  • .github/workflows/Labeler.yml (1 hunks)
  • .github/workflows/Tests.yml (13 hunks)
  • .github/workflows/bandit.yml (1 hunks)
  • .github/workflows/codeql-analysis.yml (3 hunks)
  • .github/workflows/makefile-lint.yml (1 hunks)
  • .github/workflows/markdown-lint.yml (1 hunks)
  • .github/workflows/yaml-lint.yml (2 hunks)
✅ Files skipped from review due to trivial changes (5)
  • .github/workflows/Labeler.yml
  • .github/workflows/bandit.yml
  • .github/workflows/CI-BUILD.yml
  • .github/workflows/CI-MATs.yml
  • .github/workflows/codeql-analysis.yml
🧰 Additional context used
📓 Path-based instructions (5)
.github/workflows/markdown-lint.yml (1)

Pattern .github/**: * When the project is hosted on GitHub: All GitHub-specific configurations, templates, and tools should be found in the '.github' directory tree.

  • 'actionlint' erroneously generates false positives when dealing with GitHub's ${{ ... }} syntax in conditionals.
  • 'actionlint' erroneously generates incorrect solutions when suggesting the removal of valid ${{ ... }} syntax.
.github/workflows/makefile-lint.yml (1)

Pattern .github/**: * When the project is hosted on GitHub: All GitHub-specific configurations, templates, and tools should be found in the '.github' directory tree.

  • 'actionlint' erroneously generates false positives when dealing with GitHub's ${{ ... }} syntax in conditionals.
  • 'actionlint' erroneously generates incorrect solutions when suggesting the removal of valid ${{ ... }} syntax.
.github/workflows/CI-DOCS.yml (1)

Pattern .github/**: * When the project is hosted on GitHub: All GitHub-specific configurations, templates, and tools should be found in the '.github' directory tree.

  • 'actionlint' erroneously generates false positives when dealing with GitHub's ${{ ... }} syntax in conditionals.
  • 'actionlint' erroneously generates incorrect solutions when suggesting the removal of valid ${{ ... }} syntax.
.github/workflows/yaml-lint.yml (1)

Pattern .github/**: * When the project is hosted on GitHub: All GitHub-specific configurations, templates, and tools should be found in the '.github' directory tree.

  • 'actionlint' erroneously generates false positives when dealing with GitHub's ${{ ... }} syntax in conditionals.
  • 'actionlint' erroneously generates incorrect solutions when suggesting the removal of valid ${{ ... }} syntax.
.github/workflows/Tests.yml (1)

Pattern .github/**: * When the project is hosted on GitHub: All GitHub-specific configurations, templates, and tools should be found in the '.github' directory tree.

  • 'actionlint' erroneously generates false positives when dealing with GitHub's ${{ ... }} syntax in conditionals.
  • 'actionlint' erroneously generates incorrect solutions when suggesting the removal of valid ${{ ... }} syntax.
📓 Learnings (1)
📓 Common learnings
Learnt from: reactive-firewall
PR: reactive-firewall/multicast#0
File: :0-0
Timestamp: 2024-11-21T02:05:08.096Z
Learning: Reactive-firewall prefers scripts to include explicit data processing steps that produce the expected output, ensuring accurate and useful results.
Learnt from: reactive-firewall
PR: reactive-firewall/multicast#0
File: :0-0
Timestamp: 2024-12-12T20:51:15.319Z
Learning: In the multicast project, when refactoring shell scripts, prefer improving organization within a single file over splitting into multiple files, unless the benefits of modularity clearly outweigh the added complexity in security, permissions, and debugging.
Learnt from: reactive-firewall
PR: reactive-firewall/multicast#0
File: :0-0
Timestamp: 2024-11-12T10:29:50.461Z
Learning: For future scripts, reactive-firewall prefers to use only POSIX built-ins (like `printf` instead of `echo`) to align with CEP-8 conventions.
Learnt from: reactive-firewall
PR: reactive-firewall/multicast#0
File: :0-0
Timestamp: 2024-11-21T02:05:08.096Z
Learning: Reactive-firewall prefers to specify the full raw URL when fetching files from gists to ensure correct retrieval of content, particularly when the file is in markdown format.
Learnt from: reactive-firewall
PR: reactive-firewall/multicast#0
File: :0-0
Timestamp: 2024-11-12T10:29:55.563Z
Learning: For future scripts, reactive-firewall prefers to keep the shebang line with an extra space (e.g., `#! /bin/bash`) as per project style.
Learnt from: reactive-firewall
PR: reactive-firewall/multicast#184
File: LICENSE.md:36-43
Timestamp: 2024-11-14T07:03:35.207Z
Learning: Reactive-firewall prefers that I verify URLs before suggesting changes, and avoid raising hypothetical issues without verification.
Learnt from: reactive-firewall
PR: reactive-firewall/multicast#235
File: .github/workflows/makefile-lint.yml:41-52
Timestamp: 2024-12-06T08:21:21.876Z
Learning: Reactive-firewall prefers to suppress errors in `apt-get install` commands when individual checks of the installed packages are performed afterwards, to allow for more granular error handling.
Learnt from: reactive-firewall
PR: reactive-firewall/multicast#0
File: :0-0
Timestamp: 2024-12-13T01:44:13.412Z
Learning: In the multicast project's shell scripts, prefer organizing code into logical sections with clear comments (e.g., "=== Environment Setup ===") to maintain readability and maintainability while keeping related functions together.
Learnt from: reactive-firewall
PR: reactive-firewall/multicast#184
File: tests/check_pip:259-265
Timestamp: 2024-11-15T19:32:16.878Z
Learning: Reactive-firewall prefers that code changes adhere to SOLID design principles, specifically avoiding unnecessary complexity (AHA principle), maintaining the Single Responsibility Principle, and ensuring complex work is done on separate development branches (Open/Closed Principle).
Learnt from: reactive-firewall
PR: reactive-firewall/multicast#110
File: docs/USAGE.md:66-66
Timestamp: 2024-11-12T10:29:55.563Z
Learning: Reactive-firewall prefers to use "Caveat" as a heading instead of "Caution".
🔇 Additional comments (9)
.github/workflows/yaml-lint.yml (1)

23-23: Excellent security practice: Pinning actions to specific commit hashes

The change from version tags to commit hashes for GitHub Actions is a security best practice that prevents supply chain attacks through action version tampering.

Let's verify these are the latest stable versions:

Also applies to: 27-27, 51-51

✅ Verification successful

Actions are pinned to the latest stable versions

The commit hashes used in the workflow correspond to the latest stable releases:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the pinned versions against latest releases
# Note: Using GitHub CLI to query the latest releases

# Check actions/checkout
echo "Checking actions/checkout latest release..."
gh api repos/actions/checkout/releases/latest --jq '.tag_name'

# Check ibiqlik/action-yamllint
echo "Checking ibiqlik/action-yamllint latest release..."
gh api repos/ibiqlik/action-yamllint/releases/latest --jq '.tag_name'

Length of output: 354

.github/workflows/markdown-lint.yml (1)

21-21: Consistent version pinning across workflows

The checkout action is pinned to the same commit hash as in yaml-lint.yml, maintaining consistency across workflows.

.github/workflows/CI-DOCS.yml (1)

46-46: Comprehensive security hardening with version pinning

All GitHub Actions are properly pinned to specific commit hashes, maintaining security and consistency across the workflow.

Let's verify these are the latest stable versions:

Also applies to: 48-48, 74-74

✅ Verification successful

Let me verify the actions/checkout version as well before making the final determination.


All GitHub Actions are using the latest stable versions

The verification confirms that all pinned versions match their latest stable releases:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the pinned versions against latest releases

# Check actions/setup-python
echo "Checking actions/setup-python latest release..."
gh api repos/actions/setup-python/releases/latest --jq '.tag_name'

# Check actions/upload-artifact
echo "Checking actions/upload-artifact latest release..."
gh api repos/actions/upload-artifact/releases/latest --jq '.tag_name'

Length of output: 366


Script:

#!/bin/bash
# Check actions/checkout latest release
echo "Checking actions/checkout latest release..."
gh api repos/actions/checkout/releases/latest --jq '.tag_name'

Length of output: 166

.github/workflows/makefile-lint.yml (2)

35-35: LGTM! Excellent security practice in pinning the action version.

The change from using a version tag to a specific commit hash improves security by preventing supply chain attacks.


Line range hint 40-50: Well-structured error handling implementation.

The print_error function implementation follows best practices by:

  • Using consistent error formatting
  • Including file location and line numbers
  • Following GitHub Actions' logging commands format
.github/workflows/Tests.yml (4)

88-90: LGTM! Consistent and secure action pinning across all jobs.

All instances of actions/checkout and actions/setup-python are correctly pinned to specific commit hashes, which is a security best practice to prevent supply chain attacks.

Also applies to: 173-175, 226-228, 345-347, 421-423, 474-476


130-130: Verify upload-artifact action version.

Let's verify the upload-artifact action commit hash corresponds to v4.4.3.

Also applies to: 280-280, 380-380

✅ Verification successful

Upload-artifact action version is correctly pinned

The commit hash b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 correctly corresponds to both v4.4.3 and v4 tags in the actions/upload-artifact repository, confirming the version is properly pinned.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the upload-artifact action commit hash

# Fetch the repository and verify the commit
git ls-remote https://github.com/actions/upload-artifact.git | grep "b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882"

Length of output: 222


295-295: Verify test-results action version.

Let's verify the test-results action commit hash corresponds to v1.0.1.

✅ Verification successful

The test-results action commit hash correctly corresponds to v1.0.1

The commit hash 9739113ad922ea0a9abb4b2c0f8bf6a4aa8ef820 is correctly tagged as both v1 and v1.0.1 in the codecov/test-results-action repository, confirming that the version reference is accurate.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the test-results action commit hash

# Fetch the repository and verify the commit
git ls-remote https://github.com/codecov/test-results-action.git | grep "9739113ad922ea0a9abb4b2c0f8bf6a4aa8ef820"

Length of output: 226


120-120: Verify codecov action version.

Let's verify the codecov action commit hash corresponds to v5.1.1.

Also applies to: 270-270, 370-370

✅ Verification successful

Codecov action commit hash correctly corresponds to v5.1.1

The git command confirms that the commit hash 7f8b4b4bde536c465e797be725718b88c5d95e0e is correctly tagged as v5.1.1 in the codecov/codecov-action repository.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the codecov action commit hash

# Fetch the repository and verify the commit
git ls-remote https://github.com/codecov/codecov-action.git | grep "7f8b4b4bde536c465e797be725718b88c5d95e0e"

Length of output: 224

@reactive-firewall reactive-firewall marked this pull request as draft December 16, 2024 01:53
@reactive-firewall reactive-firewall merged commit 9ceacca into master Dec 16, 2024
60 of 78 checks passed
@reactive-firewall reactive-firewall deleted the HOTFIX-203-1-GHA-Pin branch December 20, 2024 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Continuous Integration Tooling GitHub Anything Meta Testing Something can be verified
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants