Skip to main content

Install Node.js agent on VMware Tanzu

You can access a variety of VMware Tanzu (formerly Pivotal Cloud Foundry) integrations for your applications using the default Node.js buildpack.

To use the buildpack on its own as a low-level integration, you can create a user-provided service and bind it to your application. With the service broker, you can define multiple service plans and generate service instances you can bind to your applications.

Use the Contrast service broker tile to automate the BOSH deployment and configuration of the Contrast service broker. Configure the agent through the Contrast service broker tile provided with the integration, or use automatic configuration through user-provided services.

Buildpacks

To install the Node.js agent in a VMware Tanzu environment, your application must use one of these Cloud Foundry buildpacks:

Use version 1.6.52 or later for a service from the Contrast service broker, and version 1.6.56 or later for a user-provided service. Every current release includes the hook. If you use a custom buildpack, it must include the Contrast hook. Without the hook, set the Contrast environment variables on your application yourself.

The buildpacks include a Contrast hook. While your application is staged, the hook looks for a bound Contrast service in VCAP_SERVICES. If it finds one, it writes the connection settings to a .profile.d script so that they are set as environment variables when the application starts.

The hook does not download the agent and does not change how your application starts, so you install the agent and start your application with it.

Install the agent

  1. To install the agent, add @contrast/agent to the dependencies in your package.json, and start your application with the agent as described in Install Node.js agent manually. For example, set the start script like this:

    "start": "node --import @contrast/agent app.js"
  2. You can also set the NODE_OPTIONS environment variable on the application to --import @contrast/agent and restage it. The agent skips the npm process that the buildpack uses to start the application and instruments the Node.js process it starts.

Configuration

While the application is staged, the hook reads VCAP_SERVICES. A service counts as a Contrast service when its group name, service name, label or any of its tags contains contrast-security. The hook uses the credentials of the first matching service, so bind only one Contrast service to an application.

The credentials of the service must contain these keys: teamserver_url, username, api_key, and service_key. The hook sets these environment variables from them, CONTRAST__API__URL, CONTRAST__API__USER_NAME, CONTRAST__API__API_KEY and CONTRAST__API__SERVICE_KEY. The hook sets no other Contrast settings, so set the application name, the server name, and any other settings as environment variables or in a configuration file.

The following example creates a user-provided service and binds it to an application:

cf create-user-provided-service contrast-security-service -p "teamserver_url, username, api_key, service_key
"cf bind-service my-node-app contrast-security-service
cf restage my-node-app

Note

The teamserver_url should be only the protocol and host name. The hook adds /Contrast/ itself, so do not include /Contrast/ or /Contrast/api.

See also

Add Contrast service broker tile for VMware Tanzu

Add Contrast service broker for VMware Tanzu to use the service broker without the tile.