Skip to content
Google CloudService account key (JSON)

How to rotate Google Cloud service account keys

Reissue a Google Cloud service account key: create a second key, replace the JSON file, disable and watch the old key, then delete it, minding issued tokens.

Google CloudService account key (JSON)

What a leaked key reaches
Every role granted to the service account, plus any short-lived credentials already issued from the key, which survive its deletion.
Can be scoped
Partly

Some key types can be limited, others carry full rights.

Expires
Never by default; an organization policy can limit key lifetime
Switching keys
Overlap windowDelayed revocation

The old key keeps working for a while after you revoke it.

What Crunu does here

Crunu doesn't reissue keys at providers. It shows which values to replace and keeps the new one.

Build the list for a departure with the offboarding checklist
On this page

Create a second key for the same service account, replace the JSON key file everywhere it's used, disable the old key and watch your applications, then delete it once they're fine. A service account can hold up to 10 keys, so the old and the new key overlap for as long as you need (Google Cloud docs). Google's own rotation process has the same five steps: find the keys, create new ones, replace them in every application, disable the old ones and monitor, then delete (key rotation). One catch: deleting a key doesn't revoke short-lived credentials already issued from it.

Crunu doesn't create, disable or delete Google Cloud keys; it has no Google Cloud integration. It tells you which key files a departing person could read, stores the new file as a new version of the environment, and puts it on the machines that need it.

Check three things before you start

Key creation may be blocked. The iam.disableServiceAccountKeyCreation organization policy is enforced by default for organizations created on or after May 3, 2024. If creating a key fails, an administrator has to exempt the project with a tag and a conditional rule, and Google asks to exempt only projects that truly need keys.

A key file is a long-lived secret. By default, service account keys never expire. An organization policy can limit how long they stay valid, but Google doesn't recommend expiring keys as a rotation method, because they cause outages when nobody replaces them in time. Google recommends rotating at least every 90 days, and at once if a key may be compromised.

There may be a way out. For workloads outside Google Cloud, Google recommends Workload Identity Federation instead of keys, and the documentation on Application Default Credentials warns that service account keys create a security risk (ADC docs). If a reissue is due anyway, it is the cheapest moment to move a workload off keys.

Reissue without downtime

  1. Create the new key, in the console under the service account's keys or with gcloud iam service-accounts keys create. You can download the private part only once. Google notes you may need to wait 60 seconds or more before using a fresh key.
  2. Drag the downloaded JSON file into the Crunu environment that held the old one, for example data-pipeline / production, check its path and save. Then delete the downloaded copy from your laptop.
  3. On each machine, run crunu pull to write the new file in place with mode 0600, and restart the program. Applications that use Application Default Credentials find the file through GOOGLE_APPLICATION_CREDENTIALS, which holds its location.
  4. Disable the old key and watch the applications. A disabled key can be enabled again if something you missed breaks.
  5. Delete the old key when nothing has failed for a while. Deletion permanently stops the key from authenticating, and a deleted key can't be restored.
Shell
gcloud iam service-accounts keys create etl-worker-key.json \
  --iam-account=etl-worker@kiteline-data.iam.gserviceaccount.com
crunu pull --env data-pipeline/production
gcloud iam service-accounts keys delete OLD_KEY_ID \
  --iam-account=etl-worker@kiteline-data.iam.gserviceaccount.com

crunu pull keeps the previous file next to the new one with a .prev suffix, so the old key also stays on that disk until the next pull. Disabling it in Google Cloud is what makes that copy harmless.

Why deletion isn't the end

Most providers treat a deleted key as a closed door. Google Cloud adds a delay you can't shorten from the key itself: a key can be used to obtain short-lived credentials, and deleting the key doesn't revoke the ones already issued. They keep working until they expire. If you suspect misuse, deleting the key isn't enough: Google says revoking those credentials requires disabling or deleting the service account. That's why this page marks revocation as delayed.

When to reissue a key

  • A departure. A key authenticates as the service account, not as the person who downloaded it, so removing that person from your project changes nothing for the key. Reissue every key file they could read. In Crunu, removing the person produces a reissue checklist naming those files by path.
  • A leak. Delete the key immediately, and if it could have been used, disable the service account until you've reviewed what it did. Then create a new key or, better, a new setup without keys.
  • Every 90 days. To find keys older than a given date, Google suggests searching Cloud Asset Inventory for service account keys by creation time.

What to rotate when a developer leaves covers the full order of work, and the offboarding checklist lists what to reissue in your stack. Google Cloud remains the place where keys are created, disabled and deleted.

Frequently asked questions

Something else? Write to support@crunu.com

How many keys can one Google Cloud service account have?

Up to 10. That leaves room to create the replacement while the old key still works, switch every consumer, and only then disable and delete the old key.

Does deleting a service account key end all access gained with it?

No. Google says deleting a key doesn't revoke short-lived credentials that were already issued based on it. To revoke those as well, you have to disable or delete the service account itself.

Why can't I create a service account key at all?

Probably because of the iam.disableServiceAccountKeyCreation organization policy, which is enforced by default for organizations created on or after May 3, 2024. An administrator can exempt a single project, but Google suggests Workload Identity Federation instead.

Does Crunu rotate Google Cloud keys?

No. Crunu doesn't call Google Cloud. It shows which Google Cloud values a departing person received, stores the new key file as a new environment version and writes it to your machines with crunu pull.

Sources

Every source this page relies on, with the date we last checked it.

  1. Google Cloud IAM: Create and delete service account keys · checked October 30, 2026
  2. Google Cloud IAM: Rotate service account keys · checked October 30, 2026
  3. Google Cloud: How Application Default Credentials works · checked October 30, 2026
  • Hetzner

    Cloud API token

    Expiry: No expiry option in Hetzner's documentation

    Partly scopedRevocation time unknown

  • npm

    Granular access token

    Expiry: Always set; write tokens default to 7 days and last at most 90

    Scoped keysDelayed revocation

  • OpenAI

    Project API key

    Expiry: Optional at creation; admins can enforce a maximum lifetime

    Scoped keys

  • Resend

    API key

    Expiry: None: a key stays valid until you delete it

    re_…Partly scoped

  • SendGrid

    API key

    Expiry: Not documented; treat the key as valid until you delete it

    SG.…Scoped keys

  • SSH

    SSH key pair

    Expiry: None for plain keys; expiry-time= or a certificate validity adds one

    Partly scoped

Know which values to replace

Free during early access. When someone leaves, Crunu lists the values they received, changes the environment keys, and keeps each new value as a new version.