Skip to content

Commit

Permalink
Updated gitlab docs (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
Prabhu Subramanian authored Jul 29, 2020
1 parent 47bb3d3 commit 88bce99
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
55 changes: 53 additions & 2 deletions docs/integrations/gitlab.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Integration with Gitlab CI
# Integration with GitLab CI

ShiftLeft Scan scanning is available for all GitLab CI users including the free users. Simply add the below section to your `.gitlab-ci.yml` file
ShiftLeft Scan is available for all GitLab CI users including the free users. In addition, it is possible to configure scan to add notes/comments to merge requests.

Simply add the below section to your `.gitlab-ci.yml` file

```yaml
job:
Expand All @@ -22,6 +24,8 @@ scan:
name: shiftleft/sast-scan
script:
- scan --src ${CI_PROJECT_DIR} --type credscan,python,depscan --out_dir ${CI_PROJECT_DIR}/reports
rules:
- when: always
artifacts:
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
paths:
Expand All @@ -42,9 +46,56 @@ scan:
name: shiftleft/sast-scan
script:
- scan --build --src ${CI_PROJECT_DIR} --type credscan,java,depscan --out_dir ${CI_PROJECT_DIR}/reports
rules:
- when: always
artifacts:
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
paths:
- $CI_PROJECT_DIR/reports/
when: always
```

## Merge Request comment feature


Set the following Repository variables to enable merge request notes/comment feature.

- `SCAN_ANNOTATE_PR` to `true`
- GITLAB_TOKEN - Personal access token belonging to a user with `api` scope. Best is to create a separate build user and a token
- GITHUB_TOKEN - To enable dependency and licence scanning

Below are the full configuration and example screenshots:

```yaml
variables:
GITHUB_TOKEN: $GITHUB_TOKEN
GITLAB_TOKEN: $GITLAB_TOKEN
SCAN_ANNOTATE_PR: "true"
scan:
stage: test
image:
name: shiftleft/sast-scan:gl-insights
script:
- scan --src ${CI_PROJECT_DIR} --type python,depscan --out_dir ${CI_PROJECT_DIR}/reports
rules:
- when: always
artifacts:
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
paths:
- $CI_PROJECT_DIR/reports/
when: always
```

![GitLab Merge Request](img/gitlab-mr.png)

To customize the message used for the comment, create a .sastscanrc file in the repo as suggested [here](tips.md) with the below config.

```json
{
"PR_COMMENT_TEMPLATE": "## ShiftLeft Scan Summary\n%(summary)s\n## Recommendation\n%(recommendation)s\n"
}
```

- summary - Summary Table
- recommendation - One liner recommendation string (Hardcoded for now)
Binary file added docs/integrations/img/gitlab-mr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 88bce99

Please sign in to comment.