> For the complete documentation index, see [llms.txt](https://docs.sec1.io/user-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sec1.io/user-docs/2-integration-with-sec1/6-ci-cd-integrations/5-gcp-code-build-integration.md).

# GCP Code Build

## Overview

This Code Build step integrates [Sec1](https://sec1.io/) to conduct vulnerability scans on your GitHub projects. Sec1 is a powerful tool that helps identify security vulnerabilities within your codebase.

## Example Workflow

Below is an example of using the Sec1 Security step in your Code Build pipeline. This will run Sec1 Security scan on each execution of the pipeline.

In your repository, create cloudbuild.yaml. Copy below code in cloudbuild.yaml file to add Sec1 Security.

```yaml
steps:
  - name: 'gcr.io/cloud-builders/docker'
    entrypoint: 'bash'
    args:
    - '-c'
    - |
      echo "GCP Cloud Build - Sec1 Security ${REPO_FULL_NAME}"
      docker run -v /workspace:/app/gcp-scan-directory -e INPUT_APIKEY=$$SEC1_API_KEY sec1security/sec1-foss-security:v1
    secretEnv: ['SEC1_API_KEY']
availableSecrets:
  secretManager:
  - versionName: projects/$PROJECT_ID/secrets/SEC1_API_KEY/versions/latest
    env: 'SEC1_API_KEY'
```

### Customizing Scan Thresholds

Sec1 scan supports setting up threshold values. If the scan reports vulnerabilities exceeding the specified thresholds, Sec1 Security will mark the build as failed. You can set threshold values for different severities such as critical, high, medium, and low.

```yaml
steps:
  - name: 'gcr.io/cloud-builders/docker'
    entrypoint: 'bash'
    args:
    - '-c'
    - |
      echo "GCP Cloud Build - Sec1 Security ${REPO_FULL_NAME}"
      docker run -v /workspace:/app/gcp-scan-directory -e INPUT_APIKEY=$$SEC1_API_KEY -e INPUT_SCANTHRESHOLD='critical=0 high=10' sec1security/sec1-foss-security:v1
    secretEnv: ['SEC1_API_KEY']
availableSecrets:
  secretManager:
  - versionName: projects/$PROJECT_ID/secrets/SEC1_API_KEY/versions/latest
    env: 'SEC1_API_KEY'
```

### Obtaining your Sec1 API Key

To use Sec1 in your workflow, you need to obtain an API key. Follow these steps:

1. **Navigate to Sec1 Website:**
   * Visit [Sec1 portal](https://scopy.sec1.io/) and log in using your GitHub credentials.
2. **Generate API Key:**
   * In the "Settings" section, locate the "API key" and click on "Generate API key."
3. **Copy the API Token:**
   * Copy the generated API token.
4. **Add API Key to GCP Secret Manager:**

   * Add the copied API key to your GCP's secret manager. Refer to [Secret Manager documentation](https://cloud.google.com/secret-manager/docs/create-secret-quickstart) for creating secrets.

   * Remember the name of the Secret created in above step. This name will be used against `INPUT_APIKEY` in docker command.

   * Make sure you give accessor permission to the account which is triggering code build pipeline. Refer to [Access control with IAM](https://cloud.google.com/secret-manager/docs/access-control#:~:text=On%20the%20IAM%20page%2C%20next,as%20Secret%20Manager%20Secret%20Accessor.) to give accessor

   > <details>
   >
   > <summary>📷 Show Preview</summary>
   >
   > <img src="/files/DFHgAaOVpsoF1g7wDLK0" alt="Create Secret configuration" data-size="original">
   >
   > </details>
5. **Set API Key Variable in cloudbuild.yaml:**
   * In your Cloud Build config file (e.g., `cloudbuild.yml`), use `availableSecrets` to access the secret you created:

     ```yaml
     availableSecrets:
       secretManager:
       - versionName: projects/$PROJECT_ID/secrets/SEC1_API_KEY/versions/latest
         env: 'SEC1_API_KEY'
     ```

Now, your GCP Code Build pipeline is set up to leverage Sec1 for continuous security checks in your projects.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.sec1.io/user-docs/2-integration-with-sec1/6-ci-cd-integrations/5-gcp-code-build-integration.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
