Skip to main content

Configure the Go agent

To configure the agent, the recommended method is to specify environment variables. Using environment variables is useful if you are using Contrast in containers or CI/CD pipelines.

You can also specify settings in a YAML file called contrast_security.yaml.

The simplest way to get started is to use the Go Agent wizard in the Contrast web interface. The agent wizard pre-populates environment variables and the YAML file with the required settings for your organization.

Tip

If you set values with environment variables and in the agent YAML file, the agent uses the environment variables, as described in order of precedence.

The variables you can set are:

  • Agent Token: This variable is a base64 encoded JSON object containing the url, api_key, service_key, and user_name configuration settings, allowing you to set them set in a single variable.

  • CONTRAST__API__TOKEN
    

    If your agent configuration refers to both the legacy settings and the agent token, (in environment variables or the YAML file), the legacy settings take precedence. To use just the agent token value, make sure you remove references to the legacy settings.

  • Legacy settings: If you are using a Go agent version earlier than 6.11.0, the required variables are:

    CONTRAST__API__URL
    CONTRAST__API__API_KEY
    CONTRAST__API__SERVICE_KEY
    CONTRAST__API__USER_NAME
    
    
    

You can also find the keys under Organization settings > Agent in the Contrast web interface.

Location of the Go configuration file

If you are using the contrast_security.yaml file for configuration, the Go agent looks for it in the following directories until it finds one:

  • Current directory

  • /etc/contrast/go/

  • /etc/contrast/

  • Darwin:$HOME/Library/Preferences/contrast/

  • Darwin:$HOME/Library/Preferences/contrast/go/

  • Linux:$XDG_CONFIG_DIR/contrast/

  • Linux:$XDG_CONFIG_DIR/contrast/go/

Go YAML template

This template includes all available settings for the Go agent. (Learn more about YAML configuration.)

You can also find the settings and generate a custom configuration file with the Contrast agent configuration editor.

https://docs.contrastsecurity.com/common-agent-config/go_contrast_security.yaml