|
| 1 | +# Github Actions CI/CD |
| 2 | + |
| 3 | +kAFL can be integrated into your Github Actions CI/CD pipeline, thanks to the [`IntelLabs/kafl.actions`](https://github.com/IntelLabs/kafl.actions). |
| 4 | + |
| 5 | +It acts as a basic-block to compose your workflows with kAFL. |
| 6 | + |
| 7 | +With this Action you can: |
| 8 | + |
| 9 | +- automate the fuzzing process of your target and building a reusable workflow |
| 10 | +- delegate the kAFL setup from your local machine to a reproducible infrastucture |
| 11 | +- build a regression test suite, continuously updated with new seeds, to be executed at your convenience (every PR, day, week, ...) |
| 12 | + |
| 13 | +Requirements: |
| 14 | + |
| 15 | +- A kAFL-compatible server (**Intel PT**) acting as [Github Action Self-Hosted Runner](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/about-self-hosted-runners) |
| 16 | + |
| 17 | + |
| 18 | +## 1 - Deploying the kernel |
| 19 | + |
| 20 | +This first step will install the kAFL on the server of your choice. |
| 21 | + |
| 22 | +We can leverage kAFL's [Ansible playbook](../reference/deployment.md) to automate this part. |
| 23 | + |
| 24 | +```bash |
| 25 | +cd kAFL |
| 26 | +# rewrite the Ansible inventory to deploy remotely on a specified server |
| 27 | +echo 'kafl-actions-runner.example.com' > deploy/inventory |
| 28 | +# only deploy the kernel |
| 29 | +make deploy -- --tags kernel |
| 30 | +``` |
| 31 | + |
| 32 | +:::{note} |
| 33 | +This command will: |
| 34 | +- install the kernel |
| 35 | +- update GRUB |
| 36 | +- **reboot** the server |
| 37 | +::: |
| 38 | + |
| 39 | +➡️ Once this is done, you should find a `-nyx` tag in your server's `uname` |
| 40 | +```bash |
| 41 | +uname -a | grep nyx |
| 42 | +... 6.0.0-nyx+ ... |
| 43 | +``` |
| 44 | + |
| 45 | +## 2 - Setting up Docker |
| 46 | + |
| 47 | +[`kafl.actions`](https://github.com/IntelLabs/kafl.actions) will pull the latest [`intellabs/kafl`](https://hub.docker.com/r/intellabs/kafl) Docker image to run the kAFL userspace. |
| 48 | + |
| 49 | +Let's setup Docker on the runner as well ! |
| 50 | + |
| 51 | +➡️ [Install Docker Engine on Ubuntu](https://docs.docker.com/engine/install/ubuntu/) |
| 52 | + |
| 53 | +## 3 - Setup the Github Actions Runner |
| 54 | + |
| 55 | +Finally you can follow Github's official guide to add a [Self-Hosted Runner](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/adding-self-hosted-runners#adding-a-self-hosted-runner-to-a-repository) to your repository. |
| 56 | + |
| 57 | +You should now have a runner available under `Settings` `Actions` `Runners` |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +## 4 - Using `kafl.actions` |
| 62 | + |
| 63 | +Go check [`kafl.actions`](https://github.com/IntelLabs/kafl.actions)'s README and the example [`kernel.yml`](https://github.com/IntelLabs/kafl.actions/blob/master/.github/workflows/kernel.yml) to fuzz the Linux kernel ! |
| 64 | + |
| 65 | +It boils down to invoking the action, specifing the subcommand, the workdir (to be mounted in the container), and a few `extra_args` for the kAFL command line. |
| 66 | + |
| 67 | +```yaml |
| 68 | + - name: Fuzz Linux kernel |
| 69 | + uses: IntelLabs/kafl.actions@master |
| 70 | + with: |
| 71 | + action: fuzz |
| 72 | +``` |
| 73 | +
|
| 74 | +Build your own workflows, automate and fuzz all the things (continuously) ! |
| 75 | +
|
| 76 | +:::{note} |
| 77 | +The default timeout for a Github Action's job is limited to `6h`. |
| 78 | + |
| 79 | +It's possible to bypass this limit by specifying a higher value in [`jobs.<job_id>.timeout-minutes`](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idtimeout-minutes). |
| 80 | + |
| 81 | +For example, you can set it to 2 weeks: |
| 82 | +```yaml |
| 83 | +jobs: |
| 84 | + fuzz: |
| 85 | + # bypass 6h limitation |
| 86 | + # set to 2 weeks max job execution time |
| 87 | + # 60 * 24 * 7 * 2 = 20160 minutes |
| 88 | + timeout-minutes: 20160 |
| 89 | +``` |
| 90 | + |
| 91 | +And then limit your target fuzzing to any value you want (under that threshold): |
| 92 | +```yaml |
| 93 | + - name: Fuzz Linux kernel |
| 94 | + uses: IntelLabs/kafl.actions@master |
| 95 | + with: |
| 96 | + action: fuzz |
| 97 | + # 3 days |
| 98 | + # 60 * 60 * 24 * 3 = 259200 seconds |
| 99 | + timeout: 259200 |
| 100 | +``` |
| 101 | +````{warning} |
| 102 | +[kafl.actions](https://github.com/IntelLabs/kafl.actions)'s fuzz timeout is specified in **seconds**, not minutes. |
| 103 | +```` |
| 104 | +::: |
| 105 | + |
| 106 | +## References |
| 107 | + |
| 108 | +The [`kafl.actions`](https://github.com/IntelLabs/kafl.actions) Github Action has been introduced to the [Tianocore community meeting](https://www.youtube.com/watch?v=0adtDjSdSjc&t=230s) on May 4th 2023. |
0 commit comments