Skip to content

The act of erasure ​

Retention is a floor. Before retainUntil, and for a Permanent file, nothing expires a file — not the jobs, not an ordinary manual purge, and no permission. One act still passes: the erasure, the purge a data subject's request ends in (LGPD). It is a control act, with explicit marking, a reason, two authors where the file is Permanent, and a durable audit trail. This page is the contract (RN-GF-25, RN-GF-10, RN-GF-27 (f)); the ordinary purge is in Retention & Purge.

The ordinary purge and the erasure ​

Ordinary purgeErasure
Asked withPOST /files/{id}/purge; IFileStore<TScope>.PurgeAsyncThe same, with erasure: true / ConsumerPurgeRequest.Erasure
States reachedAvailableAvailable, Infected and Failed (a quarantine does not wait for its window to expire for the person who asked)
retainUntil ahead, or Permanent409 FILE_RETENTION_NOT_EXPIRED_CONFLICT, nothing changes (DEC-GF-19-9)Passes
Name on the tombstoneGone only with redactFileNameAlways gone
TrailA line, any storeA line in a durable store, or 503 FILE_AUDIT_TRAIL_UNAVAILABLE and nothing is destroyed
Legal hold of any holderFILE_LEGAL_HOLD_CONFLICTFILE_LEGAL_HOLD_CONFLICT — the hold wins over the data subject
Reference of another ownerFILE_STILL_REFERENCED_CONFLICTThe same, except the pairs the consumer names (below)

Pending and Scanning have no verdict to tombstone, and both ask the consumer to wait (FILE_NOT_AVAILABLE_CONFLICT). A quarantined file under investigation is kept by the hold of whoever needs the bytes — the erasure leaves the tombstone (signature or rejectionCode, sha256 when there is one, the scan attempts) as the proof of the incident.

A refusal on the retention floor carries the date in the message, so a screen can say until when (Permanent has no date).

Through the route ​

POST /files/{id}/purge with { "reason": "…", "erasure": true }:

  • needs purge:files; a Permanent file also needs purge-permanent:files; a product file needs the platform permission purge:product-files instead. These are checked over the record under its lock, after the file is found and before its state is judged (a missing permission is 403, never a hint about the file) — and a file of another tenant is 404 before any of it;
  • the author is the authenticated user, and the only one: a single author is enough on the route, Permanent included — the route's second guard is the permission;
  • reason is required, at most 200 characters, and may not start with job: (a person cannot borrow the prefix of an automated tombstone);
  • a product file answers FILE_AUDIT_TRAIL_UNAVAILABLE (503) for now: the Core outbox does not take a trail line without a tenant (why).

In process, by the registered consumer ​

The consumer erases its own files through its port, with no module permission checked (RN-GF-28):

csharp
var request = new ConsumerPurgeRequest
{
    Reason = "Erasure requested by the data subject — ticket 4812",
    Erasure = true,
    OwnerKeys = ["ATT-1", "ATT-2"],                       // the pairs of THIS scope to release
    RequestedBy = new DeclaredFileAuthor(registeredBy, "privacy-desk"),
    ExecutedBy  = new DeclaredFileAuthor(executedBy, "erasure-job")  // only when there is no user
};

var ready = await files.CheckPurgeAsync(fileId, tenantId, request, PurgeCheckMode.Execution, ct);
if (ready.IsSuccess)
{
    var erased = await files.PurgeAsync(fileId, tenantId, request, ct);
    // Publish "erased" only when erased.Data.PurgedAt is set; FILE_LEGAL_HOLD_CONFLICT means blocked.
}

Authors. With a user in the context, the user executes (purgedBy, recorded as authenticated), and only RequestedBy — who registered the request on the consumer's side — may be someone else; any other declared author who differs from the user is 401 FILE_CALLER_UNAUTHORIZED. Without a user, ExecutedBy is the author, recorded as declared, with the scope that declared it and the executor of service; with neither, 401 and nothing is read. An empty id is 422 FILE_ERASURE_AUTHOR_INVALID_UNPROCESSABLE.

Dual custody (ErasureDualCustody). A Permanent file — and any product file in process (DEC-GF-19-3) — needs two different people: the one who registered the request and the one who executes it. One author, or the same person twice, is 409 FILE_ERASURE_DUAL_CUSTODY_CONFLICT, nothing erased, the reference of the pair untouched and nothing on the trail. admin:system of a person does not replace the second author, and no permission is checked at all: that is what lets the replay of the act after the consumer's commit — a job with no session — finish the job.

The authors are verified, not only compared. Each one has to be an existing, active user of the file's tenant — for a product file, of the tenant the consumer named, which is the tenant in force. Empty id, unknown id, inactive user, user of another tenant: 422 FILE_ERASURE_AUTHOR_INVALID_UNPROCESSABLE, before any effect. The lookup goes through the IFileActorDirectory port; see the adapter.

The pairs. A propagated file may have more than one pair of the same scope (the same document copied to a second one). OwnerKeys lists the pairs of the consumer's scope; their active references are released in the same transaction as the tombstone, and none counts as an impediment. A reference of another scope refuses with FILE_STILL_REFERENCED_CONFLICT; one of the same scope the list left out refuses just the same — the consumer says which copies the request reaches. A pair naming another scope is 403 FILE_OWNER_SCOPE_FORBIDDEN. Two consumers with active references on one file are a deadlock the module does not coordinate (the Nexio is the only consumer of an attachment scope in v1); each consumer releases its own reference by its own act.

A product file in process has no tenant to separate who reaches what, so the link between the consumer and the file is a reference: an erasure that names no active pair of the consumer's own scope on a product file is 403 FILE_OWNER_SCOPE_FORBIDDEN.

The pre-condition query ​

CheckPurgeAsync(fileId, tenantId, request, mode) answers, with no effect and without reserving anything, whether the erasure would be accepted now — the same checks in the same order, and the same code the purge would give (the purge and the query walk the same chain, PurgePlans). It exists for the consumer to check before it writes its own act, and never to publish an erasure the module will refuse.

ModeAskedSecond author
RegistrationBefore the request is written, when only the person registering existsNot demanded — its absence is not a refusal. If both come and they are equal, FILE_ERASURE_DUAL_CUSTODY_CONFLICT anyway: answering "accepted" to what is known to be refused would make the consumer record a request the purge then refuses
ExecutionBefore executing, with both authors knownDemanded; dual custody is checked

The query does not generate an attempt on the trail. And it reserves nothing: a hold placed by another holder between the query and the purge wins — the purge answers FILE_LEGAL_HOLD_CONFLICT with the holders and purgedAt null, and the consumer treats the request as blocked, never as done.

The order of the refusals ​

Everything that can be decided without the file comes first and costs no lock; then the file is read under the lock and the chain of the act runs. For a consumer's erasure:

  1. contract: pairs or authors on a request that is not an erasure, or a declared author with no executor of service (400, no code);
  2. author: nobody (401), a declared author who is not the user in the context (401), an empty id (422);
  3. reason (400);
  4. a pair of another scope (403);
  5. the authors against the directory (422);
  6. the file: absent or another tenant's (404); then the state (409 FILE_NOT_AVAILABLE_CONFLICT for Pending/Scanning); dual custody (409); for a product file, the link (403); a hold (409); the references (409); the trail (503).

Every refusal comes before any effect: no reference is released, no name is erased, no line is written — with one exception below.

The attempt on the trail ​

A refused attempt leaves a trace (stored_file.erasure_refused, with the code, the authors and, for a hold, the holders): "the job that repeats the act and is refused every day cannot be left without any record." Two kinds of refusal do — the ones over what holds the file (the product link, a hold, a reference) and the same person in both roles of a dual custody (FILE_ERASURE_DUAL_CUSTODY_CONFLICT, the most suspicious attempt there is; DEC-GF-19-11) — and only after the authors were verified (DEC-GF-19-4). Refusals about the request itself (author, reason, contract, a dual custody whose second author is missing), the state, the marking or the trail leave no line. The pre-condition query never writes one.

The tombstone ​

The erasure writes purgedAt, purgeReason, purgeAuthorKind and the authors together: purgedBy is the executor, erasureRequestedBy is who registered, and for a declared author also purgeDeclaredScope and purgeServiceExecutor. originalFileName is null. The object dies before the tombstone and under the lock — never the other way round (RN-GF-10) — and once the object is gone the commit runs on CancellationToken.None: a request cancelled in between would leave the bytes deleted and the record Available. A commit that fails converges on the next erasure, because an object already gone is not an error.

The host adapter: IFileActorDirectory ​

GrydFiles does not reference GrydAuth, so it cannot ask whether a user exists. The host that composes both registers the adapter, before AddGrydFiles; until then the default (RejectingFileActorDirectory) answers that nobody is valid, so no erasure in process runs on a guess:

csharp
public sealed class AuthFileActorDirectory(IUserTenantEligibilityService eligibility) : IFileActorDirectory
{
    public async Task<IReadOnlySet<Guid>> FindMembersAsync(
        IReadOnlyCollection<Guid> userIds, Guid tenantId, CancellationToken ct)
    {
        var verdicts = await eligibility.CheckManyAsync(userIds, tenantId, ct);
        return verdicts.Where(v => v.IsEligible).Select(v => v.UserId).ToHashSet();
    }
}

builder.Services.AddScoped<IFileActorDirectory, AuthFileActorDirectory>();
builder.Services.AddGrydFiles(builder.Configuration);

The implementation above is the one in tools/GrydAuth.AdminDevHost. It is the host's, not a package: copy it or write the equivalent against your own identity store. A user is eligible when they exist, are active and belong to the tenant.

Errors at a glance ​

Status · codeWhen
400 (no code)Reason missing, too long or job:; pairs/authors on a request that is not an erasure
401 FILE_CALLER_UNAUTHORIZEDNo author, or a declared author who differs from the user in the context
403 (no code)A route permission is missing
403 FILE_OWNER_SCOPE_FORBIDDENA pair of another scope; a product file with no active pair of the consumer's scope
404 FILE_NOT_FOUNDAbsent, or another tenant's
409 FILE_NOT_AVAILABLE_CONFLICTPending/Scanning (and, for the ordinary purge, Failed; an Infected file answers FILE_INFECTED_CONFLICT there)
409 FILE_RETENTION_NOT_EXPIRED_CONFLICTOrdinary purge before retainUntil, or of a Permanent file
409 FILE_ERASURE_DUAL_CUSTODY_CONFLICTOne author, or the same twice, where two are required
409 FILE_LEGAL_HOLD_CONFLICTA hold of any holder; the holders are listed
409 FILE_STILL_REFERENCED_CONFLICTA reference not released by the pairs named; the scopes are listed
409 FILE_PURGED_CONFLICTThe file is already a tombstone
422 FILE_ERASURE_AUTHOR_INVALID_UNPROCESSABLEAn author that is not an existing, active user of the tenant checked
503 FILE_AUDIT_TRAIL_UNAVAILABLEThe store is not durable (NullAuditStore), or the file has no tenant to write the line to

The decisions behind this page are in ADR 0010; the contract is RN-GF-25 of the specification.

Released under the MIT License.