Skip to main content

Contrast CLI commands

General commands for the CLI are structured as follows:

contrast-cli [global options] [command] [options]

The CLI Commands for CVE Shield and the Contrast Agents use the following structure:

contrast-cli [global options] agent [command] [options]

Use these commands to evaluate protection on infrastructure you don't own, or on short-lived targets, where running contrast-cli agent install isn't practical.

Global options

Global options go before the command name. For example contrast-cli --output json agent install. They are available for every command:

Option

Behavior

--version

Prints the version of the CLI and exits.

--output <text|json>, -o <text|json>

Sets the output format. The default is text. See Output formats for details.

--help

Displays available commands, usage, and options.

Common options

Common options go after the command name:

Option

Behavior

--yes, -y

Skips all confirmation prompts, including multiple file detection, and accepts prefilled answers. Recommended for scripted or unattended installs. Available for configure, demo, and every agent command.

--help

Displays usage and options for the command. Available for every command.

Output formats

By default, the CLI prints results as text. To get results as JSON, set the --output global option to json:

contrast-cli --output json <command>

The command then returns a JSON object with the following structure:

{ "schema_version": "1.0", "command": "<command name>", "status": "ok", "data": {} }

Field

Description

schema_version

The version of the output format. It changes only when the fields in this object change, not when the CLI version changes.

command

The command that ran.

status

ok or error

data

The results of the command.

contrast-cli configure

Signs in to Contrast and fetches your API keys. You only need to run this command once after you install the CLI. You must run this command before running any other CLI commands.

Usage

contrast-cli configure --url <Your-Contrast-Instance-URL> [--yes]

Replace <Your-Contrast-Instance-URL> with the HTTPS address of your Contrast instance. For CVE Shield Free, use https://cs004.contrastsecurity.com.

You will be prompted to provide the --url of your Contrast instance if not provided. Alternatively, you can set the --url to the CONTRAST_URL environment variable.

Options

Option

Behavior

--url <Your-Contrast-Instance-URL>

The HTTPS URL of the Contrast instance to sign in to.

Behavior

  • If no valid sign-in is stored, your default browser opens to the Contrast sign-in page where you can enter your credentials. The CLI also prints the sign-in URL so you can paste it into a browser.

  • After you sign in, the CLI fetches your Contrast API key and service key.

  • Sign-in credentials are stored in your operating system keychain under the service name contrast-cli. They include your access token, your refresh token, the URL of your instance, your API key, your service key, and your user ID.

  • If you are not an existing Contrast customer, you can try CVE Shield for free.

contrast-cli agent install

Instruments a Dockerfile so the CVE Shield agent survives rebuilds, redeploys, and new instances without needing to run these actions repeatedly.

Note

This command updates your pre-built Dockerfiles so a CLI agent attachment stays in place. Without it, an agent attached with enable disappears the next time the container is rebuilt or deleted.

With it, rebuilds, redeploys, and new instances keep the agent, so you don't repeat the setup each time. It's also low commitment, because contrast-cli agent uninstall removes only what install added. Changes take effect when you next rebuild your container.

Usage

contrast-cli agent install [Dockerfile...] [--yes]

Behavior

  • Accepts a path to a Dockerfile, a directory that contains Dockerfiles, or part of a Dockerfile name. In a Git repository, it also finds Dockerfiles in subdirectories and skips files that Git ignores. Outside a Git repository, it checks only the current directory, not its subdirectories, and tells you so.

  • Before it writes anything, the CLI shows the change and asks you to confirm, unless --yes or -y is passed. If you decline, the CLI leaves every file unchanged and exits.

  • If a Dockerfile already has Contrast built in, the CLI skips it and reports it as already instrumented. The CLI also skips and reports a Dockerfile that already sets LD_PRELOAD to something else.

  • Configuration added to the Dockerfile is written with a unique, identifiable marker so it can be cleanly removed later by contrast-cli agent uninstall. Do not modify this marker.

  • The CLI edits only the Dockerfile text. It does not check whether the base image can run the agent.

  • The agent is added to the container after you run your build process to recreate the container with the application.

contrast-cli agent uninstall

Reverses contrast-cli agent install, removing only the configuration that the install command added. This command never touches source images, compose files, or pod specifications.

Usage

contrast-cli agent uninstall [Dockerfile...] [--yes]

Behavior

  • Accepts a path to a Dockerfile, a directory that contains Dockerfiles, or part of a Dockerfile name. If the CLI finds more than one Dockerfile, you are prompted to select one, multiple or all of them.

  • You are prompted for confirmation before anything is removed, unless --yes or -y is passed.

  • After a successful uninstall, the target Dockerfile contains no Contrast agent configuration data. The CLI removes only the lines that install added, and leaves the rest of the file exactly as it was.

  • Changes take effect after the container is rebuilt and redeployed. A container that is already running from the instrumented image stays instrumented until then.

contrast-cli agent enable

Attaches a Contrast CVE Shield agent to an already-running Docker container without rebuilding the container.

Usage

contrast-cli agent enable [container...] [--yes]

Behavior

  • Accepts zero or more running container names. If no container is given, the CLI lists running Docker containers for you to choose from. If a given name matches more than one running container, you are prompted to select one before making any change, unless --yes or -y is passed.

  • You are prompted to confirm before any container is instrumented, unless --yes or -y is passed. The CLI displays the active Docker context as part of that confirmation.

  • Enabling stops the current container and starts a new one with the same settings plus the agent attached. This looks like a restart, but is technically a new container. Files written at runtime in the old container are not preserved, and there will be brief downtime during the switch.

  • The CLI does not edit a Dockerfile or a compose file. If Docker Compose manages the container, the CLI recreates it like any other container, and the agent is gone the next time you run docker compose up for that service.

  • Instrumentation persists across container restarts, but is removed if the container is rebuilt, deleted, or disabled through contrast-cli agent disable.

contrast-cli agent disable

Detaches Contrast from a container that was instrumented with contrast-cli agent enable. This command has no effect on containers instrumented with contrast-cli agent install.

Usage

contrast-cli agent disable [container...] [--yes]

Behavior

  • Accepts zero or more container targets. With none given, the CLI offers only the containers that the enable command previously attached to. If more than one container qualifies, you are prompted to select one or more, unless --yes or -y is passed.

  • Disabling restarts the container with the agent removed, following the same stop-and-recreate mechanism as the contrast-cli agent enable command. Files written at runtime in the old container are not preserved. If the new container cannot be created, the CLI restores the original container and reports the failure.

  • The CLI cannot confirm that the agent unloaded. It reports only that the new container started.

contrast-cli demo

Launches a sample vulnerable application in Docker with a Contrast agent attached, so you can see CVE Shield detect a real vulnerability without instrumenting anything of your own.

Before you run this command, make sure Docker is running and that you have signed in with contrast-cli configure.

Usage

contrast-cli demo [--guided] [--yes]

Options

Option

Outcome

--guided

A manual step-by-step walkthrough of the demo that performs the following actions:

  • Downloads the sample container without an agent attached.

  • Prompts you to attach the agent with contrast-cli agent enable, arming CVE Shield, and running the exploit yourself.

--yes, -y

Skips confirmation prompts.

Behavior

The CLI picks a free port on your machine automatically, defaults to automatic mode, and performs the following actions:

  • Downloads the sample application and its MySQL database images if they are not already on your machine.

  • Starts both containers with a Contrast agent attached to the sample application, and waits for the application to respond, the load. the agent, and arm CVE Shield.

  • Exploits CVE-2021-45046 (a Log4Shell vulnerability) using a built-in payload, waits for CVE Shield to report the exploit, and prints a link to the result in Northstar.

  • Removes the demo containers. Your findings stay in Northstar.

In guided mode, the CLI starts the same containers with no agent attached and removes them when the walkthrough ends.

If you press Ctrl+C at any point, the demo cancels, exits, and removes the demo containers.

See CVE Shield and Review Contrast CVE Shield states documentation to learn more.

contrast-cli sign-out

Revokes your sign-in on the server and removes the stored credentials and keys from your machine. To use the CLI again, run contrast-cli configure.

Usage

contrast-cli sign-out

Behavior

The CLI revokes your refresh token on the server you signed in to, and then removes your stored sign-in credentials and your Contrast keys from your operating system keychain.

Your API key and service key are long-lived and might be in use elsewhere, so sign-out never rotates them. If you need them to stop working, rotate them in Contrast.

contrast-cli help

Displays the same help as --help, and can show help for a specific command.

Usage

contrast-cli help [command]

For example, run the following command to see the help for the agent install command:

contrast-cli help agent install