Rotate › Google Cloud

# How to rotate a Google Cloud service account key

A service account can hold up to 10 keys, so you can run old and new side by side. Google's own process is five steps: find the keys, create replacements, deploy them, disable the old ones and watch, then delete. Two details catch people: the console can't disable a key, and deleting a key doesn't kill the access tokens it already minted.

Keysquid team · Updated December 1, 2026 · Checked against Google Cloud's IAM documentation on December 1, 2026

**Do this in two minutes, then never again.** Keysquid replaces your Google Cloud service account key key on a schedule, everywhere it's used, and kills a leaked one in seconds. From $9.99 a month. We never see the value.

[Try it free for 7 days](https://keysquid.com/signup)

## How to rotate Google Cloud service account key keys with Keysquid

Automatic Keysquid creates, verifies, distributes and revokes Google Cloud service account key keys on a schedule, with no one in the loop. JSON keys for a GCP service account, created and deleted through the IAM API (up to 10 per account).

**Setup, as the app shows it:**

1. Create a service account “keysquid-rotator” in any project. Create one JSON key for it and paste it here.
2. On each service account Keysquid should rotate (not the project), grant keysquid-rotator the role Service Account Key Admin (roles/iam.serviceAccountKeyAdmin).
3. If your org enforces iam.disableServiceAccountKeyCreation, Keysquid can't create keys; consider Workload Identity Federation instead.

- **Writes to:** Key file (JSON) (default variable GOOGLE_APPLICATION_CREDENTIALS_JSON), in every platform and secret store you map it to.
- **Interval:** from every 1 hour to every 4 weeks, subject to your plan’s minimum.
- **Inventory:** Keysquid lists every Google Cloud service account key key the connection can see, including keys it doesn’t manage, with names and last use.

Every rotation runs in the same order: create the new key, verify it, write it everywhere, redeploy where a platform needs it, and only then revoke the previous key after a grace period. If any write fails, everything written so far is restored and the new key is revoked. The value is encrypted to the agent you run, so Keysquid’s servers never see it.

What $9.99 a month saves you

One stolen key costs more than a lifetime of Keysquid.

- **$82,314 in 48 hours.** What a stolen Google API key ran up for a 3-person startup that normally spent about $180 a month ([The Register](https://www.theregister.com/2026/03/03/gemini_api_key_82314_dollar_charge/)).
- **$15,400 before the alert landed.** A solo developer revoked a leaked key within minutes of a billing alert, and the charges had already piled up ([TechRadar](https://techradar.com/pro/security/usd15k-bill-destroyed-a-solo-developers-startup-how-hackers-are-using-leaked-google-api-keys-to-go-wild-with-gemini-ai-for-free)).
- **$9.99 a month** for scheduled rotation and a one-click kill switch. **$19.99** adds the Security suite: spend guard, leak scanning, breach alerts, blast radius and compliance packs. Cancel any time.

[Start your 7-day free trial](https://keysquid.com/signup)No card needed to look around. Your keys stay encrypted to an agent you run.

## Under the hood: Google Cloud service account key keys in detail

Everything below is what Keysquid handles for you on every rotation. It’s here so you know exactly what happens to your keys, and in case you ever need to do a step by hand.

- **Format**: A JSON file with `"type": "service_account"`, a `private_key_id` and a PEM `private_key`. Google keeps only the public half.
- **Where**: IAM & Admin → Service accounts → the account → Keys tab → Add key → Create new key → JSON.
- **Shown once**: The key file downloads once. You can't download it again.
- **Limit**: Up to 10 keys per service account.
- **Expiry**: None by default. The org policy `iam.serviceAccountKeyExpiryHours` sets one for new keys.
- **Disable**: Reversible, but only with gcloud or the REST API: the console can show disabled keys, not disable them.
- **Delete**: Permanent. A deleted key can't be restored.
- **Propagation**: After creating a key, Google says to allow 60 seconds or more before using it.
- **Role needed**: Service Account Key Admin (`roles/iam.serviceAccountKeyAdmin`) on the project or the service account.
- **Keysquid**: Automatic: a new JSON key through the IAM API, delivered to your platforms, the old key deleted.

## Before you rotate: do you need a key at all?

Google’s own guidance is to avoid user-managed keys wherever the workload already has an identity. If the code runs on Google Cloud, attach the service account to the resource. If it runs in GitHub Actions, another cloud or Kubernetes, Workload Identity Federation swaps the key for short-lived tokens. A key you don’t have can’t leak, and that beats any rotation schedule, ours included.

Keys are still the practical answer for a lot of third-party tools and hosting platforms that only accept a JSON file. For those, rotate. Google recommends at least every 90 days, and immediately if you suspect exposure.

## Rotate a key in the Google Cloud console

1. Open **IAM & Admin → Service accounts**, select the project and click the service account’s email.
2. On the **Keys** tab, note the ID and created date of the key in use, then click **Add key → Create new key**, choose **JSON** and click **Create**. The file downloads straight away.
3. Put the file’s contents in your secret store or platform variable, delete the downloaded copy, and redeploy. Wait at least a minute before you conclude the new key doesn’t work.
4. Disable the old key with gcloud (next section), because the console can’t. Watch your app and logs for a day or so.
5. When nothing has broken, go back to the **Keys** tab and click **Delete** on the old key.

## Rotate a key with gcloud

```bash
SA=app@my-project.iam.gserviceaccount.com

# 1. See the keys you have, with created and expiry dates
gcloud iam service-accounts keys list --iam-account=$SA

# 2. Create the replacement, writing the file where your deploy step expects it
gcloud iam service-accounts keys create ./new-key.json --iam-account=$SA

# 3. Deploy new-key.json, confirm the app authenticates, then disable the old key
gcloud iam service-accounts keys disable OLD_KEY_ID --iam-account=$SA --project=my-project

# 4. Something broke? Re-enable it. Nothing broke? Delete it for good.
gcloud iam service-accounts keys enable OLD_KEY_ID --iam-account=$SA --project=my-project
gcloud iam service-accounts keys delete OLD_KEY_ID --iam-account=$SA
```

The key ID is the 40-character hex string in the list output, and the same value as `private_key_id` inside the JSON file. To find out which key a running service holds, read that field from the file it was deployed with.

## Why disable before you delete

| Action | Reversible? | What it stops |
| --- | --- | --- |
| Disable | Yes, re-enable at any time | New authentication with the key |
| Delete | No | New authentication with the key, permanently |
| Disable the service account | Yes, re-enable it | Everything that uses the account, including tokens already issued |

Disabling gives you an undo button. A forgotten cron job or a second region still on the old key fails loudly, you re-enable the key, fix the deploy and try again. Google recommends exactly this: disable, wait until you’re sure the key isn’t needed, then delete.

**The gap in both:** neither disabling nor deleting a key revokes short-lived credentials already issued from it. Access tokens are valid for an hour by default. After a leak, if that hour matters, the only way to cut those tokens off is to disable or delete the service account itself, which also stops every workload using it.

## The 10-key limit

Every rotation that skips the final delete leaves a live key behind, and at 10 keys the account can’t get another. Before deleting stale keys, check which ones are still used: the **Key Authentication Events** metric shows when each key last authenticated, and service account insights flag accounts unused for 90 days. Audit log entries from many services include a `serviceAccountKeyName` field that names the exact key behind a call. For an org-wide sweep, Cloud Asset Inventory can list every key older than a date:

```bash
gcloud asset search-all-resources --scope="organizations/ORG_ID" \
  --asset-types="iam.googleapis.com/ServiceAccountKey" \
  --query="createTime < 2026-09-01" --order-by="createTime"
```

## Org policies that change the rules

| Constraint | Effect | Watch out for |
| --- | --- | --- |
| `iam.disableServiceAccountKeyCreation` | No new user-managed keys | Enforced by default for organizations created on or after May 3, 2024. Rotation fails at the create step. |
| `iam.serviceAccountKeyExpiryHours` | New keys expire after a set number of hours | Existing keys keep no expiry. Expired keys fail gradually, over up to several days. |
| Service Account Key Exposure Response | Set to `DISABLE_KEY` and Google disables leaked keys it detects | Google doesn't guarantee it finds every leak. Disabled keys carry an exposure reason in their metadata. |

If key creation is blocked and you really need a key, an administrator with the Organization Policy Administrator role can exempt one project with a tag rather than switching the policy off everywhere. Changing org policies needs `orgpolicy.policy.set`, which neither Owner nor Editor includes.

## If a key leaked

1. **Disable the key now** with gcloud, then delete it once you’ve replaced it. Removing the file from a repository is not enough; the key must be deleted in IAM.
2. If the service account had broad roles, consider disabling the account itself for an hour to kill tokens already minted from the key.
3. Search Cloud Audit Logs for the account’s `principalEmail` and the leaked `serviceAccountKeyName` to see what was done with it.
4. Turn on the exposure response policy with `DISABLE_KEY` so the next leak Google spots is shut off automatically.
5. Work through [the first 10 minutes after a key leak](https://keysquid.com/blog/leaked-api-key-first-10-minutes), and if the file was pushed to GitHub, scan the repository’s history with the [GitHub secret scanner](https://keysquid.com/tools/github-secret-scanner).

## By hand vs. with Keysquid

### By hand

1. Create a key and handle the downloaded file.
2. Paste the JSON into every platform that uses it.
3. Disable the old key with gcloud, wait, then delete it.
4. Keep each account under 10 keys.

### With Keysquid

1. Keysquid creates the key through the IAM API; no file touches a laptop.
2. It writes the JSON to every platform you mapped and redeploys.
3. It deletes the old key after the grace period.
4. It lists every user-managed key on the account, with created dates and status.

## What Keysquid does on every rotation

Keysquid writes the key’s JSON content, not a file path. Libraries that read `GOOGLE_APPLICATION_CREDENTIALS` expect a path, so either load the JSON from the variable in code or have your start command write it to a file first. The rotator service account Keysquid uses is itself a key; keep it in its own project with only the Service Account Key Admin role on the accounts it rotates. If you can move a workload to Workload Identity Federation instead, do that and take it off the rotation list.

What $9.99 a month saves you

One stolen key costs more than a lifetime of Keysquid.

- **$82,314 in 48 hours.** What a stolen Google API key ran up for a 3-person startup that normally spent about $180 a month ([The Register](https://www.theregister.com/2026/03/03/gemini_api_key_82314_dollar_charge/)).
- **$15,400 before the alert landed.** A solo developer revoked a leaked key within minutes of a billing alert, and the charges had already piled up ([TechRadar](https://techradar.com/pro/security/usd15k-bill-destroyed-a-solo-developers-startup-how-hackers-are-using-leaked-google-api-keys-to-go-wild-with-gemini-ai-for-free)).
- **About 20 hours a year** of engineering time to rotate 10 keys by hand every 90 days, at roughly 30 minutes a key. That's around $2,000 at $100 an hour (our estimate).
- **$9.99 a month** for scheduled rotation and a one-click kill switch. **$19.99** adds the Security suite: spend guard, leak scanning, breach alerts, blast radius and compliance packs. Cancel any time.

[Start your 7-day free trial](https://keysquid.com/signup)No card needed to look around. Your keys stay encrypted to an agent you run.

## Frequently asked questions

### How many keys can a Google Cloud service account have?

Up to 10. Old keys left behind by past rotations count towards the limit, so delete them once you're sure they're unused.

### Can I disable a service account key in the console?

No. The console shows disabled keys but can't disable one. Use gcloud iam service-accounts keys disable or the REST API.

### Does deleting a service account key revoke access immediately?

It stops new authentication with the key, but access tokens already issued from it stay valid until they expire (one hour by default). To revoke those, disable or delete the service account.

### Can I recover a deleted service account key?

No. Deleting is permanent, which is why Google recommends disabling the key first and deleting it only once you're sure nothing needs it.

### How often should I rotate service account keys?

Google recommends at least every 90 days, and immediately if you suspect a key was exposed. Better still, replace keys with attached service accounts or Workload Identity Federation.

### Why can't I create a service account key?

Your organization probably enforces iam.disableServiceAccountKeyCreation, which is on by default for organizations created on or after May 3, 2024. An administrator can exempt a project with a tag.

Rotate keys without ever handing them over

Keysquid rotates and revokes API keys on a schedule and encrypts every value to an agent you run, so we never see a readable key. Flat pricing from $9.99 a month, unlimited team members, 7-day free trial.

[Start 7-day free trial](https://keysquid.com/signup)

[Security model](https://keysquid.com/security)[Docs](https://keysquid.com/docs)

## Related

- [Rotate AWS IAM access keys](https://keysquid.com/rotate/aws-iam)
- [Rotate GitHub tokens and app keys](https://keysquid.com/rotate/github)
- [Rotation support for every provider](https://keysquid.com/rotate)
- [Secrets in GitHub Actions](https://keysquid.com/blog/secrets-in-github-actions)
- [OpenAI key rotation](https://keysquid.com/rotate/openai)
- [Anthropic key rotation](https://keysquid.com/rotate/anthropic)

## Sources

1. [Google Cloud IAM: Service account key rotation](https://docs.cloud.google.com/iam/docs/key-rotation)
2. [Google Cloud IAM: Create and delete service account keys](https://docs.cloud.google.com/iam/docs/keys-create-delete)
3. [Google Cloud IAM: Disable and enable service account keys](https://docs.cloud.google.com/iam/docs/keys-disable-enable)
4. [Google Cloud IAM: List and get service account keys](https://docs.cloud.google.com/iam/docs/keys-list-get)
5. [Google Cloud IAM: Best practices for managing service account keys](https://docs.cloud.google.com/iam/docs/best-practices-for-managing-service-account-keys)
6. [Google Cloud IAM: Service account credentials](https://docs.cloud.google.com/iam/docs/service-account-creds)
