View recent usage for service accounts and keys

Preview

This feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the Service Specific Terms . Pre-GA features are available "as is" and might have limited support. For more information, see the launch stage descriptions .

This page shows you how to use Activity Analyzer to see when your service accounts and keys were last used to call a Google API. These usages are called authentication activities .

Recent authentication activity can help you identify the service accounts and service account keys that you no longer use. We recommend disabling or deleting these unused service accounts and keys because they create an unnecessary security risk.

When viewing usage for service accounts, keep in mind that requests authenticated by API keys bound to service accounts aren't recorded in service account usage metrics .

Before you begin

Required roles

To get the permissions that you need to list the most recent authentication activities for your service accounts and service account keys, ask your administrator to grant you the Activity Analysis Viewer ( roles/policyanalyzer.activityAnalysisViewer ) IAM role on the project. For more information about granting roles, see Manage access to projects, folders, and organizations .

This predefined role contains the permissions required to list the most recent authentication activities for your service accounts and service account keys. To see the exact permissions that are required, expand the Required permissionssection:

Required permissions

The following permissions are required to list the most recent authentication activities for your service accounts and service account keys:

  • policyanalyzer.serviceAccountKeyLastAuthenticationActivities.query
  • policyanalyzer.serviceAccountLastAuthenticationActivities.query

You might also be able to get these permissions with custom roles or other predefined roles .

View recent usage for all service accounts or keys

To list the dates of the most recent authentication activities for all of your service accounts or service account keys, use the Google Cloud CLI or REST API.

To find the last date that specific service accounts were used, use the Google Cloud console, gcloud CLI, or REST API.

View recent usage for specific service account keys

To find the last date that specific service account keys were used, identify the service account key that you want to view recent usage for, then create a query using that ID.

If you have a JSON key file, you can find a service account key's unique ID in the file's private_key_id field.

If you don't have a JSON key file, you can find a service account key's unique ID by following these steps:

Understand activities

Console

The query results page lists the query parameters and the results of the query.

For a service account query, the results table lists each service account from the query and when it last authenticated:

For a service account key query, the results table lists each service account key from the query, the service account it's associated with, and when it last authenticated.

The results might not include very recent authentication events. Check the tooltip to see the exact date range used during the analysis. The results don't include authentication events that occurred outside of this range.

The results table for both queries also lists the IAM roles that the service account has on the project, along with any security insights. These insights highlight patterns in how your service accounts access resources. For example, some insights highlight excess permissions , or permissions that a principal doesn't need. Other insights highlight service accounts with lateral movement permissions , or permissions that let the service account impersonate a service account in another project.

Some insights also come with role recommendations that suggest changes you can make to reduce excess permissions. To learn how to manage recommendations and insights, see Review and apply recommendations .

gcloud

Activity Analyzer reports results as a list of activities . Activities have the following fields:

  • fullResourceName : The full resource name of the service account or service account key whose activity is being reported. This format is described in the following sections, and in Full resource names .
  • activityType : The type of activity that is being reported. For recent service account authentication activity, the value is serviceAccountLastAuthentication . For recent service account key authentication activity, the value is serviceAccountKeyLastAuthentication .
  • observationPeriod : Start and end times indicating the span of time for which the service account or key was observed for activity. The time in these timestamps is always T07:00:00Z .
  • activity : The details of the activity. The contents of this field vary based on the activity type. See the following sections for details.

Details for service account activities

The activity field for serviceAccountLastAuthentication activities contains the following fields:

  • serviceAccount : Details about the service account whose activity is being reported, including the following:

    • fullResourceName : The full resource name of the service account, in the format //iam.googleapis.com/projects/ PROJECT_ID /serviceAccounts/ SERVICE_ACCOUNT_EMAIL .
    • projectNumber : The numeric ID of the project that owns the service account.
    • serviceAccountId : The numeric ID of the service account.
  • lastAuthenticatedTime : A timestamp representing the date at which the most recent authentication event occurred. The time in this timestamp is always T07:00:00Z , regardless of the exact time of the authentication event.

    The results might not include very recent authentication events. Check the observationPeriod to see the exact date range used during the analysis. The results don't include authentication events that occurred outside of this range.

    This field is not included for service accounts that have never been used.

Details for service account key activities

The activity field for serviceAccountKeyLastAuthentication activities contains the following fields:

  • serviceAccountKey : Details about the service account key whose activity is being reported, including the following:

    • fullResourceName : The full resource name of the service account key, in the format //iam.googleapis.com/projects/ PROJECT_ID /serviceAccounts/ SERVICE_ACCOUNT_EMAIL /keys/ KEY_ID .
    • projectNumber : The numeric ID of the project that owns the service account that the key is associated with.
    • serviceAccountId : The numeric ID of the service account that the key is associated with.
  • lastAuthenticatedTime : A timestamp representing the date at which the most recent authentication event occurred. The time in this timestamp is always T07:00:00Z , regardless of the exact time of the authentication event.

    The results might not include very recent authentication events. Check the observationPeriod to see the exact date range used during the analysis. The results don't include authentication events that occurred outside of this range.

    This field is not included for service account keys that have never been used.

REST

Activity Analyzer reports results as a list of activities . Activities have the following fields:

  • fullResourceName : The full resource name of the service account or service account key whose activity is being reported. This format is described in the following sections, and in Full resource names .
  • activityType : The type of activity that is being reported. For recent service account authentication activity, the value is serviceAccountLastAuthentication . For recent service account key authentication activity, the value is serviceAccountKeyLastAuthentication .
  • observationPeriod : Start and end times indicating the span of time for which the service account or key was observed for activity. The time in these timestamps is always T07:00:00Z .
  • activity : The details of the activity. The contents of this field vary based on the activity type. See the following sections for details.

Details for service account activities

The activity field for serviceAccountLastAuthentication activities contains the following fields:

  • serviceAccount : Details about the service account whose activity is being reported, including the following:

    • fullResourceName : The full resource name of the service account, in the format //iam.googleapis.com/projects/ PROJECT_ID /serviceAccounts/ SERVICE_ACCOUNT_EMAIL .
    • projectNumber : The numeric ID of the project that owns the service account.
    • serviceAccountId : The numeric ID of the service account.
  • lastAuthenticatedTime : A timestamp representing the date at which the most recent authentication event occurred. The time in this timestamp is always T07:00:00Z , regardless of the exact time of the authentication event.

    The results might not include very recent authentication events. Check the observationPeriod to see the exact date range used during the analysis. The results don't include authentication events that occurred outside of this range.

    This field is not included for service accounts that have never been used.

Details for service account key activities

The activity field for serviceAccountKeyLastAuthentication activities contains the following fields:

  • serviceAccountKey : Details about the service account key whose activity is being reported, including the following:

    • fullResourceName : The full resource name of the service account key, in the format //iam.googleapis.com/projects/ PROJECT_ID /serviceAccounts/ SERVICE_ACCOUNT_EMAIL /keys/ KEY_ID .
    • projectNumber : The numeric ID of the project that owns the service account that the key is associated with.
    • serviceAccountId : The numeric ID of the service account that the key is associated with.
  • lastAuthenticatedTime : A timestamp representing the date at which the most recent authentication event occurred. The time in this timestamp is always T07:00:00Z , regardless of the exact time of the authentication event.

    The results might not include very recent authentication events. Check the observationPeriod to see the exact date range used during the analysis. The results don't include authentication events that occurred outside of this range.

    This field is not included for service account keys that have never been used.

What's next

Create a Mobile Website
View Site in Mobile | Classic
Share by: