Data-subject rights

This page covers the requests a person can make about their own data. There is one section per right: access, portability, rectification, restriction, consent withdrawal and erasure. Each is one call on ISubjectRightsService. The code is the Shop sample, where a privacy officer answers requests about the customers Astrid and Clara.

Who answers a request

ISubjectRightsService works on one data subject in the current tenant. It needs a processing context like any other access to personal data. The Shop sample gives the PrivacyOfficer role the subject-rights purpose and the Privacy database role, and its tests call the service in that context. In the snippets below, Rights(...) resolves the service inside that context, and customer.Subject is the SubjectId the customer got at sign-up.

If you start from an email address or a customer number, ISubjectRegistry.FindAsync gives you the SubjectId. Encryption and blind indexes shows that lookup.

Every call is audited. The audit records ids, entity names, field names and row counts, and never a value. Audit trail describes the entries. Custodian also maps these calls as HTTP endpoints. ASP.NET Core covers them.

Access

GetReportAsync answers an access request under Art. 15. The report holds the data itself, decrypted, and for each entity the purpose, the lawful basis, the retention period and the roles that may read it.

public Task<SubjectReport> ReportOn(ShopCustomer customer) =>
    Rights(rights => rights.GetReportAsync(customer.Subject, Cancellation));

The explanations come from the classification on your entities. You do not write the report by hand.

Portability

ExportAsync answers a portability request under Art. 20. It returns every classified entity of the subject as one JSON document, or as a zip of CSV files with ExportFormat.Csv.

public Task<SubjectExport> ExportAsJson(ShopCustomer customer) =>
    Rights(rights => rights.ExportAsync(customer.Subject, ExportFormat.Json, Cancellation));

The result carries the content, its content type and a suggested file name.

Rectification

RectifyAsync answers a correction request under Art. 16. You pass one FieldCorrection per field. Custodian applies it to every row of that entity that belongs to the subject.

public Task<RightsOutcome> Rectify(ShopCustomer customer, params FieldCorrection[] corrections) =>
    Rights(rights => rights.RectifyAsync(customer.Subject, corrections, Cancellation));

FieldCorrection.For names the field with a property expression.

[Theory, EachProvider]
public async Task After_rectification_sales_reads_the_corrected_email_address(DatabaseProvider provider)
{
    await using var shops = await servers.OpenShop(provider);
    var astrid = await shops.Nordic.SignUp(Customers.Astrid());

    await shops.Nordic.PrivacyOffice.Rectify(astrid, FieldCorrection.For<Customer, string>(c => c.Email, "astrid@lindqvist.example"));

    var emails = await shops.Nordic.As(Staff.Sales).For(Purposes.CustomerAccount).Query(db => db.Customers.Select(c => c.Email));
    Assert.Equal(["astrid@lindqvist.example"], emails);
}

Restriction

RestrictAsync answers a restriction request under Art. 18. The data stays stored, and ordinary processing of it stops. LiftRestrictionAsync ends the restriction.

public Task Restrict(ShopCustomer customer) =>
    Rights(async rights =>
    {
        await rights.RestrictAsync(customer.Subject, Cancellation);
        return true;
    });

public Task LiftRestriction(ShopCustomer customer) =>
    Rights(async rights =>
    {
        await rights.LiftRestrictionAsync(customer.Subject, Cancellation);
        return true;
    });

Your queries do not change. Custodian hides the rows of a restricted subject the same way it hides another tenant's rows.

WithdrawAsync ends processing for one purpose. Use it when a person withdraws consent under Art. 7, or objects under Art. 21.

public Task<RightsOutcome> WithdrawConsent(ShopCustomer customer, string purpose) =>
    Rights(rights => rights.WithdrawAsync(customer.Subject, purpose, Cancellation));

Data held only for the withdrawn purpose expires at once. Data that also serves another purpose stays. This is why the Shop sample keeps the newsletter preference in an entity of its own, with consent as its lawful basis.

You must still be able to show that consent existed for the newsletters you already sent. The sample writes a separate ConsentRecord at sign-up. It rests on a legal obligation, so withdrawal does not remove it. See Withdrawing_marketing_consent_keeps_the_proof_that_it_was_given and The_consent_to_the_newsletter_can_still_be_proven_after_the_preference_has_expired.

Erasure

EraseAsync answers an erasure request under Art. 17. The reason you pass is stored as you give it, so it must not contain personal data.

public Task<ErasureReceipt> Erase(ShopCustomer customer) =>
    Rights(rights => rights.EraseAsync(customer.Subject, "Customer asked to be forgotten", Cancellation));

Erasure does four things, in this order:

  1. It destroys the subject's encryption key. Every encrypted value of the subject is unreadable from then on, in the database and in every backup. Encryption and blind indexes explains why.
  2. It goes through the subject's rows entity by entity. Where the entity's expiry action is Anonymise, it sets the personal fields to null and keeps the row. Otherwise it deletes the row.
  3. It marks the subject as Erased in the subject registry.
  4. It keeps a tombstone, which holds a keyed hash of the subject id, the time and your reason.

In the Shop sample the customer account is deleted and the orders are kept without the billing name and address. The books still add up.

[Theory, EachProvider]
public async Task Erasure_keeps_what_was_paid_and_removes_the_payers_name_and_address(DatabaseProvider provider)
{
    await using var shops = await servers.OpenShop(provider);
    var astrid = await shops.Nordic.SignUp(Customers.Astrid());
    var placed = await shops.Nordic.PlaceOrder(astrid);

    await shops.Nordic.PrivacyOffice.Erase(astrid);

    var order = Assert.Single(await shops.Nordic.StoredOrders());
    Assert.Equal(placed.Total, order.Total);
    Assert.Null(order.BillingName);
    Assert.Null(order.BillingAddress);
}

A kept order still carries its subject link, so it is pseudonymous and not anonymous. The orders of one erased customer can still be grouped together. The link no longer leads to an identity that Custodian holds.

Erasure is refused with LegalHoldException while a legal hold covers the subject's data. Lift the hold first. Retention covers holds.

After you restore a backup, call ReplayErasuresAsync so that the people you erased earlier stay erased.

Next