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

feat: workflow to update actions dist #760

Merged
merged 16 commits into from
May 6, 2024

Conversation

ramonpetgrave64
Copy link
Contributor

@ramonpetgrave64 ramonpetgrave64 commented Apr 23, 2024

Add a new Post-Commit workflow, to make these renovate-bot updates a bit easier.
Previously, we had to clone the PR locally, run make package, and then push to the PR.
Now we would just need to use the github UI to invoke this new workflow against the PR number.
We could also copy this over to the slsa-github-generator repo.

A workflow to run against renovate-bot's PRs,
such as make package after it updates the package.json and package-lock.json files.
The potentially untrusted code is first run inside a low-privilege Job, and the diff is uploaded as an artifact.
Then a higher-privilege Job applies the diff and pushes the changes to the PR.
It's important to only run this workflow against PRs from trusted sources, after also reviewing the changes!

Testing.

Tested in my own private fork, where when applicable, it pushed a commit of changes to dist/ folders

Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com>
Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com>
Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com>
@ramonpetgrave64 ramonpetgrave64 marked this pull request as ready for review April 23, 2024 20:41
@ramonpetgrave64
Copy link
Contributor Author

Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com>
Copy link
Contributor

@laurentsimon laurentsimon left a comment

Choose a reason for hiding this comment

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

LGTM. Added a few nits.

.github/workflows/post-commit.yml Outdated Show resolved Hide resolved
.github/workflows/post-commit.yml Outdated Show resolved Hide resolved
runs-on: ubuntu-latest
permissions:
pull-requests: read
contents: write
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment saying we use CODEOWNERS and it's enforced thru Branch rules, so the token cannot be used to push to the main and release branches.

@mihaimaruseac can you take a look at this PR? We want to update the PR branch for renovatebot PRs

Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't have any branches other than main and release, so we can add a ruleset that prevents branch creation. Or we could add a ruleset that only lets maintainers create branches, which would prevent this action from pushing to new branches without stopping us from doing so as needed.

Copy link
Contributor

@mihaimaruseac mihaimaruseac left a comment

Choose a reason for hiding this comment

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

This seems a little bit more complex. Can this be done similar to guacsec/guac#953 (comment) ?

.github/workflows/post-commit.yml Outdated Show resolved Hide resolved
.github/workflows/post-commit.yml Outdated Show resolved Hide resolved
Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com>
Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com>
Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com>
@ramonpetgrave64
Copy link
Contributor Author

This seems a little bit more complex. Can this be done similar to guacsec/guac#953 (comment) ?

I used the gh cli because it has some conveniences like setting up the correct remote branch for the PR. If we used actions/checkout within a normal pull_request event, then we wouldn't need to use gh cli.

ramonpetgrave64 and others added 2 commits April 24, 2024 17:12
Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com>
Signed-off-by: Ramon Petgrave <32398091+ramonpetgrave64@users.noreply.github.com>
@ramonpetgrave64
Copy link
Contributor Author

@kpk47 And I added some more Repo rules that make this workflow even safer to use. Safer than cloning the PR locally and running the untrusted code.

Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com>
.github/workflows/post-commit.yml Outdated Show resolved Hide resolved
.github/workflows/post-commit.yml Outdated Show resolved Hide resolved
@@ -0,0 +1,94 @@
# A workflow to run against renovate-bot's PRs,
Copy link
Member

Choose a reason for hiding this comment

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

nit: add a doc section to the CONTRIBUTING.md that outlines how to use this workflow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No existing contributing docs, but I added one.

- name: checkout-pr
env:
GH_TOKEN: ${{ github.token }}
run: gh pr checkout ${{ inputs.pr_number }}
Copy link
Member

Choose a reason for hiding this comment

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

After git pr checkout, what is the git remote and branch set to? i.e. where does a git push go to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The remote and branch get set to the PRs repo and branch, and it pushes there.

# There have been vulnerabilities with using `git apply` https://github.blog/2023-04-25-git-security-vulnerabilities-announced-4/
# At this point a compromised git binary cannot modify any of this repo's branches, only the PR fork's branch,
# due to our branch protection rules and CODEOWNERS.
# It aslso cannot submit a new release or modify exsiting releases due to tag protection rules.
Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason this needs to run on the slsa-framework/slsa-verifier repo at all? could contributors just run it manually on their fork? That would somewhat limit exposure on our side and reduces toil for reviewers (i.e. if the dist check fails we could just tell them "run this" and point to the doc on how to run it in their fork. better yet, the error from that check could tell them).

AFAICT, this would just checkout the forked PR and push to the appropriate branch on the forked repo so wouldn't need to interact with (and thus need permissions for) the main repo at all.

Also makes it easier for us to audit since we would basically just makes sure there aren't any runs for this action on the main repo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com>
Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com>
Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com>
@ramonpetgrave64 ramonpetgrave64 requested a review from ianlewis May 6, 2024 15:44
@ramonpetgrave64 ramonpetgrave64 added this to the BYOB milestone May 6, 2024
Signed-off-by: Ramon Petgrave <32398091+ramonpetgrave64@users.noreply.github.com>
@ramonpetgrave64 ramonpetgrave64 changed the title feat: post-commit feat: workflow to update actions dist May 6, 2024
Signed-off-by: Ramon Petgrave <32398091+ramonpetgrave64@users.noreply.github.com>
@ramonpetgrave64 ramonpetgrave64 merged commit 23160d8 into slsa-framework:main May 6, 2024
14 checks passed
@ramonpetgrave64
Copy link
Contributor Author

Thanks everyone for the reviews

@ramonpetgrave64 ramonpetgrave64 mentioned this pull request May 8, 2024
1 task
ianlewis pushed a commit to slsa-framework/slsa-github-generator that referenced this pull request May 16, 2024
# Summary

Similar to slsa-verifier's
slsa-framework/slsa-verifier#760

This PR adds a manually-invoked workflow to run against renovate-bot's
PRs to update the node `dist` folders.

I made one small change to use the `${{ inputs.pr_number }} ` as an
environment variable, to harden against [script
injection](https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#good-practices-for-mitigating-script-injection-attacks).
See also slsa-framework/slsa-verifier#771

Also updating shellckeck to fix this lint error:
-
https://github.com/slsa-framework/slsa-github-generator/actions/runs/9101693389/job/25019502486#step:4:21

```
Error: input type of workflow_dispatch event must be one of "string", "boolean", "choice", "environment" but got "number"
```

## Testing Process

I ran this against my fork's version of PR #3649. It did update the dist
folders and the check-dists checks pass
-
https://github.com/ramonpetgrave64/slsa-github-generator/actions/runs/9101190828/job/25017786420?pr=9
-
https://github.com/slsa-framework/slsa-verifier/pull/760/files#diff-4c6b93aa75d5affde60dc3849606c9acd75ed444d52e99f3055fc0c7aa77e9e0

## Checklist

- [x] Review the contributing
[guidelines](https://github.com/slsa-framework/slsa-github-generator/blob/main/CONTRIBUTING.md)
- [ ] Add a reference to related issues in the PR description.
- [x] Update documentation if applicable.
- [ ] Add unit tests if applicable.
- [ ] Add changes to the
[CHANGELOG](https://github.com/slsa-framework/slsa-github-generator/blob/main/CHANGELOG.md)
if applicable.

---------

Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com>
ramonpetgrave64 added a commit that referenced this pull request May 22, 2024
Followup to #760

Fix the .github/workflows/update-actions-dist-post-commit.yml workflow
to also signoff commit

# Testing

- [x] Invoked this PR's branch copy of the workflow against #717, and it
did signoff the commit.
-
9670f76

Signed-off-by: Ramon Petgrave <32398091+ramonpetgrave64@users.noreply.github.com>
ramonpetgrave64 added a commit to ramonpetgrave64/slsa-verifier that referenced this pull request Jun 10, 2024
Add a new Post-Commit workflow, to make these renovate-bot updates a bit
easier.
Previously, we had to clone the PR locally, run `make package`, and then
push to the PR.
Now we would just need to use the github UI to invoke this new workflow
against the PR number.
We could also copy this over to the slsa-github-generator repo.

> A workflow to run against renovate-bot's PRs,
> such as `make package` after it updates the package.json and
package-lock.json files.
> The potentially untrusted code is first run inside a low-privilege
Job, and the diff is uploaded as an artifact.
> Then a higher-privilege Job applies the diff and pushes the changes to
the PR.
> It's important to only run this workflow against PRs from trusted
sources, after also reviewing the changes!

## Testing.

Tested in my own private fork, where when applicable, it pushed a commit
of changes to `dist/` folders
-
https://github.com/ramonpetgrave64/slsa-verifier/actions/runs/8806815483
  - https://github.com/ramonpetgrave64/slsa-verifier/pull/8/commits
-
https://github.com/ramonpetgrave64/slsa-verifier/actions/runs/8806841353
  - https://github.com/ramonpetgrave64/slsa-verifier/pull/16/commits

---------

Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com>
Signed-off-by: Ramon Petgrave <32398091+ramonpetgrave64@users.noreply.github.com>
Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com>
ramonpetgrave64 added a commit to ramonpetgrave64/slsa-verifier that referenced this pull request Jun 10, 2024
Followup to slsa-framework#760

Fix the .github/workflows/update-actions-dist-post-commit.yml workflow
to also signoff commit

# Testing

- [x] Invoked this PR's branch copy of the workflow against slsa-framework#717, and it
did signoff the commit.
-
slsa-framework@9670f76

Signed-off-by: Ramon Petgrave <32398091+ramonpetgrave64@users.noreply.github.com>
Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants