---
title: "Permission-Aware RAG: End-to-End Testing with the SpiceDB Testcontainer"
description: "RAG pipelines leak data when the retriever ignores permissions, so retrieved chunks can be post-filtered through SpiceDB, a Zanzibar-style ReBAC engine, before they reach the LLM."
url: "https://swe.quest/articles/permission-aware-rag-end-to-end-testing-with-the-spicedb-testcontainer-b7d33c0e8045d6b2"
canonical: "https://www.docker.com/blog/rag-permission-testing-testcontainers-spicedb/"
source: "Docker"
published: "2026-01-15"
difficulty: "medium"
kind: "How-to"
reading_minutes: 7
tags: ["rag","identity-auth","testing","go"]
---

# Permission-Aware RAG: End-to-End Testing with the SpiceDB Testcontainer

A post on [Docker](https://swe.quest/sources/docker.md), published 2026-01-15, 7 min read, How-to. Original: [https://www.docker.com/blog/rag-permission-testing-testcontainers-spicedb/](https://www.docker.com/blog/rag-permission-testing-testcontainers-spicedb/)

## Summary

RAG pipelines leak data when the retriever ignores permissions, so retrieved chunks can be post-filtered through SpiceDB, a Zanzibar-style ReBAC engine, before they reach the LLM. Testcontainers spins up a real, disposable SpiceDB instance per test, which keeps permission tests reproducible with no mocks or manual Docker setup. The walkthrough is in Go: it starts the container, loads a document schema with owner and viewer relations, writes relationships for three users, calls CheckPermission on each retrieved document, and asserts that each user only gets documents they can read. A community Python module supports the same pattern.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [RAG & retrieval](https://swe.quest/tags/rag.md) (AI & ML)
- [Identity & auth](https://swe.quest/tags/identity-auth.md) (Security)
- [Testing](https://swe.quest/tags/testing.md) (Engineering practices)
- [Go](https://swe.quest/tags/go.md) (Languages)

## Prerequisites

- RAG basics ([easy posts on RAG & retrieval](https://swe.quest/tags/rag.md?difficulty=easy))
- Docker containers ([easy posts on Containers](https://swe.quest/tags/containers.md?difficulty=easy))
- Go testing ([easy posts on Go](https://swe.quest/tags/go.md?difficulty=easy))

## Keywords

SpiceDB, Testcontainers, Google Zanzibar, ReBAC, gRPC, OWASP Top 10 for LLM

## Related posts

- [Partial data dumps using Postgres Row Level Security](https://swe.quest/articles/partial-data-dumps-using-postgres-row-level-security-7b8cbab5206adee8.md): Supabase · 2022-06-28 · Medium · 4 min read · PostgreSQL, Privacy, Identity & auth, Testing
  Postgres Row Level Security can produce a seed.sql containing only safe, non-customer rows: create a restricted \`exporter\` role, attach RLS select policies that filter which rows it can see, then run \`pg\_dump --data-only --enable-row-security\` as that role.
- [Using an AI Assistant to Script Tools](https://swe.quest/articles/using-an-ai-assistant-to-script-tools-714a1e238504d1ea.md): Docker · 2024-10-07 · Medium · 5 min read · AI agents, Sandboxing & isolation, Containers, LLMs
  Instead of feeding large datasets like Pylint violation JSON through an LLM to transform them into SQL INSERT statements, the assistant can be prompted to write a JavaScript program that performs the transformation, then run it through a tool call.
- [Modelling Authorization for a Social Network with Postgres RLS and Drizzle ORM](https://swe.quest/articles/modelling-authorization-for-a-social-network-with-postgres-rls-and-drizzle-orm-6267eb437b8171e7.md): Neon · 2024-11-11 · Medium · 8 min read · PostgreSQL, Identity & auth, TypeScript, System design
  Postgres Row-Level Security can express the full authorization model for a Twitter-like social network, defined with Drizzle ORM's crudPolicy and pgPolicy helpers and the pg\_session\_jwt extension's auth.user\_id().
- [Creating AI agent solutions for warehouse data access and security](https://swe.quest/articles/creating-ai-agent-solutions-for-warehouse-data-access-and-security-d7254720cb9e9b17.md): Meta Engineering · 2025-08-13 · Medium · 10 min read · Identity & auth, AI agents, Analytics & OLAP, Evaluation, Security
  Meta is reworking access control for its offline data warehouse around a multi-agent system.
- [Banque des Territoires (CDC Group) x Polyconseil x Hugging Face: Enhancing a Major French Environmental Program with a Sovereign Data Solution](https://swe.quest/articles/banque-des-territoires-cdc-group-x-polyconseil-x-hugging-face-enhancing-a-major-eeda57273a842369.md): Hugging Face · 2024-07-09 · Easy · 17 min read · RAG & retrieval, LLMs, System design, Inference & serving
  Banque des Territoires, Polyconseil and Hugging Face built a sovereign RAG application that drafts sourced email replies for the EduRénov school-renovation program from its internal documentation.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
