ADR-023 — Canonical consumption of hierarchical settings
Date: 2026-10-21
Status: Accepted — superseded in part by ADR-024 (§3: Settings.User.* are no longer system permissions; preferences moved to the User level); superseded in part by ADR-025 (§5: the migration that drops TenantSettings applies late updates only)
Supersedes in part: ADR-012 — the TenantSetting entity and the template's PerTenantSettingsStore are replaced; the per-tenant auth settings slices stay.
Pairs with: DevPack ADR-016 (definitions in code, overrides per scope, secrets in the store, cache after commit) — also shipped in the package, at {NuGetPackageRoot}/itlab.template.devpack/{version}/devpack-docs/adrs/016-hierarchical-settings.md.
Context
The template stored per-tenant settings as raw strings in tenancy.TenantSettings, seeded defaults for the default tenant, and resolved them through its own PerTenantSettingsStore. Callers parsed "true"/"false" and treated a missing row as "not configured". DevPack 10.23.0 ships a hierarchical mechanism (DevPack ADR-016): typed definitions with defaults in code, overrides per scope (Global, Tenant, User), authorization in the manager and the cache invalidated after the commit.
Decision
- One table.
settings.SettingValues(mapped byApplyDevPackSettingsModel(Schemas.Settings)) replacestenancy.TenantSettings. Defaults live in code; nothing is seeded. - Definitions in Application.
AuthSettingDefinitionsdeclaresAuthProvider.*(and DevPack declaresEntraID.*). Every identity key isEditableBy = System,AllowedLevels = [Tenant]andSecurityBinding— a tenant admin cannot point the Entra directory elsewhere, and no global or configuration value can become every tenant's trusted directory. - Authorizers per level — the DevPack ones (
AddPermissionScopeAuthorizers, DevPack 10.24.0), configured with the template's permission names; the template only answers whether a tenant exists (SettingTenantDirectory).GlobalneedsSettings.Global.*([SystemPermission]);TenantneedsSettings.Tenant.*on the caller's own tenant;Settings.Tenant.CrossTenant([SystemPermission]) is the system reach — another tenant's settings, and the settings only the system administrator edits (EditableBy = System) at any tenant;Userneeds the caller's tenant and a member user, withSettings.User.*, or the user editing their ownEditableBy = Userkeys. Reads outside the reach, and a tenant that does not exist, answer 404; forbidden writes answer 403. The admin read of the auth settings goes throughISettingManager.DescribeAsync, so it is authorized like the update. The auth settings endpoints keep their own permission (Tenants.AuthSettings.Read/Update) on top: a caller needs both that and the system reach.Settings.User.*are[SystemPermission]while no definition accepts the user level, so a tenant administrator's group shows no toggle that changes nothing. - Anonymous flows pass the scope.
/auth/configresolves the tenant from the host and reads withSettingContext.For(Tenant(id)); the Entra reverse lookup finds the tenant through the indexed lookup value (EntraID.TenantIdis a lookup key) and refuses a directory trusted by more than one tenant (it used to take the first match). - Data migration without a transaction. The production deploy applies the per-migration scripts (runbook 03, ADR-022) and the copy re-runs after the rollout, so the copy from
TenantSettingsis an idempotentINSERT … WHERE NOT EXISTS(TenantSettingsCopy). The value kind is driven by the key (booleans were stored withType = String), soft-deleted rows are skipped and every active row is copied, including those equal to the default; a key without a definition is copied as a string and reported by the integrity check, so nothing is dropped silently. The ciphertext of secrets is copied as is. Host rows (TenantId0 or NULL) are skipped: the old store never wrote one.TenantSettingsis frozen for one release and dropped in the next; a reconciliation step after draining the old pods copies rows they wrote late (shipped asTenantSettingsReconcile.sql, runbook 03), and the migration that drops the table runs it first, so a forgotten reconciliation cannot lose those rows. - Automation sets global values through configuration (
Settings:{key}); a client certificate (ADR-017) writes onlyTenantscope with the permission.
Consequences
- A new setting is one definition plus registration — no migration.
/auth/configand the Entra validators read resolved values: a tenant with no row sees the default, which the seed used to guarantee.- Writes are staged and committed by the caller's unit of work; the cache is invalidated only after the real commit.
- Explicit choices equal to the default become rows (no behaviour change now); a future global override does not affect them.
- Preferences (
UserPreference) move to theUserscope in a later delivery; thepreferencesHTTP contract stays.
Alternatives considered
- Keep
TenantSettingbehind the adapter: two stores for the same concept; no defaults in code. - Migrate in C# at startup: leaves the migration outside the reviewable script the deploy applies.
- Testcontainers for SQL tests: the CI's migration-scripts stage already starts a SQL Server container and points
SETTINGS_SQLSERVER_TESTSat it; locally any server with a throwaway database per run does, and the tests are skipped without the variable.