invariant-sast 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.
Files changed (28) hide show
  1. invariant_sast-0.1.0/LICENSE +201 -0
  2. invariant_sast-0.1.0/NOTICE +5 -0
  3. invariant_sast-0.1.0/PKG-INFO +209 -0
  4. invariant_sast-0.1.0/README.md +187 -0
  5. invariant_sast-0.1.0/pyproject.toml +40 -0
  6. invariant_sast-0.1.0/setup.cfg +4 -0
  7. invariant_sast-0.1.0/src/invariant/__init__.py +1 -0
  8. invariant_sast-0.1.0/src/invariant/baseline/rcp-policies/lza-core-rcp-guardrails-1.json +135 -0
  9. invariant_sast-0.1.0/src/invariant/baseline/service-control-policies/lza-core-guardrails-1.json +156 -0
  10. invariant_sast-0.1.0/src/invariant/baseline/service-control-policies/lza-core-guardrails-2.json +211 -0
  11. invariant_sast-0.1.0/src/invariant/baseline/service-control-policies/lza-core-sandbox-guardrails-1.json +111 -0
  12. invariant_sast-0.1.0/src/invariant/baseline/service-control-policies/lza-core-security-guardrails-1.json +66 -0
  13. invariant_sast-0.1.0/src/invariant/baseline/service-control-policies/lza-core-workloads-guardrails-1.json +109 -0
  14. invariant_sast-0.1.0/src/invariant/baseline/service-control-policies/lza-infrastructure-guardrails-1.json +198 -0
  15. invariant_sast-0.1.0/src/invariant/baseline/service-control-policies/lza-quarantine.json +20 -0
  16. invariant_sast-0.1.0/src/invariant/baseline/service-control-policies/lza-suspended-guardrails.json +20 -0
  17. invariant_sast-0.1.0/src/invariant/build_manifest.py +75 -0
  18. invariant_sast-0.1.0/src/invariant/checks/__init__.py +0 -0
  19. invariant_sast-0.1.0/src/invariant/checks/base.py +54 -0
  20. invariant_sast-0.1.0/src/invariant/checks/scp_permissiveness_regression.py +54 -0
  21. invariant_sast-0.1.0/src/invariant/cli.py +281 -0
  22. invariant_sast-0.1.0/src/invariant/policy_check.py +277 -0
  23. invariant_sast-0.1.0/src/invariant_sast.egg-info/PKG-INFO +209 -0
  24. invariant_sast-0.1.0/src/invariant_sast.egg-info/SOURCES.txt +26 -0
  25. invariant_sast-0.1.0/src/invariant_sast.egg-info/dependency_links.txt +1 -0
  26. invariant_sast-0.1.0/src/invariant_sast.egg-info/entry_points.txt +2 -0
  27. invariant_sast-0.1.0/src/invariant_sast.egg-info/requires.txt +5 -0
  28. invariant_sast-0.1.0/src/invariant_sast.egg-info/top_level.txt +1 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing
141
+ the origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Invariant contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,5 @@
1
+ Invariant
2
+ Copyright 2026 Invariant contributors
3
+
4
+ This product includes software developed as part of the Invariant project
5
+ (SMT-based guardrail SAST for AWS SCP/RCP JSON).
@@ -0,0 +1,209 @@
1
+ Metadata-Version: 2.4
2
+ Name: invariant-sast
3
+ Version: 0.1.0
4
+ Summary: SMT-based guardrail SAST for AWS SCP/RCP JSON (baseline + regression checks)
5
+ License-Expression: Apache-2.0
6
+ Project-URL: Homepage, https://ikurira.github.io/invariant/
7
+ Project-URL: Issues, https://github.com/Ikurira/invariant/issues
8
+ Project-URL: Repository, https://github.com/Ikurira/invariant
9
+ Classifier: Environment :: Console
10
+ Classifier: Intended Audience :: System Administrators
11
+ Classifier: Topic :: Security
12
+ Classifier: Topic :: Software Development :: Quality Assurance
13
+ Requires-Python: >=3.10
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ License-File: NOTICE
17
+ Requires-Dist: z3-solver
18
+ Provides-Extra: docs
19
+ Requires-Dist: mkdocs>=1.6; extra == "docs"
20
+ Requires-Dist: mkdocs-material>=9.5; extra == "docs"
21
+ Dynamic: license-file
22
+
23
+ # Invariant
24
+
25
+ SMT-based guardrail SAST for AWS Service Control Policies (SCPs) and Resource
26
+ Control Policies (RCPs). Instead of pattern-matching JSON, Invariant hands
27
+ your policies to the [Z3](https://github.com/Z3Prover/z3) theorem prover and
28
+ asks a precise question:
29
+
30
+ > Is there any `(action, resource, principal)` request that used to be
31
+ > denied, but isn't anymore?
32
+
33
+ If Z3 finds one, that's a guardrail regression, and you get a concrete
34
+ counterexample instead of a vague warning.
35
+
36
+ ## Why
37
+
38
+ Checkov, cfn-nag, and friends are great at "does this statement look
39
+ dangerous," but they can't tell you whether an edit to a `Condition` block
40
+ quietly widened who a `Deny` statement applies to. That requires reasoning
41
+ about the full set of requests a policy allows, not just its syntax. Invariant
42
+ answers that question with a solver instead of a regex.
43
+
44
+ ## Two checks, one engine
45
+
46
+ - **`invariant scan`** — baseline check. Point it at a directory and it
47
+ proves each `service-control-policies/*.json` / `rcp-policies/*.json` file
48
+ still upholds the security properties of the **default AWS Landing Zone
49
+ Accelerator (LZA) guardrails**, a copy of which ships inside the package
50
+ (`src/invariant/baseline/`). No reference file, no manifest, nothing to set
51
+ up — this is the "just run it" entry point.
52
+
53
+ - **`invariant regression --manifest manifest.json`** — diff check. Proves
54
+ each candidate still denies everything *its own paired reference* denied.
55
+ Use this when you want to check against something other than the bundled
56
+ LZA defaults — your org's own last-known-good policies, an upstream
57
+ release, whatever you supply. `build_manifest.py` derives the pairing from
58
+ a git diff so you don't hand-maintain it (see [CI integration](#ci-integration)).
59
+
60
+ Both share the same check registry, output formats, and exit-code
61
+ convention: `0` = no findings (or `--soft-fail`), `1` = a check failed.
62
+
63
+ ## Install
64
+
65
+ Requires Python 3.10+. `z3-solver` is installed automatically as a
66
+ dependency.
67
+
68
+ ```bash
69
+ # from a package index, once published
70
+ pip install invariant
71
+
72
+ # or straight from source
73
+ git clone https://github.com/YOUR_ORG/invariant.git
74
+ cd invariant
75
+ pip install .
76
+ ```
77
+
78
+ ## Quickstart
79
+
80
+ From the root of your AWS LZA config repo (wherever your
81
+ `service-control-policies/` and `rcp-policies/` directories live):
82
+
83
+ ```bash
84
+ invariant scan
85
+ ```
86
+
87
+ ```
88
+ [PASS] INV_AWS_001 service-control-policies/lza-core-guardrails-1.json No regression found.
89
+ [PASS] INV_AWS_001 service-control-policies/lza-quarantine.json No regression found.
90
+ [FAIL (critical)] INV_AWS_001 service-control-policies/lza-quarantine.json Candidate no longer denies a request the reference denied: {'action': '""', 'resource': '""', 'principal': '""'}
91
+ ```
92
+
93
+ A `FAIL` line means Z3 found a concrete `(action, resource, principal)`
94
+ tuple that the bundled baseline guardrail denies but your policy no longer
95
+ does. Exit code is `1` whenever any check fails, so it's CI-friendly out of
96
+ the box.
97
+
98
+ Only files with a same-named counterpart in the bundled baseline catalog are
99
+ checked. A custom SCP with no LZA-default analog has nothing to prove a
100
+ baseline property against yet — `invariant scan` reports it (to stderr) as
101
+ skipped rather than silently ignoring it. Pair it against something of your
102
+ own choosing with `invariant regression` instead.
103
+
104
+ ## CLI reference
105
+
106
+ Both subcommands accept:
107
+
108
+ | Flag | Default | Meaning |
109
+ |---|---|---|
110
+ | `--check IDS` | all | Comma-separated check IDs to run |
111
+ | `--skip-check IDS` | none | Comma-separated check IDs to exclude |
112
+ | `--output`, `-o` | `cli` | `cli`, `json`, and/or `sarif` — repeatable |
113
+ | `--soft-fail` | off | Always exit `0`, regardless of findings |
114
+ | `--compact` | off | Suppress `PASS` lines in `cli` output |
115
+ | `--out-dir` | `solver-results` | Where `json`/`sarif` reports get written |
116
+
117
+ `invariant scan` also takes:
118
+
119
+ | Flag | Default | Meaning |
120
+ |---|---|---|
121
+ | `--directory`, `-d` | `.` | Root to scan for `service-control-policies/` and `rcp-policies/` |
122
+
123
+ `invariant regression` also takes:
124
+
125
+ | Flag | Default | Meaning |
126
+ |---|---|---|
127
+ | `--manifest`, `-m` | `manifest.json` | Reference↔candidate pairing (see `build_manifest.py`) |
128
+
129
+ ## Suppressing a finding
130
+
131
+ A candidate JSON file can carry a top-level `_suppressions` array (raw AWS
132
+ policy JSON has no comment syntax to piggyback a suppression on, unlike
133
+ HCL/YAML checks):
134
+
135
+ ```json
136
+ {
137
+ "Version": "2012-10-17",
138
+ "Statement": [ ... ],
139
+ "_suppressions": [
140
+ {"check_id": "INV_AWS_001", "reason": "JIRA-1234: intentional widen"}
141
+ ]
142
+ }
143
+ ```
144
+
145
+ This key is stripped before the policy is handed to the solver, so it never
146
+ affects the request semantics Z3 reasons about.
147
+
148
+ ## Checks
149
+
150
+ | ID | Severity | What it proves |
151
+ |---|---|---|
152
+ | `INV_AWS_001` | CRITICAL | The candidate SCP/RCP denies every `(action, resource, principal)` request its reference (baseline or paired manifest entry) explicitly denied. |
153
+
154
+ Failing `INV_AWS_001`: review the counterexample. If the widened permission
155
+ is intentional, add a `_suppressions` entry (or update your own reference,
156
+ for `regression`) and document why in the PR description. If not, revert the
157
+ `Condition`/`Resource`/`Action` change that removed the denial.
158
+
159
+ ## How the solver works, and where it's intentionally conservative
160
+
161
+ Every `Deny` statement becomes a Z3 predicate over a symbolic request
162
+ context (one variable per condition key actually observed in the LZA
163
+ guardrail set); wildcard `Action`/`Resource`/ARN patterns compile to Z3
164
+ regular expressions. `invariant` then asks the solver to find a request the
165
+ reference denies that the candidate doesn't. See `policy_check.py` for the
166
+ full model. A few gaps are called out there and worth knowing about:
167
+
168
+ - **`aws:CalledVia`** is modeled as a single representative string, not a
169
+ true call chain, so `ForAllValues:StringNotEquals` on it is sound for
170
+ catching "the whole chain is now unconstrained" but can miss a regression
171
+ that only appears with one specific multi-hop chain.
172
+ - **`aws:ResourceTag/*` (`StringEquals`)** is left unconstrained — there's no
173
+ resource-tag model — which makes the checker conservative (won't
174
+ false-negative a real regression) but can over-report on tag-gated
175
+ statements.
176
+ - Any condition operator not in the model (currently seen in the wild:
177
+ `StringLike`, `StringNotLike`, `ForAnyValue:StringLike` on keys like
178
+ `rds:DatabaseEngine`) is treated as **non-constraining** and prints a
179
+ `WARNING`. A statement using one of these may be reported as denying more
180
+ than it actually does — verify those findings by hand.
181
+
182
+ None of this changes the exit-code contract; it just means a `PASS` on a
183
+ statement using one of the flagged operators is a weaker guarantee than a
184
+ `PASS` elsewhere, and the tool tells you when that's the case.
185
+
186
+ ## CI integration
187
+
188
+ `.gitlab-ci.yml` and `.github/workflows/invariant.yml` are **templates**,
189
+ meant to be copied into your own AWS LZA config repo (not into a fork of
190
+ this one) — each wires up a diff-scoped `regression` job plus a full-sweep
191
+ `scan` job, and publishes `solver-results*/results.sarif` so GitLab/GitHub
192
+ render findings natively. Both assume `invariant` is installed from wherever
193
+ you publish it — set `INVARIANT_PIP_SPEC` (GitLab) / `INVARIANT_PIP_SPEC` env
194
+ (GitHub) to your private index, package registry, or a `git+https://` URL.
195
+
196
+ ## Development
197
+
198
+ ```bash
199
+ git clone https://github.com/YOUR_ORG/invariant.git
200
+ cd invariant
201
+ python -m venv .venv
202
+ . .venv/Scripts/activate # .venv/bin/activate on macOS/Linux
203
+ pip install -e .
204
+ invariant --help
205
+ ```
206
+
207
+ ## License
208
+
209
+ Apache-2.0 — see [LICENSE](LICENSE).
@@ -0,0 +1,187 @@
1
+ # Invariant
2
+
3
+ SMT-based guardrail SAST for AWS Service Control Policies (SCPs) and Resource
4
+ Control Policies (RCPs). Instead of pattern-matching JSON, Invariant hands
5
+ your policies to the [Z3](https://github.com/Z3Prover/z3) theorem prover and
6
+ asks a precise question:
7
+
8
+ > Is there any `(action, resource, principal)` request that used to be
9
+ > denied, but isn't anymore?
10
+
11
+ If Z3 finds one, that's a guardrail regression, and you get a concrete
12
+ counterexample instead of a vague warning.
13
+
14
+ ## Why
15
+
16
+ Checkov, cfn-nag, and friends are great at "does this statement look
17
+ dangerous," but they can't tell you whether an edit to a `Condition` block
18
+ quietly widened who a `Deny` statement applies to. That requires reasoning
19
+ about the full set of requests a policy allows, not just its syntax. Invariant
20
+ answers that question with a solver instead of a regex.
21
+
22
+ ## Two checks, one engine
23
+
24
+ - **`invariant scan`** — baseline check. Point it at a directory and it
25
+ proves each `service-control-policies/*.json` / `rcp-policies/*.json` file
26
+ still upholds the security properties of the **default AWS Landing Zone
27
+ Accelerator (LZA) guardrails**, a copy of which ships inside the package
28
+ (`src/invariant/baseline/`). No reference file, no manifest, nothing to set
29
+ up — this is the "just run it" entry point.
30
+
31
+ - **`invariant regression --manifest manifest.json`** — diff check. Proves
32
+ each candidate still denies everything *its own paired reference* denied.
33
+ Use this when you want to check against something other than the bundled
34
+ LZA defaults — your org's own last-known-good policies, an upstream
35
+ release, whatever you supply. `build_manifest.py` derives the pairing from
36
+ a git diff so you don't hand-maintain it (see [CI integration](#ci-integration)).
37
+
38
+ Both share the same check registry, output formats, and exit-code
39
+ convention: `0` = no findings (or `--soft-fail`), `1` = a check failed.
40
+
41
+ ## Install
42
+
43
+ Requires Python 3.10+. `z3-solver` is installed automatically as a
44
+ dependency.
45
+
46
+ ```bash
47
+ # from a package index, once published
48
+ pip install invariant
49
+
50
+ # or straight from source
51
+ git clone https://github.com/YOUR_ORG/invariant.git
52
+ cd invariant
53
+ pip install .
54
+ ```
55
+
56
+ ## Quickstart
57
+
58
+ From the root of your AWS LZA config repo (wherever your
59
+ `service-control-policies/` and `rcp-policies/` directories live):
60
+
61
+ ```bash
62
+ invariant scan
63
+ ```
64
+
65
+ ```
66
+ [PASS] INV_AWS_001 service-control-policies/lza-core-guardrails-1.json No regression found.
67
+ [PASS] INV_AWS_001 service-control-policies/lza-quarantine.json No regression found.
68
+ [FAIL (critical)] INV_AWS_001 service-control-policies/lza-quarantine.json Candidate no longer denies a request the reference denied: {'action': '""', 'resource': '""', 'principal': '""'}
69
+ ```
70
+
71
+ A `FAIL` line means Z3 found a concrete `(action, resource, principal)`
72
+ tuple that the bundled baseline guardrail denies but your policy no longer
73
+ does. Exit code is `1` whenever any check fails, so it's CI-friendly out of
74
+ the box.
75
+
76
+ Only files with a same-named counterpart in the bundled baseline catalog are
77
+ checked. A custom SCP with no LZA-default analog has nothing to prove a
78
+ baseline property against yet — `invariant scan` reports it (to stderr) as
79
+ skipped rather than silently ignoring it. Pair it against something of your
80
+ own choosing with `invariant regression` instead.
81
+
82
+ ## CLI reference
83
+
84
+ Both subcommands accept:
85
+
86
+ | Flag | Default | Meaning |
87
+ |---|---|---|
88
+ | `--check IDS` | all | Comma-separated check IDs to run |
89
+ | `--skip-check IDS` | none | Comma-separated check IDs to exclude |
90
+ | `--output`, `-o` | `cli` | `cli`, `json`, and/or `sarif` — repeatable |
91
+ | `--soft-fail` | off | Always exit `0`, regardless of findings |
92
+ | `--compact` | off | Suppress `PASS` lines in `cli` output |
93
+ | `--out-dir` | `solver-results` | Where `json`/`sarif` reports get written |
94
+
95
+ `invariant scan` also takes:
96
+
97
+ | Flag | Default | Meaning |
98
+ |---|---|---|
99
+ | `--directory`, `-d` | `.` | Root to scan for `service-control-policies/` and `rcp-policies/` |
100
+
101
+ `invariant regression` also takes:
102
+
103
+ | Flag | Default | Meaning |
104
+ |---|---|---|
105
+ | `--manifest`, `-m` | `manifest.json` | Reference↔candidate pairing (see `build_manifest.py`) |
106
+
107
+ ## Suppressing a finding
108
+
109
+ A candidate JSON file can carry a top-level `_suppressions` array (raw AWS
110
+ policy JSON has no comment syntax to piggyback a suppression on, unlike
111
+ HCL/YAML checks):
112
+
113
+ ```json
114
+ {
115
+ "Version": "2012-10-17",
116
+ "Statement": [ ... ],
117
+ "_suppressions": [
118
+ {"check_id": "INV_AWS_001", "reason": "JIRA-1234: intentional widen"}
119
+ ]
120
+ }
121
+ ```
122
+
123
+ This key is stripped before the policy is handed to the solver, so it never
124
+ affects the request semantics Z3 reasons about.
125
+
126
+ ## Checks
127
+
128
+ | ID | Severity | What it proves |
129
+ |---|---|---|
130
+ | `INV_AWS_001` | CRITICAL | The candidate SCP/RCP denies every `(action, resource, principal)` request its reference (baseline or paired manifest entry) explicitly denied. |
131
+
132
+ Failing `INV_AWS_001`: review the counterexample. If the widened permission
133
+ is intentional, add a `_suppressions` entry (or update your own reference,
134
+ for `regression`) and document why in the PR description. If not, revert the
135
+ `Condition`/`Resource`/`Action` change that removed the denial.
136
+
137
+ ## How the solver works, and where it's intentionally conservative
138
+
139
+ Every `Deny` statement becomes a Z3 predicate over a symbolic request
140
+ context (one variable per condition key actually observed in the LZA
141
+ guardrail set); wildcard `Action`/`Resource`/ARN patterns compile to Z3
142
+ regular expressions. `invariant` then asks the solver to find a request the
143
+ reference denies that the candidate doesn't. See `policy_check.py` for the
144
+ full model. A few gaps are called out there and worth knowing about:
145
+
146
+ - **`aws:CalledVia`** is modeled as a single representative string, not a
147
+ true call chain, so `ForAllValues:StringNotEquals` on it is sound for
148
+ catching "the whole chain is now unconstrained" but can miss a regression
149
+ that only appears with one specific multi-hop chain.
150
+ - **`aws:ResourceTag/*` (`StringEquals`)** is left unconstrained — there's no
151
+ resource-tag model — which makes the checker conservative (won't
152
+ false-negative a real regression) but can over-report on tag-gated
153
+ statements.
154
+ - Any condition operator not in the model (currently seen in the wild:
155
+ `StringLike`, `StringNotLike`, `ForAnyValue:StringLike` on keys like
156
+ `rds:DatabaseEngine`) is treated as **non-constraining** and prints a
157
+ `WARNING`. A statement using one of these may be reported as denying more
158
+ than it actually does — verify those findings by hand.
159
+
160
+ None of this changes the exit-code contract; it just means a `PASS` on a
161
+ statement using one of the flagged operators is a weaker guarantee than a
162
+ `PASS` elsewhere, and the tool tells you when that's the case.
163
+
164
+ ## CI integration
165
+
166
+ `.gitlab-ci.yml` and `.github/workflows/invariant.yml` are **templates**,
167
+ meant to be copied into your own AWS LZA config repo (not into a fork of
168
+ this one) — each wires up a diff-scoped `regression` job plus a full-sweep
169
+ `scan` job, and publishes `solver-results*/results.sarif` so GitLab/GitHub
170
+ render findings natively. Both assume `invariant` is installed from wherever
171
+ you publish it — set `INVARIANT_PIP_SPEC` (GitLab) / `INVARIANT_PIP_SPEC` env
172
+ (GitHub) to your private index, package registry, or a `git+https://` URL.
173
+
174
+ ## Development
175
+
176
+ ```bash
177
+ git clone https://github.com/YOUR_ORG/invariant.git
178
+ cd invariant
179
+ python -m venv .venv
180
+ . .venv/Scripts/activate # .venv/bin/activate on macOS/Linux
181
+ pip install -e .
182
+ invariant --help
183
+ ```
184
+
185
+ ## License
186
+
187
+ Apache-2.0 — see [LICENSE](LICENSE).
@@ -0,0 +1,40 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "invariant-sast"
7
+ version = "0.1.0"
8
+ description = "SMT-based guardrail SAST for AWS SCP/RCP JSON (baseline + regression checks)"
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ requires-python = ">=3.10"
12
+ dependencies = [
13
+ "z3-solver",
14
+ ]
15
+ classifiers = [
16
+ "Environment :: Console",
17
+ "Intended Audience :: System Administrators",
18
+ "Topic :: Security",
19
+ "Topic :: Software Development :: Quality Assurance",
20
+ ]
21
+
22
+ [project.optional-dependencies]
23
+ docs = [
24
+ "mkdocs>=1.6",
25
+ "mkdocs-material>=9.5",
26
+ ]
27
+
28
+ [project.urls]
29
+ Homepage = "https://ikurira.github.io/invariant/"
30
+ Issues = "https://github.com/Ikurira/invariant/issues"
31
+ Repository = "https://github.com/Ikurira/invariant"
32
+
33
+ [project.scripts]
34
+ invariant = "invariant.cli:main"
35
+
36
+ [tool.setuptools.packages.find]
37
+ where = ["src"]
38
+
39
+ [tool.setuptools.package-data]
40
+ invariant = ["baseline/**/*.json"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"