> ## Documentation Index
> Fetch the complete documentation index at: https://docs.niteshift.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# GCP

> Give tasks Google Cloud credentials through Workload Identity Federation and Application Default Credentials.

Niteshift integrates natively with GCP tools via [Application Default Credentials (ADC)](https://docs.cloud.google.com/docs/authentication/application-default-credentials).
It relies on the `ns cloud-creds gcp` executable helper to generate a short-lived Niteshift OIDC token, which Google
exchanges for access credentials.

> [!TIP]
>
> Ask the agent in a task to connect GCP. It writes the configuration, walks you through the
> cloud-side setup below, and verifies access. See the [quick
> start](https://docs.niteshift.dev/integrations/overview.md#quick-start).

On the Niteshift side, the integration is configured with an entry in the environment's committed
`settings.yaml`. Set one workload identity provider using its project **number**.
Add `serviceAccountEmail` only if the workload will impersonate a service account:

```yaml settings.yaml theme={"dark"}
version: 1
integrations:
  gcp:
    provider: projects/123456789/locations/global/workloadIdentityPools/id-pool/providers/niteshift
    # Optional: serviceAccountEmail: workload@example-project.iam.gserviceaccount.com
```

Inspect the audience derived from your configured provider: `https://iam.googleapis.com/` followed
by the `provider` path. For the example above, run:

```bash theme={"dark"}
ns oidc-token --inspect --audience 'https://iam.googleapis.com/projects/123456789/locations/global/workloadIdentityPools/id-pool/providers/niteshift'
```

In Google Cloud, create a workload identity pool and an OIDC provider using the inspected `iss`
and `aud`. Map `google.subject` from `assertion.sub` and restrict the provider to the exact
inspected environment-specific `sub` with an attribute condition. Trusting only the issuer and
audience does not restrict access to your Niteshift environment.

For an existing pool, create its provider with the following command. Replace the project, pool,
and provider placeholders with the values from `settings.yaml`, and the claim placeholders with
the exact inspected values:

```bash theme={"dark"}
gcloud iam workload-identity-pools providers create-oidc '<provider-id>' \
  --project='<pool-project-number>' \
  --location='global' \
  --workload-identity-pool='<pool-id>' \
  --issuer-uri='<inspected-iss>' \
  --allowed-audiences='<inspected-aud>' \
  --attribute-mapping='google.subject=assertion.sub' \
  --attribute-condition="assertion.sub == '<inspected-sub>'"
```

Grant resource permissions to this environment's subject principal, using the project number
of the project that owns the pool and the entire inspected `sub`:

```text theme={"dark"}
principal://iam.googleapis.com/projects/<pool-project-number>/locations/global/workloadIdentityPools/<pool-id>/subject/<inspected-sub>
```

For direct access, grant that principal only the required resource roles. For service account
impersonation, grant it `roles/iam.workloadIdentityUser` on the selected service account and grant
resource permissions to that service account. Avoid pool-wide wildcard grants. [Google's Workload
Identity Federation guide](https://cloud.google.com/iam/docs/workload-identity-federation-with-other-providers)
covers provider setup and both access methods.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.