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-gostops 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, becausecontrast-goinstruments 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:
Under Select an installation method, select Language-specific.
Under Select a language, select Go.
The Go agent supports Linux and macOS. Windows is not yet supported.
Select the installation method
Under Select application deployment method, select Install in a pipeline.
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:
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.
Optionally, select Register the application to assign it to groups for access control.
You can also assign tags and metadata to the application.
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 secretsContrastApplicationNameandContrastApplicationMetadata, 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.
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 latestReplace
go buildwithcontrast-go buildin your build step with the following code:- name: Build instrumented app run: contrast-go build -o output-name-of-application
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
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 latestBuild 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
Store the API token in a Bitbucket secured variable named
CONTRAST__API__TOKENso 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.
In the Agent Wizard, select View agent activity to verify that your agent appears in the agents list.
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.
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.