GitLab
For more information, see FortiCNAPP Code Security for GitLab Pipelines.
The following tutorial will guide you in running FortiCNAPP Code Security scanning (SCA and IaC) in your GitLab pipelines. The template provides two scanning workflows automatically:
-
Push scanning: Runs on every push and produces a GitLab-native JSON report that populates the Security Dashboard (
dependency_scanningandsastreport types). -
Merge request (MR) scanning: Runs on MR creation and update, scans both source and target branches, compares results, and posts a comment on the MR with new findings.
Running an analysis
In your GitLab Project’s CI/CD settings, configure the API Key, API Secret, and account name. You should add three secrets LW_ACCOUNT, LW_SUBACCOUNT (when using a subaccount) , LW_API_KEY, and LW_API_SECRET to your GitLab repository. You can also add these secrets to your GitLab organization so that they can be shared across all your repositories. For information on obtaining the value for these secrets by creating and downloading an API key, see API keys.
On the repository's settings page, create a new access token with API scope. Add the token value to new variable named LW_GITLAB_TOKEN with Masked and hidden visibility. This token will be used to post merge request message with the new findings reported by the Code Security scans.
To configure the variables:
-
Navigate to Your GitLab Project.
-
Log in to your GitLab account and go to the project where you want to configure the CI/CD variables.
-
Go to Settings >CI/CD.
-
Expand the Variables configuration panel.
-
Add a new variable:
-
Click Add variable. You will see fields to enter the Key, Value, and some additional options.
-
Enter the Variable Details.
-
Key: Enter the name of the variable, for example,
LW_ACCOUNT,LW_API_KEY, orLW_API_SECRET. -
Value: Enter the value for the variable. For example, your FortiCNAPP account name, API key, or API secret.
-
Type: By default, it is set to Environment variable. You can leave this as is.
-
Protect variable: Enable this option if you want the variable to be available only in protected branches or tags (for example, main or master). This is useful for securing sensitive information.
-
Masked : Enable this option to verify that the variable value is hidden in job logs. Masked variables are obscured when displayed in logs, which adds an extra layer of security.
-
-
If you are using a self-hosted GitLab instance, you must also set the GITLAB_URL environment variable to point to your GitLab instance URL:
GITLAB_URL=https://gitlab.yourcompany.com
If GITLAB_URL is not set, the integration will default to using https://gitlab.com.
To run an analysis on merge requests or pushes:
-
Create a file named
.gitlab-ci.yaml. -
Add the following content to the file:
include: - remote: 'https://gitlab.com/lacework-security/code-security/code-security-gitlab/-/raw/main/lacework-code-security.yaml' stages: - security-scan
This provides both
push_scanandmerge_request_scanjobs automatically.