Skip to content

ci: fix semver-checks master#3028

Merged
apoelstra merged 1 commit intorust-bitcoin:masterfrom
storopoli:ci/fix-semver-checks
Jul 16, 2024
Merged

ci: fix semver-checks master#3028
apoelstra merged 1 commit intorust-bitcoin:masterfrom
storopoli:ci/fix-semver-checks

Conversation

@storopoli
Copy link
Copy Markdown
Contributor

@storopoli storopoli commented Jul 13, 2024

Ok now I think I've nailed this! 🚀
Closes #3018.

Summary

This PR fix the permissions by adding a secondary job, semver-checks-pr-label, that runs only if the semver-checks completes and does not fail, i.e. we have either Semver API breaks.
This is a secure job according to internal discussions and https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run

Implementation notes

We split the semver checks into the actual check and labeling. This is due to the fact that we were having several permission issues and the original implementation was insecure. Also it is currently failing on several PRs.

  1. semver-checks.yml: checks for API semver breaks. Upon finding API semver-checks, it creates a file named semver-break that has the PR number inside. If this file is present we upload an artifact representing that the API semver was broken with the PR number.
  2. semver-checks-pr-label.yml: runs after the semver-checks.yml is completed. It uses actions/github-script (in JavaScript) to list the previous workflow artifacts and, if finds that an API semver break is present, adds a corresponding label and a comment to the PR that is inside the file semver-break. We sanitize the hell out of the thing to be a number only, both in BASH but also in JavaScript.

How I tested this?

  1. I merged this PR to my master branch in my storopoli/rust-bitcoin repo.

  2. I've set the following settings in the repo settings to mimic what we have for rust-bitcoin:

    image

  3. I've made a PR (cherry-picked from Toby) that breaks semver, see https://github.com/storopoli/rust-bitcoin/pull/10. It correctly labelled as API break and added a comment to the PR

image

@github-actions github-actions bot added the ci label Jul 13, 2024
Comment on lines 27 to 35
Copy link
Copy Markdown
Contributor Author

@storopoli storopoli Jul 13, 2024

Choose a reason for hiding this comment

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

@Kixunil I cannot read the PR number in the semver-checks-pr-label.yml from the previous semver-checks-pr.yml workflow.
I've tried a couple of things, most notoriously this:

# in semver-checks-pr-label.yml

    env:
      # hack to get PR number from the workflow_run object
      PR_NUMBER: ${{ github.event.workflow_run.conclusion.pull_requests[0].number }}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That sucks. But if someone griefs us we'll have an argument for GH to fix that.

@coveralls
Copy link
Copy Markdown

coveralls commented Jul 13, 2024

Pull Request Test Coverage Report for Build 9939267405

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 83.153%

Totals Coverage Status
Change from base Build 9931259856: 0.0%
Covered Lines: 19634
Relevant Lines: 23612

💛 - Coveralls

Copy link
Copy Markdown
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

The remaining vulnerability needs to be fixed.

Comment on lines 27 to 35
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That sucks. But if someone griefs us we'll have an argument for GH to fix that.

@storopoli storopoli requested review from Kixunil and obi1kenobi July 14, 2024 11:41
Copy link
Copy Markdown
Contributor

@obi1kenobi obi1kenobi left a comment

Choose a reason for hiding this comment

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

I'm generally very risk-averse when it comes to security things, so my personal preference is to obsessively quote everything and eliminate anything that might be a vector for code injection, even if it is currently not exploitable due to an existing check. I basically don't trust that a future refactoring won't accidentally remove or reduce the check just enough that an attacker could slip through.

I've left some suggestions in that spirit, but it's entirely possible your preferences are not the same. So consider my comments purely advisory and feel free to ignore them if you don't think they are right for your style and development process.

Copy link
Copy Markdown
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK 6ab8f99

My comments can be addressed in a follow up PR since I believe this is sufficiently secure even without it and we desperately need to fix master. Note that I'm going AFK soon, so pushing will remove my ACK for around 8 hours.

fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/semver-break.zip`, Buffer.from(download.data));
- name: "Unzip artifact"
if: ${{ hashFiles('semver-break.zip') != '' }}
run: unzip semver-break.zip
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

FTR, I did check whether unzip is vulnerable to path traversal attacks. It looks like it's not. But maybe we should use the -n switch just to be sure. (Why the f didn't GH provide a first class API for this?!)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You mean the -n that I get when I run unzip -h in my linux machine:

-n  never overwrite existing files

?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Correct.

PR_NUMBER: ${{ github.event.number }}
run: |
# check if PR_NUMBER is a number
if ! [[ "$PR_NUMBER" =~ ^-?[0-9]+$ ]]; then
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This isn't really needed since the attacker won't attack himself.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But I prefer to have it in there. It is not doing anything now since the ENV var is set by Github.
Do you really see that it could be a problem in the near future?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's just a bloat. Not a big deal but I'd remove it if it was entirely my choice.

Copy link
Copy Markdown
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

FWIW ACK merging this. I can't put a proper ACK because I don't even know what scripting language is being used so my review is too shallow to warrant any worth.

@Kixunil
Copy link
Copy Markdown
Collaborator

Kixunil commented Jul 15, 2024

because I don't even know what scripting language is being used

Ignorance is a bliss. I wish I didn't know either.

@tcharding
Copy link
Copy Markdown
Member

Lol, glad I didn't look it up :)

@storopoli
Copy link
Copy Markdown
Contributor Author

storopoli commented Jul 15, 2024

FWIW ACK merging this. I can't put a proper ACK because I don't even know what scripting language is being used so my review is too shallow to warrant any worth.

I think I am more a JS hater (it belongs only in the browser to make things do things) than Rust maximalist.
The Geiger counter is going crazy with all the exposure to radioactive JS over these past days.
But I trimmed it down to the bare minimum.

I've updated the PR description with an overview and some implementation notes.
That might help people that want to review this.

@storopoli storopoli requested a review from obi1kenobi July 15, 2024 21:42
Copy link
Copy Markdown
Contributor

@obi1kenobi obi1kenobi left a comment

Choose a reason for hiding this comment

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

This looks good to me 👍

Just a note that the unzip -n conversation got resolved but the -n argument doesn't look like it made it into the PR. Entirely possible this is intentional and I've just been out of the loop, so I'm just flagging it for your consideration.

@Kixunil
Copy link
Copy Markdown
Collaborator

Kixunil commented Jul 16, 2024

it belongs only in the browser

WASM belongs there ;)

Thanks @obi1kenobi we had a rule to resolve conversations before but removed it. It was intentionally left out of the PR to not trigger re-review but should not have been marked as resolved.

@storopoli
Copy link
Copy Markdown
Contributor Author

Yeah my bad, I got trigger-happy with the resolve to unclutter things for the reviewers since we are planning to merge this without the -n and tackle in a new PR. I'll add in the TODO to #3003.

Copy link
Copy Markdown
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 6ab8f99 thanks for sticking with this!!

@storopoli
Copy link
Copy Markdown
Contributor Author

ACK 6ab8f99 thanks for sticking with this!!

Thanks, after this is merged I'll get back to #3003 TODO list.

@apoelstra apoelstra merged commit 59c8069 into rust-bitcoin:master Jul 16, 2024
@storopoli storopoli deleted the ci/fix-semver-checks branch July 16, 2024 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

semver job is failing intermittently on master

6 participants