piitrace 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- piitrace-1.0.0/LICENSE +202 -0
- piitrace-1.0.0/NOTICE +4 -0
- piitrace-1.0.0/PKG-INFO +259 -0
- piitrace-1.0.0/README.md +224 -0
- piitrace-1.0.0/piiscanner/__init__.py +69 -0
- piitrace-1.0.0/piiscanner/audit/__init__.py +55 -0
- piitrace-1.0.0/piiscanner/audit/misses.py +151 -0
- piitrace-1.0.0/piiscanner/audit/report.py +193 -0
- piitrace-1.0.0/piiscanner/audit/sampling.py +247 -0
- piitrace-1.0.0/piiscanner/audit/scoring.py +421 -0
- piitrace-1.0.0/piiscanner/audit/storage.py +58 -0
- piitrace-1.0.0/piiscanner/audit/worksheet.py +185 -0
- piitrace-1.0.0/piiscanner/benchmark.py +151 -0
- piitrace-1.0.0/piiscanner/classify/__init__.py +0 -0
- piitrace-1.0.0/piiscanner/classify/checksums.py +218 -0
- piitrace-1.0.0/piiscanner/classify/engine.py +398 -0
- piitrace-1.0.0/piiscanner/classify/layer1_names.py +310 -0
- piitrace-1.0.0/piiscanner/classify/layer2_values.py +186 -0
- piitrace-1.0.0/piiscanner/classify/patterns.py +436 -0
- piitrace-1.0.0/piiscanner/cli.py +382 -0
- piitrace-1.0.0/piiscanner/config.py +118 -0
- piitrace-1.0.0/piiscanner/connectors/__init__.py +0 -0
- piitrace-1.0.0/piiscanner/connectors/base.py +291 -0
- piitrace-1.0.0/piiscanner/connectors/keyspace.py +138 -0
- piitrace-1.0.0/piiscanner/connectors/mongodb.py +586 -0
- piitrace-1.0.0/piiscanner/connectors/mysql.py +1007 -0
- piitrace-1.0.0/piiscanner/connectors/postgres.py +402 -0
- piitrace-1.0.0/piiscanner/models.py +312 -0
- piitrace-1.0.0/piiscanner/report/__init__.py +0 -0
- piitrace-1.0.0/piiscanner/report/json_out.py +47 -0
- piitrace-1.0.0/piiscanner/report/text_out.py +127 -0
- piitrace-1.0.0/piiscanner/testdata/__init__.py +0 -0
- piitrace-1.0.0/piiscanner/testdata/generate.py +1025 -0
- piitrace-1.0.0/piiscanner/testdata/load_mongodb.py +76 -0
- piitrace-1.0.0/piiscanner/testdata/load_mysql.py +158 -0
- piitrace-1.0.0/piitrace.egg-info/PKG-INFO +259 -0
- piitrace-1.0.0/piitrace.egg-info/SOURCES.txt +56 -0
- piitrace-1.0.0/piitrace.egg-info/dependency_links.txt +1 -0
- piitrace-1.0.0/piitrace.egg-info/entry_points.txt +2 -0
- piitrace-1.0.0/piitrace.egg-info/requires.txt +9 -0
- piitrace-1.0.0/piitrace.egg-info/top_level.txt +1 -0
- piitrace-1.0.0/pyproject.toml +53 -0
- piitrace-1.0.0/setup.cfg +4 -0
- piitrace-1.0.0/tests/test_api.py +75 -0
- piitrace-1.0.0/tests/test_audit.py +616 -0
- piitrace-1.0.0/tests/test_checksums.py +343 -0
- piitrace-1.0.0/tests/test_layer1_names.py +181 -0
- piitrace-1.0.0/tests/test_layer2_values.py +444 -0
- piitrace-1.0.0/tests/test_models.py +262 -0
- piitrace-1.0.0/tests/test_mongo_flatten.py +146 -0
- piitrace-1.0.0/tests/test_mongo_sampling.py +438 -0
- piitrace-1.0.0/tests/test_mongo_scan_quality.py +224 -0
- piitrace-1.0.0/tests/test_mysql_connector.py +35 -0
- piitrace-1.0.0/tests/test_mysql_sampling.py +738 -0
- piitrace-1.0.0/tests/test_no_pii_leakage.py +202 -0
- piitrace-1.0.0/tests/test_postgres_connector.py +111 -0
- piitrace-1.0.0/tests/test_sampling_spread.py +168 -0
- piitrace-1.0.0/tests/test_scan_quality.py +208 -0
piitrace-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
piitrace-1.0.0/NOTICE
ADDED
piitrace-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: piitrace
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Read-only personal data discovery for MySQL, PostgreSQL and MongoDB, built for India's DPDP Act
|
|
5
|
+
Author: Shubham Kumar
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/shubhamjjw14/piiscanner
|
|
8
|
+
Project-URL: Source, https://github.com/shubhamjjw14/piiscanner
|
|
9
|
+
Project-URL: Issues, https://github.com/shubhamjjw14/piiscanner/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/shubhamjjw14/piiscanner/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: pii,dpdp,privacy,data-discovery,mysql,postgresql,mongodb,aadhaar,pan
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: System Administrators
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Database
|
|
21
|
+
Classifier: Topic :: Security
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
License-File: NOTICE
|
|
26
|
+
Requires-Dist: pydantic>=2.0
|
|
27
|
+
Requires-Dist: click>=8.1
|
|
28
|
+
Requires-Dist: rich>=13.0
|
|
29
|
+
Requires-Dist: PyMySQL>=1.1
|
|
30
|
+
Requires-Dist: pymongo>=4.6
|
|
31
|
+
Requires-Dist: psycopg[binary]>=3.1
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
# piiscanner
|
|
37
|
+
Open-source PII scanner for India's DPDP Act
|
|
38
|
+
Find the personal data in your database, without writing to it and without
|
|
39
|
+
keeping any of it.
|
|
40
|
+
|
|
41
|
+
piiscanner connects to MySQL, PostgreSQL or MongoDB with a read-only account,
|
|
42
|
+
reads a small sample of every column, and tells you which ones hold personal
|
|
43
|
+
data: names, phone numbers, email addresses, and the Indian identifiers that
|
|
44
|
+
India's Digital Personal Data Protection Act (DPDP) cares about -- Aadhaar,
|
|
45
|
+
PAN, GSTIN, voter ID, passport, UPI, IFSC, bank and card numbers.
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
$ piiscanner scan --source mysql://piiscanner_ro:PASSWORD@127.0.0.1:3306/piiscanner_testdata
|
|
49
|
+
|
|
50
|
+
scanned 1 dataset(s), 8 collection(s), 63 field(s) examined, 1 skipped
|
|
51
|
+
findings 36
|
|
52
|
+
|
|
53
|
+
Conf Location PII type Match Rows Via Evidence (masked)
|
|
54
|
+
0.99 kyc.aadhaar_no AADHAAR 100% 3k name+value 54XXXXXXXX62, 71XXXXXXXX51
|
|
55
|
+
0.99 kyc.gstin GSTIN 100% 3k name+value 21XXXXXXXXXXXZM, ...
|
|
56
|
+
0.95 legacy_import.col_17 AADHAAR 100% 2k value 41XXXXXXXX34, 69XXXXXXXX37
|
|
57
|
+
0.95 legacy_import.field_x CARD_NUMBER 100% 2k value 35XXXXXXXXXXX12, ...
|
|
58
|
+
0.85 users.mobile INDIAN_MOBILE 100% 5k name+value +9XXXXXXXXXX68, 63XXXXXX88
|
|
59
|
+
...
|
|
60
|
+
10 finding(s) rest on the field name alone and were not confirmed by values.
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
(That is the synthetic test dataset that ships with it; `legacy_import.col_17`
|
|
64
|
+
is a column with a meaningless name that holds Aadhaar numbers, found by the
|
|
65
|
+
values alone.)
|
|
66
|
+
|
|
67
|
+
Every value it shows is masked. Nothing it reads is kept.
|
|
68
|
+
|
|
69
|
+
## Install
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install piitrace
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Python 3.11 or newer. The database drivers come with it.
|
|
76
|
+
|
|
77
|
+
## Use
|
|
78
|
+
|
|
79
|
+
Give it an account that can only read. On MySQL:
|
|
80
|
+
|
|
81
|
+
```sql
|
|
82
|
+
CREATE USER 'piiscanner_ro'@'%' IDENTIFIED BY '...';
|
|
83
|
+
GRANT SELECT, SHOW VIEW ON shop.* TO 'piiscanner_ro'@'%';
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
On PostgreSQL:
|
|
87
|
+
|
|
88
|
+
```sql
|
|
89
|
+
CREATE ROLE piiscanner_ro LOGIN PASSWORD '...';
|
|
90
|
+
GRANT USAGE ON SCHEMA public TO piiscanner_ro;
|
|
91
|
+
GRANT SELECT ON ALL TABLES IN SCHEMA public TO piiscanner_ro;
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Then:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
piiscanner scan --source mysql://piiscanner_ro:PASSWORD@host:3306/shop --out findings.json
|
|
98
|
+
piiscanner scan --source postgresql://piiscanner_ro:PASSWORD@host:5432/shop
|
|
99
|
+
piiscanner scan --source mongodb://host:27017/shop --include 'prod_*' --exclude '*_archive'
|
|
100
|
+
|
|
101
|
+
piiscanner report findings.json --format text --all
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The last line reads a saved scan again.
|
|
105
|
+
|
|
106
|
+
| Option | |
|
|
107
|
+
|---|---|
|
|
108
|
+
| `--sample-size` | values read per column (default 500) |
|
|
109
|
+
| `--include`, `--exclude` | table name patterns to scan or skip |
|
|
110
|
+
| `--dataset` | which databases or schemas to scan, when the connection can see several |
|
|
111
|
+
| `--out` | write the findings as JSON |
|
|
112
|
+
| `--all` | print every finding, not the top 10 |
|
|
113
|
+
| `--inventory` | record every column examined, not just findings |
|
|
114
|
+
| `--verbose` | the full log; it never contains values |
|
|
115
|
+
|
|
116
|
+
On PostgreSQL every schema is scanned unless you add `?schema=name` to the
|
|
117
|
+
connection string or pass `--dataset`.
|
|
118
|
+
|
|
119
|
+
## Use from Python
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
import piiscanner
|
|
123
|
+
|
|
124
|
+
result = piiscanner.scan("mysql://piiscanner_ro:PASSWORD@host:3306/shop")
|
|
125
|
+
|
|
126
|
+
for f in result.findings:
|
|
127
|
+
print(f.collection, f.field, f.pii_type.value, f.confidence, f.evidence)
|
|
128
|
+
# kyc aadhaar_no AADHAAR 0.99 ['54XXXXXXXX62', '71XXXXXXXX51']
|
|
129
|
+
|
|
130
|
+
if result.tables_not_read:
|
|
131
|
+
print("not covered:", result.tables_not_read)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
`scan()` takes the same choices as the command: `sample_size`, `include`,
|
|
135
|
+
`exclude` and `datasets`. It connects, scans and closes, with the same
|
|
136
|
+
guarantees -- read-only, evidence masked, nothing kept. The result is a
|
|
137
|
+
`ScanResult`; `result.model_dump_json()` gives the JSON `--out` writes.
|
|
138
|
+
|
|
139
|
+
`tables_not_read` names tables that could not be read (a permission, a
|
|
140
|
+
timeout). They are not covered by the result -- which is not the same as
|
|
141
|
+
holding no personal data.
|
|
142
|
+
|
|
143
|
+
## What it finds
|
|
144
|
+
|
|
145
|
+
26 types, in three groups:
|
|
146
|
+
|
|
147
|
+
| | |
|
|
148
|
+
|---|---|
|
|
149
|
+
| **Confirmed from the values** (checksum, structure or format) | Aadhaar (Verhoeff), card number (Luhn), GSTIN (mod-36), PAN, IFSC, Indian passport, vehicle registration, UPI ID, Indian mobile, email, date of birth, IP address (public and private) |
|
|
150
|
+
| **Confirmed from the values, only when the column name agrees** | bank account, PIN code, voter ID, device ID, age, gender |
|
|
151
|
+
| **Recognised by the column name only** | person name, address, location, health data, salary, religion, caste |
|
|
152
|
+
|
|
153
|
+
The first group is reported when enough of a column's sampled values pass
|
|
154
|
+
the check, whatever the column is called. The second group's patterns are
|
|
155
|
+
too generic on their own -- every 16-digit transaction id looks like a bank
|
|
156
|
+
account -- so the name must agree too. The third cannot be confirmed from
|
|
157
|
+
values at all (there is no checksum for a name), so these are reported at
|
|
158
|
+
confidence 0.5, marked *unverified*, for a person to look at.
|
|
159
|
+
|
|
160
|
+
### Why checksums matter
|
|
161
|
+
|
|
162
|
+
Roughly 1 in 10 random 12-digit numbers passes the Aadhaar checksum by chance,
|
|
163
|
+
because a single check digit has ten possible values. So a 12-digit
|
|
164
|
+
`order_reference` column will have about 10% of its values look like valid
|
|
165
|
+
Aadhaar numbers. Match *rate*, not the checksum alone, keeps it out: a real
|
|
166
|
+
Aadhaar column matches at 95-100%, an order reference at about 10%, and the
|
|
167
|
+
threshold sits between them. A test pins that 1-in-10 rate.
|
|
168
|
+
|
|
169
|
+
Three more rules keep false alarms down:
|
|
170
|
+
|
|
171
|
+
- **Refutation.** A column named `pan` whose values contradict it (solar-panel
|
|
172
|
+
SKUs) is dropped, not reported on its name.
|
|
173
|
+
- **Name support.** The second group above, as described.
|
|
174
|
+
- **One verdict per column.** `ip_addr` is an IP address, not also an address.
|
|
175
|
+
|
|
176
|
+
## What it guarantees
|
|
177
|
+
|
|
178
|
+
Enforced in code and checked by tests, not promised in prose. The code that
|
|
179
|
+
touches your database is in `piiscanner/connectors/`; read it.
|
|
180
|
+
|
|
181
|
+
| | How |
|
|
182
|
+
|---|---|
|
|
183
|
+
| **Read-only** | MySQL sessions are set `TRANSACTION READ ONLY`, PostgreSQL sessions `default_transaction_read_only`. On top of that, any statement that is not a read raises `ReadOnlyViolation` before it is sent. MongoDB pipelines containing `$out` or `$merge` are refused. Run it as a SELECT-only account anyway. |
|
|
184
|
+
| **No values kept** | A finding's evidence is masked when it is created -- `9876543210` becomes `98XXXXXX10` -- by a validator on the model. No code path builds a finding holding a raw value. |
|
|
185
|
+
| **No values in logs** | Logs carry table and column names and counts only; a filter strips anything else; samples print as `<redacted>`. A test reads real values from the database and checks they appear nowhere in the JSON, the report or a full debug log. |
|
|
186
|
+
| **No network but your database** | No HTTP client is imported anywhere. |
|
|
187
|
+
| **Bounded cost** | Never a full table scan. Large MySQL tables are sampled by index seeks, PostgreSQL by `TABLESAMPLE`, MongoDB by `$sample` or `_id` ranges. |
|
|
188
|
+
|
|
189
|
+
## Accuracy
|
|
190
|
+
|
|
191
|
+
`piiscanner benchmark` scans a synthetic Indian dataset with a known answer
|
|
192
|
+
key, and exits non-zero on any miss or false alarm, so it drops into CI.
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
MySQL MongoDB
|
|
196
|
+
precision 1.000 1.000
|
|
197
|
+
recall 1.000 1.000
|
|
198
|
+
type accuracy 1.000 1.000
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Read that honestly: the detectors and the answer key were written together,
|
|
202
|
+
so these numbers say it handles the cases we thought of. They are a floor,
|
|
203
|
+
not a measurement of your data. `piiscanner audit` is how to measure it on
|
|
204
|
+
yours: it draws a sample of columns for a person to label, and scores the
|
|
205
|
+
scan against the labels.
|
|
206
|
+
|
|
207
|
+
## Known limits
|
|
208
|
+
|
|
209
|
+
- **Personal data leaked into free text is mostly missed.** A sample shows
|
|
210
|
+
whether a *column* is personal data. One Aadhaar number in ten thousand chat
|
|
211
|
+
messages is below the reporting floor, and lowering the floor naively
|
|
212
|
+
floods the report with transaction references that happen to pass the
|
|
213
|
+
checksum.
|
|
214
|
+
- **Name-only findings can be noisy.** `card_name` (a card *product*) is
|
|
215
|
+
reported as a person's name until the stop-list learns it. They are marked
|
|
216
|
+
unverified so they can be sorted out.
|
|
217
|
+
- **Encrypted columns are found by name only.** Ciphertext matches no
|
|
218
|
+
pattern.
|
|
219
|
+
- **No language understanding.** Names in prose are not found.
|
|
220
|
+
- **MongoDB's `local` database is skipped** as a system database; an
|
|
221
|
+
application storing data there needs `--dataset local`.
|
|
222
|
+
- MySQL row counts come from the optimiser's statistics and are approximate.
|
|
223
|
+
|
|
224
|
+
## Finding one person's data
|
|
225
|
+
|
|
226
|
+
A scan answers "which tables hold personal data". A DPDP request asks the
|
|
227
|
+
next question: *where is this one person's data, in every table, and how do
|
|
228
|
+
I delete it or give them a copy?* That needs every route from every table to
|
|
229
|
+
a person, including tables with no name in them at all (their orders, their
|
|
230
|
+
payments).
|
|
231
|
+
|
|
232
|
+
piiscanner's full version does that: it traces one person's rows across the
|
|
233
|
+
database and writes a dry-run deletion plan, a review file for rows shared
|
|
234
|
+
with somebody else, and the export owed to the person -- and, like this
|
|
235
|
+
package, never runs any of it. It is not open source. Write to
|
|
236
|
+
shubhamjjw14@gmail.com.
|
|
237
|
+
|
|
238
|
+
## Development
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
git clone https://github.com/shubhamjjw14/piiscanner.git && cd piiscanner
|
|
242
|
+
python3 -m venv .venv && .venv/bin/pip install -e '.[dev]'
|
|
243
|
+
.venv/bin/pytest
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
Tests that need a database skip without one. To run them, load the synthetic
|
|
247
|
+
data into a local MySQL (this also creates the read-only account):
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
python -m piiscanner.testdata.load_mysql --admin-url mysql://root@127.0.0.1:3306/
|
|
251
|
+
docker run -d --name piiscanner-mongo -p 27017:27017 mongo:7 && python -m piiscanner.testdata.load_mongodb
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
[CODE_WALKTHROUGH.md](https://github.com/shubhamjjw14/piiscanner/blob/main/CODE_WALKTHROUGH.md) explains the internals, stage by
|
|
255
|
+
stage. `scripts/explain.py` shows why a column was or was not flagged.
|
|
256
|
+
|
|
257
|
+
## Licence
|
|
258
|
+
|
|
259
|
+
Apache 2.0. See [LICENSE](https://github.com/shubhamjjw14/piiscanner/blob/main/LICENSE) and [NOTICE](https://github.com/shubhamjjw14/piiscanner/blob/main/NOTICE).
|