gcp.iam.no-user-managed-service-account-keys

Service accounts have no user-managed keys

No service account in any project carries a downloadable key; every service account credential is Google-managed and short-lived.

High Attested Preventive

Assertion

for every service account sa in every project: count(keys(sa, managed-by=user)) == 0

Evaluated against gcloud iam service-accounts list; gcloud iam service-accounts keys list --managed-by=user, collected daily.

Rationale

A user-managed service account key is a long-lived bearer secret in a JSON file. Once downloaded it lives on laptops, in CI secret stores, and in git history, and nothing on the Google side can tell those copies apart or revoke one without revoking all. Workloads inside Google Cloud get credentials from the attached service account; workloads outside it get them through workload identity federation. Neither needs a key file to exist.

Observation

The collector lists the service accounts in each project, then lists keys for each with --managed-by=user. The assertion holds when every list is empty. Google-managed keys, which rotate automatically and are never exportable, are not counted. Default service accounts created by services are in scope like any other.

Remediation

Delete the key and move the workload to an attached service account or to workload identity federation. For CI runners outside Google Cloud, federate the runner’s identity provider rather than creating a key for it. To stop regression, set the organisation policy constraint iam.disableServiceAccountKeyCreation so that new keys cannot be created.