> ## Documentation Index
> Fetch the complete documentation index at: https://docs.endorlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Scanning with GitHub Actions

> Learn how to implement Endor Labs in GitHub action workflows.

GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline.
You can use GitHub Actions to include Endor Labs in your CI pipeline.

Using this pipeline, developers can view and detect:

* Policy violations in the source code
* Secrets inadvertently included in the source code

The Endor Labs verifications are conducted as automated checks and help you discover violations before pushing code to the repository. Information about the violations can be included as comments on the corresponding pull request (PR). This enables developers to easily identify issues and take remedial measures early in the development life cycle.

* For policy violations, the workflow is designed to either emit a warning or return an error based on your action policy configurations.
* For secrets discovered in the commits, developers can view the PR comments and take necessary remedial measures.

## Install Software Prerequisites

To ensure the successful execution of the Endor Labs GitHub action, the following prerequisites must be met:

* The GitHub action must be able to authenticate with the Endor Labs API.
* You must have the value of the Endor Labs namespace handy for authentication.
* You must have access to the Endor Labs API.
* If you use keyless authentication, you must set an authorization policy in Endor Labs. See [Authorization policies](https://docs.endorlabs.com/platform-administration/rbac/authorization-policies.md) for details.

## Secure GitHub Actions with immutable commit SHA

Endor Labs recommends pinning the commit SHA of the GitHub Actions to enhance security. By pinning GitHub Actions to a commit SHA, you make the code immutable even if the tag version is changed or the code is updated.

🛡️

Latest GitHub Action Release

Pin to an immutable commit SHA for enhanced security.

To manually find the Endor Labs GitHub action's latest commit SHA:

1. Go to [Endor Labs GitHub Actions](https://github.com/endorlabs/github-action) and select the latest release version in **Releases**.
2. Click the commit of the release.

   ![Select commit SHA of latest release](https://mintcdn.com/endorlabs-b4795f4f/266r_aE9BWR2B51C/images/setup-deployment/ci-cd/github-action-pin-commit-sha.webp?fit=max\&auto=format\&n=266r_aE9BWR2B51C\&q=85\&s=df3236e1f4de50139982cae07e862b29)
3. Copy the commit SHA from the URL.

   The commit SHA is the 40-character alphanumeric string in the URL after `/commit/`.

   ![Copy commit SHA](https://mintcdn.com/endorlabs-b4795f4f/266r_aE9BWR2B51C/images/setup-deployment/ci-cd/github-action-copy-commit-sha.webp?fit=max\&auto=format\&n=266r_aE9BWR2B51C\&q=85\&s=cc1d3b48266370066f11aca515c2e65f)

## Example GitHub Action Workflow

Endor Labs scanning workflow using GitHub Actions that accomplishes the following tasks in your CI environment:

* Tests PRs to the default branch and monitors the most recent push to the default branch.
* Builds a Java project and sets up the Java build tools. If your project is not on Java, then configure this workflow with your project-specific steps and build tools.
* Authenticates to Endor Labs with GitHub Actions keyless authentication.
* Scan with Endor Labs.
* Comments on PRs if any policy violations occur.
* Generates findings and uploads results to GitHub in SARIF format.

The following example workflow shows how to scan with Endor Labs for a Java application using the recommended keyless authentication for GitHub Actions.

> [!NOTE]
>
> The examples pin the Endor Labs GitHub Action to release `v1.1.12`. To use a newer release, copy the **Use in your workflow** reference from **Latest GitHub Action Release** in [Secure GitHub Actions with immutable commit SHA](https://docs.endorlabs.com/setup-deployment/ci-cd/scan-with-github-actions.md#secure-github-actions-with-immutable-commit-sha).

```yaml expandable theme={null}
name: Endor Labs Dependency and Secrets Scan
on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]
jobs:
  scan:
    permissions:
      security-events: write # Used to upload Sarif artifact to GitHub
      contents: read # Used to check out a private repository
      actions: read # Required for private repositories to upload Sarif files. GitHub Advanced Security licenses are required.
      id-token: write # Used for keyless authentication with Endor Labs
      pull-requests: write # Required to automatically comment on PRs for new policy violations
      issues: write # Required to comment on PRs for new policy violations
    runs-on: ubuntu-latest
    steps:
    - name: Checkout Repository
      uses: actions/checkout@v3
    - name: Setup Java
      uses: actions/setup-java@v3
      with:
        distribution: 'microsoft'
        java-version: '17'
    - name: Build Package
      run: mvn clean install
    - name: Endor Labs Scan Pull Request
      if: github.event_name == 'pull_request'
      uses: endorlabs/github-action@b8992820cc4d9c9e7ded5022adf6cabe2dc11946 # v1.1.12
      with:
        namespace: 'example' # Replace with your Endor Labs tenant namespace
        scan_dependencies: true
        scan_secrets: true
        pr: true
        pr_incremental: true # Scans only files and dependencies that changed, for faster PR scans
        enable_pr_comments: true # Required to automatically comment on PRs for new policy violations
        github_token: ${{ secrets.GITHUB_TOKEN }} # Required for PR comments on new policy violations

  scan-main:
    permissions:
      id-token: write
      repository-projects: read
      pull-requests: read
      contents: read
    name: endorctl-scan
    runs-on: ubuntu-latest
    steps:
    - name: Checkout Repository
      uses: actions/checkout@v3
    - name: Setup Java
      uses: actions/setup-java@v3
      with:
        distribution: 'microsoft'
        java-version: '17'
    - name: Build Package
      run: mvn clean install
    - name: 'Endor Labs Scan Push to main'
      if: ${{ github.event_name == 'push' }}
      uses: endorlabs/github-action@b8992820cc4d9c9e7ded5022adf6cabe2dc11946 # v1.1.12
      with:
        namespace: 'example' # Replace with your Endor Labs tenant namespace
        scan_dependencies: true
        scan_secrets: true
        pr: false
        scan_summary_output_type: 'table'
        sarif_file: 'findings.sarif'
    - name: Upload findings to github
      uses: github/codeql-action/upload-sarif@v3
      with:
        sarif_file: 'findings.sarif'
```

> [!NOTE]
>
> A policy violation makes the scan exit with a non-zero code, which fails the job. Failing the job does not block a merge on its own. To block pull requests, mark the scan job as a required status check in GitHub. See [Block pull requests on findings](https://docs.endorlabs.com/scan/pr-scans/block-pull-requests.md).

To speed up PR scans further, set `additional_args: '--quick-scan'`. A quick scan skips call graph generation, so findings do not include reachability information.

## Set up branch tracking in GitHub Actions

In Git, a detached HEAD state occurs when the repository checks out a specific commit instead of a branch reference. In this state, Git points the HEAD directly to a commit hash, without associating it with a named branch. As a result, actions performed, such as creating new commits or running automated scans, do not carry branch identity unless explicitly specified.

Proper branch context enables Endor Labs to:

* Associate scans with the correct branch
* Identify scans on the monitored default branch
* Track findings and display metrics accurately across branches

Without proper branch configuration, Endor Labs may create multiple branch entries for the same logical branch, leading to fragmented reporting and inaccurate metrics.

![Project with multiple branch entries](https://mintcdn.com/endorlabs-b4795f4f/266r_aE9BWR2B51C/images/setup-deployment/ci-cd/branch-fragmentation.webp?fit=max\&auto=format\&n=266r_aE9BWR2B51C\&q=85\&s=da0b5af516eb674f7a243de8d5ce3a73)

GitHub Actions typically maintains proper branch context automatically. However, to ensure scans are properly tracked, when using the Endor Labs GitHub Action, set `pr: false` to create monitored versions that appear on dashboards. Use `if: github.event_name == 'push'` to trigger only on pushes to the default branch:

```yaml theme={null}
- name: Endor Labs Scan Push to main
  if: github.event_name == 'push'
  uses: endorlabs/github-action@b8992820cc4d9c9e7ded5022adf6cabe2dc11946 # v1.1.12
  with:
    namespace: 'example'
    scan_dependencies: true
    pr: false
```

## Scan containers with OS reachability

You can use the Endor Labs GitHub Action to scan container images with [OS reachability](https://docs.endorlabs.com/scan/containers/container-reachability.md) enabled. Container reachability identifies which packages inside a container image are actually used at runtime, helping you prioritize the most critical vulnerabilities for remediation. Set `scan_container: true` and `os_reachability: true` to enable container scanning with reachability analysis:

```yaml theme={null}
    - name: Scan container with OS reachability
      uses: endorlabs/github-action@b8992820cc4d9c9e7ded5022adf6cabe2dc11946 # v1.1.12
      with:
        namespace: 'example'
        enable_github_action_token: 'true'
        scan_container: true
        scan_dependencies: false
        image: "nginx:latest"
        os_reachability: true
        pr: false
        project_name: 'my-project'
```

## Authenticate with Endor Labs

Endor Labs recommends using keyless authentication in CI environments. Keyless authentication is more secure and reduces the cost of secret rotation. To set up keyless authentication see [Keyless Authentication](https://docs.endorlabs.com/setup-deployment/ci-cd/keyless-authentication.md).

If you choose not to use keyless authentication, you can configure an API key and secret in GitHub for authentication as outlined in [Managing API keys](https://docs.endorlabs.com/platform-administration/api-keys.md).

### Authentication Without Keyless Authentication for GitHub

If you are not using keyless authentication for GitHub Actions, you must not provide `id-token: write` permissions to your GitHub token unless specifically required by a step in this job. You must also set `enable_github_action_token: false` in your Endor Labs GitHub Action configuration.

The following example configuration uses the Endor Labs API key for authentication:

```yaml theme={null}
      - name: Scan with Endor Labs
        uses: endorlabs/github-action@b8992820cc4d9c9e7ded5022adf6cabe2dc11946 # v1.1.12
        with:
          namespace: 'example'
          api_key: ${{ secrets.ENDOR_API_CREDENTIALS_KEY }}
          api_secret: ${{ secrets.ENDOR_API_CREDENTIALS_SECRET }}
          enable_github_action_token: false
```

The following example configuration uses a GCP service account for keyless authentication to Endor Labs:

```yaml theme={null}
      - name: Scan with Endor Labs
        uses: endorlabs/github-action@b8992820cc4d9c9e7ded5022adf6cabe2dc11946 # v1.1.12
        with:
          namespace: 'example'
          gcp_service_account: '<Insert_Your_Service_Account>@<Insert_Your_Project>.iam.gserviceaccount.com'
          enable_github_action_token: false
```

## Configure for the EU cluster

If you're an EU tenant, set the `ENDOR_API` environment variable to `https://api.eu.endorlabs.com` in your workflow and use an API key generated from your EU tenant at `https://app.eu.endorlabs.com`.

Add an `env` block at the job level to apply the EU endpoint to all steps in the job:

```yaml theme={null}
jobs:
  scan:
    runs-on: ubuntu-latest
    env:
      ENDOR_API: https://api.eu.endorlabs.com
    steps:
    - name: Checkout Repository
      uses: actions/checkout@v3
    - name: Scan with Endor Labs
      uses: endorlabs/github-action@b8992820cc4d9c9e7ded5022adf6cabe2dc11946 # v1.1.12
      with:
        namespace: '<your-eu-namespace>'
        api_key: ${{ secrets.ENDOR_API_CREDENTIALS_KEY }}
        api_secret: ${{ secrets.ENDOR_API_CREDENTIALS_SECRET }}
        enable_github_action_token: false
        scan_dependencies: true
        scan_secrets: true
        pr: false
```

> [!NOTE]
>
> Store your EU API credentials as secrets in your GitHub repository (for example, `ENDOR_API_CREDENTIALS_KEY` and `ENDOR_API_CREDENTIALS_SECRET`) and generate them from your EU tenant at `https://app.eu.endorlabs.com`.

## Endor Labs GitHub Action Configuration Parameters

The following input configuration parameters are supported for the Endor Labs GitHub Action:

### Common parameters

Endor Labs GitHub Actions supports the following input global parameters:




&#x20; \- Flags: \`api\`
&#x20; Description: Set the Endor Labs API to use. If you are using a EU tenant, use \`https\://api.eu.endorlabs.com\`. (Default: \`https\://api.endorlabs.com\`)

&#x20; \- Flags: \`api\_key\`
&#x20; Description: Set the API key used to authenticate with Endor Labs.

&#x20; \- Flags: \`api\_secret\`
&#x20; Description: Set the secret corresponding to the API key used to authenticate with Endor Labs.

&#x20; \- Flags: \`enable\_github\_action\_token\`
&#x20; Description: Set to \`false\` if you prefer to use another form of authentication over GitHub action OIDC tokens. (Default: \`true\`)

&#x20; \- Flags: \`endorctl\_checksum\`
&#x20; Description: Set to the checksum associated with a pinned version of endorctl.

&#x20; \- Flags: \`endorctl\_version\`
&#x20; Description: Set to a version of endorctl to pin this specific version for use. Defaults to the latest version.

&#x20; \- Flags: \`gcp\_service\_account\`
&#x20; Description: Set the target service account for GCP based authentication. GCP authentication is only enabled if this flag is set. Cannot be used with \`api\_key\`.

&#x20; \- Flags: \`log\_level\`
&#x20; Description: Set the log level. (Default: \`info\`)

&#x20; \- Flags: \`log\_verbose\`
&#x20; Description: Set to \`true\` to enable verbose logging. (Default: \`false\`)

&#x20; \- Flags: \`namespace\`
&#x20; Description: Set to the namespace of the project that you are working with. (Required)


&#x20;&#x20;

### Scanning parameters

The following input parameters are also supported for the Endor Labs GitHub Action when used for scanning:




&#x20; \- Flags: \`additional\_args\`
&#x20; Description: Use \`additional\_args\` with \`endorctl scan\` for advanced scenarios. However, no example use case currently exists as standard options suffice for typical needs.

&#x20; \- Flags: \`use\_bazel\`
&#x20; Description: Set to \`true\` to enable the usage of Bazel for the scan. Required for the other \`bazel\_\*\` inputs to take effect. (Default: \`false\`)

&#x20; \- Flags: \`bazel\_exclude\_targets\`
&#x20; Description: Specify a comma-separated list of Bazel targets to exclude from the targets that \`bazel\_targets\_query\` selects, or from the default query if it is not set. Targets must be explicit labels such as \`//foo:bar\`, not patterns such as \`//...\`, \`:all\`, or \`:\*\`. Cannot be set together with \`bazel\_include\_targets\`. Ignored unless \`use\_bazel\` is \`true\`.

&#x20; \- Flags: \`bazel\_include\_targets\`
&#x20; Description: Specify a comma-separated list of Bazel targets to scan. Targets must be explicit labels such as \`//foo:bar\`, not patterns such as \`//...\`, \`:all\`, or \`:\*\`. If not set, \`bazel\_targets\_query\` determines which targets to scan. Cannot be set together with \`bazel\_exclude\_targets\` or \`bazel\_targets\_query\`. Ignored unless \`use\_bazel\` is \`true\`.

&#x20; \- Flags: \`bazel\_targets\_query\`
&#x20; Description: Specify a Bazel query to determine which Bazel targets to scan. If not set, the default query selects \`py\_binary\` and \`java\_binary\` targets. Cannot be set together with \`bazel\_include\_targets\`. Ignored unless \`use\_bazel\` is \`true\`.

&#x20; \- Flags: \`pr\`
&#x20; Description: Set to \`false\` to track this scan as a monitored version within Endor Labs, as opposed to a point-in-time policy and finding test for a PR. (Default: \`true\`)

&#x20; \- Flags: \`enable\_pr\_comments\`
&#x20; Description: Set to \`true\` to publish new findings as review comments. Requires \`pr\` and \`github\_token\`. Additionally, the \`issues: write\` and \`pull-requests: write\` permissions must be set in the workflow. (Default: \`false\`)

&#x20; \- Flags: \`pr\_incremental\`
&#x20; Description: Set to \`true\` to scan only files and packages whose dependencies changed compared to the baseline scan. Requires a pull request ID or \`pr\_baseline\`. (Default: \`false\`)

&#x20; \- Flags: \`pr\_baseline\`
&#x20; Description: Set to the Git reference that you are merging to, such as the default branch. Enables endorctl to compare findings, so developers are only alerted to issues in the current changeset. Example: \`pr\_baseline: "main"\`. Note: Not needed if \`enable\_pr\_comments\` is set to \`true\`, except for AI SAST PR scans.

&#x20; \- Flags: \`github\_token\`
&#x20; Description: Set the token used to authenticate with GitHub. Mandatory if \`enable\_pr\_comments\` is set to \`true\`

&#x20; \- Flags: \`run\_stats\`
&#x20; Description: Set to \`true\` to report CPU/RAM/time scan statistics via \`time -v\`. Not supported on Windows runners. (Default: \`false\`)

&#x20; \- Flags: \`phantom\_dependencies\`
&#x20; Description: Set to \`true\` to enable phantom dependency analysis. (Default: \`false\`)

&#x20; \- Flags: \`project\_name\`
&#x20; Description: Specify a project name for a container image scan or a package scan.

&#x20; \- Flags: \`image\`
&#x20; Description: Specify a container image to scan.

&#x20; \- Flags: \`image\_tar\`
&#x20; Description: Specify a container image tar file to scan, as an alternative to \`image\`.

&#x20; \- Flags: \`as\_ref\`
&#x20; Description: Set to \`true\` to keep the container scan as a version of the project. (Default: \`false\`)

&#x20; \- Flags: \`project\_tags\`
&#x20; Description: Specify a comma-separated list of user-defined tags to add to the container scan project.

&#x20; \- Flags: \`container\_scan\_path\`
&#x20; Description: Set the path to a valid Git repository for container scan context. (Default: \`.\`)

&#x20; \- Flags: \`profiling\_data\_dir\`
&#x20; Description: Add a directory containing profiling data to include in the container scan. See \[Container reachability]\(/scan/containers/container-reachability) to learn more.

&#x20; \- Flags: \`tags\`
&#x20; Description: Specify a list of user-defined tags to add to this scan. You can use tags to search and filter scans later.

&#x20; \- Flags: \`scan\_dependencies\`
&#x20; Description: Scan Git commits and generate findings for all dependencies. (Default: \`true\`)

&#x20; \- Flags: \`scan\_git\_logs\`
&#x20; Description: Perform a more complete and detailed scan of secrets in the repository history. Must be used together with \`scan\_secrets\`. (Default: \`false\`)

&#x20; \- Flags: \`scan\_github\_actions\`
&#x20; Description: Scan source code repository for GitHub Actions used in workflow files to analyze vulnerabilities and malware. (Default: \`false\`)

&#x20; \- Flags: \`scan\_path\`
&#x20; Description: Set the path of the directory to scan. (Default: \`.\`)

&#x20; \- Flags: \`scan\_secrets\`
&#x20; Description: Scan the source code repository and generate findings for secrets. See also \`scan\_git\_logs\`. (Default: \`false\`)

&#x20; \- Flags: \`scan\_tools\`
&#x20; Description: Scan source code repository for CI/CD tools. (Default: \`false\`)

&#x20; \- Flags: \`scan\_package\`
&#x20; Description: Scan a specified artifact or a package. Set the path to an artifact with \`scan\_path\`. (Default: \`false\`)

&#x20; \- Flags: \`scan\_container\`
&#x20; Description: Scan a specified container image. The image must be set with \`image\` and a project can be defined with \`project\_name\`. (Default: \`false\`)

&#x20; \- Flags: \`os\_reachability\`
&#x20; Description: Enable OS reachability analysis for container image scans. When set to \`true\`, Endor Labs profiles the container at runtime to determine which OS packages are actually used, helping prioritize vulnerability remediation. Must be used with \`scan\_container\`. (Default: \`false\`)

&#x20; \- Flags: \`scan\_sast\`
&#x20; Description: Scan the source code repository and generate findings for SAST. (Default: \`false\`)

&#x20; \- Flags: \`scan\_ai\_sast\`
&#x20; Description: Scan the source code repository and generate findings for AI SAST. AI SAST PR scans need the pull request ID and \`pr\_baseline\`. The action passes the pull request ID only when \`enable\_pr\_comments\` is \`true\`. Set \`pr\_baseline\` to the target branch, such as \`main\`. To run AI SAST PR scans without PR comments, also set \`additional\_args: '--scm-pr-id=\$\{\{ github.event.pull\_request.number }}'\`. (Default: \`false\`)

&#x20; \- Flags: \`scan\_ai\_models\`
&#x20; Description: Scan the source code repository for AI models. (Default: \`false\`)

&#x20; \- Flags: \`disable\_code\_snippet\_storage\`
&#x20; Description: Disable code snippet storage for SAST scans. (Default: \`false\`)

&#x20; \- Flags: \`scan\_summary\_output\_type\`
&#x20; Description: Set the desired output format to \`table\`, \`json\`, \`yaml\`, or \`summary\`. (Default: \`json\`)

&#x20; \- Flags: \`sarif\_file\`
&#x20; Description: Set to a path on your GitHub runner to store the analysis results in SARIF format.

&#x20; \- Flags: \`export\_scan\_result\_artifact\`
&#x20; Description: Set to \`false\` to disable the json scan result artifact export. (Default: \`true\`)

&#x20; \- Flags: \`output\_file\`
&#x20; Description: Set a file to save the scan results. Use this instead of \`export\_scan\_result\_artifact\` to save any scan results data to a file in the workspace for processing by others steps in the same job, instead of the workflow run log.


&#x20;&#x20;

### Environmental variables

You can use the following environmental variable for the Endor Labs GitHub Action:




&#x20; \- Flags: \`ENDOR\_JS\_ENABLE\_TSSERVER\`
&#x20; Description: Set to \`false\` to skip installing \`tsserver\` when function reachability analysis is not required for JavaScript/TypeScript projects.


&#x20;&#x20;

### Artifact scanning parameters

Use the following parameters and the latest sign action to build artifact signing through Endor Labs GitHub Actions.

The optional parameters are required only if `enable_github_action_token` in [common parameters](#common-parameters) is `false`. If `true` (default value), GitHub automatically populates the optional and other parameters as token claims and sends them to Endor Labs.




&#x20; \- Flags: \`artifact\_name\`
&#x20; Required: Mandatory
&#x20; Description: Set to the name of the artifact to be signed.

&#x20; \- Flags: \`source\_repository\_ref\`
&#x20; Required: Optional
&#x20; Description: Set to the repository reference on which the build run was based. For example, \`ref/tags/v1.0.1\`.

&#x20; \- Flags: \`certificate\_oidc\_issuer\`
&#x20; Required: Optional
&#x20; Description: Set to the OIDC issuer of the token expected in the certificate. For example, \`https\://token.actions.githubusercontent.com\`.


&#x20;&#x20;

### Artifact verifying parameters

Use the following verification parameters and the latest verify action to build artifact verification through Endor Labs GitHub Actions.




&#x20; \- Flags: \`artifact\_name\`
&#x20; Required: Mandatory
&#x20; Description: Set to the name of the artifact to be verified.

&#x20; \- Flags: \`certificate\_oidc\_issuer\`
&#x20; Required: Mandatory
&#x20; Description: Set to the OIDC issuer of the token expected in the certificate. For example, \`https\://token.actions.githubusercontent.com\`.


&#x20;&#x20;


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.