Skip to content

Commit 5bc7095

Browse files
committed
The user-data-cleanup examnple is now moved to its own repo.
1 parent 1cda2ba commit 5bc7095

33 files changed

+6
-5483
lines changed

user-data-cleanup/README.md

+4-146
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,7 @@
1-
21
# Wipeout user data when account deleted
32

4-
To be compliant with privacy regulations you may need to ensure that a
5-
user's data is deleted when they delete their account.
6-
7-
This library contains a Cloud Function triggered by account deletion.
8-
It wipes out all the data in the Firebase Realtime Database that
9-
belongs to the user that was deleted.
10-
11-
To determine what data belonged to the user, the Cloud Function analyzes the app's
12-
Security Rules, considering any data that can only be written by a
13-
particular user to belong to that user.
14-
15-
Also included here is a simple demo app showing how the library works.
16-
17-
The instructions below explain how to *use* this library. If you want
18-
to *contribute* to the library, or are just curious about how it is
19-
built, please see the overview [Design Doc](doc/design.md) and the
20-
detailed explanation of [Auto Rules
21-
Extraction](doc/auto_rules_extraction.md).
22-
23-
24-
## Functions Code
25-
26-
See file [functions/wipeout.js](functions/wipeout.js) for the data cleanup code.
27-
28-
When a user deletes their account, their data in the database will be deleted
29-
automatically. The function needs configuration to find according user data.
30-
The configuration can be specified in local file
31-
[functions/wipeout_config.json](functions/wipeout_conifg.json). If the file
32-
doesn't exists or doesn't contain a valid configuration object, the function
33-
will go ahead and infer the configuration from Firebase database authorization
34-
rules (verification of the inferred rules will be in the next release).
35-
36-
The configuration is a json object and its `wipeout` filed is a list of objects.
37-
Each object in the list has a string field called `path` specifying a path where
38-
user data is stored. The path string could use variable `$WIPEOUT_UID` which
39-
will be replaced by UID of the deleted user account when triggered.
40-
41-
Please don't change the `WIPEOUT_CONFIG` object in `functions/index.js` unless
42-
you want to customize the function and know the code well.
43-
44-
The dependencies are listed in [functions/package.json](functions/package.json).
45-
46-
47-
## Sample Database Structure
48-
49-
When a user signs-in we write some sample personal data of the following form:
50-
51-
```
52-
/functions-project-12345
53-
/users
54-
$uid : "Some user data"
55-
```
56-
57-
When the user delete their account a Function will trigger and automatically
58-
delete the corresponding user data in the realtime database.
59-
60-
## Trigger rules
61-
62-
The function triggers on user account deletions. While a developer confirmation
63-
is needed before the trigger stats to work, see step 9 in Deploy and test for
64-
details.
65-
66-
67-
## Deploy and test
68-
69-
This sample comes with a Function and web-based UI for testing the function.
70-
To configure it:
71-
72-
1. Create a Firebase Project using the
73-
[Firebase Console](https://console.firebase.google.com).
74-
1. Enable Google Auth. In the Firebase Console open the
75-
**Authentication** section > **SIGN IN METHOD** tab
76-
you need to enable the **Google** Sign-in Provider and click **SAVE**.
77-
1. Clone or download this repo and open the `user-data-cleanup` directory.
78-
1. You must have the Firebase CLI installed. If you don't have it install it
79-
with `npm install -g firebase-tools` and then configure it with
80-
`firebase login`.
81-
1. Configure the CLI locally by using `firebase use --add` and select
82-
your project in the list.
83-
1. Install dependencies locally by running: `cd functions; npm install; cd -`
84-
1. Run local tests using `cd functions; npm test`
85-
1. Deploy your project using `firebase deploy`, and note the showWipeoutConfig
86-
URL printed out.
87-
1. Visit the showWipeoutConfig URL in a browser and Initialized the library for
88-
this database by clicking the "INITIALIZE" button.
89-
1. Go to the showWipeoutConfig URL again to verify the wipeout rules. The
90-
webpage will show the source of these wipeout rules, either loaded from local
91-
config or generated from security rules.
92-
1. The format of wipeout rules are described in the next section. If the rules
93-
are correct, click the "CONFIRM DEPLOYMENT" button, or else change the local
94-
configuration file
95-
[functions/wipeout_config.json](functions/wipeout_conifg.json) and redeploy.
96-
**Note a developer confirmation is required after every deployment.**
97-
1. Open the app using `firebase open hosting:site`, this will open a browser.
98-
1. Sign in using Google Sign-In and delete the account using
99-
the provided button. You can check at each step of the way if the data
100-
has been deleted using the Firebase console.
101-
102-
## Understanding the wipeout rules
103-
104-
The wipepout rules is a list of JSON object, each of them describes a pattern of
105-
user data storage. When a user account is deleted, the library go through every
106-
config to remove any match with these patterns. A sinlge config rule can have
107-
four fields:
108-
* `path`: Mandatory field. A String indicating a location of user data. A path
109-
can include place holder variables `#WIPEOUT_UID` which will be replaced by
110-
`auth.uid` at execution time. It can also include free variables which
111-
starts with `$`. A simple example `path` is `/users/#WIPEOUT_UID`, and an
112-
example `path` field for a chat app is `/chat/$room`.
113-
* `authVar`: Optional field, List of data references. Besides the locations
114-
marked by `#WIPEOUT_UID` in `path`, authVar is a list of values/data
115-
references which should equals to the authentication uid. For example, the
116-
previous chat app example could have `authVar:
117-
['val(rules,chat,$room,creator)']`(see data reference below for format
118-
details). This will restrict the free variable `$room` to the set of chat
119-
rooms created by the user who just deleted the account because it requires
120-
data at `/chat/$room/creator` to be `auth.uid`.
121-
* `condition`: Optional field, string. Any additional restriction on the path
122-
which is not related to authentication. Logic `&&` and `||` supported, free
123-
variable not supported. An example condition: `#WIPTOUT_UID !== someID &&
124-
val(rules,user,#WIPEOUT_UID,creatYear) > 2016`.
125-
* `except`: Optional field. Subpath which doesn't belong to a single user,
126-
shouldn't be removed at account deletion. For example, shared data under a
127-
user data folder. Currently only subpaths which are one level deeper than
128-
its parent path is supported. An example `except` for `/chat/$room/` is
129-
`/chat/$room/members`.
130-
131-
Data reference: A string representing the value or existence of data at a
132-
location in the database. The string format is a call of `val()` or `exists()`,
133-
and the list of arguments stands for the path to the location. The root of the
134-
path is always 'rules'. e.g. `val(rules,chat,$room,creator)` stands for the
135-
value at location `/chat/$room/creator`.
136-
137-
At execution time, a config will go through the following process to get a set
138-
of materialized absolute paths in the database:
139-
1. Swap `#WIPEOUT_UID` place holder with `auth.uid` of deleted account.
140-
1. Evaluate condition, filter out any config with a false condition.
141-
1. Evaluate authVar, retrieve values for variables in path.
142-
1. Evaluate exception,
143-
1. Remove any remaining trailing free variables since they represent wildcard
144-
values in paths. After the removal, any path which still have free variable
145-
is not supported for deletion and will be ignored.
3+
**This code has moved to its own repo at
4+
https://github.com/firebase/user-data-protection**
1465

147-
After these steps, we'll have a list of concrete deletion path. The library goes
148-
ahead and deletes the data and record the the paths together with a timestamp at
149-
`/wipeout/history/#WIPEOUT_UID` in the realtime database.
6+
(For archeologists, Git history prior to mid October 2017 is here, while
7+
subsequent history is in the new repo.)

user-data-cleanup/database.rules.json

-47
This file was deleted.

0 commit comments

Comments
 (0)