Skip to main content

Install Go agent in a pipeline

Use the Agent Wizard to install and configure the Go agent in a GitHub or Bitbucket pipeline. Using the wizard is the simplest way to deploy a new agent.

Before you begin a Go agent installation

Make sure you have everything you need before you start.

  • Install Go and build your application with a supported Go version. If you build with an unsupported version, contrast-go stops with an error. See Go supported technologies for the Go agent for the current versions. You also need access to your application’s build environment, because contrast-go instruments the application when you build it.

  • The agent will need to be able to reach your Contrast instance. It can be a local/on-premise instance, or a hosted instance. A proxy can be configured if the environment has limited network access.

  • Understand the agent order of precedence.

  • You will also need access to a command line interface and to your organization's instance of Contrast.

Start the Agent Wizard

To open the Agent Wizard:

  • In Northstar: From the left navigation, select Administration > Agent management, then select Add agent at the top of the view.

  • In Contrast: Use one of the following options:

    • From the header, select Add New, and then select the Application card.

    • From the header, select Administration > Agent Management, and then select Add agent at the top of the view.

Select the Go agent

To select the Go agent in the Agent Wizard:

  1. Under Select an installation method, select Language-specific.

  2. Under Select a language, select Go.

    The Go agent supports Linux and macOS. Windows is not yet supported.

Select the installation method

  1. Under Select application deployment method, select Install in a pipeline.

  2. Under Select method to deploy pipelines, select GitHub or Bitbucket.

Configure the agent

The easiest way to configure the agent is to use the Agent Wizard or the Contrast Agent Configuration Editor.

Using the Agent Wizard:

  1. Under Configure the agent, select the Agent Key you want to use to generate your API keys.

    If only one key exists, it is preselected. See Configure agent keys to learn how to create multiple agent keys.

  2. Optionally, select Register the application to assign it to groups for access control.

    You can also assign tags and metadata to the application.

  3. Select Use Connection Token and copy the displayed value. The agent requires an API token to connect to Contrast, so store the value in a GitHub secret named ContrastAPIToken. The workflow also reads the secrets ContrastApplicationName and ContrastApplicationMetadata, so create those as well or remove the lines you do not need.

Install the agent for GitHub

The Go agent is used by replacing go with contrast-go in the command that builds your application. The contrast-go build command builds an executable with Contrast embedded in it. Command line arguments for Go are also available.Command line arguments for Go

  1. If you use GitHub pipelines, add the following step to your GitHub Action to install the agent:

    - name: Install Agent
      shell: bash
      run: |
        go run github.com/contrast-security-oss/contrast-go-installer@latest latest
  2. Replace go build with contrast-go build in your build step with the following code:

    - name: Build instrumented app
      run: contrast-go build -o output-name-of-application
  3. Add the following code to the step running your application:

    env:
      CONTRAST__API__TOKEN: ${{ secrets.ContrastAPIToken }}
      CONTRAST__APPLICATION__NAME: ${{ secrets.ContrastApplicationName }}
      CONTRAST__APPLICATION__METADATA: ${{ secrets.ContrastApplicationMetadata }}

Install the agent for Bitbucket

  1. If you use Bitbucket Pipelines, add the following step to your pipeline to install the agent:

    - step:
        script:
            - go run github.com/contrast-security-oss/contrast-go-installer@latest latest
  2. Build the application by replacing your normal go build command with contrast-go build. This builds an executable with Contrast embedded in it:

    contrast-go build -o output-name-of-application
  3. Store the API token in a Bitbucket secured variable named CONTRAST__API__TOKEN so the agent can read it from the environment when the application runs.

Verify the agent deployment

Interact with your application as you normally would. For example, interact with your application's web interface or send API commands.

  1. In the Agent Wizard, select View agent activity to verify that your agent appears in the agents list.

  2. Verify that you see the name of your application in the applications list.

    • In Northstar, select Applications from the left navigation.

    • In Contrast, select Applications from the header.

  3. Verify that you see the name of your local server in the servers list.

    • In Northstar, select Servers from the left navigation.

    • In Contrast, select Servers from the header.