Skip to content
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

For actions that are pinned-by-hash, bump the human readable version number in the code comment #4691

Closed
ChrisCarini opened this issue Feb 1, 2022 · 5 comments · Fixed by #5951
Labels
L: github:actions GitHub Actions T: feature-request Requests for new features

Comments

@ChrisCarini
Copy link

Hello!

As good security practice and guided by the code scanning alert for 'Pinned-Dependencies' from the ossf/scorecard project, users are encouraged to pin GitHub workflow actions by hash. The example provided by the scorecard repoincludes a comment following the action+pinned-hash, example below:

     - name: Clone the code
       uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4

Subsequent updates by dependabot do not bump the version in the comment, leading to confusion and incorrect information. An example of this can be found here: ChrisCarini/environment-variable-settings-summary-intellij-plugin#36

Below is a before & after example of the above linked PR

Before

Screen Shot 2022-01-31 at 22 53 54

After

Screen Shot 2022-01-31 at 22 52 13

Summary

Dependabot updated ossf/scorecard-action from version v1.0.1 to v1.0.2.

In the "Before", the hash was updated correctly, however the trailing comment with the tag version, was not.

Hash Tag Version
e3e75cf2ffbf9364bbff86cdbdf52b23176fe492 v1.0.1
c8416b0b2bf627c349ca92fc8e3de51a64b005cf v1.0.2

I believe this change would help GitHub workflow owners to have a better security posture w.r.t. using hash-pinned GitHugb action dependencies, while also having improved ergonomics to be able to quickly verify they are on the correct version.

This idea shares similar sentiment of #3699

(I would consider trying to make a code change for this, however I lack expertise in Ruby and have thus far struggled to get the project opened for development.)

@jeffwidman
Copy link
Member

jeffwidman commented Sep 17, 2022

I think this is a great idea and we'd happily merge a PR if anyone wants to take a crack at it. Looking at the relevant code, I don't think it'd be that hard to implement.

A few design notes:

  1. Another comment format we should support (from Update version comment when hashes are updated in pull requests #5314) is # pin @v2.4.0. Other variations are probably # @v2.4.0 etc. Or we could simply pick one and go with it... I doubt most users would complain after the initial migration.
  2. Probably we should only bump this pin if it's present... although a part of me wonders if always appending it to SHAs might be both more useful and easier to implement/maintain??
  3. It should only be modified if the actual version is a SHA... that avoids accidentally bumping random other comments if the actual version is already human readable.

@jeffwidman jeffwidman changed the title [GitHub Actions] Comment with version after updating pin-by-hash action workflow dependencies For actions that are pinned-by-hash, bump the human readable version number in the code comment Sep 17, 2022
@lucacome
Copy link

lucacome commented Oct 7, 2022

I want to pin the dependencies in our repos, but I'm kinda waiting for this feature to be implemented. It will make it much easier to maintain.

I was looking into StepSecurity to do the first pass in all the workflows and found step-security/secure-repo#1087. They removed the tag comment because dependabot doesn't support updating it.

I also wanted to point out that the OpenSSF action uses yet another format for the comment when you create their workflow

  - name: "Checkout code"
    uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # tag=v3.0.0

not sure how popular this is...I think # v3.0.0 is more than enough and I'd be okay with dependabot overwriting the comment when updating the dependency.

marcwrobel added a commit to marcwrobel/jbanking that referenced this issue Oct 19, 2022
Until dependabot/dependabot-core#4691 is fixed this is too much work to maintain those comments. Note that git history can be used to know the version.
@jeffwidman
Copy link
Member

I just deployed this feature, many thanks to @jproberts for contributing the PR.

Many variations of version tags are supported, for examples see the unit tests:

- uses: actions/checkout@01aecccf739ca6ff86c0539fbc67a7a5007bbc81 # v2.1.0
- uses: actions/checkout@01aecccf739ca6ff86c0539fbc67a7a5007bbc81 # 2.1.0
- uses: actions/checkout@01aecccf739ca6ff86c0539fbc67a7a5007bbc81 # @v2.1.0
- uses: actions/checkout@01aecccf739ca6ff86c0539fbc67a7a5007bbc81 # pin @v2.1.0
- uses: actions/checkout@01aecccf739ca6ff86c0539fbc67a7a5007bbc81 # tag=v2.1.0
- uses: actions/checkout@01aecccf739ca6ff86c0539fbc67a7a5007bbc81 # v2.1.0
- uses: actions/checkout@01aecccf739ca6ff86c0539fbc67a7a5007bbc81 #v2.1.0
# The comment on the next line has a trailing tab. The version should still be updated.
- uses: actions/checkout@01aecccf739ca6ff86c0539fbc67a7a5007bbc81 #v2.1.0
- uses: actions/checkout@01aecc # v2.1.0
integration:
- uses: actions/checkout@v2.1.0 # comments that include the version (v2.1.0) shouldn't be updated for non-SHA refs
- uses: actions/checkout@01aecc#v2.1.0 # this shouldn't be updated, because the version is part of the ref, not a comment.
# The version in the comment for the next action shouldn't be updated
# because it refers to past behavior.
- uses: actions/checkout@01aecccf739ca6ff86c0539fbc67a7a5007bbc81 # Versions older than v2.1.0 have a security vulnerability
# The versions in the comment for the next action won't be updated.
# The first version could be updated, but it's difficult to create
# a heuristic that recognizes the first version as a version alias
# for the SHA commit, and the second version as a concrete version
# that shouldn't change. For simplicity, we don't update either.
- uses: actions/checkout@01aecccf739ca6ff86c0539fbc67a7a5007bbc81 # v2.1.0 - Versions older than v2.1.0 have a security vulnerability

If you hit bugs please let us know.

airtower-luna added a commit to airtower-luna/hello-github-actions that referenced this issue Nov 2, 2022
I'm intentionally pinning a slightly older version of actions/checkout
to see if the update works like it should.

See: dependabot/dependabot-core#4691
marcofranssen added a commit to philips-labs/slsa-provenance-action that referenced this issue Jan 2, 2023
Dependabot is also capable of pinning to future tag releases
and will maintain the comment that descibes the shasum.

dependabot/dependabot-core#4691
Signed-off-by: Marco Franssen <marco.franssen@philips.com>
marcofranssen added a commit to marcofranssen/spire that referenced this issue Jan 2, 2023
Dependabot is also capable of pinning to future tag releases
and will maintain the comment that descibes the shasum.

dependabot/dependabot-core#4691
Signed-off-by: Marco Franssen <marco.franssen@gmail.com>
marcofranssen added a commit to philips-labs/slsa-provenance-action that referenced this issue Jan 3, 2023
Dependabot is also capable of pinning to future tag releases
and will maintain the comment that descibes the shasum.

dependabot/dependabot-core#4691
Signed-off-by: Marco Franssen <marco.franssen@philips.com>
marcofranssen added a commit to marcofranssen/spire that referenced this issue Jan 3, 2023
Dependabot is also capable of pinning to future tag releases
and will maintain the comment that descibes the shasum.

dependabot/dependabot-core#4691
Signed-off-by: Marco Franssen <marco.franssen@gmail.com>
marcofranssen added a commit to marcofranssen/spire that referenced this issue Jan 3, 2023
Dependabot is also capable of pinning to future tag releases
and will maintain the comment that descibes the shasum.

dependabot/dependabot-core#4691
Signed-off-by: Marco Franssen <marco.franssen@gmail.com>
marcofranssen added a commit to philips-labs/slsa-provenance-action that referenced this issue Jan 3, 2023
Dependabot is also capable of pinning to future tag releases
and will maintain the comment that descibes the shasum.

dependabot/dependabot-core#4691
Signed-off-by: Marco Franssen <marco.franssen@philips.com>
JeroenKnoops added a commit to philips-software/sbom-tool-installer-action that referenced this issue Jan 7, 2023
Dependabot is also capable of pinning to future tag releases
and will maintain the comment that descibes the shasum.

dependabot/dependabot-core#4691
edwarddavidbaker added a commit to edwarddavidbaker/perfmon that referenced this issue Jan 24, 2024
Instead of referencing versions, the guidance is to pin actions to a
full length SHA corresponding to the release tag [1] [2]. Dependabot
will continue to automatically monitor and open PRs for versions [3].

| Action                            | Old | New                    |
| checkout                          | v4  | v4.1.1 release commit  |
| github-action-markdown-link-check | v1  | v1.0.15 release commit |
| setup-python                      | v5  | v5.0.0 release commit  |
| upload-artifact                   | v4  | v4.3.0 release commit  |

[1] https://securityscorecards.dev/viewer/?uri=github.com/intel/perfmon
[2] https://github.com/ossf/scorecard/blob/497b851040f18b6cacfbc67500b6fad98ac5e367/docs/checks.md#pinned-dependencies
[3] dependabot/dependabot-core#4691
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L: github:actions GitHub Actions T: feature-request Requests for new features
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants