# GitLab

Akto integrates with GitLab to add automated AI Red Teaming to your CI/CD pipeline. This integration enables you to:

* Run red teaming scans during your GitLab pipelines
* View security scan results directly in merge requests
* Block merges based on security scan results

<figure><img src="https://3128331180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ftog5ODwYfqPOf4eQhsOC%2Fuploads%2Fgit-blob-2a68105046c6fe70c6df55c02c82dcf0406201d2%2Fimage%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

### Prerequisites

* GitLab account with maintainer or owner permissions
* GitLab repository with CI/CD enabled
* Docker runner configured in GitLab
* [Akto dashboard access](https://app.akto.io/)
* [Akto API credentials](https://ai-security-docs.akto.io/integrations/ci-cd-integrations/broken-reference) (API key and dashboard URL)
* [Valid test ID from your Akto Probe](https://ai-security-docs.akto.io/integrations/ci-cd-integrations/broken-reference)

### Steps to Configure GitLab

1. Add GitLab CI Configuration
   1. Create or update `.gitlab-ci.yml` in your repository root:

```yaml
stages:    # List of stages for jobs, and their order of execution
  - build
  - test

build-job:       # This job runs in the build stage, which runs first.
  stage: build
  script:
    - echo "Compiling the code..."
    - echo "Compile complete."

variables:
  AKTO_DASHBOARD_URL: "https://app.akto.io"
  AKTO_API_KEY: "${AKTO_API_KEY}"        # Use GitLab CI/CD variable
  AKTO_TEST_ID: "${AKTO_TEST_ID}"        # Use GitLab CI/CD variable
  WAIT_TIME_FOR_RESULT: "1000"

test_scan:
  stage: test
  image: aktosecurity/akto-testing-scan:latest # Use Docker image to run docker commands
  script:
    - cd /usr/src/app
    - echo $AKTO_DASHBOARD_URL
    - echo $AKTO_API_KEY
    - echo $AKTO_TEST_ID
    - node index.js
```

<figure><img src="https://3128331180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ftog5ODwYfqPOf4eQhsOC%2Fuploads%2Fgit-blob-a85088875b6dd585d5e67d5e6018398aeb746d4c%2Fimage%20(74).png?alt=media" alt=""><figcaption></figcaption></figure>

2. Configure GitLab CI/CD Variables
   1. Go to Settings > CI/CD > Variables
   2. Add these variables:
      * `AKTO_API_KEY` (mark as masked and protected)
      * `AKTO_TEST_ID`

<figure><img src="https://3128331180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ftog5ODwYfqPOf4eQhsOC%2Fuploads%2Fgit-blob-158f2eac8048eb20fdd6868b9ee79978c4b6cb3a%2Fimage%20(73)%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

#### 3. Verify Integration

1. Create a merge request
2. Pipeline will automatically run
3. Check "CI/CD > Pipelines" for scan results

<figure><img src="https://3128331180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ftog5ODwYfqPOf4eQhsOC%2Fuploads%2Fgit-blob-2d2fb963d9e2eee148c038ffaf2d76f92be9aafb%2Fimage%20(75).png?alt=media" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Note: Never commit sensitive credentials like API keys directly in your configuration files. Always use GitLab CI/CD variables for sensitive data.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ai-security-docs.akto.io/integrations/ci-cd-integrations/gitlab.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
