Keep a tenant's accounts' disk quotas within its own, together (inbuxa-admin#257) #497

Merged
jcoffey-dev merged 1 commits from fix/tenant-disk-quota-total into main 2026-11-20 14:42:49 +00:00
1 Commits
Author SHA1 Message Date
jcoffey-dev 3b6b9b699f Keep a tenant's accounts' disk quotas within its own, together (inbuxa-admin#257)
ci / fork-checks (pull_request) Skipped
ci / build (pull_request) Skipped
github/ci (branch) GitHub Actions
ci / github (pull_request) Successful in 13m27s
#494 stopped any one account's disk quota going past its tenant's, but
not several adding up to more: a 5 GB tenant could still give four
accounts 5 GB each. BulTester spotted it on the issue.

- x:Account/set (JMAP and SCIM) now refuses a disk quota that doesn't
  fit in what the tenant has left to give: its maxDiskQuota less the
  quotas of its other accounts, users and groups alike. The refusal
  names the limit, what's already given out and what's left. Accounts
  with no quota are always allowed and share what's left, which JMAP,
  IMAP and DAV already report. Only a write that grows the total is
  checked (a new quota, a raised one, an account joining the tenant),
  so lowering or clearing one always saves, even in a tenant already
  over a lowered limit (MT-18). The server administrator is held to it
  too.
- Restoring a deleted account is checked as well. It skipped the check
  before, so a tenant could delete an account, give its space away and
  restore it. The refusal tells the restorer to lower other quotas
  first, since a kept account's quota can't be edited.
- Moving a domain into a tenant counts the disk quotas of the accounts
  it brings (Refusal::DiskQuota, overQuota).
- A write that could grow the total takes a per-tenant lock in the
  in-memory store (so across a cluster) before its checks and releases
  it once saved; one left behind expires after 30 seconds. Without it,
  two writes at the same moment could each fit the space left and
  together pass it. A write that can't get the lock in five seconds is
  refused with forbidden, "try again".

Checked live against a debug build (5 GB tenant): four 5 GB accounts,
one created; a batch of two 2 GB with 3 GB left, one created; raising
past what's left refused, lowering saved; no-quota account created;
the server admin refused too; 8 parallel 3 GB creates, 1 created;
delete, give the space away, restore refused; a domain whose account
has 2 GB moved into 1 GB left refused; the tenant admin can't raise its
own tenant's limit. tenant_tests gains the sum and lowering cases;
tenant, undelete, scim and legal_hold suites pass.
2026-11-20 07:27:51 -07:00