Skip to main content

Configure 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 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 include:

  • 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 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: Go agent versions earlier than 6.11.0 do not support the agent token, so if you use one of those versions, the following variables are required:

    CONTRAST__API__URL
    CONTRAST__API__API_KEY
    CONTRAST__API__SERVICE_KEY
    CONTRAST__API__USER_NAME
    

    Current agent versions continue to accept them.

You can also find the agent 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:

If you use the contrast_security.yaml file for configuration, you can set the CONTRAST_CONFIG_PATH environment variable to the full path of the file. If the variable is not set, the Go agent looks for contrast_security.yaml or contrast_security.yml in the following directories, in the order listed, until it finds one:

  • The working directory of the application

  • /etc/contrast/go/

  • /etc/contrast/

  • On macOS: $HOME/Library/Preferences/contrast/ or $HOME/Library/Preferences/contrast/go/

  • On Linux: $XDG_CONFIG_HOME/contrast/ or $XDG_CONFIG_HOME/contrast/go/

    If XDG_CONFIG_HOME is not set: $HOME/.config/contrast/ or $HOME/.config/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