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

[#1272] Actions: move deployment to Surge to a secure workflow #1411

Merged
merged 22 commits into from
Jan 22, 2021

Conversation

dcshzj
Copy link
Member

@dcshzj dcshzj commented Jan 18, 2021

Resolves security issue.
Fixes #1272.

The current continuous integration workflow on GitHub Actions
includes a deployment to surge.sh. This is a security concern, as
it exposes the secrets configured in GitHub Actions to potential
bad actors when they create a pull request.

Let's separate the deployment to surge.sh as a different workflow
and pass the generated RepoSense report as well as the MarkBind
documentation website as an artifact. This reduces the exposure of
repository secrets to untrusted code and improves security, as the
untrusted code cannot be executed when repository secrets are made
available to the workflow.

Let's also change the way the deployment previews are reported in
the pull request by taking advantage of the deployment status
available in the GitHub API.

@dcshzj dcshzj requested a review from fzdy1914 January 18, 2021 10:09
Copy link
Member

@fzdy1914 fzdy1914 left a comment

Choose a reason for hiding this comment

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

LGTM

@fzdy1914
Copy link
Member

@dcshzj Can you propose a nicer commit message that describes the dangering we are facing and how we are going to solve it? It is a good PR to practice your commit message writing ability.

@dcshzj
Copy link
Member Author

dcshzj commented Jan 18, 2021

@fzdy1914 I have updated the commit message, is it okay?

@fzdy1914
Copy link
Member

The commit message is good now. But the sample run you provided does not have a showcase of how current deployment will be.

You have mentioned that workflow_run job can only execute if the file is on the default branch. What branch you are referring to? Is it master? It will be bad since we want to preview PRs to other branches also.

Why we have to use the workflow_run job? Why a pull_request event can not do the same thing?

@fzdy1914 fzdy1914 self-requested a review January 18, 2021 10:37
@dcshzj
Copy link
Member Author

dcshzj commented Jan 18, 2021

The commit message is good now. But the sample run you provided does not have a showcase of how current deployment will be.

Sorry, are you referring to the deployment to surge? It's not included because only this repository has access to the secret, so only jobs that run on this repository will be able to successfully deploy to surge.

You have mentioned that workflow_run job can only execute if the file is on the default branch. What branch you are referring to? Is it master? It will be bad since we want to preview PRs to other branches also.

Yep it is only the master branch. This is a restriction noted in the GitHub documentation. However, this is referring to the workflow file being present in the master branch, but any PRs that is created to non-default branches will still work.

This is an example where it is a PR from one branch to another non-default branch: dcshzj#3

Why we have to use the workflow_run job? Why a pull_request event can not do the same thing?

The workflow_run job is needed because we can only run the deployment after the CI workflow has completed, since it is that workflow that generates the artifact. The pull_request event will run concurrently, causing it to try and get an artifact that has not been created yet.

@fzdy1914
Copy link
Member

Sorry, are you referring to the deployment to surge? It's not included because only this repository has access to the secret, so only jobs that run on this repository will be able to successfully deploy to surge.

Can you set up a surge for your repo? This set up will not conflict with the setting of RepoSense.

Yep it is only the master branch. This is a restriction noted in the GitHub documentation. However, this is referring to the workflow file being present in the master branch, but any PRs that is created to non-default branches will still work.

OK, in this case. To have a test, can you temporarily merge your new branch in your master (and revert it when the testing is done)? And then, send one PR to master and another PR to another branch to see if the workflow goes well?

@fzdy1914
Copy link
Member

If the workflow-run can not work. I found this and this links that can also solve our issue.

@dcshzj
Copy link
Member Author

dcshzj commented Jan 18, 2021

@fzdy1914 Here are the links for the workflows:

Seems to work as expected.

@fzdy1914
Copy link
Member

fzdy1914 commented Jan 18, 2021

Seems to work as expected.

Yep, it is working. However, to be more precise, can you refer to the way how deploy-surge.sh create a state in PR checklist to also create an entry for the surge workflow? So in case, we want to navigate to the detail of it, we do not need to find it in the action tab but directly in the checklist?

But you can argue that showing the PR preview links is enough to indicate that the workflow is running without any error. But anyway, I am thinking of effectively locating certain workflow if we indeed need to find it.

@Tejas2805
Copy link
Contributor

@dcshzj Thank you for the quick work on the PR.

I think it would be a good practice to document this in some repository or in some way since we all won't be working on the project all the time. This would help future maintainers and developers be more prepared and avoid such code.

@damithc @fzdy1914 What do you think?

@damithc
Copy link
Collaborator

damithc commented Jan 18, 2021

I think it would be a good practice to document this in some repository or in some way since we all won't be working on the project all the time. This would help future maintainers and developers be more prepared and avoid such code.

@damithc @fzdy1914 What do you think?

Sure, can add a note in the DG. Alternatively, a good commit message should be enough as it can be reached using git or github?

@dcshzj
Copy link
Member Author

dcshzj commented Jan 18, 2021

Yep, it is working. However, to be more precise, can you refer to the way how deploy-surge.sh create a state in PR checklist to also create an entry for the surge workflow? So in case, we want to navigate to the detail of it, we do not need to find it in the action tab but directly in the checklist?

I have implemented this by expanding on the commit status that we have used in the past. I also took the opportunity to remove the redundant code, since we are not doing surge.sh builds for pushes. Thus, the failure of the pull_request_target job is expected, due to changes in the way the script needs to be called.

GitHub Actions will now first report a pending status first. If any step fails for some reason, a failure status will be reported for the dashboard and docs deployments. Otherwise, it will remain pending until the deployment to surge is completed, then a success status will be reported.

A sample PR is available here: dcshzj#2

I think it would be a good practice to document this in some repository or in some way since we all won't be working on the project all the time. This would help future maintainers and developers be more prepared and avoid such code.

Would it be okay to keep it as part of the commit message? I think the separation of workflow files would raise eyebrows, but the commit history will have this PR for record.

config/gh-actions/deploy-surge.sh Outdated Show resolved Hide resolved
@dcshzj dcshzj requested a review from fzdy1914 January 19, 2021 06:37
Copy link
Member

@fzdy1914 fzdy1914 left a comment

Choose a reason for hiding this comment

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

Set the env_url to pull_request event if fail, but to workflow even when success.

@dcshzj dcshzj changed the title Separate deployment to Surge as a different workflow in GitHub Actions [#1272] Separately deploy to Surge in GitHub Actions Jan 20, 2021
@github-actions github-actions bot requested a deployment to dashboard January 20, 2021 08:11 Abandoned
@github-actions github-actions bot requested a deployment to docs January 20, 2021 08:11 Abandoned
@dcshzj dcshzj requested a review from fzdy1914 January 20, 2021 08:14
@dcshzj
Copy link
Member Author

dcshzj commented Jan 20, 2021

It should be working now. To verify:

  • PR Test GitHub Actions for forked repositories #1402 tests if the GITHUB_TOKEN works as intended for forked repositories. This is verified by the existence of the "Pending" status for the deployment of the RepoSense report and documentation. The status is not at "Success" due to that step being run in workflow_run, which is not yet available in the default branch.
  • PR Test dcshzj/RepoSense#2 tests if the actual deployment to surge.sh works. This is verified by the successful deployment for both the RepoSense report and documentation.

Untrusted code is now only run in integration.yml, which does not require secrets. Steps that require secrets are either in pending.yml or in surge.yml.

Copy link
Member

@fzdy1914 fzdy1914 left a comment

Choose a reason for hiding this comment

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

LGTM

@fzdy1914 fzdy1914 changed the title [#1272] Separately deploy to Surge in GitHub Actions [#1272] Actions: move deployment to Surge to a secure workflow Jan 22, 2021
@fzdy1914 fzdy1914 merged commit ae22646 into reposense:master Jan 22, 2021
@fzdy1914 fzdy1914 deleted the security-actions branch January 22, 2021 06:15
@fzdy1914 fzdy1914 restored the security-actions branch January 22, 2021 06:15
@dcshzj dcshzj deleted the security-actions branch January 25, 2021 03:10
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.

The Branch is showing not deployed:
4 participants