Recovering Deleted Default Service Account in Google Cloud Platform

Enes Turan
3 min readJul 9, 2023

--

Introduction

Google Cloud Platform (GCP) offers powerful services and resources for cloud computing, including the Compute Engine. However, errors can occur while working with these services, such as the "Operation type [start] failed" error. This particular error message often indicates that the default service account for Compute Engine has been inadvertently deleted. In this article, we will explore the causes of this error, its implications, and provide step-by-step solutions to address the issue.

Understanding the Compute Engine Default Service Account

In GCP projects with the Compute Engine API enabled, a default service account called the Compute Engine default service account is automatically created. This service account plays a crucial role in providing credentials for applications that rely on GCP services. Its email address follows the format: <PROJECT_NUMBER>-compute@developer.gserviceaccount.com .

Causes and Implications of Deleting the Default Service Account

Accidentally deleting the Compute Engine default service account can have significant implications for applications and services relying on its credentials. Without the service account, access to Compute Engine resources may be compromised, resulting in failures during operations such as starting instances. The "Operation type [start] failed" error is a common consequence of such deletions.

Resolving the Error

Undelete the Service Account (if deleted within 30 days):

  • Utilize the following command to restore a recently deleted service account:
gcloud iam service-accounts undelete <EMAIL>

Replace <EMAIL> with the email address of the deleted service account.

  • Verify that there are no existing service accounts with the same name as the deleted service account. If found, consider renaming or deleting them to prevent conflicts.

Create a New Service Account:

  • If the deleted service account cannot be undeleted, create a new service account with the same name using the following commands:
gcloud iam service-accounts create <NEW_ACCOUNT_NAME>
gcloud projects add-iam-policy-binding <PROJECT_ID> --member="serviceAccount:<NEW_EMAIL>" --role=<ROLE>
  • Replace <NEW_ACCOUNT_NAME> with the desired name for the new service account, <PROJECT_ID> with your project ID, <NEW_EMAIL> with the email address of the new service account, and <ROLE> with the appropriate roles to grant.
  • Revoke all roles from the deleted service account to prevent conflicts:
gcloud projects remove-iam-policy-binding <PROJECT_ID> --member="serviceAccount:<DELETED_EMAIL>" --role=<ROLE>
  • Replace <PROJECT_ID> with your project ID, <DELETED_EMAIL> with the email address of the deleted service account, and <ROLE> with the roles to revoke.
  • Assign the same roles to the newly created service account:
gcloud projects add-iam-policy-binding <PROJECT_ID> --member="serviceAccount:<NEW_EMAIL>" --role=<ROLE>
  • Replace <PROJECT_ID> with your project ID, <NEW_EMAIL> with the email address of the new service account, and <ROLE> with the roles to grant.

Preventing Future Issues

To avoid encountering similar issues in the future, it is crucial to exercise caution when managing service accounts within GCP. Take note of the following recommendations:

  • Regularly review the list of service accounts to ensure critical accounts are not accidentally deleted.
  • Implement proper access control and permissions to prevent unauthorized deletions.
  • Document and follow best practices when working with service accounts.

Conclusion

The "Operation type [start] failed" error in Google Cloud Platform is a common occurrence when the default service account for Compute Engine has been deleted. This error can disrupt the functionality of applications relying on the service account's credentials. However, by following the provided solutions, such as undeleting the service account or creating a new one, users can resolve the error and restore access to Compute Engine resources. By exercising caution and adhering to best practices, users can prevent such issues in the future, ensuring a smooth and uninterrupted experience within the Google Cloud Platform.

References

--

--