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

feat: gitlab templates #41

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,5 @@ commitizen:
version: 0.22.2
version_files:
- internal/cli/app.go:Version
- gitlab/templates/sheriff.gitlab-ci.yml:sheriff:v
- README.md:tags/v
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Sheriff is a tool to scan repositories and generate security reports.
- [Source code hosting services](#source-code-hosting-services)
- [Messaging services](#messaging-services)
- [Scanners](#scanners)
- [Usage in CI](#usage-in-ci)
- [In Gitlab](#in-gitlab)
- [Contributors ✨](#contributors-)

## Quick Usage
Expand Down Expand Up @@ -239,6 +241,34 @@ Sets the token to be used when reporting the security report on slack
- [x] [OSV-Scanner](https://github.com/google/osv-scanner)
- [ ] [Trivy](https://github.com/aquasecurity/trivy)

## Usage in CI

Sheriff was designed so it could be run as part of a CI pipeline.

### In Gitlab

To run sheriff on Gitlab, we suggest the following set-up:
1. Create a repostory which will contain your CI runner, you can call it `sheriff-runner` for example
2. Create a CI file in this repository which extends from our template
```yaml
include:
- remote: 'https://raw.githubusercontent.com/elementsinteractive/sheriff/refs/tags/v0.22.2/gitlab/templates/sheriff.gitlab-ci.yml'

sheriff:
extends: .sheriff
```
3. Go to **Build** -> **Pipeline schedules** -> **New schedule**
a. Add a name & a preferred cron interval. We prefer a weekly scan such as `0 7 * * 1` (every Monday at 7am)
b. Add a **Variable** Variable named `SHERIFF_CLI_ARGS` which extra CLI arguments you wish to add (see CLI configuration section)
c. Add a **File** Variable named `SHERIFF_CONFIG` containing your sheriff configuration (see file configuration section)
4. Go to **Settings** -> **CI/CD** -> **Variables**
a. If scanning gitlab projects, add your gitlab token in **GITLAB_TOKEN** with *Protected*, *Masked*, *Hidden*
b. If publishing reports to slack, add your slack token in **SLACK_TOKEN** with *Protected*, *Masked*
5. Test your pipeline by going to **Build** -> **Pipeline schedules** & clicking the play button on your pipline
5. Enjoy! Your pipeline should now run & scan your projects on a weekly basis 😀

We have a gitlab template set up for convenience, which runs sheriff with a set of configurable options.

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Expand Down
28 changes: 28 additions & 0 deletions gitlab/templates/sheriff.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
variables:
GITLAB_TOKEN:
description: "GitLab token for API access"
SLACK_TOKEN:
description: "Slack token for notifications"
SHERIFF_CONFIG:
description: "Sheriff TOML configuration file contents. Will be available to sheriff as a file `sheriff.toml`"
SHERIFF_CLI_ARGS:
description: "Add CLI arguments to pass to the sheriff patrol command"

.sheriff:
stage: deploy
image:
name: elementsinteractive/sheriff:v0.22.2
entrypoint: [""]
resource_group: production
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_PIPELINE_SOURCE == "web"
script:
- sheriff patrol
--gitlab-token $GITLAB_TOKEN
--slack-token $SLACK_TOKEN
--config $SHERIFF_CONFIG
$SHERIFF_CLI_ARGS

sheriff:
extends: .sheriff
Loading