Metadata-Version: 2.5
Name: datapace-collector
Version: 0.4.0
Summary: Collect read-only RDS evidence from AWS accounts you choose into an allowlisted Datapace evidence bundle.
Project-URL: Homepage, https://datapace.ai
License-Expression: Apache-2.0
License-File: LICENSE
Classifier: Environment :: Console
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.10
Requires-Dist: boto3
Provides-Extra: azure
Requires-Dist: azure-identity; extra == 'azure'
Provides-Extra: gcp
Requires-Dist: google-auth[requests]; extra == 'gcp'
Description-Content-Type: text/markdown

# datapace-collector

Collects read-only RDS evidence from the AWS accounts you choose, for a Datapace Cloud
Self-Assessment. It writes one evidence bundle (`.tgz`) to send to Datapace, plus a
local `aliases.json` that maps each alias in the bundle back to the real resource and
never leaves your machine.

Python ≥ 3.10, one runtime dependency (boto3). Azure needs the `[azure]` extra, which
adds `azure-identity` only; Google Cloud needs the `[gcp]` extra, which adds
`google-auth` only.

```
datapace-collector --profile 111111111111=prod --profile 222222222222=stage \
  [--billing-profile payer] --regions us-east-1,eu-west-1 --out ./evidence
```

- **Only the named profiles are opened.** Without `--profile` it exits 2; it never
  lists local profiles. Each profile must really be the account it is mapped to
  (`sts:GetCallerIdentity`), or it exits 3.
- **Preflight** probes every permission per account and region and prints each denial
  with the IAM action and the input it costs. `rds:DescribeDBInstances` denied
  everywhere → exit 3, nothing written.
- **Collects** inventory, 90 days of daily and monthly RDS cost, RI/Savings Plans
  coverage, reserved instances, manual snapshots and 30 days of hourly metrics.
- **`--billing-profile`** reads Cost Explorer from a payer; lines for accounts not
  selected are dropped.
- **Exit codes:** 0 bundle written (complete or partial), 1 internal error, 2 usage,
  3 preflight failed, 130 interrupted (partial bundle kept).

## Azure

Reads PostgreSQL and MySQL flexible servers, SQL Database (vCore and DTU, elastic-pool
membership noted) and SQL Managed Instance from the subscriptions you name, signed in
as your existing `az login` identity:

```
uvx 'datapace-collector[azure]' --provider azure \
  --subscription 00000000-0000-0000-0000-000000000000 [--subscription …] \
  --regions eastus,westeurope --out ./evidence
```

- **Install the extra.** Without it, `--provider azure` exits 2 and names
  `pip install 'datapace-collector[azure]'`. Without `--provider`, the collector runs
  on AWS as above.
- **Roles:** Reader and Monitoring Reader on each subscription (flexible servers, SQL
  logical servers and their databases, managed instances, and their metrics), Cost
  Management Reader (90 days of daily cost) and Reservations Reader. Preflight prints
  each denial with the role it needs; a missing Cost Management or Reservations role is
  recorded as denied and the bundle is still written. A subscription the identity
  cannot read, or every server and instance list denied everywhere → exit 3, nothing
  written.
- **Only reservations scoped to a subscription you name are read.** Shared and
  management-group reservations, and those of other subscriptions, are dropped before
  the bundle is written, so the report says their coverage was not observed.
- Subscription ids, resource ids, resource group, server, database and pool names,
  FQDNs, admin logins and tags never reach the bundle. The `.pyz` is AWS-only.

## Google Cloud

Reads Cloud SQL instances (PostgreSQL, MySQL and SQL Server) and AlloyDB for
PostgreSQL clusters (primary and read pool instances) from the projects you name, signed in with your application-default credentials
(`gcloud auth application-default login`); no keys or service accounts:

```
uvx 'datapace-collector[gcp]' --provider gcp \
  --project my-prod-project [--project …] \
  [--billing-dataset my-billing-project.billing_export] \
  --regions us-central1,europe-west1 --out ./evidence
```

- **Install the extra.** Without it, `--provider gcp` exits 2 and names
  `pip install 'datapace-collector[gcp]'`.
- **Roles:**

  | Role                        | Where                           | For                     |
  | --------------------------- | ------------------------------- | ----------------------- |
  | `roles/cloudsql.viewer`     | each `--project`                | instances               |
  | `roles/alloydb.viewer`      | each `--project`                | AlloyDB clusters        |
  | `roles/monitoring.viewer`   | each `--project`                | 30 days of metrics      |
  | `roles/bigquery.dataViewer` | the billing export dataset      | 90 days of daily spend  |
  | `roles/bigquery.jobUser`    | the `--billing-dataset` project | running the spend query |

  Preflight prints each denial with the role it needs, and names any API that is not
  enabled. A project without the AlloyDB API enabled has no AlloyDB, so that is a
  note, not a gap. Cloud SQL listing denied and AlloyDB denied or not enabled in
  every project, or no application-default credentials → exit 3, nothing written.

- **Spend is optional.** Without `--billing-dataset`, spend is recorded as not
  provided and the report estimates it from list prices, as it does when the BigQuery
  roles are denied. With it, the collector runs **one** query over the Cloud Billing
  export for all the projects you name. The query runs in, and is billed to, the
  `--billing-dataset` project, and is capped at 50 GiB scanned (about $0.31 at
  on-demand rates); a larger scan fails and spend falls back to list prices.
  Preflight dry-runs it first, which is free.
- Project ids become aliases. Instance, cluster and connection names, uids, IP
  addresses, labels, annotations, database flags, networks, service accounts and
  your token never reach the bundle. The `.pyz` is AWS-only.

## Running it

Python ≥ 3.10. macOS's system `python3` is 3.9: the `.pyz` stops with a message
naming the minimum version and exits 2; install a newer Python (python.org, Homebrew
or uv) and run it with that. The same version ships three ways:

- **The `.pyz`**, for machines where nothing can be installed:
  `python3 datapace-collector-<v>.pyz --profile … --out …`. boto3 is inside the file,
  so it needs no network install. Bundles record `distribution: pyz`.
  Azure and Google Cloud have no `.pyz`: where you can't install uv, run the `uvx`
  command in Azure Cloud Shell (`pip install --user uv` first) or Google Cloud Shell
  (uv preinstalled), both already signed in.
- **The downloaded wheel**: `pip install ./datapace_collector-<v>-py3-none-any.whl`,
  then `datapace-collector …`.
- **PyPI**: `uvx datapace-collector@0.4.0 …` <!-- x-release-please-version -->
  or `pip install datapace-collector==0.4.0`. <!-- x-release-please-version -->

PyPI and the downloaded wheel are the same file, so both record `distribution: wheel`
and the bundle cannot tell them apart.

On first run the `.pyz` unpacks itself into
`~/.shiv/datapace-collector-<v>.pyz_<build-id>/`, or under `$SHIV_ROOT` if set, and
reuses that copy afterwards. It unpacks before the version check, so a run refused
on Python 3.9 leaves the copy too. Remove it with `rm -rf ~/.shiv/datapace-collector-*`.

## What keeps the bundle safe

- The collector only makes read-only AWS calls, listed in
  `datapace_collector/operations.py` (`READ_ONLY_OPERATIONS`). On Azure it only sends
  the requests in `datapace_collector/azure/operations.py` (`READ_ONLY_REQUESTS`), all
  GET except the read-only Cost Management query, and only to `management.azure.com`.
  On Google Cloud it only sends the requests in
  `datapace_collector/gcp/operations.py` (`READ_ONLY_REQUESTS`), all GET except the
  one fixed `SELECT` on your billing export, and only to the Cloud SQL Admin,
  AlloyDB, Monitoring and BigQuery APIs.
- Every record is built field by field from a closed schema: an allowlist, not a
  redaction. Raw ids become `HMAC(salt, kind|account|region|id)` aliases. Account ids,
  ARNs, endpoints, tags and usernames never reach the bundle.
- A denied input is `denied` with a reason code in the manifest, never empty data that
  looks like a result.
- `aliases.json` (mode 0600) sits beside the bundle, never inside it. A later run into
  the same `--out` reuses its salt, so aliases stay stable across bundles. It also
  holds the salt: keep it, and do not upload it.
