githubgithub-actionsgithub-secret

How to restrict the use of GitHub secrets to particular workflow to prevent bypassing of checks/reviews?


The .github folder holds the workflows, and YAML file has all the checks and tests that run and uses GitHub secrets to build/deploy. The main branch has branch protection rules requiring review before merge.

With write access to the repo, one can bypass all the checks/branch protection rules and deploy directly. Below are the steps:

This triggers the deployment job to target env bypassing all the checks and rules

Is there a way to prevent to the usage of secrets and restrict to particular workflows/branches?


Solution

  • The only way I can think of is moving away from Repository secrets to Environment secrets and setup rules in the Environment to restrict the branches/tags allowed to deploy to the environment.

    With this we would have an additional approval steps for the workflow run.

    More details here: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules