Skip to main content

Employee Database Tenant Isolation

Summary​

Employee domain and organization rows persist a tenant identifier. EF Core global query filters restrict normal queries to the current tenant, while selected uniqueness checks deliberately bypass filters and reapply an explicit tenant predicate.

Audience​

  • Backend and QA engineers
  • Security engineers and solution architects

Isolation flow​

Filter inventory​

Object groupTenant fieldGlobal filterSource
EmployeesIntegerCurrent tenant or super-adminInfrastructure/EmployeeDbContext.cs
Eight Employee child objectsIntegerCurrent tenant or super-adminsame
Departments and DesignationsIntegerCurrent tenant or super-adminsame
Employee audit logsIntegerCurrent tenant or super-adminsame
Outbox messagesShared optional tenant conceptNo end-user global filter; operational storesame

When no tenant is present, the context filter compares normal tenant-scoped objects with a non-business sentinel value; command/query handlers separately call RequireTenantId for approved direct operations. Compatibility paths do not apply that requirement uniformly, so their missing-context behavior remains Requires confirmation.

Scoped constraints and repositories​

  • Employee code, department code, and designation code are database-unique within tenant scope.
  • Employee email uniqueness is checked in application/repository code within the tenant, but no unique email database index exists.
  • Child tenant identifiers are stamped from the aggregate rather than accepted independently.
  • Uniqueness repositories use IgnoreQueryFilters only with an explicit tenant condition.

Super-admin boundary​

The query filters contain a confirmed super-admin bypass. Which public operations may invoke it and how access is governed are outside this database model and Requires confirmation. Its existence is not a complete security assurance; authorization, deployment, and database privileges remain separate controls.

Source References​

  • microservices/src/employee-service/Infrastructure/EmployeeDbContext.cs
  • microservices/src/employee-service/Infrastructure/Persistence.cs
  • microservices/src/employee-service/Application/Common/Abstractions.cs
  • microservices/src/employee-service/Application/Validators/EmployeeCommandValidators.cs

See Also​

Keywords​

  • Global query filter
  • Tenant-scoped uniqueness
  • Super-admin context

Revision Information​

  • Status: Draft
  • Last reviewed: 2026-07-15
  • Review cycle: Quarterly