Control: 1.7 Ensure User-Managed/External Keys for Service Accounts Are Rotated Every 90 Days or Fewer
Description
Service Account keys consist of a key ID (Private_key_Id) and Private key, which are used to sign programmatic requests users make to Google cloud services accessible to that particular service account. It is recommended that all Service Account keys are regularly rotated.
Rotating Service Account keys will reduce the window of opportunity for an access key that is associated with a compromised or terminated account to be used. Service Account keys should be rotated to ensure that data cannot be accessed with an old key that might have been lost, cracked, or stolen.
Each service account is associated with a key pair managed by Google Cloud Platform (GCP). It is used for service-to-service authentication within GCP. Google rotates the keys daily.
Remediation
From Console
Delete any external (user-managed) Service Account Key older than 90 days:
- Go to GCP console at
APIs & Services\Credentialsusing https://console.cloud.google.com/apis/credentials. - In the Section
Service Account Keys, for every external (user-managed) service account key wherecreation dateis greater than or equal to the past 90 days, clickDelete Bin IcontoDelete Service Account key.
Create a new external (user-managed) Service Account Key for a Service Account:
- Go to
APIs & Services\Credentialsusing https://console.cloud.google.com/apis/credentials. - Click
Create Credentialsand SelectService Account Key. - Choose the service account in the drop-down list for which an External (user-managed) Service Account key needs to be created.
- Select the desired key type format among
JSONorP12. - Click
Create. It will download theprivate key. Keep it safe. - Click
Closeif prompted. - The site will redirect to the
APIs & Services\Credentialspage. Make a note of the newIDdisplayed in theService account keyssection.
Default Value
GCP does not provide an automation option for External (user-managed) Service key rotation.
Usage
Run the control in your terminal:
powerpipe control run gcp_compliance.control.cis_v300_1_7Snapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run gcp_compliance.control.cis_v300_1_7 --shareSQL
This control uses a named query:
select 'https://iam.googleapis.com/v1/projects/' || project || '/serviceAccounts/' || service_account_name || '/keys/' || name as resource, case when valid_after_time <= (current_date - interval '90' day) then 'alarm' else 'ok' end as status, service_account_name || ' ' || name || ' created ' || to_char(valid_after_time , 'DD-Mon-YYYY') || ' (' || extract(day from current_timestamp - valid_after_time) || ' days).' as reason , project as projectfrom gcp_service_account_keywhere key_type = 'USER_MANAGED';