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

NETOBSERV-229 CI: create pre-merge images #100

Merged
merged 3 commits into from
Mar 26, 2022

Conversation

jotak
Copy link
Member

@jotak jotak commented Mar 21, 2022

https://issues.redhat.com/browse/NETOBSERV-229

New github action workflow to build and push images per pull request.

Some security consideration: pushing images requires QUAY_SECRET to be used, which isn't
available in the 'pull_request' trigger, so we have to use
'pull_request_target' instead. This trigger uses the base branch HEAD,
rather than the PR's HEAD to execute the workflow, to prevent attacks
stealing secrets. Still, it could be vulnerable to attacks stealing secret from the build itself. So as an additional measure, we inculde a user validation check, so that only allowed users (maintainers) have their PR image built.

@jotak
Copy link
Member Author

jotak commented Mar 21, 2022

FYI I've partly tested here: https://github.com/jotak/test-actions/actions

@jotak
Copy link
Member Author

jotak commented Mar 21, 2022

@memodi this CI script should allow the pre-merge image building
@eranra I've included you as reviewer as it is likely something we want to introduce as well in FLP

@jotak
Copy link
Member Author

jotak commented Mar 21, 2022

reviewers: as explained here: https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ there is a security risk when we try to build / push images per PR. I think the workflow I'm suggesting is ok, but let me know if you have concerns.

@jotak
Copy link
Member Author

jotak commented Mar 21, 2022

reviewers: as explained here: https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ there is a security risk when we try to build / push images per PR. I think the workflow I'm suggesting is ok, but let me know if you have concerns.

Actually, the site mentions maybe a better way to achieve what I want: using labels such as "safe to test":

Add a condition to the pull_request_target to run only if a certain label is assigned the PR, like safe to test that indicates the PR has been vetted by someone with write privileges to the target repository:

Maybe it's better than an explicit whitelist; however it means that we should never ever allow label creation publicly, so there's also some risk.

- name: validate user
id: validate_user
run: |
allowed=(${{ env.ALLOWED_USERS }})
Copy link
Contributor

Choose a reason for hiding this comment

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

@jotak as you suggest, I think that using a label might be more "clean" also I suggest triggering this also if someone is adding a level to a PR (is this possible?) .... this will allow working on a PR and if needed just tag the pr with "push_image" and this will cause in this action to start creating images for the PR

Copy link
Contributor

Choose a reason for hiding this comment

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

We also need to make sure that only specific users will be able to add the labels to the PR

Copy link
Member Author

@jotak jotak Mar 25, 2022

Choose a reason for hiding this comment

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

Ok, I've changed to use a label .. it's cleaner and shorter. So the new workflow is:

  1. A PR is opened
  2. Maintainer makes sure this PR is safe to test (no risk of attack / stealing secret)
  3. He adds the "ok-to-test" label
  4. That triggers a build and push image to quay
  5. If the PR is modified, the "ok-to-test" label is automatically removed. Then GOTO 2.

Also, I've modified the shortlived image creation to stick with what we said on FLP previously.

Copy link
Member Author

Choose a reason for hiding this comment

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

of course this is not a mandatory workflow, we can continue to work as today, it's only something to follow if tester / QE wants an easy way to get the image

Copy link
Member Author

Choose a reason for hiding this comment

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

BTW, setting a label requires write permission on the repo, so it should be safe

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@eranra
Copy link
Contributor

eranra commented Mar 25, 2022

@memodi this CI script should allow the pre-merge image building @eranra I've included you as a reviewer as it is likely something we want to introduce as well in FLP

Yes, once we agree on this ... makes sense to add to FLP ( and maybe also to the operator ?)

jotak added 3 commits March 25, 2022 09:18
https://issues.redhat.com/browse/NETOBSERV-229

New github action workflow to build and push images per pull request.

Some security consideration: pushing images requires QUAY_SECRET to be used, which isn't
available in the 'pull_request' trigger, so we have to use
'pull_request_target' instead. This trigger uses the base branch HEAD,
rather than the PR's HEAD to execute the workflow, to prevent attacks
stealing secrets. As an additional measure, we inculde a user validation check, so that only allowed users (maintainers) have their PR image built.
Label is also automatically removed when a change is detected
@openshift-ci openshift-ci bot removed the lgtm label Mar 25, 2022
Copy link
Contributor

@memodi memodi left a comment

Choose a reason for hiding this comment

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

/lgtm thanks @jotak

@jotak
Copy link
Member Author

jotak commented Mar 26, 2022

/approve

@openshift-ci
Copy link

openshift-ci bot commented Mar 26, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jotak

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit 0a0e086 into netobserv:main Mar 26, 2022
@jotak jotak deleted the push-image-pr branch November 7, 2024 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants