Use Google Cloud Secret Manager secrets in API tests

Services on Google Cloud usually keep their credentials in Secret Manager. API tests that need the same credentials shouldn't keep a second copy. The Requestarium CLI fetches secrets from Secret Manager when a run starts, with your own Google Cloud sign-in, and makes them {{variables}} for that run.

Point an environment at secrets

Terminal
requestarium env set Staging RQ_GCP_PROJECT orders-staging
requestarium env set Staging RQ_GCP_SECRET_NAME orders-api-key,partner-credentials
VariableMeaning
RQ_GCP_PROJECTProject id. Defaults to GOOGLE_CLOUD_PROJECT, then the project of your credentials file
RQ_GCP_SECRET_NAMESecret names, separated by commas. name@5 pins a version. Leave it out to use every secret of the project

Or for one run: --gcp-project orders-staging --gcp-secret orders-api-key.

Which variables you get

  • A plain secret becomes a variable named after it: orders-api-key → {{orders-api-key}}.
  • A secret whose value is a JSON object gives one variable per key:
partner-credentials
{ "clientId": "orders-test", "clientSecret": "..." }

→ {{clientId}} and {{clientSecret}}.

All of them are masked in the terminal, JSON, JUnit and HTML reports.

Pin versions, or follow the latest

RQ_GCP_SECRET_NAME=orders-api-key@7 always uses version 7. Without a version, the run uses the latest, so a rotated key is picked up by the next run with nothing to change. Pin when you want a test to keep passing against a known credential while a rotation is in progress; follow the latest the rest of the time.

Signing in

The CLI looks for credentials in this order:

  1. a token in GOOGLE_OAUTH_ACCESS_TOKEN;
  2. a service account key or user credentials file in GOOGLE_APPLICATION_CREDENTIALS;
  3. a token from gcloud.

So on your machine:

Terminal
gcloud auth login
requestarium run-collection "Orders API" --env Staging

In GitHub Actions, with no stored key

.github/workflows/api-tests.yml
permissions:
  id-token: write
  contents: read

steps:
  - uses: google-github-actions/auth@v2
    with:
      workload_identity_provider: projects/123456789/locations/global/workloadIdentityPools/github/providers/repo
      service_account: [email protected]
  - uses: google-github-actions/setup-gcloud@v2
  - uses: actions/setup-node@v4
    with:
      node-version: 22
  - run: npm install -g @requestarium/cli
  - env:
      REQUESTARIUM_TOKEN: ${{ secrets.REQUESTARIUM_TOKEN }}
    run: requestarium run-collection "Orders API" --env Staging --junit results.xml

Workload identity federation means no service account key is stored in GitHub at all.

Permissions

The identity needs Secret Manager Secret Accessor on the secrets it reads. Using every secret of a project (no RQ_GCP_SECRET_NAME) also needs permission to list them, such as Secret Manager Viewer. Naming the secrets is usually better: the role can be granted on just those secrets.