Skip to content
Browse documentation

Workload identity

Google Cloud workloads

Use a Google service account to access one Bulgur environment from Cloud Run.

Before you start

Use Bulgur CLI or Node SDK 1.3.0 or newer, a Bulgur Cloud project and workload identity policy, and a Cloud Run service using a dedicated service account. Google tokens have been verified against a local Bulgur API; hosted Bulgur Cloud has not been tested end to end.

Choose a service account

Use a dedicated user-managed service account for the workload and configure it as the Cloud Run service identity. Find its immutable numeric unique ID with the following command; the email is only used to look up the ID.

shell
gcloud iam service-accounts describe SERVICE_ACCOUNT_EMAIL --format='value(uniqueId)'

Any workload that can use or impersonate this service account can authenticate. The policy does not pin a Cloud Run service, project, or environment based on names or environment variables. Limit who can use or impersonate the account.

Create a Bulgur identity

In organization settings, create a Google Cloud workload identity using the numeric service account unique ID. Select one Bulgur project and one non-Shared environment. Its inherited Shared values are included. Bulgur verifies the Google-signed token and the service account ID; the email and environment variables are not identity proof.

Run on Cloud Run

Use Bulgur CLI 1.3.0 or newer for the container architecture. If building from source, build inside a Linux image or cross-compile; run it with the configured service account on Cloud Run. The fixed metadata endpoint provides a Google ID token for https://api.bulgur.dev.

shell
cd bulgur-cli
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bulgur .
# On Cloud Run:
export BULGUR_AUTH=gcp-oidc
export BULGUR_IDENTITY_ID="YOUR_IDENTITY_ID"
./bulgur run -- ./start.sh

Choose the architecture used by your container. Google metadata is unavailable on a normal local machine.

Use the Node SDK

The server-side SDK requires Bulgur 1.3.0 or newer and Node.js 18 or newer; install it with npm install bulgur@^1.3.0. It has no Google SDK dependency. loadValues returns a request-local object without changing process.env; omit a DSN to use the policy-bound target.

js
const { loadValues } = require("bulgur");

async function main() {
  const secrets = await loadValues({
    auth: "gcp-oidc",
    identityId: "YOUR_IDENTITY_ID",
  });
  // Use secrets in your application.
}

main().catch(() => {
  console.error("Could not load secrets");
  process.exitCode = 1;
});

The SDK requests a Google ID token from the fixed metadata endpoint and caches the short-lived Bulgur session in memory. Explicit Google Cloud mode never falls back to token credentials, even with optional mode.

Token lifetime and revocation

Google metadata may return the same ID token more than once. Google ID tokens can remain valid for up to one hour and cannot be individually revoked. Bulgur accepts a still-valid Google token again; each Bulgur session lasts at most five minutes and never beyond the source token's expiry.

Disabling or changing the Bulgur policy revokes its existing Bulgur sessions and blocks exchanges under the old policy. It does not revoke a Google token at Google. Restrict service account use and impersonation in IAM.

Troubleshooting

If token acquisition fails, run on Cloud Run with the intended service identity: a normal local shell cannot reach its metadata endpoint. If exchange is denied, check the numeric unique ID rather than the service account email, the workload identity ID and whether the policy is enabled.

For a dotenv file, run bulgur pull --auth gcp-oidc --identity <identity-id> --out .env --yes. An identity is bound to one environment and cannot read a sibling environment or write secrets.