Skip to main content

More Info:

Service account keys should be rotated periodically.

Risk Level

High

Address

Security

Compliance Standards

  • APRA CPS 234 (Australia)
  • BSI C5 (Germany)
  • Brazil LGPD
  • CCPA / CPRA (California)
  • CIS Critical Security Controls v8
  • CIS GCP
  • CIS GCP 2.0.0
  • CMMC 2.0
  • CSA Cloud Controls Matrix v4
  • Cloudanix Best Practice
  • DPDPA
  • Digital Operational Resilience Act (EU)
  • Essential 8
  • ISO/IEC 27017
  • ISO/IEC 27018
  • ISO/IEC 27701
  • KSA PDPL
  • MAS Technology Risk Management (Singapore)
  • MITRE ATT&CK (Cloud)
  • NIS2 Directive
  • NIST SP 800-171
  • NYDFS 23 NYCRR 500
  • Reserve Bank of India (RBI) Master Direction – Information Technology Framework
  • SWIFT Customer Security Controls Framework
  • Sarbanes-Oxley IT General Controls
  • UK NCSC Cyber Assessment Framework

Triage and Remediation

Remediation

Using Console

To remediate the misconfiguration “Service Account Keys Should Be Rotated” for GCP using GCP console, follow the steps below:
  1. Login to the Google Cloud Console using your credentials.
  2. Navigate to the IAM & Admin page from the left-hand menu.
  3. Click on Service Accounts from the list of options.
  4. Select the service account for which you want to rotate the keys.
  5. Click on the Edit button for the selected service account.
  6. Scroll down to the Keys section and click on the Add Key button.
  7. Select the type of key you want to add from the dropdown list.
  8. Click on the Create button to generate the new key.
  9. Once the new key is created, download it and store it securely.
  10. Delete the old key(s) that are no longer required.
By following these steps, you have successfully rotated the service account keys for your GCP project. Make sure to repeat this process periodically to keep your service account keys up to date.

To remediate the misconfiguration “Service Account Keys Should Be Rotated” for GCP using GCP CLI, you can follow the below steps:
  1. First, you need to identify the Service Account Keys that need to be rotated. You can use the below command to list all the Service Accounts in your project:
  1. Once you have identified the Service Account that needs to be rotated, you can create a new key for that Service Account using the below command:
Replace [FILE_NAME] with the name of the file you want to create for the new key and replace [SERVICE_ACCOUNT_EMAIL] with the email of the Service Account that needs to be rotated.
  1. After creating the new key, you need to delete the old key. You can use the below command to list all the keys for a Service Account:
  1. Once you have identified the old key that needs to be deleted, you can use the below command to delete it:
Replace [KEY_ID] with the ID of the key that needs to be deleted and replace [SERVICE_ACCOUNT_EMAIL] with the email of the Service Account.
  1. Finally, you need to ensure that the new key is being used by all the applications that were using the old key. You can update the applications with the new key manually or by using automation tools like Ansible or Terraform.
By following the above steps, you can remediate the misconfiguration “Service Account Keys Should Be Rotated” for GCP using GCP CLI.
To remediate the misconfiguration “Service Account Keys Should Be Rotated” in GCP using Python, you can follow the below steps:Step 1: Install the required librariesInstall the Google Cloud SDK and the Python client library using pip.
Step 2: Authenticate the clientAuthenticate the client using the service account key that you want to rotate.
Step 3: Rotate the service account keyCreate a new service account key and delete the old one.
Step 4: Save the new service account keySave the new service account key to a file.
Step 5: Update the service account key in the applicationUpdate the service account key in the application with the new key that you have generated.Note: Make sure to update the service account key in all the places where it is being used.By following these steps, you can remediate the misconfiguration “Service Account Keys Should Be Rotated” in GCP using Python.
Terraform cannot rotate GCP service account keys based on age; the provider exposes key creation/deletion (google_service_account_key) but not “rotate after N days” behavior, so enforcing a 90‑day threshold is an external/process concern, not a declarative setting.You can manage keys with Terraform, but rotation must be driven by you (e.g., CI pipeline that periodically runs terraform apply with a forced replacement). A minimal pattern is:
To rotate every ≤90 days:
  1. Update rotation_id (or another keepers field) on your schedule.
  2. terraform plan should show google_service_account_key.example_key as forces replacement.
  3. terraform apply creates a new key and destroys the old one.
Because updating workloads to use the new key and validating that it works are runtime actions, they must be handled outside Terraform. Console/API alternative: create a new key on the service account, update consumers to use it, then delete the old key, repeating at least every 90 days.