DEV Community

realNameHidden
realNameHidden

Posted on

What is a Service Account in GCP?

In the world of cloud computing, security isn't just about locking the front door; it’s about making sure the delivery driver can’t walk into your bedroom. If you've ever wondered what is a service account in GCP, you’re essentially asking how Google Cloud Platform handles "non-human" identities.

Whether you're an engineer or a business owner, understanding service accounts is the key to building secure, automated apps that don't rely on your personal login.


What is a Service Account in GCP?

A service account in GCP is a special type of Google account intended for applications, virtual machines (VMs), and other automated workloads rather than people. Unlike your personal email address, a service account doesn't have a password and cannot be used to log in via a browser. Instead, it uses cryptographic keys to prove its identity.

The Simple Analogy: The "Office Badge" vs. "Master Key"

Think of your User Account like a master key tied to your face and ID. You use it to enter the building, access the HR files, and go into the server room.

A Service Account, however, is like a temporary visitor badge given to a printer repair technician. The badge doesn't "belong" to a person; it belongs to the role of "Repairing the Printer." It only allows access to the hallway and the printer room. If the technician leaves, the badge stays behind for the next one.


Why Do You Need Service Accounts?

If you have a script running on a server that needs to upload files to a storage bucket, you could use your own username and password. But what happens if you leave the company? Or what if that script is hacked?

Service accounts solve this by:

  • Automation: Allowing apps to talk to each other 24/7 without a human typing in a code.
  • Security: Following the Principle of Least Privilege (giving the app only the specific permissions it needs).
  • Auditability: Helping you see exactly which app did what in your logs, rather than seeing your own name everywhere.

Types of Service Accounts in GCP

Not all service accounts are created equal. Depending on your project, you'll encounter three main types:

Type Created By Description
User-Managed You Custom accounts you create for specific apps. Best for production.
Default GCP Created automatically when you enable certain APIs (like Compute Engine).
Service Agents GCP Managed entirely by Google to perform background tasks for you.

Real-World Example:

Imagine you are building a photo-sharing app. You would create a User-Managed Service Account named photo-uploader. You give it permission to "Write" to a specific folder in Google Cloud Storage, but nothing else. Even if someone finds the credentials for that app, they can't delete your entire database.


How Service Accounts Authenticate

Since service accounts don't have passwords, they use Service Account Keys. These are typically JSON files that contain a private key.

Expert Tip: In GCP, it is a "Best Practice" to avoid downloading JSON keys whenever possible. Instead, "attach" the service account directly to the VM or use Service Account Impersonation for better security.


3 Best Practices for Managing Service Accounts

  1. Grant Least Privilege: Don't give a service account the "Editor" or "Owner" role. If it only needs to read files, give it the Storage Object Viewer role.
  2. Use Unique Accounts: Don't use one service account for ten different apps. If one app is compromised, you'll have to shut down all ten to fix it.
  3. Rotate Keys Regularly: If you must use JSON keys, change them every 90 days to minimize the risk of a leak.

Actionable Takeaway

To master the basics of service accounts, follow these three steps today:

  1. Audit your IAM page: Go to the Google Cloud Console and see how many "Default" service accounts have the "Editor" role.
  2. Create a test account: Create one User-Managed Service Account and try giving it only one specific role.
  3. Delete unused keys: Check for any downloaded JSON keys that aren't being used and revoke them immediately.

Top comments (0)