gha-trigger - Webhook Server and Actions for Secure GitHub Actions
Published: 2022-09-24 11:34:25

Today, gha-trigger [v0.1.0](https://github.com/gha-trigger/gha-trigger/releases/tag/v0.1.0) has been released. In this post, I introduce [gha-trigger](https://gha-trigger.github.io/). 

## What's gha-trigger?

gha-trigger is Webhook Server and Actions to run GitHub Actions securely.
It prevents Workflows and scripts from being modified and running malicious commands.

## Background

GitHub Actions is very powerful CI Platform, but also has a security risk that someone modifies workflows and workflow scripts and run malicious commands.
For example, secrets with strong permission may be abused and stolen.

GitHub provides several features such as [CODEOWNERS](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners), [branch protection rule](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/managing-a-branch-protection-rule), [OIDC Support](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), and so on, but they can't solve the above threat perfectly.

You can use other CI Platform to prevent workflows from being modified, but we would like to use GitHub Actions because GitHub Actions is very powerful.

So we design the architecture and develop gha-trigger to achieve the above goal.

## Architecture

![gha-trigger drawio](https://user-images.githubusercontent.com/13323303/188292546-53f0b4d2-fbe6-4bec-8b28-1b635b5e2eb0.png)

You create two GitHub repositories.

- Main Repository
  - Users develop this repository
  - Disable GitHub Actions
- CI Repository
  - Manage GitHub Actions Workflows and CI scripts
  - Only CI maintainers have write permissiono and other users have only read permission

When events such as `push` and `pull_request` occur in Main Repository, the webhook is sent to `gha-trigger`.
`gha-trigger` validates and filters webhooks and triggers GitHub Actions Workflows of CI Repository via GitHub API.
Workflows of CI Repository update commit statuses of Main Repository and send pull request comments so that users can refer CI results from Main Repository's pull request pages.

The important thing is that workflows and CI scripts are managed at the repository other than `Main Repository` and only restricted people have the write permission of `CI Repository`.
This prevents users from modifying workflows and CI scripts and makes GitHub Actions secure.

`gha-trigger` supports multiple pairs of `Main Repository` and `CI Repository`.
You can also share `CI Repository` for multiple `Main Repository`.

## GitHub Actions

We provide some GitHub Actions for gha-trigger.

- [start-action](https://github.com/gha-trigger/start-action)
  - [set-env-action](https://github.com/gha-trigger/set-env-action)
  - [commit-status-action](https://github.com/gha-trigger/commit-status-action)
- [end-action](https://github.com/gha-trigger/end-action)
  - [commit-status-action](https://github.com/gha-trigger/commit-status-action)
- [step-summary-action](https://github.com/gha-trigger/step-summary-action)

gha-trigger's Workflow is different from normal GitHub Actions Workflow, so you have to do some additional tasks.
For example, you have to update commit statuses yourself.

These actions do the common tasks and let you concentrate on the main workflow implementation.

- Show how to rerun and cancel workflow in GITHUB_STEP_SUMMARY
- Set useful Environment Variables
- Generate GitHub App Token
- Update commit statuses
- Checkout Main Repository and CI Repository

For the detail, please see [the document](https://gha-trigger.github.io/github-actions/).

## How to use

You have to create GitHub repositories, GitHub Apps, and AWS resources such as Amazon API Gateway, AWS Lambda, AWS SecretsManager, and so on.

Please see [Getting Started](https://gha-trigger.github.io/getting-started).

gha-trigger supports only AWS Lambda at the moment,
but we're considering to support other platform such as Google Cloud Function too.

## Conclusion

In this post, I introduce [gha-trigger](https://gha-trigger.github.io/), which is Webhook Server and Actions to run GitHub Actions securely.

For the detail, please see the official document.

https://gha-trigger.github.io/