Skip to main content

Contrast CLI

Contrast CLI is a command-line tool, distributed through Homebrew on macOS and Linux, and as an installer on Windows, that signs you in to Contrast, instruments Docker containers with a Contrast agent, and runs a CVE Shield demo for users evaluating the Free tier.

Note

This CLI installs separately from the existing Contrast CLI used by Contrast enterprise customers to scan code and open-source dependencies in static application security testing (SAST).

The Contrast CLI commands help Free tier users who find instrumenting their first application challenging. Enterprise customers can use them too, but they are intended for temporary debugging, troubleshooting, and evaluation. For production rollouts, keep using your usual agent deployment method.

Installing the Contrast CLI does not install, remove, or otherwise affect any instance of the existing Contrast CLI. There is no shared configuration or overlapping commands between them.

Before you begin

Make sure you have everything you need before you start.

  • macOS, Linux, or Windows 11, 64-bit (x64) with a UI and browser

    • On macOS or Linux:

    • On Windows:

      • PowerShell. Command Prompt is not supported.

      • Docker Desktop must run Linux containers (which is its default). Windows containers are not supported. This includes Docker Engine installed directly on Windows, which runs Windows containers.

      • WSL 2 is optional. The Windows CLI works with Docker Desktop whether or not WSL is installed.

  • A Java application (optional if running a demo)

  • A Contrast account and the URL of your Contrast instance

  • A web browser on the same machine for signing in to Contrast

Install the CLI

Install on macOS, Linux, or WSL 2 from Homebrew by running the following command:

brew install contrastsecurity/tap/contrast-cli

In WSL, run the command inside your WSL distribution, not in PowerShell. Do not use the Windows installer.

Install on Windows:

  1. Open PowerShell.

  2. Run the following commands to download the installer, run it, and refresh the PATH so this PowerShell window can find the CLI:

    Invoke-WebRequest https://download.cli.contrastsecurity.com/ContrastCli.msi -OutFile ContrastCli.msi
    Start-Process msiexec.exe -ArgumentList '/i ContrastCli.msi /quiet' -Wait
    $env:Path = [Environment]::GetEnvironmentVariable('Path','User') + ';' + [Environment]::GetEnvironmentVariable('Path','Machine')

Verify the installation

Run the following command to confirm that the CLI installed and to see which version you have:

contrast-cli --version

Sign in to Contrast

After you install the CLI, run the following command to authenticate it with your Contrast account. Replace <Your-Contrast-Instance-URL> with the HTTPS address of your Contrast instance.

contrast-cli configure --url <Your-Contrast-Instance-URL>

For example, if you have signed up for CVE Shield Free, run the following command:

contrast-cli configure --url https://cs004.contrastsecurity.com

Your default browser opens to the Contrast sign-in page. Sign in there. If the browser does not open, copy the sign-in URL that the CLI prints in your terminal and paste it into a browser on the same machine.

In WSL, the CLI opens the sign-in page in your Windows browser. If it doesn’t open, copy the sign-in URL that the CLI prints and paste it into a browser on Windows. You stay signed in when you open a new WSL terminal and after you run wsl --shutdown.

After signing in, close the browser window and return to your terminal window. The CLI stores your sign-in on your machine.

  • On macOS, it uses your login keychain.

  • On Linux, it uses files in ~/.config/contrast-cli/credentials that only your account can read.

  • On Windows, it uses encrypted files in %LOCALAPPDATA%\contrast-cli\credentials. Only your Windows account can decrypt them.

  • In WSL, it uses files in ~/.config/contrast-cli/credentials inside the distribution. This sign-in is separate from any Windows sign-in, so sign in to each one.

You have five minutes to finish signing in. If time runs out, run the command again.

To watch CVE Shield detect a real vulnerability in a sample application, see Demo Contrast CVE Shield.