archive / 2018

7 things the GDPR changed in our code

Yesterday the GDPR came into force. Not legal advice, just what it meant for us as developers in practice: logs, retention, erasure requests and a pile of ugly SQL.

Yesterday, 25 May, was the day: the GDPR now applies. My inbox is full of “we’re updating our privacy policy” and “do you want to stay subscribed?” from companies I didn’t even know had my address. Which is, in itself, a nice summary of the problem this law is trying to solve.

At the scale-up we’ve been working on it since the autumn. Most of the work was legal and organisational, and I’m not going to write about that, because I’m not qualified to. But a decent chunk landed with us, the developers. This is what changed in practice.

1. We now know where the personal data lives.

Sounds trivial. It wasn’t. The first step was an inventory: which tables, services, queues, S3 buckets and third-party tools contain anything that can be traced back to a person? The answer was “a lot more than we thought”. Email addresses in an audit_events table nobody used anymore. Full names in the payload of messages we keep in a queue for seven days. A CSV export from 2016 in a bucket called tmp. That bucket no longer exists.

2. Logs are data too.

This was the biggest eye-opener. Our logs contained IP addresses, email addresses in error messages, and sometimes complete request bodies at debug level. And those logs stayed in Elasticsearch for ninety days, searchable by everyone in engineering.

We added a small scrubber to our shared Go logging package that masks fields before they go out:

var sensitiveFields = map[string]bool{
	"email":    true,
	"phone":    true,
	"iban":     true,
	"password": true,
}

func scrub(fields map[string]interface{}) map[string]interface{} {
	clean := make(map[string]interface{}, len(fields))
	for k, v := range fields {
		if sensitiveFields[strings.ToLower(k)] {
			clean[k] = "[redacted]"
			continue
		}
		clean[k] = v
	}
	return clean
}

Is it watertight? No. Someone writing log.Printf("failed for %s", user.Email) still slips right through. That’s why it’s now on our code review checklist as well. A tool helps, a habit helps more.

3. Retention is a feature, not an afterthought.

“We keep everything, you never know” isn’t a policy anymore. Every table with personal data now has a retention period, and a nightly job cleans up. For most tables it’s something along these lines:

DELETE FROM login_attempts
WHERE created_at < now() - interval '30 days';

For big tables we do it in batches, otherwise you end up with a transaction holding locks for an hour. We learned that, ahem, from experience.

4. Deleting is harder than you think.

The right to be forgotten. A user asks to be deleted, and then you have to go through everything. The database is the easy part. But backups? Analytics? That one support ticket system? The emails that were already sent?

We went with a central erasure service that receives a deletion request and publishes an event. Every service that stores personal data listens for it and confirms when it’s done. If not every service has confirmed after 48 hours, we get an alert. For backups we were pragmatic: they expire after 35 days, and when we restore one, we replay the erasure requests from the last 35 days.

5. Sometimes anonymising beats deleting.

You can’t delete an order, because accounting has to keep it for years. What you can do is cut the link to the person. Name, address and email go, the amount and date stay. Mind you: a hash of an email address is not anonymisation. With a word list you can reverse that in a few minutes.

6. Test data no longer comes from production.

That was a bad idea all along, but it was “convenient”. A production dump on a staging environment that thirty people have access to. We now have a seed script that generates realistic fake data. It took a week, and the honest answer is that we should have done it years ago.

7. “Privacy by design” mostly means: don’t ask for it if you don’t need it.

The cheapest piece of personal data is the one you never store. For every new form we now ask: why do we want this field? Date of birth “for marketing” is not a good reason. Less data means less to secure, less to delete, and less to explain.

Wrapping up#

I’ve heard plenty of grumbling about the GDPR over the past months, and I get part of it. The law is vague in places, and small companies are getting swamped by it. But as a developer I have to be honest: nearly everything on the list above is stuff we should have been doing anyway. The only thing that changed is that there’s now a fine attached to it.

And now I’m off to unsubscribe from about twenty newsletters. Thank you, GDPR.

    Tip: / opens search, ↑↓ to select, ↵ to open.