Skip to content

emka.web.id

writing knowledge, recording civilization

Menu
  • Home
  • Tutorial
  • Search
Menu

API Keys vs. Service Accounts vs. OAuth: How do you pick the right credential on Google Cloud?

Posted on December 5, 2026

Security in the cloud is often treated as a checkbox exercise until the first five-figure bill from a leaked credential hits the accounting department. If you have spent any time in the Google Cloud Console, you have faced that specific moment of friction: you just want your code to work, but you are staring at a screen asking you to choose between an API Key, a Service Account, or an OAuth 2.0 Client ID.

The temptation is always to take the path of least resistance. Usually, that means grabbing an API Key because it is a simple string you can paste into a config file. But convenience in cloud architecture is almost always a debt that you will have to pay back with interest when your project scales or gets audited. Understanding the nuances between these three credential types is not just about following “best practices” it is about understanding the fundamental difference between identifying a project, identifying a machine, and identifying a human.

API Keys: The False Comfort of Simplicity

API Keys are the “lowest” form of credential on Google Cloud. Think of them as a guest pass to a building that identifies which company sent the guest, but not who the guest actually is. When you use an API Key, you are telling Google Cloud: “Charge this request to Project X.”

The technical reality of API Keys is that they provide zero inherent security for the data itself. They are meant for public data or services that do not require access to private user information. If you are building a site that displays a Google Map or uses the Translation API for generic text, an API Key is fine. However, because these keys are often embedded in client-side code (JavaScript in a browser or a mobile app), they are effectively public.

The biggest mistake I see practitioners make is treating an API Key like a secret. It is not a secret; it is a billing identifier. If you do not apply API Restrictions (limiting which APIs the key can call) and Application Restrictions (limiting which IP addresses or referrers can use the key), you are essentially handing a blank check to anyone who views your source code. Even with restrictions, API Keys are brittle. They lack the sophisticated “identity” layer that modern security requires.

Service Accounts: The Backbone of Machine-to-Machine Trust

When we move into the realm of backend services say, a Compute Engine instance talking to a Cloud Storage bucket API Keys are no longer on the table. We need something that represents the application’s identity. This is where Service Accounts come in.

A Service Account is essentially a non-human identity. It is an email-like identifier (e.g., my-app@project-id.iam.gserviceaccount.com) that you grant specific IAM roles to. The mechanism here is far more robust than an API Key because it leverages Google’s Identity and Access Management (IAM) framework. Instead of a static string, Service Accounts typically use RSA key pairs for authentication.

But here is where most teams get it wrong: the management of Service Account Keys (.json files). Downloading a JSON key to your local machine or hardcoding it into a GitHub repository is a cardinal sin of cloud security. If that key is compromised, the “blast radius” is determined by whatever roles you assigned to that account.

The modern, professional way to handle this is through Workload Identity. If you are running on GKE (Google Kubernetes Engine) or even on-premises, you should never be touching a JSON key file. Workload Identity allows you to map a local service account to a Google Service Account, swapping short-lived, automatically rotated tokens. This removes the “identity debt” of having to manage, rotate, and secure static secrets. If you are still manually rotating JSON keys every 90 days, you are working harder, not smarter.

OAuth 2.0: Managing the Human Element

The third pillar is OAuth 2.0, and it is the most complex because it involves a third party: the end user. While API Keys identify a project and Service Accounts identify an application, OAuth identifies a user and their intent.

If your application needs to read a user’s Google Calendar or upload a file to their personal Drive, you cannot use a Service Account. Why? Because a Service Account represents your application’s permissions, not the user’s. OAuth 2.0 introduces the concept of “scopes” and “consent.” It is the protocol that powers that familiar “App X wants to access your contacts” screen.

The trade-off with OAuth is the implementation overhead. You have to manage redirect URIs, handle authorization codes, and securely exchange them for access and refresh tokens. From an architectural standpoint, OAuth is about delegation. You are asking the user to delegate a slice of their authority to your application.

One edge case often missed by developers is the “Confidential” vs. “Public” client distinction. If your code runs on a server you control, it is a confidential client and can safely hold a client secret. If it is a mobile app or a Single Page App (SPA), it is a public client, and you should be using the PKCE (Proof Key for Code Exchange) extension to prevent authorization code interception. Ignoring PKCE in 2024 is a massive red flag in any security audit.

The Decision Matrix: How to Choose

The choice usually comes down to two questions: Who is the caller, and whose data are they touching?

If the caller is an anonymous browser and the data is a public Google Map, use an API Key (and restrict it heavily).

If the caller is your own server or a background job and the data belongs to your project (like your own database or bucket), use a Service Account (preferably via Workload Identity).

If the caller is an end-user and the data belongs to them (their Gmail, their Drive), use OAuth 2.0.

There is a tempting “grey area” where people use Service Accounts for everything by using “Domain-Wide Delegation.” This allows a Service Account to impersonate any user in a Google Workspace. While powerful, it is also incredibly dangerous. It should be treated like a nuclear option useful for specific administrative tools, but a massive liability if used for general application logic.

Conclusion

If there is one takeaway from the current shift in Google Cloud’s security posture, it is the move toward “Keyless” authentication. Static credentials whether they are API Keys or Service Account JSONs are architectural vulnerabilities. They are difficult to rotate, easy to leak, and provide a permanent backdoor if not audited.

The industry is moving toward short-lived, identity-based tokens. By leveraging tools like the Cloud SDK (gcloud auth application-default login) during development and Workload Identity Federation in production, you can build systems where “keys” don’t even exist to be stolen. It requires more configuration upfront, but it eliminates the single most common cause of cloud data breaches: the forgotten credential in a public repository.

Stop looking for the easiest way to authenticate and start looking for the way that reduces your long-term liability. Your future self and your security team will thank you.

Terbaru

  • API Keys vs. Service Accounts vs. OAuth: How do you pick the right credential on Google Cloud?
  • Why Your Private Subnet is Offline: The DevOps Interview Breakdown
  • The Laravel-ification of Everything: Why Go and Rust are Racing to Steal PHP’s Crown
  • Why Redis is actually fast
  • The Fake 2FA Scandals and Fake AI Apps on Microsoft Store
  • Stop Overengineering Your Infrastructure: Docker Compose vs Kubernetes Resources
  • Traefik 3.8 New Feature: Yaegi v2 and the Gateway API Finally Make Custom Plugins Worth the Effort
  • Raspberry Pi OS: Why the November Update is a Win for Minimalism
  • React Can useState Hook Explained in 60 Seconds
  • How Do You Build an MMO Solo?
  • NixOS 26.11 “Zokor” Might Be the Most Practical Release for Desktop Power Users Yet
  • Why Your AWS Bill Can Just Tripled Overnight?
  • Why Indonesia’s Battle with Google is a Dangerous Game of Chicken
  • SYS010 Malware Explained: How Malvertising on Meta Bypasses MFA and Hijacks Your Digital Identity
  • Linux Mint 27 Adrien: Why This Version Jump is Make Sense?
  • NFS2ROOT: A 12-Year Reminder That Your Linux Kernel Is Never Truly Safe
  • The Death of Browsing and the Rise of the “Answer Engine Economy”
  • What’s new in Proxmox VE 9.3?
  • Why Your Morning Routine Needs an API: The Art of iOS Automation
  • Proof of Work is the New Certification: 5 AWS Projects to Build Before 2027
  • Omarchy is Our first agentic operating system
  • The Death of Popper.js: Why CSS Anchor Positioning is the New Standard for Connected UI
  • Why Your 2027 Cloud Career Depends on Moving Beyond Basic AWS Services
  • Why Discord is Ditching Electron for Rust: Is GPUi Actually the Future?
  • The End of the KDE Era: Why KaOS 2026.11 Is a Bold, Dangerous Gamble
  • The $2 Billion Code: Why GTA 6 is a Technical Miracle and a Hardware Nightmare
  • LibreDB Studio Explained
  • PHP 8.6 Is Officially Out: What’s New, What Breaks, and How We’re Upgrading
  • Rewriting Legacy Apps: 4 Data Migration Strategies That Actually Work
  • How to Install Clean Windows 11 Without Any Bloatware (Step-by-Step Guide)
  • Canonical: Ubuntu coming soon to Snapdragon X2 Series platforms
  • Finally, wolfSSL adds post-quantum algorithms!
  • How to Run Gemma Embedding Models Using Docker
  • Deploy Nginx Rootful Container with Podman
  • How to Sandboxing Browser on Linux Desktop with Flatpak
  • The Qwen4-35B-A3B: Is This the “Impossible” Model for Local AI?
  • Why Running LLMs Locally in Python is No Longer Optional for Serious Developers
  • Digital Ghetto: People are hacking their own houses with Claude
  • How to Let ChatGPT Control Your Computer From Your Phone (Step-by-Step)
  • Ternary Bonsai 2.5 at 215 TPS! Splash + DFlash2 on Apple M5 Max

©2026 emka.web.id | Design: Newspaperly WordPress Theme