Technik Go LLC is professionals at web development, digital marketing, and IT consulting. Our modern designs, innovative tech solutions, and innovative marketing tactics will transform your online presence and optimize IT processes for outstanding efficiency.
Setting up automation in Google Cloud can sound tricky, but it doesn’t have to be. In this guide, you’ll learn how to create and manage GCP service accounts for automation – the safe way. We’ll walk through step-by-step setup for CI/CD pipelines, explain why secure keys matter, and explore modern tools like Workload Identity Federation to keep your system both efficient and secure.
Think of a GCP service account as a robot user that helps your programs talk to Google Cloud – safely and automatically. Instead of a person logging in, a service account lets tools, scripts, or pipelines (like CI/CD systems, cron jobs, or APIs) access resources securely. These accounts handle the behind-the-scenes work, such as deploying apps or storing data.
In automation, they’re essential – but come with a key choice:
There are two main ways to let your automation tools talk to Google Cloud securely.
(A) Service Accounts with Keys:
This is the classic method – you create a service account and download a private key (JSON file). It’s simple and works well for local scripts or small projects. But keys can get lost, shared, or leaked, which makes them a security risk if not managed carefully.
(B) Workload Identity Federation (WIF):
This newer, keyless approach lets your system (like GitHub Actions or AWS) authenticate to Google Cloud using short-lived credentials instead of static keys. It’s safer, scales better, and follows Google’s zero-trust model.
Recommendation: Use Workload Identity Federation for most CI/CD and automation workflows. It removes key management hassles and keeps your security posture strong.
Creating a service account in Google Cloud is simple – and you can do it in three main ways: through the Console (UI), using the gcloud command line, or with Terraform for automation. No matter the method, remember: each service account should have one clear purpose and only the permissions it needs.
The easiest method for beginners.
Tip: Don’t give full “Owner” access unless absolutely necessary.
You can automate creation using a command like this:
gcloud iam service-accounts create ci-cd-deployer \ --description="Service account for CI/CD pipeline" \ --display-name="CI/CD Deployer"
Then attach a role (for example, Storage Admin) with:
gcloud projects add-iam-policy-binding PROJECT_ID \ --member="serviceAccount:ci-cd-deployer@PROJECT_ID.iam.gserviceaccount.com" \ --role="roles/storage.admin"
This method is great for scripting and repeatable setups.
For large teams or DevOps pipelines, Terraform is ideal.
resource "google_service_account" "cicd" {
account_id = "ci-cd-deployer"
display_name = "CI/CD Deployer"
description = "Service account for CI/CD automation"
}
You can also attach roles using the google_project_iam_member resource.
Tip: Store your Terraform state securely and version control your configs.
Service account keys are powerful – and risky if not handled correctly. Think of them like “master keys” to your cloud house. If someone else gets them, they can unlock everything.
Google Cloud gives you two key types:
If you must use user-managed keys, follow these rules:
Better Alternative: Avoid long-lived keys completely. Instead, use Workload Identity Federation, which allows short-lived credentials and removes the need for key storage.
By rotating, restricting, and monitoring keys – or better, going keyless – you keep automation safe while reducing your cloud security risks.
(Source: Google Cloud – Best Practices for Managing Service Account Keys)
When you build automation or CI/CD pipelines in Google Cloud, service accounts act as the “robots” that perform deployments, builds, or API calls. To keep your setup secure and reliable, follow these key best practices:
Example:
A Cloud Build pipeline can use Workload Identity Federation to deploy to GKE. Instead of storing a JSON key, Cloud Build temporarily “impersonates” a service account, ensuring safer and fully automated authentication.
Following these practices keeps your automation clean, secure, and ready for scale – without the risk of leaking long-lived credentials.
(Source: Google Cloud Documentation – Best Practices for Using Service Accounts in Automation and CI/CD)
Let’s see how to automate GCP service account creation and usage using three simple tools – gcloud, Terraform, and Python. These examples are short and practical so you can copy and adapt them to your own setup.
# Create a service account gcloud iam service-accounts create ci-cd-bot \ --display-name="CI/CD Automation Bot" # Grant IAM role gcloud projects add-iam-policy-binding my-project-id \ --member="serviceAccount:[email protected]" \ --role="roles/storage.admin"
Good for quick setup or scripting automation steps.
Docs: Create service accounts | Google Cloud
resource "google_service_account" "ci_cd_bot" {
account_id = "ci-cd-bot"
display_name = "CI/CD Automation Bot"
}resource “google_project_iam_member” “ci_cd_storage” {
project = “my-project-id”
role = “roles/storage.admin”
member = “serviceAccount:${google_service_account.ci_cd_bot.email}”
}
Great for repeatable, version-controlled setups.
from Google.cloud import iam_credentials_v1
client = iam_credentials_v1.IAMCredentialsClient()
name = “projects/-/serviceAccounts/[email protected]”
token = client.generate_access_token(
name=name,
scope=[“https://www.googleapis.com/auth/cloud-platform”]
)
print(“Token:”, token.access_token)
Best for automation pipelines that need temporary credentials – no key files required!
These examples show how easily you can automate service account creation, role binding, and secure authentication using Google Cloud tools.
(Source: Google Cloud Documentation – IAM Client Libraries & Terraform Provider)
Keeping your GCP service accounts secure is not a one-time job – it’s an ongoing habit. Here’s a quick checklist to help you audit, rotate, and clean up safely and efficiently:
Tip: Download Technik Go’s free GCP Service Account Audit Checklist to make this routine easy!
(Source: Google Cloud Documentation – Best Practices for Managing Service Account Keys)
Even skilled teams hit bumps when managing GCP service accounts. Here are some quick tips to fix the most common problems:
You can only create a certain number of service accounts and keys per project.
Fix: Delete old or unused accounts, or request a quota increase in Google Cloud Console.
If your automation fails, it’s often due to missing or overly broad permissions.
Fix: Check IAM policy bindings and grant only the needed roles (principle of least privilege).
Exposed keys in GitHub or scripts are a major risk.
Fix: Revoke and rotate the key immediately, and scan your repos for credentials.
Using default accounts gives too much access.
Fix: Disable default service accounts and create purpose-built ones for each task.
If impersonation calls fail, the caller might lack roles/iam.serviceAccountTokenCreator.
Fix: Add this specific role and check Audit Logs for denied actions.
(Sources: Google Cloud Documentation, Stack Overflow discussions, Datadog Security Blog)
Want to automate your Google Cloud workflows the right way?
Technik Go helps businesses design secure service accounts, automate setups with Terraform, and connect safely with GKE and Cloud Build - all following Google’s best practices.
Today, for a free cloud security audit or automation setup guide.
A GCP service account is like a “robot user” that helps apps or scripts access Google Cloud securely without using a human login.
You can create a new key, update your app, and then delete the old one. It’s good to rotate keys every 90 days or automate it using policies.
Workload Identity Federation lets apps use short-lived credentials instead of long-term keys – it’s safer and recommended for automation.
Yes. Use the google_service_account and google_project_iam_member resources in Terraform to create and assign roles automatically.
Never store keys in GitHub or code files. Use Secret Manager or Vault instead, and limit who can create or download keys.
Rotate keys every 60–90 days or sooner if there’s any security change. You can also use IAM policies to enforce key rotation rules.
2025 TechnikGo LLC. All Rights Reserved.