Aller au contenu

Use service tokens in CI and on servers

A service token lets a machine, such as a CI job, a server or a container, read one environment of one project without a personal login. Tokens are read only or read and write, they expire, and you can revoke them at any time. The CLI and a small HTTP API accept them.

Mis à jour le

Cette page n’est disponible qu’en anglais pour le moment.

Create a token

  1. Open the project, then project settings and Service tokens, and choose New token.
  2. Give it a Name, pick the Environment, the Access (Read only or Read & write) and when it Expires after (7, 30 or 90 days, 1 year, or never; 90 days by default).
  3. Choose Create token and copy it from Copy your service token. It starts with pe_st_ and is shown only once: ProductEnv keeps only a hash.
  4. Store it in your CI's secret store, for example as PRODUCTENV_SERVICE_TOKEN (the name the dashboard's snippet uses).
  • You need the Manage service tokens permission. A Read & write token also needs Edit secrets.
  • A protected environment needs Reveal protected values, and its tokens are always read only: changes there go through change requests.
  • Tokens can't target the Shared app's environments: a token for an app's environment already includes its Shared keys.
  • The Free plan includes 3 active tokens per project; Team and Business have no limit.

Use it with the CLI

The CLI reads a token from PRODUCTENV_SERVICE_TOKEN (or PRODUCTENV_TOKEN) before any saved login, so CI needs no productenv login. Commands that read the token's environment, such as pull, run and export, work with any token; writing with push needs a Read & write token. Options that span several environments, such as --all, need a personal login.

GitHub Actions
# .github/workflows/deploy.yml
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: actions/setup-node@v5
        with:
          node-version: 22

      # .productenv.json is committed, so only the environment is needed.
      - name: Fetch production secrets
        run: npx productenv pull --env production --output .env --force
        env:
          PRODUCTENV_SERVICE_TOKEN: ${{ secrets.PRODUCTENV_SERVICE_TOKEN }}

      - run: npm ci
      - run: npm run build

Prefer npx productenv run -- <command> when the process can read its environment directly: the values never touch the disk. To push values into GitHub Actions secrets instead, see GitHub Actions sync.

Use it over HTTP

Service tokens also work without the CLI. Send the token in the x-api-key header:

curl
# Read the environment as a .env file (or ?format=json)
curl -sS "https://api.product-env.com/v1/cli/service/secrets?format=dotenv" \
  -H "x-api-key: $PRODUCTENV_SERVICE_TOKEN"

# Check what the token can reach
curl -sS "https://api.product-env.com/v1/cli/service/whoami" \
  -H "x-api-key: $PRODUCTENV_SERVICE_TOKEN"
Endpoints a service token can call
EndpointWhat it does
GET /v1/cli/service/whoamiThe token's project, environment and access
GET /v1/cli/service/secrets?format=dotenvThe environment's values (format=json and the config formats work too)
PUT /v1/cli/service/secretsWrites values (Read & write tokens only)

The base URL is https://api.product-env.com/v1. Requests are limited to 200 per minute per IP address; over it, the API answers 429 with a Retry-After header. These are the only API routes meant for scripts: ProductEnv has no general public REST API yet.

Watch and revoke tokens

  • The token list shows Last used with the time and IP address, or Never used. Each use is also recorded in the project's audit log.
  • Revoke stops a token immediately; anything using it fails on its next request. Revoked and expired tokens are deleted 30 days later.
  • Your organization's IP address rules apply to service tokens too (see security).

Questions fréquentes

Which environment variable should CI use for the token?

PRODUCTENV_SERVICE_TOKEN, the name the dashboard's snippet uses. The CLI also reads PRODUCTENV_TOKEN, which wins when both are set. Avoid the --token flag, which can end up in shell history and logs.

Can one service token read several environments?

No. A token reaches exactly one environment of one project, which keeps a leaked token's reach small. Create one token per environment your pipeline needs.

Does ProductEnv have a public REST API?

Not a general one yet. Scripts can read and write an environment's values with a service token through the endpoints on this page; everything else goes through the dashboard, the CLI and the VS Code extension.