agentleFS
Bhanuj-AIBhanuj-AI/ai-governance-oss/skills/tenant-isolation/SKILL.md

tenant-isolation

Skill2 starsChanged 4 months agoApache-2.0View on GitHub

Implement, review, or test AI Governance Control Plane authentication, authorization, tenant context propagation, and tenant data isolation. Use for protected reads or writes, repositories, workers, audit records, cache and ontology access, external-provider calls, and any change that could expose one tenant's data to another.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 5 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Treat tenant and actor context as mandatory security input for every protected operation.

    line 8
  2. Very specific:

    Read root AGENTS.md and src/ai_governance/tenancy/AGENTS.md, then read the scoped instructions for each changed transport, service, …

    line 13
  3. Distinctive:

    Add a negative test: create or request the same identifier in two tenants, then prove that each tenant can see only its own resource.

    line 24
  4. Distinctive:

    Do not log raw tokens, secrets, or unnecessary identity attributes.

    line 26
  5. Distinctive:

    Run the integration test first, followed by the closest protected API, service, or worker test:

    line 64
  6. Distinctive:

    When a change spans a repository, worker, audit path, ontology projection, or provider call, add a focused negative test in that boundary …

    line 72

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Tenant Isolation

Treat tenant and actor context as mandatory security input for every protected operation.

Workflow

  1. Read root AGENTS.md and src/ai_governance/tenancy/AGENTS.md, then read the scoped instructions for each changed transport, service, repository, worker, or provider layer.
  2. Trace the context from authenticated principal through the approved context dependency or factory into the application service and every persistence or provider call.
  3. Authenticate first, authorize second, then access data. Deny by default when context is missing, invalid, or ambiguous.
  4. Scope every lookup, list, idempotency key, event, audit record, cache entry, ontology identifier, and external request by organisation and project where applicable.
  5. Add a negative test: create or request the same identifier in two tenants, then prove that each tenant can see only its own resource.
  6. Do not log raw tokens, secrets, or unnecessary identity attributes.

Context pattern

Pass the established immutable context; do not rebuild it from client-supplied values inside application code.

@dataclass(frozen=True)
class TenantContext:
    organization_id: str
    project_id: str | None
    actor_id: str
    request_id: str
    correlation_id: str | None = None

For an API route, depend on get_compatible_tenant_context and pass the resulting context to the service. For a worker, reconstruct only the tenant context captured when the job was submitted; never accept a new caller scope for an existing job.

Isolation test pattern

Make collisions intentional. The current integration test submits the same input and idempotency key in two tenant scopes, then verifies that IDs and lists do not cross the boundary. Use the same approach for the resource being changed.

assert repository.find_by_id("job_a", "org_b", "project_b") is None
assert repository.list_jobs(
    organization_id="org_a", project_id="project_a"
) == [first]

Verify

Run the integration test first, followed by the closest protected API, service, or worker test:

uv run ruff check src/ai_governance/tenancy
uv run pytest tests/integration/test_tenant_isolation.py

When a change spans a repository, worker, audit path, ontology projection, or provider call, add a focused negative test in that boundary as well.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.