> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/artifact-registry/3.0/reference/environment-variables.md). Agents can also search and read this documentation through its [MCP server](https://developer.harness.io/~gitbook/mcp).

# Environment variables

Reference for every environment variable used with Harness Artifacts: authentication, CLI, pipeline context, package managers, and Terraform.

Environment variables let you configure Harness Artifacts clients and tooling without hard-coding credentials or account identifiers in scripts. This page lists every variable used across the CLI, package manager clients, CI integrations, and Terraform provider.

## Core authentication variables

These variables authenticate you or a service account to Harness. Set them before running any `hc` CLI command, `docker login`, package manager configuration, or REST API call.

| Variable             | Description                                                                                                                                                                                                        | Required                         |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------- |
| `HARNESS_API_KEY`    | Harness personal access token (PAT) or service account token. Used as the password for all package manager clients (Docker, Helm, npm, Maven, pip, Cargo, NuGet) and as the `x-api-key` header for REST API calls. | Yes                              |
| `HARNESS_ACCOUNT_ID` | Your Harness account identifier. Appears in every registry URL (`pkg.harness.io/pkg/<ACCOUNT_ID>/...`) and in Terraform resource references.                                                                       | Yes                              |
| `HARNESS_EMAIL`      | The email address associated with your Harness account. Used as the username when authenticating Docker, Helm, Maven, pip, and similar clients.                                                                    | Yes (for client auth)            |
| `HARNESS_URL`        | Base URL of the Harness platform. Defaults to `https://app.harness.io` for SaaS; set to your on-prem hostname for self-managed deployments.                                                                        | Yes (for CLI and GitHub Actions) |

**Example: set core auth variables in a shell session**

```bash
export HARNESS_ACCOUNT_ID="<your-account-id>"
export HARNESS_EMAIL="user@example.com"
export HARNESS_API_KEY="<your-pat>"
export HARNESS_URL="https://app.harness.io"
```

**Example: GitHub Actions secrets**

```yaml
- uses: harness/artifacts-action@v1
  with:
    api-url: ${{ secrets.HARNESS_URL }}
    account: ${{ secrets.HARNESS_ACCOUNT_ID }}
    token: ${{ secrets.HARNESS_PAT_TOKEN }}
```

Store `HARNESS_API_KEY` (sometimes named `HARNESS_PAT_TOKEN` in GitHub Actions workflows) as a secret, not as a plain environment variable. Go to [Authentication and identity tokens](https://developer.harness.io/artifact-registry/3.0/concepts/authentication-and-identity-tokens.md) for guidance on token types and scopes.

***

## hc CLI variables

The `hc` CLI reads these variables automatically when they are set. Command-line flags override them when both are present.

| Variable             | CLI flag equivalent | Description                                                       |
| -------------------- | ------------------- | ----------------------------------------------------------------- |
| `HARNESS_API_TOKEN`  | `--api-key`         | API token for all `hc` commands. Equivalent to `HARNESS_API_KEY`. |
| `HARNESS_ACCOUNT_ID` | `--account-id`      | Account identifier.                                               |
| `HARNESS_URL`        | `--url`             | Harness platform base URL.                                        |

{% hint style="info" %}
The CLI accepts both `HARNESS_API_TOKEN` and `HARNESS_API_KEY`. If both are set, `HARNESS_API_TOKEN` takes precedence.
{% endhint %}

Go to [CLI reference](https://developer.harness.io/artifact-registry/3.0/reference/cli.md) for a full list of commands and flags.

***

## Dependency Firewall: pipeline context variables

When `hc` runs inside a Harness CI pipeline, it reads these variables automatically to link the dependency audit to the pipeline execution. The Dependency Firewall uses this context to populate the **Affected Pipelines** view.

| Variable              | Maps to              | Description                                             |
| --------------------- | -------------------- | ------------------------------------------------------- |
| `HARNESS_PIPELINE_ID` | Pipeline identifier  | The pipeline that triggered the build.                  |
| `HARNESS_BUILD_ID`    | Execution identifier | The specific run of the pipeline.                       |
| `HARNESS_STAGE_ID`    | Stage identifier     | The stage inside the pipeline where `hc fw audit` runs. |
| `ORG_IDENTIFIER`      | Organization         | The Harness organization the pipeline belongs to.       |
| `PROJECT_IDENTIFIER`  | Project              | The Harness project the pipeline belongs to.            |

Harness CI injects all five variables automatically. If you run `hc fw audit` outside a Harness CI pipeline (for example, in a local shell or a third-party CI system), set them manually so the firewall report is attributed correctly.

**Example: Jenkins declarative pipeline**

```groovy
environment {
    HARNESS_PIPELINE_ID = "${env.JOB_NAME}"
    HARNESS_BUILD_ID    = "${env.BUILD_NUMBER}"
    HARNESS_STAGE_ID    = "dependency-audit"
    ORG_IDENTIFIER      = "default"
    PROJECT_IDENTIFIER  = "my-project"
}
```

***

## Package manager variables

These variables configure individual package manager clients to route traffic through Harness.

### Go modules

| Variable  | Description                                                                                                            |
| --------- | ---------------------------------------------------------------------------------------------------------------------- |
| `GOPROXY` | Go module proxy URL. Set to your Harness registry Go endpoint to route `go get` and `go mod download` through Harness. |

**Example**:

```bash
export GOPROXY="https://${HARNESS_EMAIL}:${HARNESS_API_KEY}@pkg.harness.io/pkg/${HARNESS_ACCOUNT_ID}/<REGISTRY>/go"
```

### Hugging Face

| Variable                  | Description                                                                                     |
| ------------------------- | ----------------------------------------------------------------------------------------------- |
| `HF_ENDPOINT`             | Overrides the default `huggingface.co` endpoint. Set to your Harness registry Hugging Face URL. |
| `HF_TOKEN`                | Hugging Face authentication token. Set to your Harness identity token (from **Setup Client**).  |
| `HF_HUB_ETAG_TIMEOUT`     | Seconds before the Hub ETag check times out. Increase for large models on slow connections.     |
| `HF_HUB_DOWNLOAD_TIMEOUT` | Seconds before a model download times out. Increase for large files.                            |

**Example**:

```bash
export HF_ENDPOINT="https://pkg.harness.io/pkg/${HARNESS_ACCOUNT_ID}/<REGISTRY>/huggingface"
export HF_TOKEN="<identity-token>"
export HF_HUB_ETAG_TIMEOUT=86400
export HF_HUB_DOWNLOAD_TIMEOUT=86400
```

### Maven plugin

The Harness Maven plugin reads these variables instead of requiring credentials in `~/.m2/settings.xml`.

| Variable              | Description                                                                          | Required         |
| --------------------- | ------------------------------------------------------------------------------------ | ---------------- |
| `DEPLOY_REPO_URL`     | Maven repository URL for `mvn deploy`.                                               | Yes (deploy)     |
| `DEPLOY_USERNAME`     | Username for deployment.                                                             | Yes (deploy)     |
| `DEPLOY_TOKEN`        | Token or password for deployment.                                                    | Yes (deploy)     |
| `DEPLOY_THREAD_COUNT` | Number of threads for parallel artifact upload. Defaults to the number of CPU cores. | No               |
| `RESOLVER_REPO_URL`   | Repository URL for `mvn harness:enforce-resolution`.                                 | Yes (resolution) |
| `RESOLVER_USERNAME`   | Username for resolution.                                                             | Yes (resolution) |
| `RESOLVER_TOKEN`      | Token or password for resolution.                                                    | Yes (resolution) |

**Example**:

```bash
export DEPLOY_REPO_URL="https://pkg.harness.io/pkg/${HARNESS_ACCOUNT_ID}/<REGISTRY>/maven"
export DEPLOY_USERNAME="${HARNESS_EMAIL}"
export DEPLOY_TOKEN="${HARNESS_API_KEY}"
export DEPLOY_THREAD_COUNT=4
```

Go to [Maven client setup](https://developer.harness.io/artifact-registry/3.0/setup/maven.md) for the full plugin configuration.

***

## Migration variables

These variables are referenced in migration configuration files. They follow standard shell-substitution syntax (`${VAR}`) when used in YAML migration configs.

| Variable          | Used in               | Description                                                                                                  |
| ----------------- | --------------------- | ------------------------------------------------------------------------------------------------------------ |
| `HARNESS_TOKEN`   | Migration config YAML | Same as `HARNESS_API_KEY`; some migration tool examples use this alias.                                      |
| `HARNESS_USER`    | Migration config YAML | Same as `HARNESS_EMAIL`; used as the username in migration tool authentication.                              |
| `SOURCE_PASSWORD` | Migration config YAML | The token or password for the source registry (JFrog, ECR, and other source registries) being migrated from. |

**Example migration config fragment**:

```yaml
source:
  url: https://your-artifactory.example.com
  username: "${HARNESS_USER}"
  password: "${SOURCE_PASSWORD}"
destination:
  url: https://pkg.harness.io/pkg/${HARNESS_ACCOUNT_ID}/<REGISTRY>
  username: "${HARNESS_USER}"
  password: "${HARNESS_TOKEN}"
```

Go to [Migrate to Harness Artifacts](https://developer.harness.io/artifact-registry/3.0/get-started/migrate-to-harness-artifacts.md) for step-by-step migration guides.

***

## Terraform provider variables

The Harness Terraform provider reads these `TF_VAR_*` variables automatically when they correspond to declared input variables in your configuration.

| Variable                          | Maps to                              | Description                                                   |
| --------------------------------- | ------------------------------------ | ------------------------------------------------------------- |
| `TF_VAR_harness_platform_api_key` | `harness_platform_api_key` input var | API key passed to the provider's `platform_api_key` argument. |
| `TF_VAR_harness_account_id`       | `harness_account_id` input var       | Account ID passed to the provider's `account_id` argument.    |
| `TF_VAR_space_ref`                | `space_ref` input var                | Registry scope reference (account, org, or project path).     |

**Example: provider configuration using env vars**

```hcl
variable "harness_platform_api_key" {}
variable "harness_account_id" {}

provider "harness" {
  endpoint   = "https://app.harness.io/gateway"
  account_id = var.harness_account_id
  platform_api_key = var.harness_platform_api_key
}
```

```bash
export TF_VAR_harness_account_id="${HARNESS_ACCOUNT_ID}"
export TF_VAR_harness_platform_api_key="${HARNESS_API_KEY}"
terraform apply
```

Go to [Terraform provider reference](https://developer.harness.io/artifact-registry/3.0/reference/terraform-provider.md) for full resource documentation.

***

## Troubleshooting

<details>

<summary>Commands fail with "unauthorized" even though the token looks correct</summary>

Check which variable name the tool expects. Some tools require `HARNESS_API_KEY`; the `hc` CLI also accepts `HARNESS_API_TOKEN`. If both are set, `HARNESS_API_TOKEN` takes precedence. Run `echo $HARNESS_API_KEY` and `echo $HARNESS_API_TOKEN` to confirm one is populated and not accidentally empty.

Also confirm the token has not expired. Go to **My Profile > API Keys** in the Harness UI to check the token's expiry date.

</details>

<details>

<summary>GOPROXY resolves modules from the public proxy instead of Harness</summary>

Go reads `GOPROXY` as a comma-separated list and tries each proxy in order. If `GOPROXY` is not set, Go falls back to `https://proxy.golang.org`. Check the value with `go env GOPROXY`. To force all resolution through Harness and block the public proxy, set `GOPROXY` to your Harness endpoint only (no comma-separated fallback). For private modules that should not be sent to the public proxy or checksum database, set `GOPRIVATE` to your module path prefix. This tells Go to fetch those modules directly and skip checksum validation:

```bash
export GOPRIVATE="github.com/your-org/*"
# Or disable the checksum database entirely for all modules:
export GOSUMDB=off
```

</details>

<details>

<summary>Dependency Firewall shows no pipeline context in the Affected Pipelines view</summary>

The pipeline context variables (`HARNESS_PIPELINE_ID`, `HARNESS_BUILD_ID`, `HARNESS_STAGE_ID`, `ORG_IDENTIFIER`, `PROJECT_IDENTIFIER`) must be set before `hc fw audit` runs. In Harness CI, they are injected automatically. In Jenkins, GitHub Actions, or a local shell, set them manually in the step that runs the audit command.

</details>

<details>

<summary>Terraform apply fails with "account_id: required field is missing"</summary>

The `TF_VAR_*` naming convention requires the variable to be declared in your `.tf` files. If your config uses `var.harness_account_id`, the matching env var is `TF_VAR_harness_account_id`. Check for capitalisation mismatches; Terraform variable names are case-sensitive.

</details>

{% @harness-feedback/feedback %}
