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

推荐订阅源

F
Fortinet All Blogs
有赞技术团队
有赞技术团队
量子位
N
Netflix TechBlog - Medium
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
Google DeepMind News
Google DeepMind News
aimingoo的专栏
aimingoo的专栏
GbyAI
GbyAI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
Martin Fowler
Martin Fowler
Y
Y Combinator Blog
宝玉的分享
宝玉的分享
博客园 - 司徒正美
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
V
V2EX
IT之家
IT之家
L
LangChain Blog
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

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
How I built multi-tenant Row Level Security with Aurora P...
Carolina · 2026-06-26 · via DEV Community

Carolina

I'll be honest: I almost did multi-tenancy the wrong way.

When I started building InspectIQ "a SaaS platform for Florida home inspectors" my first instinct was to add a tenant_id column to every table and filter it in the application layer. Every query would have a WHERE tenant_id = :current_tenant clause. Simple, familiar, done.

Then I thought about what happens when you forget one.

One missing WHERE clause. One endpoint that skips the filter. One inspector sees another inspector's client data. In a home inspection business, that's not just a bug — it's a HIPAA-adjacent nightmare and a trust-destroying moment with your first customer.

So I did it properly from day one: Row Level Security at the database layer.

What is Row Level Security?

RLS is a PostgreSQL feature that lets you define policies directly on tables.
When a user queries a table, the policy runs automatically, before your application code even sees the results. You can't forget to apply it. You can't bypass it with a careless JOIN. It's enforced at the lowest possible layer.

For a multi-tenant SaaS, this is exactly what you want.

How I implemented it

Every table in InspectIQ has this pattern:

ALTER TABLE inspections ENABLE ROW LEVEL SECURITY;
ALTER TABLE inspections FORCE ROW LEVEL SECURITY;

CREATE POLICY tenant_isolation ON inspections
  USING (tenant_id = NULLIF(current_setting('app.current_tenant_id',true), '')::uuid);

The FORCE is important — it applies the policy even to the table owner.
No superuser backdoor.

The tenant context comes from the JWT. When an inspector logs in, theirtenant_id is embedded as a custom Cognito claim. The FastAPI middleware extracts it and sets it at the start of every request:

await session.execute(
    text(f"SET LOCAL app.current_tenant_id = '{tenant_id}'")
)

SET LOCAL scopes the setting to the current transaction. When the transaction ends, it's gone. No leakage between requests.

Aurora PostgreSQL Serverless v2

I'm running this on Aurora PostgreSQL Serverless v2 on AWS. For an early-stage SaaS, the economics are compelling: you pay for what you use, it scales to zero between requests, and you get full PostgreSQL compatibility.

The RLS policies work identically on Aurora as they do on vanilla PostgreSQL.
No Aurora-specific gotchas, no driver changes.

One thing I learned the hard way: Aurora with restricted database users (which is the right security posture) means your migration user needs DDL privileges separately from your application user. I run schema migrations via a bastion EC2 through AWS SSM — no SSH, no exposed credentials, no public IP on the database.

The moment it clicked

The first time I tested with two tenants, I logged in as Tenant A and ran a query that should only return Tenant B's data. I got an empty result set.

Not an error. Not "access denied." Just nothing — because from the database's perspective, those rows don't exist for this tenant.

That's the right behavior. That's what you want. And I didn't have to write a single WHERE clause in my application code to get it.

The tradeoff

RLS adds complexity to your migration process and your database user setup.
You need to think carefully about which user runs DDL vs. which user runs application queries. You need to test that your policies actually work, both that they block the right data AND that they return the right data for the correct tenant.

But for a B2B SaaS where tenant isolation is a hard requirement, the tradeoff is worth it. The alternative — application-level filtering — is a security debt that compounds with every new endpoint you add.

What's next

InspectIQ is live at mcag-h0.vercel.app with a confirmed first customer (REBS Property Specialist LLC, a 30-year Florida licensed inspector) starting July 2026.

If you're building multi-tenant SaaS on Aurora PostgreSQL and want to talk architecture, find me here on dev.to.


I created this content for the purposes of entering the H0: Hack the Zero Stack
Hackathon by AWS and Vercel. #H0Hackathon