nonroot variant of the Semgrep docker image with GitHub Actions, there is some extra workflow configuration required to ensure that scans run as intended despite the limited permissions of the nonroot image.
This sample GitHub Actions configuration file uses the default Semgrep docker image, which has root permissions, making it very simple to declare it as a container image running on top of something like Ubuntu, using the GitHub Actions workflow YAML syntax.
With the nonroot image, the same YAML syntax cannot be used to declare the image, as it then runs into permissions issues when trying to check out the repository during scan time. Instead, the image must be declared using a docker run command, along with the proper user and group permissions applied beforehand.
Furthermore, various pieces of Git metadata stored as environment variables or in the GITHUB_EVENT_PATH JSON file must be copied over from the runner environment to the nonroot image environment, as Semgrep uses this information to properly configure the scan.
Sample GitHub Actions workflow file using the nonroot Semgrep docker image
The following example workflow file contains the extra steps required to successfully use the nonroot image, along with commented explanations before each step.