statewatch 0.1.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.
- statewatch-0.1.0/.claude/settings.local.json +16 -0
- statewatch-0.1.0/.gitignore +29 -0
- statewatch-0.1.0/CONTRIBUTING.md +70 -0
- statewatch-0.1.0/Dockerfile +11 -0
- statewatch-0.1.0/KNOWN_ISSUES.md +68 -0
- statewatch-0.1.0/LICENSE +202 -0
- statewatch-0.1.0/PKG-INFO +178 -0
- statewatch-0.1.0/README.md +145 -0
- statewatch-0.1.0/action/entrypoint.py +116 -0
- statewatch-0.1.0/action.yml +38 -0
- statewatch-0.1.0/docs/LEARNING.md +144 -0
- statewatch-0.1.0/docs/img/scan-showcase.svg +122 -0
- statewatch-0.1.0/pyproject.toml +73 -0
- statewatch-0.1.0/spec.md +404 -0
- statewatch-0.1.0/src/statewatch/__init__.py +3 -0
- statewatch-0.1.0/src/statewatch/adapters/__init__.py +0 -0
- statewatch-0.1.0/src/statewatch/adapters/base.py +98 -0
- statewatch-0.1.0/src/statewatch/adapters/gcp.py +264 -0
- statewatch-0.1.0/src/statewatch/attribution/__init__.py +0 -0
- statewatch-0.1.0/src/statewatch/attribution/client.py +1 -0
- statewatch-0.1.0/src/statewatch/attribution/correlator.py +1 -0
- statewatch-0.1.0/src/statewatch/attribution/extractor.py +1 -0
- statewatch-0.1.0/src/statewatch/classifier.py +88 -0
- statewatch-0.1.0/src/statewatch/cli.py +351 -0
- statewatch-0.1.0/src/statewatch/config.py +76 -0
- statewatch-0.1.0/src/statewatch/differ.py +129 -0
- statewatch-0.1.0/src/statewatch/graph/__init__.py +0 -0
- statewatch-0.1.0/src/statewatch/graph/builder.py +267 -0
- statewatch-0.1.0/src/statewatch/graph/inferred.py +124 -0
- statewatch-0.1.0/src/statewatch/graph/manual.py +90 -0
- statewatch-0.1.0/src/statewatch/graph/render.py +130 -0
- statewatch-0.1.0/src/statewatch/graph/validator.py +73 -0
- statewatch-0.1.0/src/statewatch/impact/__init__.py +0 -0
- statewatch-0.1.0/src/statewatch/impact/analyzer.py +73 -0
- statewatch-0.1.0/src/statewatch/impact/rules.py +42 -0
- statewatch-0.1.0/src/statewatch/normalizer.py +139 -0
- statewatch-0.1.0/src/statewatch/notifiers/__init__.py +0 -0
- statewatch-0.1.0/src/statewatch/notifiers/slack.py +67 -0
- statewatch-0.1.0/src/statewatch/notifiers/terminal.py +98 -0
- statewatch-0.1.0/src/statewatch/report.py +139 -0
- statewatch-0.1.0/src/statewatch/resources/__init__.py +68 -0
- statewatch-0.1.0/src/statewatch/resources/compute_instance.py +200 -0
- statewatch-0.1.0/src/statewatch/resources/firewall.py +120 -0
- statewatch-0.1.0/src/statewatch/resources/gke_cluster.py +138 -0
- statewatch-0.1.0/src/statewatch/resources/subnetwork.py +104 -0
- statewatch-0.1.0/src/statewatch/tfstate.py +153 -0
- statewatch-0.1.0/src/statewatch/watchstate.py +75 -0
- statewatch-0.1.0/tests/__init__.py +0 -0
- statewatch-0.1.0/tests/conftest.py +25 -0
- statewatch-0.1.0/tests/fixtures/compute_instance.tfstate.json +176 -0
- statewatch-0.1.0/tests/fixtures/firewall_subnet_drift.tfstate.json +170 -0
- statewatch-0.1.0/tests/fixtures/statewatch.manual.yaml +9 -0
- statewatch-0.1.0/tests/test_classifier.py +85 -0
- statewatch-0.1.0/tests/test_differ.py +81 -0
- statewatch-0.1.0/tests/test_graph.py +185 -0
- statewatch-0.1.0/tests/test_impact.py +130 -0
- statewatch-0.1.0/tests/test_normalizer.py +107 -0
- statewatch-0.1.0/tests/test_phase4.py +161 -0
- statewatch-0.1.0/tests/test_resources.py +96 -0
- statewatch-0.1.0/tests/test_tfstate.py +60 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(git push *)",
|
|
5
|
+
"Bash(git add *)",
|
|
6
|
+
"Bash(git commit *)",
|
|
7
|
+
"Bash(git fetch *)",
|
|
8
|
+
"Bash(git ls-tree *)",
|
|
9
|
+
"Bash(echo \"graph module on dev? $\\(git ls-tree -r --name-only origin/dev)",
|
|
10
|
+
"Bash(awk 'length>100{print FILENAME\":\"FNR\" \\(\"length\"\\)\"}' tests/test_classifier.py tests/test_impact.py tests/test_resources.py)",
|
|
11
|
+
"Bash(gh pr *)",
|
|
12
|
+
"Bash(git stash *)",
|
|
13
|
+
"Bash(echo \"PR #4: $\\(gh pr view 4 --json state,mergeCommit -q '.state + \" merge=\" + \\(.mergeCommit.oid // \"not-merged\"\\)' \\)\")"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
build/
|
|
6
|
+
dist/
|
|
7
|
+
.eggs/
|
|
8
|
+
|
|
9
|
+
# Virtualenvs
|
|
10
|
+
.venv/
|
|
11
|
+
venv/
|
|
12
|
+
env/
|
|
13
|
+
|
|
14
|
+
# Tooling caches
|
|
15
|
+
.pytest_cache/
|
|
16
|
+
.mypy_cache/
|
|
17
|
+
.ruff_cache/
|
|
18
|
+
|
|
19
|
+
# Editors / OS
|
|
20
|
+
.vscode/
|
|
21
|
+
.idea/
|
|
22
|
+
.DS_Store
|
|
23
|
+
|
|
24
|
+
# Generated graph renders
|
|
25
|
+
graph.png
|
|
26
|
+
*.dot.png
|
|
27
|
+
|
|
28
|
+
# Local-only build-in-public posting log (never committed)
|
|
29
|
+
docs/social/x-posts.md
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Contributing to statewatch
|
|
2
|
+
|
|
3
|
+
statewatch is GCP-only in v0.1 by design. The two highest-value contributions are **new
|
|
4
|
+
cloud adapters** (AWS, Azure) and **new GCP resource types** — both have explicit
|
|
5
|
+
extension seams so you don't have to touch the engine.
|
|
6
|
+
|
|
7
|
+
## Dev setup
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
python -m venv .venv && . .venv/bin/activate
|
|
11
|
+
pip install -e ".[dev]"
|
|
12
|
+
pytest -q # 40+ tests, all green
|
|
13
|
+
ruff check .
|
|
14
|
+
mypy src/statewatch
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Offline run (no GCP project needed): `statewatch scan --tfstate
|
|
18
|
+
tests/fixtures/firewall_subnet_drift.tfstate.json --project demo-project --stub`.
|
|
19
|
+
|
|
20
|
+
## Adding a cloud adapter (AWS / Azure)
|
|
21
|
+
|
|
22
|
+
The boundary is `src/statewatch/adapters/base.py` — a `CloudAdapter` `Protocol`. An
|
|
23
|
+
adapter's only job is **auth + return live state as normalized `Resource` objects**. It
|
|
24
|
+
does not diff, classify, or know about Terraform.
|
|
25
|
+
|
|
26
|
+
Implement four things (see the protocol docstring for the full contract):
|
|
27
|
+
|
|
28
|
+
1. `name` — `"aws"` / `"azure"`.
|
|
29
|
+
2. `authenticate()` — establish credentials via the provider's standard mechanism and make
|
|
30
|
+
one cheap call to validate them. Raise `AdapterAuthError` on failure.
|
|
31
|
+
3. `supported_resource_types()` — the Terraform type names you can fetch
|
|
32
|
+
(e.g. `{"aws_instance", "aws_security_group"}`).
|
|
33
|
+
4. `fetch_resources(types, *, scope)` — query the provider inventory API
|
|
34
|
+
(AWS Config / Azure Resource Graph) and map each native object into a `Resource`,
|
|
35
|
+
deriving a `resource_id` that matches what Terraform-side normalization produces, and
|
|
36
|
+
filling `parent_refs` from obvious attribute references.
|
|
37
|
+
|
|
38
|
+
Nothing else in the codebase needs to change — the differ, graph, classifier and impact
|
|
39
|
+
analyzer are provider-agnostic.
|
|
40
|
+
|
|
41
|
+
## Adding a GCP resource type
|
|
42
|
+
|
|
43
|
+
One module per type under `src/statewatch/resources/` (see `compute_instance.py`,
|
|
44
|
+
`firewall.py`, `subnetwork.py`, `gke_cluster.py` for the pattern):
|
|
45
|
+
|
|
46
|
+
1. Create `resources/<type>.py` with `RESOURCE_TYPE`, `normalize_from_tfstate(...)`, and
|
|
47
|
+
`normalize_from_cai(...)`. Build `resource_id` from the shared id helpers in
|
|
48
|
+
`normalizer.py` so it unifies with other resources' `parent_refs` (this is what makes
|
|
49
|
+
the graph connect — see KNOWN_ISSUES history for why it matters).
|
|
50
|
+
2. Register it in `resources/__init__.py` (`_TF`, `_CAI`, `_CAI_ASSET_TO_TYPE`) and add
|
|
51
|
+
the CAI asset type to `adapters/gcp.py`.
|
|
52
|
+
3. Whitelist only *comparable* attributes; never copy server-generated noise
|
|
53
|
+
(`*_fingerprint`, `self_link`, ids, timestamps).
|
|
54
|
+
4. Add severity rules in `classifier.py` if the type has security-relevant changes.
|
|
55
|
+
5. Add a realistic fixture and tests. **Fixtures are the README of the test suite** —
|
|
56
|
+
real-shaped `.tfstate`, not toy examples.
|
|
57
|
+
|
|
58
|
+
## Conventions
|
|
59
|
+
|
|
60
|
+
- Edge direction is `A → B` = "A depends on B"; impact flows against it (predecessors).
|
|
61
|
+
- Don't overclaim: severity is a heuristic proxy for propagation, stated as such in
|
|
62
|
+
output and docs. Keep it that way.
|
|
63
|
+
- Deferred work goes in `KNOWN_ISSUES.md` with *why* and *when*, never silently.
|
|
64
|
+
- ruff + mypy clean; tests green; honest commit messages (phase/scope-enabling edits to
|
|
65
|
+
shared modules committed separately).
|
|
66
|
+
|
|
67
|
+
## Out of scope (v0.1)
|
|
68
|
+
|
|
69
|
+
Auto-remediation, multi-cloud in one run, a web dashboard, a SaaS, and replacing
|
|
70
|
+
`terraform plan`. See "What this is NOT trying to be" in `spec.md`.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Container image for the statewatch GitHub Action.
|
|
2
|
+
FROM python:3.12-slim
|
|
3
|
+
|
|
4
|
+
WORKDIR /opt/statewatch
|
|
5
|
+
COPY pyproject.toml README.md LICENSE ./
|
|
6
|
+
COPY src ./src
|
|
7
|
+
RUN pip install --no-cache-dir .
|
|
8
|
+
|
|
9
|
+
COPY action/entrypoint.py /action/entrypoint.py
|
|
10
|
+
|
|
11
|
+
ENTRYPOINT ["python", "/action/entrypoint.py"]
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Known issues / deferred work
|
|
2
|
+
|
|
3
|
+
Tracked, deliberately-deferred items. Each says *why* it was deferred and *when* it must
|
|
4
|
+
be addressed. A deferred fix that isn't written down is a forgotten bug.
|
|
5
|
+
|
|
6
|
+
## Resolved
|
|
7
|
+
|
|
8
|
+
### 1. Subnet ref dropped the region for bare-name inputs — RESOLVED in Phase 3
|
|
9
|
+
Resolved at Phase 3 entry as planned. `normalizer.subnetwork_ref_from_attr` now produces
|
|
10
|
+
a region-qualified canonical id for full-URL, path, **and** bare-name forms; for bare
|
|
11
|
+
names the region is derived from the instance's own zone (a GCP instance's subnet is
|
|
12
|
+
always in its region). `resources/subnetwork.py` builds its `resource_id` from the same
|
|
13
|
+
shared `subnetwork_id`, so an instance's inferred subnet ref and the subnet resource node
|
|
14
|
+
unify into one node. Regression locked by
|
|
15
|
+
`tests/test_resources.py::test_known_issue_1_subnet_ref_unifies_across_input_forms`.
|
|
16
|
+
Original report retained below for history.
|
|
17
|
+
|
|
18
|
+
<details><summary>Original deferral (Phase 2)</summary>
|
|
19
|
+
|
|
20
|
+
### 1. `_normalize_subnetwork_ref` drops the region for bare-name inputs
|
|
21
|
+
- **Where:** `src/statewatch/normalizer.py` — `_normalize_subnetwork_ref`.
|
|
22
|
+
- **What:** When a compute instance's `subnetwork` attribute is a *full URL* or a
|
|
23
|
+
`projects/.../regions/.../subnetworks/...` path, the inferred `parent_ref` id keeps the
|
|
24
|
+
region segment (`projects/<p>/regions/<r>/subnetworks/<n>`). When it's a *bare name*,
|
|
25
|
+
the fallback emits `projects/<p>/subnetworks/<n>` — **no region**.
|
|
26
|
+
- **Why it matters:** Phase 3 makes `google_compute_subnetwork` a first-class normalized
|
|
27
|
+
resource. Its node `resource_id` will be the regional form. If Phase 1's bare-name
|
|
28
|
+
fallback id doesn't match that form, an inferred edge and the real subnet node will *not
|
|
29
|
+
unify* — the graph will show a duplicate/dangling external node instead of connecting
|
|
30
|
+
the instance to its actual subnet. This is exactly the "Phase 3 fights the graph"
|
|
31
|
+
failure mode flagged during Phase 2 design.
|
|
32
|
+
- **Why deferred:** Fixing it in Phase 2 means churning Phase 1 normalization mid-phase
|
|
33
|
+
with no Phase 2 consumer that needs it (the fixtures use full URLs, which are already
|
|
34
|
+
correct). Approved for deferral during Phase 2 architectural review.
|
|
35
|
+
- **Fix at Phase 3 entry:** make the subnetwork (and, symmetrically, network/SA) id
|
|
36
|
+
derivation produce the *same* canonical id the Phase 3 subnetwork normalizer will assign
|
|
37
|
+
— region-qualified — and add a normalizer test asserting an instance's inferred subnet
|
|
38
|
+
ref equals the subnet resource's `resource_id` for bare-name, path, and URL inputs.
|
|
39
|
+
|
|
40
|
+
</details>
|
|
41
|
+
|
|
42
|
+
### 2. `scan` degraded instead of failing when GCP auth was unavailable — RESOLVED in Phase 4
|
|
43
|
+
`adapters/gcp.py` now makes a real `AssetServiceClient.list_assets` call by default.
|
|
44
|
+
`scan` no longer degrades: a missing-credentials situation is a hard `typer.Exit(2)`
|
|
45
|
+
(`cli._produce_report`). Offline demo/CI is an explicit, separate path — `--stub` or
|
|
46
|
+
`STATEWATCH_STUB_GCP=1` — never a silent fallback. Original carry-forward retained below.
|
|
47
|
+
|
|
48
|
+
<details><summary>Original follow-up (Phases 1–3)</summary>
|
|
49
|
+
|
|
50
|
+
`scan` printed a warning and continued against stubbed CAI when ADC was absent, because
|
|
51
|
+
the live-state fetch was stubbed and degrading kept it demonstrable offline. The fix was
|
|
52
|
+
gated on a real `list_assets` call landing, which it did in Phase 4.
|
|
53
|
+
|
|
54
|
+
</details>
|
|
55
|
+
|
|
56
|
+
## Carried to v0.2 (none)
|
|
57
|
+
|
|
58
|
+
Nothing is being silently carried. v0.2 (drift attribution) is a separate, scoped release
|
|
59
|
+
per `spec.md`; it is not a deferred bug.
|
|
60
|
+
|
|
61
|
+
## Heuristics stated honestly (not bugs, but tracked)
|
|
62
|
+
|
|
63
|
+
- **Severity as a propagation proxy.** Impact labelling treats severity ≥ MEDIUM as
|
|
64
|
+
"propagates." This is a deliberate heuristic, not dataflow analysis, and is stated as
|
|
65
|
+
such in terminal output, JSON, and the README. A future enhancement could model
|
|
66
|
+
per-attribute propagation; v0.1 intentionally does not.
|
|
67
|
+
- **Firewall applicability inference** matches on network + target tags/SAs, not a
|
|
68
|
+
packet-level evaluation. Documented in `graph/inferred.py`.
|
statewatch-0.1.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.
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: statewatch
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Dependency-aware infrastructure drift detector for GCP
|
|
5
|
+
Project-URL: Homepage, https://github.com/pyjeebz/statewatch
|
|
6
|
+
Project-URL: Repository, https://github.com/pyjeebz/statewatch
|
|
7
|
+
Author: pyjeebz
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: drift,gcp,infrastructure,sre,terraform
|
|
11
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: System Administrators
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: System :: Systems Administration
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Requires-Dist: google-auth>=2.0
|
|
20
|
+
Requires-Dist: google-cloud-asset>=3.20
|
|
21
|
+
Requires-Dist: google-cloud-storage>=2.10
|
|
22
|
+
Requires-Dist: networkx>=3.0
|
|
23
|
+
Requires-Dist: pyyaml>=6.0
|
|
24
|
+
Requires-Dist: rich>=13.0
|
|
25
|
+
Requires-Dist: schedule>=1.2
|
|
26
|
+
Requires-Dist: typer>=0.12
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
31
|
+
Requires-Dist: types-pyyaml>=6.0; extra == 'dev'
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# statewatch
|
|
35
|
+
|
|
36
|
+
**Your infrastructure drifted. statewatch tells you what breaks.**
|
|
37
|
+
|
|
38
|
+
A dependency-aware drift detector for GCP. It compares live Cloud Asset Inventory state
|
|
39
|
+
against your Terraform state, builds a resource dependency graph (including dependencies
|
|
40
|
+
Terraform itself doesn't track), and reports, per drift, **how bad it is** and **what
|
|
41
|
+
else is affected**.
|
|
42
|
+
|
|
43
|
+
Detection is commodity — every tool tells you a field changed. The hard question on call
|
|
44
|
+
at 2 AM is *"what does this break?"* That's what statewatch answers.
|
|
45
|
+
|
|
46
|
+

|
|
47
|
+
|
|
48
|
+
## Install
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install statewatch
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Python 3.11+. Apache-2.0.
|
|
55
|
+
|
|
56
|
+
## Quickstart
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# 1. Point it at your Terraform state and GCP project (needs roles/cloudasset.viewer)
|
|
60
|
+
statewatch scan --tfstate ./terraform.tfstate --project my-gcp-project
|
|
61
|
+
|
|
62
|
+
# 2. See the dependency graph it builds (text | json | dot)
|
|
63
|
+
statewatch graph --tfstate ./terraform.tfstate --project my-gcp-project --format dot | dot -Tpng > graph.png
|
|
64
|
+
|
|
65
|
+
# 3. Generate a starter config
|
|
66
|
+
statewatch init --tfstate ./terraform.tfstate --project my-gcp-project
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
No GCP project handy? Add `--stub` to any `scan` for an offline demo against bundled
|
|
70
|
+
sample state. State can also live in GCS: `--tfstate gs://my-bucket/env/prod.tfstate`.
|
|
71
|
+
|
|
72
|
+
## What statewatch does
|
|
73
|
+
|
|
74
|
+
- **Severity × impact, not just "drift detected."** Every finding carries a severity
|
|
75
|
+
(CRITICAL / MEDIUM / LOW) *and* a blast radius — the resources that depend on the
|
|
76
|
+
drifted one, labelled **DIRECT** (one hop), **INDIRECT** (two hops), or **WATCH**
|
|
77
|
+
(further, or low-propagation drift). `CRITICAL firewall drift — 2 DIRECT` is a
|
|
78
|
+
different alert than `drift detected`.
|
|
79
|
+
- **A real dependency graph.** Built automatically from Terraform `depends_on`, from
|
|
80
|
+
manual edges in `statewatch.yaml`, and — the defensible part — **inferred from resource
|
|
81
|
+
attributes**: a subnet referenced in an instance's `subnetwork` field, or a firewall
|
|
82
|
+
that applies to an instance by tag, is a real dependency even when `depends_on` never
|
|
83
|
+
mentions it. Terraform doesn't track those. statewatch does.
|
|
84
|
+
- **Exit codes for CI.** `0` clean · `1` low/medium drift · `2` critical, or any drift
|
|
85
|
+
with a significant blast radius. Wire it into a pipeline and the build fails when it
|
|
86
|
+
should.
|
|
87
|
+
|
|
88
|
+
Resource types in v0.1: `google_compute_instance`, `google_compute_firewall`,
|
|
89
|
+
`google_compute_subnetwork`, `google_container_cluster`.
|
|
90
|
+
|
|
91
|
+
## Who this is for
|
|
92
|
+
|
|
93
|
+
statewatch is for **SRE on-call, incident response, and large-scale Terraform setups** —
|
|
94
|
+
the engineer staring at drift in infrastructure they didn't write, who needs to triage
|
|
95
|
+
fast, and any setup where implicit dependencies live in attribute fields that Terraform's
|
|
96
|
+
own dependency tree doesn't capture.
|
|
97
|
+
|
|
98
|
+
**It is not for everyone, and that's deliberate.** If you wrote the Terraform and you're
|
|
99
|
+
the one running `plan`, you know what depends on what — `terraform plan` is enough and you
|
|
100
|
+
don't need this. statewatch earns its keep when the person seeing the drift *isn't* the
|
|
101
|
+
person who wrote the code, or when there are too many simultaneous drift events to triage
|
|
102
|
+
by hand. Underclaiming who it's for is the point.
|
|
103
|
+
|
|
104
|
+
One honesty note: statewatch uses **severity as a heuristic proxy for whether drift
|
|
105
|
+
propagates** to dependents. It is not dataflow analysis and doesn't claim to be — the
|
|
106
|
+
terminal output and JSON say so too.
|
|
107
|
+
|
|
108
|
+
## Why statewatch and not …
|
|
109
|
+
|
|
110
|
+
| | what it tells you | what it doesn't |
|
|
111
|
+
|---|---|---|
|
|
112
|
+
| `terraform plan` | exactly what *your* config would change | nothing about live drift you didn't cause; only what's in the dependency tree |
|
|
113
|
+
| Terraform Cloud drift detection | a resource drifted | what *else* is affected; implicit attribute-level dependencies |
|
|
114
|
+
| driftctl | unmanaged / drifted resources, broadly | severity, and the downstream blast radius |
|
|
115
|
+
| **statewatch** | what drifted, how bad, **and what depends on it** | it's GCP-only, detection-only (no auto-fix), and intentionally narrow in audience |
|
|
116
|
+
|
|
117
|
+
statewatch is a *complement* to `terraform plan`, not a replacement.
|
|
118
|
+
|
|
119
|
+
## How it works
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
GCP live state Terraform state
|
|
123
|
+
(Cloud Asset Inventory) (local file or gs://)
|
|
124
|
+
└──────────┬──────────┘
|
|
125
|
+
▼
|
|
126
|
+
normalize → structural diff
|
|
127
|
+
▼
|
|
128
|
+
severity classifier dependency graph
|
|
129
|
+
└─────────┬────────┘
|
|
130
|
+
▼
|
|
131
|
+
impact analyzer (walk predecessors)
|
|
132
|
+
▼
|
|
133
|
+
severity × impact report (terminal · JSON · Slack · GitHub PR)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Impact flows *against* dependency edges: when B drifts, the affected resources are B's
|
|
137
|
+
transitive predecessors (everything that depends on B).
|
|
138
|
+
|
|
139
|
+
## Running in CI
|
|
140
|
+
|
|
141
|
+
A GitHub Action ships in this repo (`action.yml`): it runs a scan, upserts a single
|
|
142
|
+
findings comment on the PR, and fails the check when statewatch exits `2`.
|
|
143
|
+
|
|
144
|
+
```yaml
|
|
145
|
+
- uses: google-github-actions/auth@v2
|
|
146
|
+
with: { workload_identity_provider: ..., service_account: ... }
|
|
147
|
+
- uses: pyjeebz/statewatch@v0.1.0
|
|
148
|
+
with:
|
|
149
|
+
tfstate: gs://my-bucket/env/prod.tfstate
|
|
150
|
+
project: my-gcp-project
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Slack notifications and `--watch` (continuous, notify-only-on-new-drift) are configured
|
|
154
|
+
via `statewatch.yaml` — run `statewatch init` to scaffold one.
|
|
155
|
+
|
|
156
|
+
## Future
|
|
157
|
+
|
|
158
|
+
statewatch is the intelligence layer — *what changed and what it breaks*. **v0.2** adds
|
|
159
|
+
drift attribution: *who* changed it and *when*, by correlating GCP Audit Logs. AWS and
|
|
160
|
+
Azure adapters are open for community contribution behind a stable adapter interface; the
|
|
161
|
+
runtime layer is a separate, later effort.
|
|
162
|
+
|
|
163
|
+
## Roadmap
|
|
164
|
+
|
|
165
|
+
- **v0.2** — drift attribution (Audit Logs: actor, method, timestamp). Opt-in.
|
|
166
|
+
- AWS adapter (Config + CloudTrail) and Azure adapter (Resource Graph + Activity Log) —
|
|
167
|
+
community contributions welcome; see [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
168
|
+
- Tracked, deliberately-deferred items live in [KNOWN_ISSUES.md](KNOWN_ISSUES.md).
|
|
169
|
+
|
|
170
|
+
## Contributing
|
|
171
|
+
|
|
172
|
+
The adapter and per-resource-type seams are designed for external contribution —
|
|
173
|
+
[CONTRIBUTING.md](CONTRIBUTING.md) explains the `CloudAdapter` interface and how to add a
|
|
174
|
+
resource type without touching the engine.
|
|
175
|
+
|
|
176
|
+
## License
|
|
177
|
+
|
|
178
|
+
Apache-2.0. See [LICENSE](LICENSE).
|