datapace-collector 0.2.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.
@@ -0,0 +1,192 @@
1
+ # Python (the backend keeps its own .gitignore at src/.gitignore; these cover
2
+ # stray caches created outside it, e.g. by an editor run from the repo root)
3
+ __pycache__/
4
+ *.py[cod]
5
+ .venv/
6
+ .ruff_cache/
7
+ .pytest_cache/
8
+
9
+ # Logs
10
+ logs
11
+ *.log
12
+ npm-debug.log*
13
+ yarn-debug.log*
14
+ yarn-error.log*
15
+ lerna-debug.log*
16
+
17
+ # Diagnostic reports (https://nodejs.org/api/report.html)
18
+ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
19
+
20
+ # Runtime data
21
+ pids
22
+ *.pid
23
+ *.seed
24
+ *.pid.lock
25
+
26
+ # Directory for instrumented libs generated by jscoverage/JSCover
27
+ lib-cov
28
+
29
+ # Coverage directory used by tools like istanbul
30
+ coverage
31
+ *.lcov
32
+
33
+ # nyc test coverage
34
+ .nyc_output
35
+
36
+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
37
+ .grunt
38
+
39
+ # Bower dependency directory (https://bower.io/)
40
+ bower_components
41
+
42
+ # node-waf configuration
43
+ .lock-wscript
44
+
45
+ # Compiled binary addons (https://nodejs.org/api/addons.html)
46
+ build/Release
47
+
48
+ # Dependency directories
49
+ node_modules/
50
+ jspm_packages/
51
+
52
+ # Snowpack dependency directory (https://snowpack.dev/)
53
+ web_modules/
54
+
55
+ # TypeScript cache
56
+ *.tsbuildinfo
57
+
58
+ # Optional npm cache directory
59
+ .npm
60
+
61
+ # Optional eslint cache
62
+ .eslintcache
63
+
64
+ # Optional stylelint cache
65
+ .stylelintcache
66
+
67
+ # Optional REPL history
68
+ .node_repl_history
69
+
70
+ # Output of 'npm pack'
71
+ *.tgz
72
+ !src/tests/fixtures/assessment/bundles/*.tgz
73
+
74
+ # Yarn Integrity file
75
+ .yarn-integrity
76
+
77
+ # dotenv environment variable files
78
+ .env
79
+ .env.*
80
+ !.env.example
81
+
82
+ # parcel-bundler cache (https://parceljs.org/)
83
+ .cache
84
+ .parcel-cache
85
+
86
+ # Next.js build output
87
+ .next
88
+ out
89
+
90
+ # Storybook build output
91
+ storybook-static
92
+
93
+ # Turborepo
94
+ .turbo
95
+
96
+ # Vercel
97
+ .vercel
98
+
99
+ # Nuxt.js build / generate output
100
+ .nuxt
101
+ dist
102
+ .output
103
+
104
+ # Gatsby files
105
+ .cache/
106
+ # Comment in the public line in if your project uses Gatsby and not Next.js
107
+ # https://nextjs.org/blog/next-9-1#public-directory-support
108
+ # public
109
+
110
+ # vuepress build output
111
+ .vuepress/dist
112
+
113
+ # vuepress v2.x temp and cache directory
114
+ .temp
115
+ .cache
116
+
117
+ # Sveltekit cache directory
118
+ .svelte-kit/
119
+
120
+ # vitepress build output
121
+ **/.vitepress/dist
122
+
123
+ # vitepress cache directory
124
+ **/.vitepress/cache
125
+
126
+ # Docusaurus cache and generated files
127
+ .docusaurus
128
+
129
+ # Serverless directories
130
+ .serverless/
131
+
132
+ # FuseBox cache
133
+ .fusebox/
134
+
135
+ # DynamoDB Local files
136
+ .dynamodb/
137
+
138
+ # Firebase cache directory
139
+ .firebase/
140
+
141
+ # TernJS port file
142
+ .tern-port
143
+
144
+ # Stores VSCode versions used for testing VSCode extensions
145
+ .vscode-test
146
+
147
+ # yarn v3
148
+ .pnp.*
149
+ .yarn/*
150
+ !.yarn/patches
151
+ !.yarn/plugins
152
+ !.yarn/releases
153
+ !.yarn/sdks
154
+ !.yarn/versions
155
+
156
+ # Playwright (scripts/e2e-stack.sh)
157
+ playwright-report/
158
+ test-results/
159
+ blob-report/
160
+ .playwright/
161
+
162
+ # Validation-gate runs (scripts/gates.py) — logs and collected artifacts
163
+ .gates/
164
+
165
+ # Vite files
166
+ vite.config.js.timestamp-*
167
+ vite.config.ts.timestamp-*
168
+ .vite/
169
+
170
+ # MacOS
171
+ .DS_Store
172
+
173
+ # Claude Code worktrees (local-only feature branches)
174
+ .claude/worktrees/
175
+
176
+ # graphify runs out of its own venv (see the `graph` target). Kept at the repo
177
+ # root, outside src/, so ruff and pyright never walk it.
178
+ .venv-graph/
179
+
180
+ # graphify: the graph and the agent-crawlable wiki are committed so a fresh
181
+ # clone starts with both; report, html and caches are regenerated on demand and
182
+ # would churn every run.
183
+ graphify-out/*
184
+ !graphify-out/graph.json
185
+ !graphify-out/wiki/
186
+
187
+ # `graphify install --project` regenerates these on every upgrade. The skill is
188
+ # picked up from .claude/skills/ without them, and the settings.json it writes
189
+ # hardcodes an absolute path to the installing machine's binary.
190
+ .claude/CLAUDE.md
191
+ .claude/settings.json
192
+ .import_linter_cache/
@@ -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.
@@ -0,0 +1,98 @@
1
+ Metadata-Version: 2.5
2
+ Name: datapace-collector
3
+ Version: 0.2.0
4
+ Summary: Collect read-only RDS evidence from AWS accounts you choose into an allowlisted Datapace evidence bundle.
5
+ Project-URL: Homepage, https://datapace.ai
6
+ License-Expression: Apache-2.0
7
+ License-File: LICENSE
8
+ Classifier: Environment :: Console
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Requires-Python: >=3.10
17
+ Requires-Dist: boto3
18
+ Description-Content-Type: text/markdown
19
+
20
+ # datapace-collector
21
+
22
+ The customer-run half of the Cloud Self-Assessment (DAT-891, ADR-0023). A prospect runs
23
+ it against AWS accounts they pick. It writes one evidence bundle (`.tgz`) that matches
24
+ the frozen v1 schema at `src/datapace/domain/assessment/bundle_schema_v1.json`, plus a
25
+ local `aliases.json` that maps each alias in the bundle back to the real resource.
26
+
27
+ Its own distribution, Python ≥ 3.10, one runtime dependency (boto3). It imports nothing
28
+ from `datapace`.
29
+
30
+ ```
31
+ datapace-collector --profile 111111111111=prod --profile 222222222222=stage \
32
+ [--billing-profile payer] --regions us-east-1,eu-west-1 --out ./evidence
33
+ ```
34
+
35
+ - **Only the named profiles are opened.** Without `--profile` it exits 2; it never
36
+ lists local profiles. Each profile must really be the account it is mapped to
37
+ (`sts:GetCallerIdentity`), or it exits 3.
38
+ - **Preflight** probes every permission per account and region and prints each denial
39
+ with the IAM action and the input it costs. `rds:DescribeDBInstances` denied
40
+ everywhere → exit 3, nothing written.
41
+ - **Collects** inventory, 90 days of daily and monthly RDS cost, RI/Savings Plans
42
+ coverage, reserved instances, manual snapshots and 30 days of hourly metrics (eight
43
+ `GetMetricData` workers, 60 s timeout, 3 retries).
44
+ - **`--billing-profile`** reads Cost Explorer from a payer; lines for accounts not
45
+ selected are dropped.
46
+ - **Exit codes:** 0 bundle written (complete or partial), 1 internal error, 2 usage,
47
+ 3 preflight failed, 130 interrupted (partial bundle kept).
48
+
49
+ ## Running it
50
+
51
+ Python ≥ 3.10. macOS's system `python3` is 3.9: the `.pyz` stops with a message
52
+ naming the minimum version and exits 2; install a newer Python (python.org, Homebrew
53
+ or uv) and run it with that. The same version ships three ways, built by `build.sh`:
54
+
55
+ - **The `.pyz`**, for machines where nothing can be installed:
56
+ `python3 datapace-collector-<v>.pyz --profile … --out …`. boto3 is inside the file,
57
+ so it needs no network install. Its dependencies are exactly the hash-checked set
58
+ in `uv.lock`, never a fresh resolution. Bundles record `distribution: pyz`.
59
+ - **The downloaded wheel**: `pip install ./datapace_collector-<v>-py3-none-any.whl`,
60
+ then `datapace-collector …`.
61
+ - **PyPI**: `uvx datapace-collector@0.2.0 …` <!-- x-release-please-version -->
62
+ or `pip install datapace-collector==0.2.0`. <!-- x-release-please-version -->
63
+
64
+ PyPI and the downloaded wheel are the same file, so both record `distribution: wheel`
65
+ and the bundle cannot tell them apart.
66
+
67
+ On first run the `.pyz` unpacks itself into
68
+ `~/.shiv/datapace-collector-<v>.pyz_<build-id>/`, or under `$SHIV_ROOT` if set, and
69
+ reuses that copy afterwards. It unpacks before the version check, so a run refused
70
+ on Python 3.9 leaves the copy too. Remove it with `rm -rf ~/.shiv/datapace-collector-*`.
71
+
72
+ ## What keeps the bundle safe
73
+
74
+ - `operations.py`'s `READ_ONLY_OPERATIONS` is every AWS call the collector may make.
75
+ `tests/test_safety.py` records each botocore call and fails on anything outside it.
76
+ - Every record is built field by field from the schema's closed properties: an
77
+ allowlist, not a redaction. Raw ids become `HMAC(salt, kind|account|region|id)`
78
+ aliases. `tests/test_leaks.py` seeds account ids, ARNs, endpoints, tags,
79
+ `MasterUsername` and ARN-bearing AccessDenied messages, and asserts none reaches a
80
+ bundle byte.
81
+ - A denied input is `denied` with a reason code in the manifest, never empty data that
82
+ looks like a result.
83
+ - `aliases.json` (mode 0600) sits beside the bundle, never inside it. A later run into
84
+ the same `--out` reuses its salt, so aliases stay stable across bundles. It also
85
+ holds the salt: keep it, and do not upload it.
86
+
87
+ ## Development
88
+
89
+ ```bash
90
+ cd collector
91
+ uv run pytest # reads the platform's schema by repository path
92
+ uv run pyright
93
+ ./build.sh # dist/datapace_collector-0.1.0-py3-none-any.whl and
94
+ # dist/datapace-collector-0.1.0.pyz, smoke-run on 3.10 and 3.9
95
+ ```
96
+
97
+ `make ci-collector` from the repo root runs all of it plus ruff. Ruff and pyright both
98
+ target Python 3.10, so newer syntax fails the check rather than a prospect's install.
@@ -0,0 +1,79 @@
1
+ # datapace-collector
2
+
3
+ The customer-run half of the Cloud Self-Assessment (DAT-891, ADR-0023). A prospect runs
4
+ it against AWS accounts they pick. It writes one evidence bundle (`.tgz`) that matches
5
+ the frozen v1 schema at `src/datapace/domain/assessment/bundle_schema_v1.json`, plus a
6
+ local `aliases.json` that maps each alias in the bundle back to the real resource.
7
+
8
+ Its own distribution, Python ≥ 3.10, one runtime dependency (boto3). It imports nothing
9
+ from `datapace`.
10
+
11
+ ```
12
+ datapace-collector --profile 111111111111=prod --profile 222222222222=stage \
13
+ [--billing-profile payer] --regions us-east-1,eu-west-1 --out ./evidence
14
+ ```
15
+
16
+ - **Only the named profiles are opened.** Without `--profile` it exits 2; it never
17
+ lists local profiles. Each profile must really be the account it is mapped to
18
+ (`sts:GetCallerIdentity`), or it exits 3.
19
+ - **Preflight** probes every permission per account and region and prints each denial
20
+ with the IAM action and the input it costs. `rds:DescribeDBInstances` denied
21
+ everywhere → exit 3, nothing written.
22
+ - **Collects** inventory, 90 days of daily and monthly RDS cost, RI/Savings Plans
23
+ coverage, reserved instances, manual snapshots and 30 days of hourly metrics (eight
24
+ `GetMetricData` workers, 60 s timeout, 3 retries).
25
+ - **`--billing-profile`** reads Cost Explorer from a payer; lines for accounts not
26
+ selected are dropped.
27
+ - **Exit codes:** 0 bundle written (complete or partial), 1 internal error, 2 usage,
28
+ 3 preflight failed, 130 interrupted (partial bundle kept).
29
+
30
+ ## Running it
31
+
32
+ Python ≥ 3.10. macOS's system `python3` is 3.9: the `.pyz` stops with a message
33
+ naming the minimum version and exits 2; install a newer Python (python.org, Homebrew
34
+ or uv) and run it with that. The same version ships three ways, built by `build.sh`:
35
+
36
+ - **The `.pyz`**, for machines where nothing can be installed:
37
+ `python3 datapace-collector-<v>.pyz --profile … --out …`. boto3 is inside the file,
38
+ so it needs no network install. Its dependencies are exactly the hash-checked set
39
+ in `uv.lock`, never a fresh resolution. Bundles record `distribution: pyz`.
40
+ - **The downloaded wheel**: `pip install ./datapace_collector-<v>-py3-none-any.whl`,
41
+ then `datapace-collector …`.
42
+ - **PyPI**: `uvx datapace-collector@0.2.0 …` <!-- x-release-please-version -->
43
+ or `pip install datapace-collector==0.2.0`. <!-- x-release-please-version -->
44
+
45
+ PyPI and the downloaded wheel are the same file, so both record `distribution: wheel`
46
+ and the bundle cannot tell them apart.
47
+
48
+ On first run the `.pyz` unpacks itself into
49
+ `~/.shiv/datapace-collector-<v>.pyz_<build-id>/`, or under `$SHIV_ROOT` if set, and
50
+ reuses that copy afterwards. It unpacks before the version check, so a run refused
51
+ on Python 3.9 leaves the copy too. Remove it with `rm -rf ~/.shiv/datapace-collector-*`.
52
+
53
+ ## What keeps the bundle safe
54
+
55
+ - `operations.py`'s `READ_ONLY_OPERATIONS` is every AWS call the collector may make.
56
+ `tests/test_safety.py` records each botocore call and fails on anything outside it.
57
+ - Every record is built field by field from the schema's closed properties: an
58
+ allowlist, not a redaction. Raw ids become `HMAC(salt, kind|account|region|id)`
59
+ aliases. `tests/test_leaks.py` seeds account ids, ARNs, endpoints, tags,
60
+ `MasterUsername` and ARN-bearing AccessDenied messages, and asserts none reaches a
61
+ bundle byte.
62
+ - A denied input is `denied` with a reason code in the manifest, never empty data that
63
+ looks like a result.
64
+ - `aliases.json` (mode 0600) sits beside the bundle, never inside it. A later run into
65
+ the same `--out` reuses its salt, so aliases stay stable across bundles. It also
66
+ holds the salt: keep it, and do not upload it.
67
+
68
+ ## Development
69
+
70
+ ```bash
71
+ cd collector
72
+ uv run pytest # reads the platform's schema by repository path
73
+ uv run pyright
74
+ ./build.sh # dist/datapace_collector-0.1.0-py3-none-any.whl and
75
+ # dist/datapace-collector-0.1.0.pyz, smoke-run on 3.10 and 3.9
76
+ ```
77
+
78
+ `make ci-collector` from the repo root runs all of it plus ruff. Ruff and pyright both
79
+ target Python 3.10, so newer syntax fails the check rather than a prospect's install.
@@ -0,0 +1 @@
1
+ """The customer-run Datapace evidence collector (DAT-891)."""
@@ -0,0 +1,74 @@
1
+ """Stable, salted aliases for every raw AWS identifier, and the local lookup.
2
+
3
+ An alias is `kind_` plus 12 hex digits of HMAC-SHA256(salt, kind|account|
4
+ region|identifier), the construction the DAT-886 fixtures use. The salt stays
5
+ on the prospect's machine in `aliases.json`, beside the bundle and never inside
6
+ it (ADR-0023 §3). A later run into the same `--out` reuses that salt, so the
7
+ same resource gets the same alias across bundles.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import hashlib
13
+ import hmac
14
+ import json
15
+ import os
16
+ import secrets
17
+ from pathlib import Path
18
+
19
+ ALIASES = "aliases.json"
20
+
21
+
22
+ class AliasFileError(Exception):
23
+ """An `aliases.json` exists but cannot be used; replacing it would break stability."""
24
+
25
+
26
+ class Aliaser:
27
+ def __init__(self, salt: bytes, entries: dict[str, dict[str, str]]) -> None:
28
+ self._salt = salt
29
+ self._entries = entries
30
+
31
+ @classmethod
32
+ def load(cls, out: Path) -> Aliaser:
33
+ path = out / ALIASES
34
+ if not path.exists():
35
+ return cls(secrets.token_bytes(32), {})
36
+ try:
37
+ data = json.loads(path.read_text())
38
+ return cls(bytes.fromhex(data["salt"]), dict(data["aliases"]))
39
+ except (OSError, ValueError, KeyError, TypeError) as exc:
40
+ raise AliasFileError(
41
+ f"{path} is unreadable ({type(exc).__name__}); move it away to start"
42
+ " with a new salt, which changes every alias"
43
+ ) from None
44
+
45
+ def alias(self, kind: str, account: str, region: str, identifier: str) -> str:
46
+ message = f"{kind}|{account}|{region}|{identifier}".encode()
47
+ digest = hmac.new(self._salt, message, hashlib.sha256).hexdigest()
48
+ alias = f"{kind}_{digest[:12]}"
49
+ self._entries[alias] = {
50
+ "kind": kind,
51
+ "account": account,
52
+ "region": region,
53
+ "identifier": identifier,
54
+ }
55
+ return alias
56
+
57
+ def account(self, account: str) -> str:
58
+ return self.alias("acct", account, "", account)
59
+
60
+ def save(self, out: Path) -> Path:
61
+ """Write the lookup into `out`, mode 0600, atomically."""
62
+ path = out / ALIASES
63
+ tmp = out / f".{ALIASES}.tmp"
64
+ body = {"salt": self._salt.hex(), "aliases": self._entries}
65
+ tmp.unlink(missing_ok=True)
66
+ try:
67
+ fd = os.open(tmp, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
68
+ with os.fdopen(fd, "w") as f:
69
+ json.dump(body, f, indent=1, sort_keys=True)
70
+ os.replace(tmp, path)
71
+ except BaseException:
72
+ tmp.unlink(missing_ok=True)
73
+ raise
74
+ return path