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 report explains why orders are kept and for how long.
See
The_access_report_explains_why_orders_are_kept_and_for_how_long. - It names consent as the basis of the newsletter.
See
The_access_report_explains_that_the_newsletter_rests_on_consent. - Encrypted fields appear decrypted.
See
The_access_report_shows_the_email_address_decrypted. - Nothing about another customer is in it.
See
The_access_report_holds_nothing_about_other_customers.
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.
- The JSON export is served as
application/json. SeeThe_export_is_a_json_document. - It holds the account and the orders.
See
The_export_carries_the_customers_account_and_orders. - The file name contains nothing personal.
See
The_export_file_name_gives_nothing_away_about_the_customer.
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);
}
- A corrected value of an encrypted field is encrypted again.
See
A_rectified_email_address_is_stored_encrypted. - The outcome tells you how many rows changed per entity.
See
Rectification_reports_how_many_rows_it_corrected.
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;
});
- A restricted customer drops out of what sales can read. Other customers are unaffected.
See
A_restricted_customer_is_no_longer_processed_by_sales. - The subject registry reports the status
Restricted. SeeA_restricted_customer_is_recorded_as_restricted. - After the restriction is lifted, sales reads the customer again.
See
Lifting_the_restriction_lets_sales_process_the_customer_again.
Your queries do not change. Custodian hides the rows of a restricted subject the same way it hides another tenant's rows.
Consent withdrawal
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.
- After withdrawal there is no newsletter preference left to process.
See
Withdrawing_marketing_consent_ends_newsletter_processing. - The customer account rests on the contract and is untouched.
See
Withdrawing_marketing_consent_keeps_the_customer_account.
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:
- 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.
- 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. - It marks the subject as
Erasedin the subject registry. - 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);
}
- The account row is gone from the table.
See
Erasure_deletes_the_customer_account. - A backup taken before the erasure can no longer be decrypted.
See
A_backup_taken_before_erasure_cannot_be_decrypted_afterwards. - The registry reports the status
Erased. SeeAn_erased_customer_is_recorded_as_erased. - The returned
ErasureReceiptcarries the tombstone hash as proof. SeeErasing_a_patient_leaves_a_tombstone_as_proof. - The erased person's record no longer opens for anyone.
See
An_erased_patients_record_no_longer_opens_for_her_doctor.
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.