Skip to content

Commit cbfd3ce

Browse files
committed
feat: gitlab templates
1 parent eef1319 commit cbfd3ce

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

.cz.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,5 @@ commitizen:
109109
version: 0.22.2
110110
version_files:
111111
- internal/cli/app.go:Version
112+
- gitlab/templates/sheriff.gitlab-ci.yml:sheriff:v
113+
- README.md:tags/v

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Sheriff is a tool to scan repositories and generate security reports.
3838
- [Source code hosting services](#source-code-hosting-services)
3939
- [Messaging services](#messaging-services)
4040
- [Scanners](#scanners)
41+
- [Usage in CI](#usage-in-ci)
42+
- [In Gitlab](#in-gitlab)
4143
- [Contributors ✨](#contributors-)
4244

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

244+
## Usage in CI
245+
246+
Sheriff was designed so it could be run as part of a CI pipeline.
247+
248+
### In Gitlab
249+
250+
To run sheriff on Gitlab, we suggest the following set-up:
251+
1. Create a repostory which will contain your CI runner, you can call it `sheriff-runner` for example
252+
2. Create a CI file in this repository which extends from our template
253+
```yaml
254+
include:
255+
- remote: 'https://raw.githubusercontent.com/elementsinteractive/sheriff/refs/tags/v0.22.2/gitlab/templates/sheriff.gitlab-ci.yml'
256+
257+
sheriff:
258+
extends: .sheriff
259+
```
260+
3. Go to **Build** -> **Pipeline schedules** -> **New schedule**
261+
a. Add a name & a preferred cron interval. We prefer a weekly scan such as `0 7 * * 1` (every Monday at 7am)
262+
b. Add a **Variable** Variable named `SHERIFF_CLI_ARGS` which extra CLI arguments you wish to add (see CLI configuration section)
263+
c. Add a **File** Variable named `SHERIFF_CONFIG` containing your sheriff configuration (see file configuration section)
264+
4. Go to **Settings** -> **CI/CD** -> **Variables**
265+
a. If scanning gitlab projects, add your gitlab token in **GITLAB_TOKEN** with *Protected*, *Masked*, *Hidden*
266+
b. If publishing reports to slack, add your slack token in **SLACK_TOKEN** with *Protected*, *Masked*
267+
5. Test your pipeline by going to **Build** -> **Pipeline schedules** & clicking the play button on your pipline
268+
5. Enjoy! Your pipeline should now run & scan your projects on a weekly basis 😀
269+
270+
We have a gitlab template set up for convenience, which runs sheriff with a set of configurable options.
271+
242272
## Contributors ✨
243273

244274
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
variables:
2+
GITLAB_TOKEN:
3+
description: "GitLab token for API access"
4+
SLACK_TOKEN:
5+
description: "Slack token for notifications"
6+
SHERIFF_CONFIG:
7+
description: "Sheriff TOML configuration file contents. Will be available to sheriff as a file `sheriff.toml`"
8+
SHERIFF_CLI_ARGS:
9+
description: "Add CLI arguments to pass to the sheriff patrol command"
10+
11+
.sheriff:
12+
stage: deploy
13+
image:
14+
name: elementsinteractive/sheriff:v0.22.2
15+
entrypoint: [""]
16+
resource_group: production
17+
rules:
18+
- if: $CI_PIPELINE_SOURCE == "schedule"
19+
- if: $CI_PIPELINE_SOURCE == "web"
20+
script:
21+
- sheriff patrol
22+
--gitlab-token $GITLAB_TOKEN
23+
--slack-token $SLACK_TOKEN
24+
--config $SHERIFF_CONFIG
25+
$SHERIFF_CLI_ARGS
26+
27+
sheriff:
28+
extends: .sheriff

0 commit comments

Comments
 (0)