Sitemap
Stackademic

Stackademic is a learning hub for programmers, devs, coders, and engineers. Our goal is to democratize free coding education for the world.

GCP- Mastering Google Cloud Identity-Aware Proxy (IAP) — A Feynman-Style Crash Course

4 min readMay 18, 2025

--

Press enter or click to view image in full size

Imagine this first

You’ve built a sleek internal dashboard for your team, deployed it to Cloud Run, and shared the link. But suddenly — anyone with the URL can access it. Yikes. You start wondering: Do I need to spin up a VPN? Set up a firewall? Add login logic to my app?

Nope. You need IAP.

Let’s explore what Identity-Aware Proxy is, how it works, and how you can use it — without jargon, just like you’d explain it to your curious 12-year-old self (or a friend over coffee).

What Is IAP, Really?

Google Cloud’s Identity-Aware Proxy is like the bouncer at a nightclub, but smarter. Instead of checking your shoes or dress code, it checks:

  • Who you are (identity)
  • If you’re allowed in (IAM roles)

It’s a protective layer that sits in front of your apps and APIs — no matter whether they’re on App Engine, Cloud Run, or GKE. When someone tries to access your app, IAP intercepts the request, confirms the user’s identity using Google Sign-In (OAuth 2.0), checks if they’re authorized, and then lets them through.

Without IAP: anyone with the link can hit your app. With IAP: only the right people get in — secure, simple, and centrally managed.

How Does It Work?

Here’s the flow, simplified:

  1. You visit an IAP-protected app.
  2. IAP stops you and says, “Hold up — who are you?”
  3. It sends you to Google Sign-In.
  4. You log in. Google gives IAP a token proving who you are.
  5. IAP checks a list (IAM roles) to see if you’re allowed in.
  6. If yes, IAP passes your request to the app — adding headers like your email.
Press enter or click to view image in full size
How IAP Authentication Works

If you’ve ever used a doorman system or badge scanner at work, same idea — but this one works globally and scales instantly.

Setting It Up (Without Breaking a Sweat)

Let’s say you’ve got a Cloud Run service. Here’s the basic flow:

1. Deploy Your App Publicly First

gcloud run deploy my-app \
--source=. \
--allow-unauthenticated \
--region=us-central1

Why public? Because IAP only works on reachable URLs — it replaces the need for public access.

2. Enable IAP in GCP

gcloud services enable iap.googleapis.com

3. Assign Access with IAM

gcloud projects add-iam-policy-binding my-project-id \
--member="user:you@example.com" \
--role="roles/iap.httpsResourceAccessor"

Also make sure IAP can invoke the app:

gcloud run services add-iam-policy-binding my-app \
--member="user:you@example.com" \
--role="roles/run.invoker"

Boom — your app is now gated by identity.

🔐 IAM + Conditions = Fine-Grained Control

Think of IAM roles like room keys. Now imagine giving keys that only work:

  • On weekdays
  • For people from your company
  • During business hours

That’s what IAM Conditions let you do.

Example: Restrict Access to Your Company Only

--condition="expression=request.auth.claims.email.endsWith('@company.com'),title=CompanyOnly"

Want to go nerdier? You can restrict access by time zones, device attributes, and more.

OAuth 2.0 — The Engine Behind IAP

When you log in to a Google account, you’re using OAuth 2.0 — a protocol that hands you a JWT (identity token) that proves who you are.

Get allglenn’s stories in your inbox

Join Medium for free to get updates from this writer.

IAP uses this system. It gets a token from Google, verifies it, and uses it to allow or deny access.

If you’re writing a backend API, you can validate the token yourself using Google’s libraries. Here’s a quick example:

from google.oauth2 import id_token
from google.auth.transport import requests

token = id_token.fetch_id_token(Request(), 'https://your-api-url')

Then verify it and extract the email. Easy.

Securing APIs (Your Backend’s Bodyguard)

IAP can guard not just web UIs, but APIs too.

Imagine you’re building a private backend that only your mobile app should talk to. Instead of doing API keys or IP checks, you let the mobile app fetch an IAP identity token and send it:

Authorization: Bearer <ID_TOKEN>

IAP checks the token, verifies IAM, and forwards the request only if everything checks out.

Logging, Monitoring, Troubleshooting

When something breaks (and it will), logs are your best friend.

Common IAP Errors:

  • 401 Unauthorized: No token or invalid token
  • 403 Forbidden: You’re logged in, but not allowed (missing IAM role)
  • 500 Internal Server Error: Your app blew up

Where to Look:

  • Cloud Logging — search for IAP logs
  • Audit Logs — to see who tried what and when
  • Monitoring — alert on 403s or failures

Bonus: Logging Filter Example

resource.type="iap_web"
logName="projects/YOUR_PROJECT_ID/logs/cloudaudit.googleapis.com%2Factivity"

Real-World Use Cases

Press enter or click to view image in full size
World Use Cases IAP

The Final Mental Model

You can think of IAP like this:

“It’s a login door that appears before your app even loads — letting only the right people through, using identity instead of networks.”

It simplifies your life, centralizes your security, and fits beautifully into a zero-trust architecture.

Congratulations — you now understand IAP the way Richard Feynman would’ve loved: clear, intuitive, and unburdened by fluff.

Ready to go build something secure?

Thank you for being a part of the community

Before you go:

--

Tech builder Testing AI agents, LLMs, cloud infrastructure, and developer tools beyond the hype.

Stackademic
Stackademic

Published in Stackademic

Stackademic is a learning hub for programmers, devs, coders, and engineers. Our goal is to democratize free coding education for the world.