User-Managed Service Account Keys in Use

Service accounts have user-managed keys, long-lived private key files that let whoever holds them act as the service account from anywhere until the key is deleted.

SeverityMedium
CVSS 3.14.8 CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:N Open in the calculator
CVSS 4.06.3 CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:L/VI:L/VA:N/SC:N/SI:N/SA:N Open in the calculator
CWECWE-522: Insufficiently Protected Credentials
OWASP Top 10A06:2025 Insecure Design
MITRE ATT&CKT1552.001 Credentials In Files, T1078.004 Cloud Accounts, T1098.001 Additional Cloud Credentials
CategorySecurity Misconfiguration

Description

A Google Cloud service account can authenticate with keys managed by Google, which are used internally and rotated automatically, or with user-managed keys, which are downloaded as JSON files containing a private key. A user-managed key does not expire unless an expiry is enforced by organisation policy and is not bound to any device or network, so whoever holds the file can obtain tokens for the service account from anywhere, with no further authentication, and act as it with all of its permissions until the key is disabled or deleted. Their activity appears in the logs as the service account rather than as a person.

Key files tend to spread: they are copied onto developer workstations, committed to source code repositories, built into container images, stored in CI/CD variables and passed between teams, and the organisation often cannot say how many copies of a key exist or who holds them. Where service accounts hold broad roles, a single leaked key can expose data or infrastructure across a project or the whole organisation, and where key creation is not restricted, an attacker who gains suitable IAM permissions can also create new keys as a persistent backdoor. The impact depends on the permissions of the affected service accounts and on how widely the key files have travelled. Google recommends avoiding user-managed keys wherever a keyless alternative exists.

The finding is identified by listing each service account's keys with gcloud iam service-accounts keys list --managed-by=user, by reviewing key age and recent use, and by checking whether the constraints/iam.disableServiceAccountKeyCreation organisation policy constraint is enforced. During testing, key files are frequently recovered from repositories, file shares and build systems.

Remediation

  • Replace user-managed keys with keyless alternatives: attach service accounts to Compute Engine, Cloud Run and other resources so that code obtains short-lived tokens from the metadata server; use Workload Identity Federation for workloads in other clouds, on premises and in CI/CD systems such as GitHub Actions; and use service account impersonation for administrators and tools.
  • Delete keys that are unused or no longer needed, starting with the oldest and those of the most privileged service accounts.
  • Enforce the constraints/iam.disableServiceAccountKeyCreation and constraints/iam.disableServiceAccountKeyUpload organisation policy constraints, with documented exceptions only for projects that genuinely cannot avoid keys.
  • Where a key must remain, store it in a secrets manager rather than in code or images, rotate it regularly by creating a new key and deleting the old one, consider enforcing a maximum key lifetime by organisation policy, and limit who holds roles that can create keys.
  • Monitor the Admin Activity audit logs for key creation, and alert on keys created outside the approved process.
gcloud iam service-accounts keys list --iam-account="$SA_EMAIL" --managed-by=user gcloud iam service-accounts keys delete "$KEY_ID" --iam-account="$SA_EMAIL"

Confirm the fix by listing user-managed keys again and finding none outside the documented exceptions, and by checking that the organisation policy prevents new keys from being created.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Google Cloud Findings

Every Google Cloud finding