From a38aa1d80a0ab5cc8af03a3c7046e34086427b8c Mon Sep 17 00:00:00 2001 From: Eric Proulx Date: Sat, 21 Nov 2026 00:10:11 +0100 Subject: [PATCH] Pin workflow actions to commits and grant their tokens only what they need Every action and reusable workflow was referenced by a tag or a branch its owner can move, and every job ran with the repository's default read/write token. Both Danger callers also passed `secrets: inherit`, handing every repository secret to another repository's workflow, though Danger uses only the token. Each reference now names the commit its tag or branch points to today, with the version as a comment, so what runs is unchanged. test and edge read only. The Danger callers grant what the called workflows ask for, and no secrets. Dependabot keeps the pins current, proposing a release once it is a week old. Co-Authored-By: Claude Opus 5.5 --- .github/dependabot.yml | 14 ++++++++++++++ .github/workflows/danger-comment.yml | 9 +++++++-- .github/workflows/danger.yml | 6 ++++-- .github/workflows/edge.yml | 10 ++++++---- .github/workflows/test.yml | 15 +++++++++------ CHANGELOG.md | 1 + 6 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..4c39c94b9 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,14 @@ +# Keeps the actions and reusable workflows that .github/workflows pins to +# commits up to date, with their version comments. A release is proposed once +# it is a week old, so that a compromised one has time to be caught and pulled. +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly + cooldown: + default-days: 7 + groups: + github-actions: + patterns: ['*'] diff --git a/.github/workflows/danger-comment.yml b/.github/workflows/danger-comment.yml index 8e15cb6c1..69d984b7e 100644 --- a/.github/workflows/danger-comment.yml +++ b/.github/workflows/danger-comment.yml @@ -7,5 +7,10 @@ on: jobs: comment: - uses: numbata/danger-pr-comment/.github/workflows/danger-comment.yml@v0.1.0 - secrets: inherit + uses: numbata/danger-pr-comment/.github/workflows/danger-comment.yml@34fd37617a87c09a408c39646d871cd3b6135eb9 # v0.1.0 + # What the called workflow asks for. It needs no secret but the token. + permissions: + contents: read + actions: read + issues: write + pull-requests: write diff --git a/.github/workflows/danger.yml b/.github/workflows/danger.yml index 7fb36395a..57ede094b 100644 --- a/.github/workflows/danger.yml +++ b/.github/workflows/danger.yml @@ -6,8 +6,10 @@ on: jobs: danger: - uses: numbata/danger-pr-comment/.github/workflows/danger-run.yml@v0.2.0 - secrets: inherit + uses: numbata/danger-pr-comment/.github/workflows/danger-run.yml@6152b4436901a31e3ebbf09152ae182282487a75 # v0.2.0 + # What the called workflow asks for. It needs no secret but the token. + permissions: + contents: read with: ruby-version: '3.4' gemfile: gemfiles/danger.gemfile diff --git a/.github/workflows/edge.yml b/.github/workflows/edge.yml index 305e6e914..067d0c877 100644 --- a/.github/workflows/edge.yml +++ b/.github/workflows/edge.yml @@ -1,6 +1,8 @@ --- name: edge on: workflow_dispatch +permissions: + contents: read jobs: test: strategy: @@ -13,10 +15,10 @@ jobs: env: BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 - name: Set up Ruby - uses: ruby/setup-ruby@v1 + uses: ruby/setup-ruby@be3c7df29b3349ec6bcfc6b4792f1cf9f5237d18 # v1.343.0 with: ruby-version: ${{ matrix.ruby }} bundler-cache: true @@ -25,7 +27,7 @@ jobs: run: "RUBYOPT='--enable=frozen-string-literal' bundle exec rspec" - name: Coveralls - uses: coverallsapp/github-action@v2 + uses: coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2.3.8 with: github-token: ${{ secrets.GITHUB_TOKEN }} flag-name: run-${{ matrix.ruby }}-${{ matrix.gemfile }} @@ -36,7 +38,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Coveralls Finished - uses: coverallsapp/github-action@v2 + uses: coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2.3.8 with: github-token: ${{ secrets.github_token }} parallel-finished: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0f7b3ef6a..033eea9e2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,15 +2,18 @@ name: test on: [push, pull_request] +permissions: + contents: read + jobs: lint: name: RuboCop runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 - name: Set up Ruby - uses: ruby/setup-ruby@v1 + uses: ruby/setup-ruby@be3c7df29b3349ec6bcfc6b4792f1cf9f5237d18 # v1.343.0 with: ruby-version: 3.4 bundler-cache: true @@ -60,10 +63,10 @@ jobs: env: BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }} steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 - name: Set up Ruby - uses: ruby/setup-ruby@v1 + uses: ruby/setup-ruby@be3c7df29b3349ec6bcfc6b4792f1cf9f5237d18 # v1.343.0 with: ruby-version: ${{ matrix.ruby }} bundler-cache: true @@ -72,7 +75,7 @@ jobs: run: "RUBYOPT='--enable=frozen-string-literal' bundle exec rspec ${{ matrix.specs }}" - name: Coveralls - uses: coverallsapp/github-action@v2 + uses: coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2.3.8 with: github-token: ${{ secrets.GITHUB_TOKEN }} flag-name: run-${{ matrix.ruby }}-${{ matrix.gemfile }} @@ -83,7 +86,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Coveralls Finished - uses: coverallsapp/github-action@v2 + uses: coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2.3.8 with: github-token: ${{ secrets.github_token }} parallel-finished: true diff --git a/CHANGELOG.md b/CHANGELOG.md index 17ac4bbe1..715971949 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * [#3056](https://github.com/ruby-grape/grape/pull/3056): Drop support for Rails 7.2 and require ActiveSupport 8.0 - [@ericproulx](https://github.com/ericproulx). * [#3062](https://github.com/ruby-grape/grape/pull/3062): Use the reusable Danger workflow with a separate Gemfile - [@dblock](https://github.com/dblock). * [#3063](https://github.com/ruby-grape/grape/pull/3063): Drop support for Rack 2.2 and 3.0 and require Rack 3.1 - [@ericproulx](https://github.com/ericproulx). +* [#3088](https://github.com/ruby-grape/grape/pull/3088): Pin workflow actions to commits and grant their tokens only what they need - [@ericproulx](https://github.com/ericproulx). * Your contribution here. #### Fixes