Skip to main content
Version: Next (Unreleased)

Managing API keys

Harbor uses API keys for server-side access. Keys are prefixed by environment and can be unrestricted or limited to specific scopes.

Harbor API keys are secret credentials passed as secretKey in the SDK or Authorization: Bearer in REST calls.

Key types

TypePrefixTypical use
Sandbox secrethb_test_Local development and CI against sandbox
Live secrethb_live_Production backends
RestrictedEither prefixServices that need minimal access

Create and revoke keys in the Harbor dashboard under Settings → API keys.

Authenticate with an API key

import { Harbor } from '@harbor/sdk';

const harbor = new Harbor({
secretKey: process.env.HARBOR_SECRET_KEY,
});

The SDK selects sandbox.api.harbor.dev or api.harbor.dev from the key prefix.

Restricted keys and scopes

Assign scopes when a service should not use a full secret:

ScopeGrants
events:readList and retrieve events
events:writeCreate events
webhooks:manageRegister and update webhook endpoints
workspaces:readRead workspace metadata

A worker that only emits events needs events:write, not webhooks:manage.

info

Calls outside the key's scopes return permission_denied. See Common errors.

Rotation

Rotate keys on a schedule or immediately after suspected exposure:

  1. Create a new key with the same scopes in the dashboard.
  2. Update your deployment secrets (HARBOR_SECRET_KEY).
  3. Redeploy or reload configuration.
  4. Revoke the old key after traffic moves over.

Both keys remain valid until you revoke the old one, so you can roll out without downtime.

Separate keys by service

Split credentials so a compromised read worker cannot register webhooks:

ServiceSuggested scopes
Event emitterevents:write
Analytics exporterevents:read
Webhook provisionerwebhooks:manage
Admin toolingUnrestricted (rotate frequently)

Environment variables

VariablePurpose
HARBOR_SECRET_KEYServer-side API authentication
HARBOR_WEBHOOK_SECRETSigning secret for one webhook endpoint

If you run multiple handlers, store each endpoint secret separately (for example, HARBOR_WEBHOOK_SECRET_STAGING and HARBOR_WEBHOOK_SECRET_PROD).

Keep secrets out of git. Use your platform's secret manager in staging and production.

Next steps

See Creating events for scope requirements on write paths. Bearer token format in REST API overview.