tenant-context-propagation

Propagate and validate tenant context across HTTP requests and background jobs.

Updated Mar 29, 2026
One-click install
npx skills add https://github.com/marquesfelip/agents-and-skills --skill tenant-context-propagation
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tenant-context-propagation
Source: https://github.com/marquesfelip/agents-and-skills/tree/main/skills/tenant-context-propagation
Command: npx skills add https://github.com/marquesfelip/agents-and-skills --skill tenant-context-propagation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Ensures safe propagation of tenant context across HTTP requests, service boundaries, and background jobs in a multi-tenant SaaS environment, preventing cross-tenant data leakage and misidentification.

Core Features & Use Cases

  • Extract and validate tenant context at the request boundary using a typed context key.
  • Propagate tenant information through application layers without passing raw identifiers.
  • Detach context for asynchronous work and goroutines to avoid cancellation of in-flight operations.
  • Enforce tenant presence and membership at service boundaries to guarantee isolation.
  • Provide fast feedback through boundary assertions and test helpers to catch propagation gaps early.

Quick Start

Integrate TenantMiddleware into your HTTP router and replace any direct tenant_id usage in services with tenant derived from context.

Frequently Asked Questions about tenant-context-propagation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I propagate tenant context across HTTP requests in a multi-tenant Go application?

To propagate tenant context across HTTP requests in a multi-tenant Go application, extract and validate the tenant identity at the request boundary using HTTP middleware, then pass it through service layers via a typed context key to prevent data leakage.

Why does my background job lose tenant context in Go?

Background jobs lose tenant context in Go because child goroutines inherit parent context cancellation signals. Detaching the context for asynchronous work prevents in-flight operations from being cancelled when the initial HTTP request completes.

What is the best way to prevent cross-tenant data leakage in a SaaS architecture?

The best way to prevent cross-tenant data leakage in a SaaS architecture is enforcing tenant presence and membership at service boundaries using a RequireTenant assertion, ensuring strict isolation by validating identity before processing any logic.

How do I enforce tenant isolation at service boundaries in Go?

You enforce tenant isolation at service boundaries in Go by requiring tenant extraction at middleware entry points and using boundary assertions to immediately catch context propagation gaps, guaranteeing operations only execute with valid tenant identity.

Do I need to pass raw tenant identifiers through my Go service layers?

No, you do not need to pass raw tenant identifiers through Go service layers. By using a typed context key, you securely propagate tenant information through application layers without exposing raw identifiers to business logic.