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

Added a validation check for pr approval in the deploy-pr workflow #660

Merged

Conversation

devanshkansagra
Copy link
Contributor

This Pull request adds an additional pr approval check in deploy-pr.yml workflow. This adds validation to ensure the deploy-pr workflow runs only after PRs are approved by collaborators or owners. The GitHub API is used to verify approval status, preventing unauthorized deployments from forked repositories.

Acceptance Criteria fulfillment

  • Add an approval validation check in the deploy-pr workflow

Videos/Screenshots

N/A

@devanshkansagra
Copy link
Contributor Author

Hey @Spiral-Memory, I have worked on this vulnerablity which btw was difficult to find out and finally I have found the fix after researching. I have tested using my other github account, you can also test it here for better clearence https://github.com/devanshkansagra/Embedded-Chat . Also please review this pull request

@Spiral-Memory
Copy link
Collaborator

Awesome work @devanshkansagra

Will discuss about this with you today.

@devanshkansagra
Copy link
Contributor Author

devanshkansagra commented Nov 8, 2024

Okay sure. Then let's finish up this as early as possible coz this was very long time awaited

Copy link
Collaborator

@Spiral-Memory Spiral-Memory left a comment

Choose a reason for hiding this comment

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

Still carries the same vulnerability as discussed.

@devanshkansagra
Copy link
Contributor Author

Hey @Spiral-Memory, I have removed the part of transfering pr number as artifact and instead I have used github api to fetch the pr number in deploy-pr workflow

@devanshkansagra
Copy link
Contributor Author

You can check and review whenever you are free

@Spiral-Memory
Copy link
Collaborator

Awesome work @devanshkansagra

Is it working ?
Also, can you explain a bit, how exactly are you getting PR number ? I mean how will this workflow know, which build-pr workflow triggered it ?

@devanshkansagra
Copy link
Contributor Author

devanshkansagra commented Nov 15, 2024

Yes @Spiral-Memory, this workflow is working. You can check it out here in my test repo https://github.com/devanshkansagra/Embedded-Chat by raising a demo pr
The thing I researched and found out that the URL for the GitHub API endpoint to list pull requests. It filters PRs by the head branch github.head_ref and repository owner github.repository_owner. jq -r '.[0].number': Pipes the JSON response to jq, which is a command-line JSON processor. It extracts the number of the first pull request in the list

This is based on the thing I researched on the internet and various AIs including ChatGPT, Github-Copilot etc. also I haven't gone in depth regarding this Github-API, and jq stuff

and same goes with the checking approval status

@Spiral-Memory
Copy link
Collaborator

No, what i am asking is, with this, it will check the PR permission for the first PR in the list, not the PR it is triggered on, have you tested this ?

@devanshkansagra
Copy link
Contributor Author

Yea I have tested it by raising two different prs in parallel

@Spiral-Memory
Copy link
Collaborator

Okay then tomorrow, we will see how exactly is it working and then will merge it if testing succeeds.

@devanshkansagra
Copy link
Contributor Author

Okay No problem

@devanshkansagra
Copy link
Contributor Author

No, what i am asking is, with this, it will check the PR permission for the first PR in the list, not the PR it is triggered on, have you tested this ?

Hey you are right, yesterday I ran the approval check was shown the respective pr numbers but today I have tested very parallel, it was checking the top of the list pr number

@devanshkansagra
Copy link
Contributor Author

Hey @Spiral-Memory, I have pushed the commit, you can check / review it

@devanshkansagra
Copy link
Contributor Author

Hey @Spiral-Memory, I have one thing to ask, in build-and-lint workflow is the last step of building the project necessary or is it going to use further? if not then we can consider it unnecessary and remove it. also I think the major work of this workflow is to check format and linting issues in the pull request right?

@Spiral-Memory
Copy link
Collaborator

No not just that, it also tests if project is getting built correctly after the new change so it shouldn't break the project

@devanshkansagra
Copy link
Contributor Author

ohh okay

@devanshkansagra
Copy link
Contributor Author

devanshkansagra commented Dec 22, 2024

One thing to share, I have observed currently that if you merge/close/approve multiple prs at same time or the small time diff then pages-build workflow will be skipped, this is currently there

@devanshkansagra
Copy link
Contributor Author

To overcome this let the workflow get's fully completed then approve / merge next pr

@Spiral-Memory
Copy link
Collaborator

That's Okay... Apart from that, is it good to merge this?

@devanshkansagra
Copy link
Contributor Author

Yea sure, you can go for it

@Spiral-Memory Spiral-Memory merged commit f0d2848 into RocketChat:develop Dec 22, 2024
5 checks passed
@Spiral-Memory
Copy link
Collaborator

image

Getting a critial security alert, for now reverting the PR, You can take your time to research why codescan is giving this alert

@devanshkansagra
Copy link
Contributor Author

But how it can cause, during this research I didn't got any this type of error, I have the duplicated the exact things and created a dummy test repo

@Spiral-Memory
Copy link
Collaborator

That's fine @devanshkansagra
Take your time...

Before reverting, let me atleast test that if it is working or not (ignoring security alert)

@devanshkansagra
Copy link
Contributor Author

Okk

@Spiral-Memory
Copy link
Collaborator

Hi @devanshkansagra
It is working fine, just a security alert is present, what do you think, should i revert ?

or you will add a fix soon ?

@Spiral-Memory
Copy link
Collaborator

@devanshkansagra
Copy link
Contributor Author

devanshkansagra commented Dec 22, 2024

You made me sweaty in winters after showing me that security alert error. Currently it is more secure than before, so I will add that fix in my next pr

@Spiral-Memory
Copy link
Collaborator

@Spiral-Memory
Copy link
Collaborator

Spiral-Memory commented Dec 22, 2024

This new change is something causing deploy error too
jq: error (at :5): Cannot index string with string "submitted_at"

@Spiral-Memory
Copy link
Collaborator

I need to revert this change, let me know once you test it well and working fine
No need to worry

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.

2 participants