惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
H
Help Net Security
Last Week in AI
Last Week in AI
The Cloudflare Blog
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
IT之家
IT之家
aimingoo的专栏
aimingoo的专栏
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
Google DeepMind News
Google DeepMind News
B
Blog
C
Check Point Blog
T
Tailwind CSS Blog
云风的 BLOG
云风的 BLOG
D
Docker
Recent Announcements
Recent Announcements
Vercel News
Vercel News
博客园 - 聂微东
阮一峰的网络日志
阮一峰的网络日志
MyScale Blog
MyScale Blog
The GitHub Blog
The GitHub Blog
Stack Overflow Blog
Stack Overflow Blog
雷峰网
雷峰网
人人都是产品经理
人人都是产品经理
月光博客
月光博客
F
Fortinet All Blogs
Blog — PlanetScale
Blog — PlanetScale
B
Blog RSS Feed
The Register - Security
The Register - Security
V
Visual Studio Blog
F
Full Disclosure
Hugging Face - Blog
Hugging Face - Blog
T
Threat Research - Cisco Blogs
Latest news
Latest news
PCI Perspectives
PCI Perspectives
Cisco Talos Blog
Cisco Talos Blog
博客园 - Franky
D
DataBreaches.Net
A
Arctic Wolf
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
Google Developers Blog
P
Palo Alto Networks Blog
Engineering at Meta
Engineering at Meta
Microsoft Azure Blog
Microsoft Azure Blog
T
Tenable Blog
L
LINUX DO - 热门话题
Spread Privacy
Spread Privacy

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Part 1 — Why we built an Auth Gateway instead of putting auth in every service
Akarshan Gan · 2026-05-05 · via DEV Community

If you've been on a platform team long enough, you've probably watched this slow-motion failure:

You ship an auth library. Three services adopt it. Six months later, two of them are still on v1.0, one forked it to add a custom claim, and a fourth service rolled its own because the library "didn't fit their use case." A CVE drops. Now you're hunting through repos to find every place that decodes a JWT.

We've been running a multi-tenant platform on Kubernetes for a while, and we kept ending up there. So a couple of years ago we made a call: stop trying to protect every service and start making the decision once — at the edge.

This is the first post in a 10-part series about that gateway. The actual gateway is two pieces:

  • NGINX, packaged as a Helm chart, that fronts every authenticated route.
  • Auth Service, a small Go service that exposes a single POST /auth endpoint. NGINX hits it as a subrequest on every protected request.

I'll skip the marketing in this series. I'll show real code, real config, and the parts that hurt.

The decision: three things, three different homes

The mistake we kept making was treating "auth" as one thing. It's three:

  1. Authentication — who is this caller? (Authorization: Bearer ..., signature, expiry, revocation)
  2. Authorization — are they allowed to call this endpoint? (role, access level, tenant)
  3. Routing — where does this request go? (multi-tenant DNS, single-tenant vs multi-tenant upstream, header propagation)

If you put all three inside every service, every service ends up with its own opinion. So we split:

  • NGINX owns routing and fail-closed posture. It already sits in the request path. It's the cheapest place on earth to say "no."
  • Auth Service owns the decision — token validity, endpoint classification, access level check.
  • Upstream services own the business logic and trust the identity headers NGINX injects.

What this looks like on a single request

Here's the happy path, as it actually runs in production. A user calls GET /user-management/users/me with a bearer token and a tenant header.

A few things worth noticing:

  • The subrequest is a POST, not a GET. NGINX's auth_request always uses proxy_method POST in our chart. The Auth Service doesn't need a body — it decides from X-Original-URI, X-Original-Method, X-Tenant-ID, and the bearer token.
  • The Auth Service responds with identity headers. NGINX pulls them out with auth_request_set and re-injects them into the upstream proxy call. Upstream services never look at the JWT — they trust X-Identity-ID because they trust NGINX.
  • X-Request-ID is propagated end-to-end. Every log line on every hop carries the same id. (More on that in Chapter 9.)

The deny path is where centralization actually pays off

Two things that we got for free the moment we centralized:

  1. Identical error envelopes. Whether the failure is "no tenant header," "expired token," "wrong access level," or "the Auth Service itself is down," the client sees the same shape: {"source":"auth","message":"...","code":"...","error":"..."}. We didn't have to coordinate this across 30 services.
  2. Upstream services never run on a bad token. They aren't even invoked. That alone fixed a long tail of "service X returned 200 with weird data because the token didn't validate but the framework didn't care."

The corresponding NGINX config is small and worth showing in full. Trimmed to the parts that matter:

# auth.conf — the subrequest endpoint
location = /auth {
  internal;                                # only callable from auth_request

  proxy_pass_request_body off;             # auth doesn't need the body
  proxy_method POST;
  proxy_set_header Content-Length "";

  proxy_set_header X-Original-URI    $request_uri;
  proxy_set_header X-Original-Method $request_method;
  proxy_set_header X-Original-Host   $host;
  proxy_set_header X-Request-ID      $request_id;
  proxy_set_header X-Tenant-ID       $tenant_id;
  proxy_pass_request_headers on;            # forward Authorization etc.

  proxy_connect_timeout 5s;
  proxy_read_timeout    10s;
  proxy_next_upstream   error timeout http_500 http_502 http_503 http_504;
  proxy_next_upstream_tries 2;
  proxy_next_upstream_timeout 15s;

  error_page 502 503 504 = @auth_unavailable;   # fail-closed: 503 to the client

  proxy_pass http://auth_service/auth;
}

Enter fullscreen mode Exit fullscreen mode

And here's how a regular service location uses it:

location /user-management/ {
  set $product "incore";
  set $microservice "user-service";

  auth_request     /auth;
  auth_request_set $identity_id        $upstream_http_x_identity_id;
  auth_request_set $identity_type      $upstream_http_x_identity_type;
  auth_request_set $session_id         $upstream_http_x_session_id;
  auth_request_set $auth_error_message $upstream_http_x_auth_error_message;
  auth_request_set $auth_error_code    $upstream_http_x_auth_error_code;

  error_page 401 = @unauthorized;
  error_page 403 = @forbidden;
  error_page 502 503 504 = @upstream_unavailable;

  proxy_set_header X-Identity-ID  $identity_id;
  proxy_set_header X-Tenant-ID    $tenant_id;
  proxy_set_header X-Request-ID   $request_id;

  rewrite ^/user-management/(.*)$ /$1 break;
  proxy_pass http://user-service;
}

Enter fullscreen mode Exit fullscreen mode

That's roughly 25 lines per route, generated by a Helm range over the services dictionary. Adding a new service is a values change — no NGINX expert required.

Why NGINX, specifically

We didn't pick NGINX because of opinions. We picked it because of one directive: auth_request.

auth_request lets you tell NGINX: before you proxy the main request, fire a subrequest to this internal location. If the subrequest returns 200, continue. If it returns 401 or 403, stop and run my error handler. If it returns 5xx, run my "auth is down" error handler.

That sounds boring. It's not. It means:

  • Your upstream services don't see unauthenticated traffic at all.
  • You can change auth logic by deploying one service. No client SDK update, no library bump in 30 repos.
  • You get a single observable choke-point. auth_request_time_ms is one log field. We graph it. We page on it.
  • You can implement fail-closed by default with one line: error_page 502 503 504 = @auth_unavailable;. If the Auth Service is unhealthy, NGINX returns 503 to the client instead of letting the request through. We pay this cost on purpose. Allowing traffic through a broken auth check is how data leaks happen.

We'll dissect auth_request in Chapter 2.

Where the Auth Service fits

The Auth Service is intentionally small. It does five things:

  1. Reads a few request headers.
  2. Resolves the tenant.
  3. Matches the request path to an endpoint metadata record (we call this the trie — Chapter 4).
  4. Classifies the endpoint as OPEN, AUTHENTICATED, or ACCESS_CONTROLLED and runs the right validation pipeline.
  5. Emits exactly one structured AUTH_DECISION log line with the timing, identity, decision reason, and outcome.

It does not store sessions. It does not mint tokens (a separate service does). It does not know about your business logic. It's a policy decision point — the thing whose only job is to answer "yes or no, and why."

Here's the controller, paraphrased:

func (c *AuthController) Auth(ctx *gin.Context) {
    log := helpers.GetAuthDecisionLog(ctx)

    log.URI    = ctx.GetHeader("X-Original-URI")
    log.Method = ctx.GetHeader("X-Original-Method")
    log.TenantID = ctx.GetHeader("X-Tenant-ID")

    slug, trieKey, perms, trieExists, found := c.routeResolver.
        ResolveEndpointWithMetrics(ctx, log.URI, log.Method)

    if !trieExists { /* 503: trie not initialized */ }
    if !found      { /* 404: no such API found  */ }

    switch endpointType(perms) {
    case OPEN:
        log.DecisionReason = ReasonOpenEndpoint
        log.Outcome = "allow"
        ctx.Status(http.StatusOK)
    case AUTHENTICATED:
        c.runAuthN(ctx, log)
    case ACCESS_CONTROLLED:
        c.runAuthN(ctx, log)
        c.runAuthZ(ctx, log, perms)
    }
}

Enter fullscreen mode Exit fullscreen mode

Five branches. That's the entire shape of the gateway. The next nine posts are about what's inside each branch and what we learned operating it at ~50k RPS.

What centralizing actually costs

I'd be lying if I said this was free. Three real costs:

One extra hop on the hot path. Every authenticated request now does an in-cluster RPC to the Auth Service before it goes anywhere. We make this cheap with caching (Chapter 8) and with Ristretto-backed JWT verification, but the hop is still there. Median auth_request_time_ms is in the low single digits in our environment, but it's a budget you have to keep.

The Auth Service has to be HA. When it's down, everything is 503. We chose fail-closed on purpose — a permissive default would mean unauthenticated traffic could hit business services during an outage — but it raises the bar on availability. We run it with an HPA (2–10 replicas, 75% CPU/mem), keep alive 64 connections per worker, and gate readiness on the trie being loaded. Even with that, the Auth Service is the single most carefully operated thing on the platform.

auth_request is not cached. This surprises people. NGINX does not cache auth subrequest responses by default, and the obvious caching workarounds (caching by Authorization header) are dangerous in a multi-tenant world. Every protected request hits the auth pod. So everything inside the auth pod has to be fast. That constraint is what shaped the entire internal design — and is why Chapters 7 and 8 spend a lot of time on caches that live inside the auth process, not in NGINX.

Before vs after, at a glance

flowchart LR
    subgraph Before["Before — auth in every service"]
      C1[Client] --> S1[Service A<br/>auth lib v1.2] & S2[Service B<br/>auth lib v1.0] & S3[Service C<br/>custom auth]
    end
    subgraph After["After — Auth Gateway"]
      C2[Client] --> NX[NGINX<br/>auth_request] --> AU[Auth Service]
      NX --> SA[Service A] & SB[Service B] & SC[Service C]
    end

Enter fullscreen mode Exit fullscreen mode

What's coming

This series moves from primitive to production-grade:

  • Chapter 2auth_request in depth. Subrequest lifecycle, auth_request_set, named error_page locations.
  • Chapter 3 — inside the Auth Service. JWT validation, the per-tenant RSA key cache, the decision-reason model.
  • Chapter 4 — endpoint classification (OPEN / AUTHENTICATED / ACCESS_CONTROLLED) and the trie that drives it.
  • Chapter 5 — multi-tenant routing. SNI server blocks, X-Tenant-ID vs X-Tenant-Host, MT vs ST upstreams, and why we 400 on no tenant.
  • Chapter 6 — authorization at scale. Role → access level → endpoint, and the bitmap fast path that replaced string-set matching.
  • Chapter 7 — token revocation without killing performance. Redis ZSET + Stream + local cache, the race-condition fixes, and service-account rotation.
  • Chapter 8 — every cache in the hot path and how each one is invalidated.
  • Chapter 9 — operating the gateway. The AUTH_DECISION log, OpenTelemetry, health probes, and degraded-mode alerts.
  • Chapter 10 — what we'd build differently on day one.

Chapter 2 is up next: auth_request is a 12-character directive that quietly does most of the work in this post. I want to show you exactly why it's the right primitive — and what its sharp edges are.

If you're working on something similar and want to compare notes, drop a comment. We made plenty of mistakes; happy to share which ones bit hardest.