cdk-preflight 0.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cdk_preflight-0.0.0/LICENSE +202 -0
- cdk_preflight-0.0.0/MANIFEST.in +1 -0
- cdk_preflight-0.0.0/PKG-INFO +117 -0
- cdk_preflight-0.0.0/README.md +89 -0
- cdk_preflight-0.0.0/pyproject.toml +9 -0
- cdk_preflight-0.0.0/setup.cfg +4 -0
- cdk_preflight-0.0.0/setup.py +67 -0
- cdk_preflight-0.0.0/src/cdk_preflight/__init__.py +306 -0
- cdk_preflight-0.0.0/src/cdk_preflight/_jsii/__init__.py +28 -0
- cdk_preflight-0.0.0/src/cdk_preflight/_jsii/bin/cdk-preflight +17 -0
- cdk_preflight-0.0.0/src/cdk_preflight/_jsii/cdk-preflight@0.0.0.jsii.tgz +0 -0
- cdk_preflight-0.0.0/src/cdk_preflight/py.typed +1 -0
- cdk_preflight-0.0.0/src/cdk_preflight.egg-info/PKG-INFO +117 -0
- cdk_preflight-0.0.0/src/cdk_preflight.egg-info/SOURCES.txt +15 -0
- cdk_preflight-0.0.0/src/cdk_preflight.egg-info/dependency_links.txt +1 -0
- cdk_preflight-0.0.0/src/cdk_preflight.egg-info/requires.txt +4 -0
- cdk_preflight-0.0.0/src/cdk_preflight.egg-info/top_level.txt +1 -0
|
@@ -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 @@
|
|
|
1
|
+
include pyproject.toml
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: cdk-preflight
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Catch deploy-time CloudFormation failures at synth time: a Rego rule pack for constraints that resource schemas miss, injected into the AWS CDK built-in validator
|
|
5
|
+
Home-page: https://github.com/badmintoncryer/cdk-preflight.git
|
|
6
|
+
Author: Kazuho CryerShinozuka<malaysia.cryer@gmail.com>
|
|
7
|
+
License: Apache-2.0
|
|
8
|
+
Project-URL: Source, https://github.com/badmintoncryer/cdk-preflight.git
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: JavaScript
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
20
|
+
Classifier: License :: OSI Approved
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: aws-cdk-lib<3.0.0,>=2.267.0
|
|
25
|
+
Requires-Dist: constructs<11.0.0,>=10.5.1
|
|
26
|
+
Requires-Dist: jsii<2.0.0,>=1.140.0
|
|
27
|
+
Requires-Dist: publication>=0.0.3
|
|
28
|
+
|
|
29
|
+
# cdk-preflight
|
|
30
|
+
|
|
31
|
+
**Catch deploy-time CloudFormation failures at `cdk synth` time.**
|
|
32
|
+
|
|
33
|
+
Some CloudFormation constraints are not expressed in resource provider schemas — they live only in documentation, in service API validation, or across multiple properties. Templates that violate them pass `cdk synth`, pass CloudFormation pre-deployment validation, and then fail minutes into a deployment, burning a rollback cycle.
|
|
34
|
+
|
|
35
|
+
cdk-preflight is a curated [Rego rule pack](docs/rules.md) for exactly those constraints. It injects the rules into the AWS CDK built-in CloudFormation validator (`aws-cdk-lib` >= 2.267.0), so violations surface at synth with construct-level traces — before you deploy.
|
|
36
|
+
|
|
37
|
+
Every bundled rule is backed by a `fail`/`pass` template pair, and the failure has been reproduced against real AWS (or is explicitly marked `doc-only`). Rules that the built-in validation engine already covers are deliberately **not** duplicated — a test suite enforces this.
|
|
38
|
+
|
|
39
|
+
## Quick start
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm i -D cdk-preflight
|
|
43
|
+
npx cdk-preflight init # inserts Preflight.apply(app) into your CDK app
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
or add one line yourself:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import { Preflight } from 'cdk-preflight';
|
|
50
|
+
|
|
51
|
+
const app = new App();
|
|
52
|
+
Preflight.apply(app);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`cdk synth` then reports violations like:
|
|
56
|
+
|
|
57
|
+
```text
|
|
58
|
+
WARNING idle_timeout.timeout_seconds is 5000 but must be between 1 and 4000 seconds (CloudFormation Validate)
|
|
59
|
+
MyStack/Alb (Alb) aws-cdk-lib.aws_elasticloadbalancingv2.CfnLoadBalancer
|
|
60
|
+
Acknowledge with 'CloudFormation-Validate::pf-elbv2-lb-idle-timeout-range'
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Failing the build
|
|
64
|
+
|
|
65
|
+
By default findings are warnings (matching the CDK built-in validator behavior). To make violations fail `cdk synth`:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
Preflight.apply(app, { enforce: true });
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
| Option | Default | Effect |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| `enforce` | `false` | Violations of bundled rules fail synthesis instead of warning |
|
|
74
|
+
| `strict` | `false` | With `enforce`: also fail on error-class findings (`ERROR`/`FATAL`, e.g. `F3034`) of the built-in validation engine itself, which the CDK currently downgrades to warnings |
|
|
75
|
+
| `exclude` | `[]` | Rule ids to disable |
|
|
76
|
+
| `includeUpstreamPending` | `true` | Include rules already proposed to the upstream engine but not yet merged |
|
|
77
|
+
|
|
78
|
+
Individual findings can also be suppressed with the CDK acknowledge mechanism shown in the warning text.
|
|
79
|
+
|
|
80
|
+
## Bundled rules
|
|
81
|
+
|
|
82
|
+
See [docs/rules.md](docs/rules.md) for the generated rule table. Highlights:
|
|
83
|
+
|
|
84
|
+
* **ELBv2**: `idle_timeout` / `deregistration_delay` / `slow_start` attribute ranges (stringly-typed Key/Value attributes are invisible to schema validation)
|
|
85
|
+
* **IAM**: managed (6,144 chars) and inline (role/group/user) policy document size limits
|
|
86
|
+
* **CloudFront**: `MinTTL <= DefaultTTL <= MaxTTL` ordering, ACM certificates must live in `us-east-1`
|
|
87
|
+
* **Step Functions**: `StartAt`/`Next`/`Default`/`Choices` must reference defined states
|
|
88
|
+
* **EC2**: security group TCP/UDP port ranges and `FromPort <= ToPort`
|
|
89
|
+
|
|
90
|
+
## For AI agents
|
|
91
|
+
|
|
92
|
+
To add cdk-preflight to a CDK app:
|
|
93
|
+
|
|
94
|
+
1. `npm i -D cdk-preflight`
|
|
95
|
+
2. `npx cdk-preflight init` (finds the entry point via `cdk.json` and inserts `Preflight.apply(app)`; use `--dry-run` to preview)
|
|
96
|
+
3. Run `cdk synth` and read the warnings; each carries a rule id, a suggested fix, and a construct trace
|
|
97
|
+
4. If the user wants synthesis to fail on violations, change the call to `Preflight.apply(app, { enforce: true })`
|
|
98
|
+
|
|
99
|
+
The machine-readable findings are written to `cdk.out/validation-report.json` when synthesizing with `-c @aws-cdk/core:validationReportJson=true`.
|
|
100
|
+
|
|
101
|
+
## How it works
|
|
102
|
+
|
|
103
|
+
`Preflight.apply()` registers the rules with the CDK built-in `CloudFormationValidatePlugin` (the [cloudformation-validate](https://github.com/aws-cloudformation/cloudformation-validate) Rust/WASM engine that ships inside `aws-cdk-lib`). No extra binaries, no network access at synth time. In `enforce` mode the same engine is invoked through a dedicated validation plugin so that violations fail synthesis.
|
|
104
|
+
|
|
105
|
+
Constraints that *can* be expressed in schemas or generic engine rules are contributed upstream instead of living here; each rule's `meta.yaml` tracks its upstream status, and rules retire once the engine covers them.
|
|
106
|
+
|
|
107
|
+
## Requirements
|
|
108
|
+
|
|
109
|
+
* `aws-cdk-lib` >= 2.267.0 (the first release that bundles the built-in CloudFormation validator)
|
|
110
|
+
|
|
111
|
+
## Contributing
|
|
112
|
+
|
|
113
|
+
Rule authoring, the verification gates (including real-deploy reproduction), and the test layout are documented in [AGENTS.md](AGENTS.md) — written for AI coding agents and humans alike.
|
|
114
|
+
|
|
115
|
+
## License
|
|
116
|
+
|
|
117
|
+
Apache-2.0
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# cdk-preflight
|
|
2
|
+
|
|
3
|
+
**Catch deploy-time CloudFormation failures at `cdk synth` time.**
|
|
4
|
+
|
|
5
|
+
Some CloudFormation constraints are not expressed in resource provider schemas — they live only in documentation, in service API validation, or across multiple properties. Templates that violate them pass `cdk synth`, pass CloudFormation pre-deployment validation, and then fail minutes into a deployment, burning a rollback cycle.
|
|
6
|
+
|
|
7
|
+
cdk-preflight is a curated [Rego rule pack](docs/rules.md) for exactly those constraints. It injects the rules into the AWS CDK built-in CloudFormation validator (`aws-cdk-lib` >= 2.267.0), so violations surface at synth with construct-level traces — before you deploy.
|
|
8
|
+
|
|
9
|
+
Every bundled rule is backed by a `fail`/`pass` template pair, and the failure has been reproduced against real AWS (or is explicitly marked `doc-only`). Rules that the built-in validation engine already covers are deliberately **not** duplicated — a test suite enforces this.
|
|
10
|
+
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm i -D cdk-preflight
|
|
15
|
+
npx cdk-preflight init # inserts Preflight.apply(app) into your CDK app
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
or add one line yourself:
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
import { Preflight } from 'cdk-preflight';
|
|
22
|
+
|
|
23
|
+
const app = new App();
|
|
24
|
+
Preflight.apply(app);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`cdk synth` then reports violations like:
|
|
28
|
+
|
|
29
|
+
```text
|
|
30
|
+
WARNING idle_timeout.timeout_seconds is 5000 but must be between 1 and 4000 seconds (CloudFormation Validate)
|
|
31
|
+
MyStack/Alb (Alb) aws-cdk-lib.aws_elasticloadbalancingv2.CfnLoadBalancer
|
|
32
|
+
Acknowledge with 'CloudFormation-Validate::pf-elbv2-lb-idle-timeout-range'
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Failing the build
|
|
36
|
+
|
|
37
|
+
By default findings are warnings (matching the CDK built-in validator behavior). To make violations fail `cdk synth`:
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
Preflight.apply(app, { enforce: true });
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
| Option | Default | Effect |
|
|
44
|
+
|---|---|---|
|
|
45
|
+
| `enforce` | `false` | Violations of bundled rules fail synthesis instead of warning |
|
|
46
|
+
| `strict` | `false` | With `enforce`: also fail on error-class findings (`ERROR`/`FATAL`, e.g. `F3034`) of the built-in validation engine itself, which the CDK currently downgrades to warnings |
|
|
47
|
+
| `exclude` | `[]` | Rule ids to disable |
|
|
48
|
+
| `includeUpstreamPending` | `true` | Include rules already proposed to the upstream engine but not yet merged |
|
|
49
|
+
|
|
50
|
+
Individual findings can also be suppressed with the CDK acknowledge mechanism shown in the warning text.
|
|
51
|
+
|
|
52
|
+
## Bundled rules
|
|
53
|
+
|
|
54
|
+
See [docs/rules.md](docs/rules.md) for the generated rule table. Highlights:
|
|
55
|
+
|
|
56
|
+
* **ELBv2**: `idle_timeout` / `deregistration_delay` / `slow_start` attribute ranges (stringly-typed Key/Value attributes are invisible to schema validation)
|
|
57
|
+
* **IAM**: managed (6,144 chars) and inline (role/group/user) policy document size limits
|
|
58
|
+
* **CloudFront**: `MinTTL <= DefaultTTL <= MaxTTL` ordering, ACM certificates must live in `us-east-1`
|
|
59
|
+
* **Step Functions**: `StartAt`/`Next`/`Default`/`Choices` must reference defined states
|
|
60
|
+
* **EC2**: security group TCP/UDP port ranges and `FromPort <= ToPort`
|
|
61
|
+
|
|
62
|
+
## For AI agents
|
|
63
|
+
|
|
64
|
+
To add cdk-preflight to a CDK app:
|
|
65
|
+
|
|
66
|
+
1. `npm i -D cdk-preflight`
|
|
67
|
+
2. `npx cdk-preflight init` (finds the entry point via `cdk.json` and inserts `Preflight.apply(app)`; use `--dry-run` to preview)
|
|
68
|
+
3. Run `cdk synth` and read the warnings; each carries a rule id, a suggested fix, and a construct trace
|
|
69
|
+
4. If the user wants synthesis to fail on violations, change the call to `Preflight.apply(app, { enforce: true })`
|
|
70
|
+
|
|
71
|
+
The machine-readable findings are written to `cdk.out/validation-report.json` when synthesizing with `-c @aws-cdk/core:validationReportJson=true`.
|
|
72
|
+
|
|
73
|
+
## How it works
|
|
74
|
+
|
|
75
|
+
`Preflight.apply()` registers the rules with the CDK built-in `CloudFormationValidatePlugin` (the [cloudformation-validate](https://github.com/aws-cloudformation/cloudformation-validate) Rust/WASM engine that ships inside `aws-cdk-lib`). No extra binaries, no network access at synth time. In `enforce` mode the same engine is invoked through a dedicated validation plugin so that violations fail synthesis.
|
|
76
|
+
|
|
77
|
+
Constraints that *can* be expressed in schemas or generic engine rules are contributed upstream instead of living here; each rule's `meta.yaml` tracks its upstream status, and rules retire once the engine covers them.
|
|
78
|
+
|
|
79
|
+
## Requirements
|
|
80
|
+
|
|
81
|
+
* `aws-cdk-lib` >= 2.267.0 (the first release that bundles the built-in CloudFormation validator)
|
|
82
|
+
|
|
83
|
+
## Contributing
|
|
84
|
+
|
|
85
|
+
Rule authoring, the verification gates (including real-deploy reproduction), and the test layout are documented in [AGENTS.md](AGENTS.md) — written for AI coding agents and humans alike.
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
Apache-2.0
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import setuptools
|
|
3
|
+
|
|
4
|
+
kwargs = json.loads(
|
|
5
|
+
"""
|
|
6
|
+
{
|
|
7
|
+
"name": "cdk-preflight",
|
|
8
|
+
"version": "0.0.0",
|
|
9
|
+
"description": "Catch deploy-time CloudFormation failures at synth time: a Rego rule pack for constraints that resource schemas miss, injected into the AWS CDK built-in validator",
|
|
10
|
+
"license": "Apache-2.0",
|
|
11
|
+
"url": "https://github.com/badmintoncryer/cdk-preflight.git",
|
|
12
|
+
"long_description_content_type": "text/markdown",
|
|
13
|
+
"author": "Kazuho CryerShinozuka<malaysia.cryer@gmail.com>",
|
|
14
|
+
"bdist_wheel": {
|
|
15
|
+
"universal": true
|
|
16
|
+
},
|
|
17
|
+
"project_urls": {
|
|
18
|
+
"Source": "https://github.com/badmintoncryer/cdk-preflight.git"
|
|
19
|
+
},
|
|
20
|
+
"package_dir": {
|
|
21
|
+
"": "src"
|
|
22
|
+
},
|
|
23
|
+
"packages": [
|
|
24
|
+
"cdk_preflight",
|
|
25
|
+
"cdk_preflight._jsii"
|
|
26
|
+
],
|
|
27
|
+
"package_data": {
|
|
28
|
+
"cdk_preflight._jsii": [
|
|
29
|
+
"cdk-preflight@0.0.0.jsii.tgz"
|
|
30
|
+
],
|
|
31
|
+
"cdk_preflight": [
|
|
32
|
+
"py.typed"
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
"python_requires": ">=3.10",
|
|
36
|
+
"install_requires": [
|
|
37
|
+
"aws-cdk-lib>=2.267.0, <3.0.0",
|
|
38
|
+
"constructs>=10.5.1, <11.0.0",
|
|
39
|
+
"jsii>=1.140.0, <2.0.0",
|
|
40
|
+
"publication>=0.0.3"
|
|
41
|
+
],
|
|
42
|
+
"classifiers": [
|
|
43
|
+
"Intended Audience :: Developers",
|
|
44
|
+
"Operating System :: OS Independent",
|
|
45
|
+
"Programming Language :: JavaScript",
|
|
46
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
47
|
+
"Programming Language :: Python :: 3.10",
|
|
48
|
+
"Programming Language :: Python :: 3.11",
|
|
49
|
+
"Programming Language :: Python :: 3.12",
|
|
50
|
+
"Programming Language :: Python :: 3.13",
|
|
51
|
+
"Programming Language :: Python :: 3.14",
|
|
52
|
+
"Typing :: Typed",
|
|
53
|
+
"Development Status :: 5 - Production/Stable",
|
|
54
|
+
"License :: OSI Approved"
|
|
55
|
+
],
|
|
56
|
+
"scripts": [
|
|
57
|
+
"src/cdk_preflight/_jsii/bin/cdk-preflight"
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
"""
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
with open("README.md", encoding="utf8") as fp:
|
|
64
|
+
kwargs["long_description"] = fp.read()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
setuptools.setup(**kwargs)
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
r'''
|
|
2
|
+
# cdk-preflight
|
|
3
|
+
|
|
4
|
+
**Catch deploy-time CloudFormation failures at `cdk synth` time.**
|
|
5
|
+
|
|
6
|
+
Some CloudFormation constraints are not expressed in resource provider schemas — they live only in documentation, in service API validation, or across multiple properties. Templates that violate them pass `cdk synth`, pass CloudFormation pre-deployment validation, and then fail minutes into a deployment, burning a rollback cycle.
|
|
7
|
+
|
|
8
|
+
cdk-preflight is a curated [Rego rule pack](docs/rules.md) for exactly those constraints. It injects the rules into the AWS CDK built-in CloudFormation validator (`aws-cdk-lib` >= 2.267.0), so violations surface at synth with construct-level traces — before you deploy.
|
|
9
|
+
|
|
10
|
+
Every bundled rule is backed by a `fail`/`pass` template pair, and the failure has been reproduced against real AWS (or is explicitly marked `doc-only`). Rules that the built-in validation engine already covers are deliberately **not** duplicated — a test suite enforces this.
|
|
11
|
+
|
|
12
|
+
## Quick start
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm i -D cdk-preflight
|
|
16
|
+
npx cdk-preflight init # inserts Preflight.apply(app) into your CDK app
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
or add one line yourself:
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
import { Preflight } from 'cdk-preflight';
|
|
23
|
+
|
|
24
|
+
const app = new App();
|
|
25
|
+
Preflight.apply(app);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`cdk synth` then reports violations like:
|
|
29
|
+
|
|
30
|
+
```text
|
|
31
|
+
WARNING idle_timeout.timeout_seconds is 5000 but must be between 1 and 4000 seconds (CloudFormation Validate)
|
|
32
|
+
MyStack/Alb (Alb) aws-cdk-lib.aws_elasticloadbalancingv2.CfnLoadBalancer
|
|
33
|
+
Acknowledge with 'CloudFormation-Validate::pf-elbv2-lb-idle-timeout-range'
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Failing the build
|
|
37
|
+
|
|
38
|
+
By default findings are warnings (matching the CDK built-in validator behavior). To make violations fail `cdk synth`:
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
Preflight.apply(app, { enforce: true });
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
| Option | Default | Effect |
|
|
45
|
+
|---|---|---|
|
|
46
|
+
| `enforce` | `false` | Violations of bundled rules fail synthesis instead of warning |
|
|
47
|
+
| `strict` | `false` | With `enforce`: also fail on error-class findings (`ERROR`/`FATAL`, e.g. `F3034`) of the built-in validation engine itself, which the CDK currently downgrades to warnings |
|
|
48
|
+
| `exclude` | `[]` | Rule ids to disable |
|
|
49
|
+
| `includeUpstreamPending` | `true` | Include rules already proposed to the upstream engine but not yet merged |
|
|
50
|
+
|
|
51
|
+
Individual findings can also be suppressed with the CDK acknowledge mechanism shown in the warning text.
|
|
52
|
+
|
|
53
|
+
## Bundled rules
|
|
54
|
+
|
|
55
|
+
See [docs/rules.md](docs/rules.md) for the generated rule table. Highlights:
|
|
56
|
+
|
|
57
|
+
* **ELBv2**: `idle_timeout` / `deregistration_delay` / `slow_start` attribute ranges (stringly-typed Key/Value attributes are invisible to schema validation)
|
|
58
|
+
* **IAM**: managed (6,144 chars) and inline (role/group/user) policy document size limits
|
|
59
|
+
* **CloudFront**: `MinTTL <= DefaultTTL <= MaxTTL` ordering, ACM certificates must live in `us-east-1`
|
|
60
|
+
* **Step Functions**: `StartAt`/`Next`/`Default`/`Choices` must reference defined states
|
|
61
|
+
* **EC2**: security group TCP/UDP port ranges and `FromPort <= ToPort`
|
|
62
|
+
|
|
63
|
+
## For AI agents
|
|
64
|
+
|
|
65
|
+
To add cdk-preflight to a CDK app:
|
|
66
|
+
|
|
67
|
+
1. `npm i -D cdk-preflight`
|
|
68
|
+
2. `npx cdk-preflight init` (finds the entry point via `cdk.json` and inserts `Preflight.apply(app)`; use `--dry-run` to preview)
|
|
69
|
+
3. Run `cdk synth` and read the warnings; each carries a rule id, a suggested fix, and a construct trace
|
|
70
|
+
4. If the user wants synthesis to fail on violations, change the call to `Preflight.apply(app, { enforce: true })`
|
|
71
|
+
|
|
72
|
+
The machine-readable findings are written to `cdk.out/validation-report.json` when synthesizing with `-c @aws-cdk/core:validationReportJson=true`.
|
|
73
|
+
|
|
74
|
+
## How it works
|
|
75
|
+
|
|
76
|
+
`Preflight.apply()` registers the rules with the CDK built-in `CloudFormationValidatePlugin` (the [cloudformation-validate](https://github.com/aws-cloudformation/cloudformation-validate) Rust/WASM engine that ships inside `aws-cdk-lib`). No extra binaries, no network access at synth time. In `enforce` mode the same engine is invoked through a dedicated validation plugin so that violations fail synthesis.
|
|
77
|
+
|
|
78
|
+
Constraints that *can* be expressed in schemas or generic engine rules are contributed upstream instead of living here; each rule's `meta.yaml` tracks its upstream status, and rules retire once the engine covers them.
|
|
79
|
+
|
|
80
|
+
## Requirements
|
|
81
|
+
|
|
82
|
+
* `aws-cdk-lib` >= 2.267.0 (the first release that bundles the built-in CloudFormation validator)
|
|
83
|
+
|
|
84
|
+
## Contributing
|
|
85
|
+
|
|
86
|
+
Rule authoring, the verification gates (including real-deploy reproduction), and the test layout are documented in [AGENTS.md](AGENTS.md) — written for AI coding agents and humans alike.
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
Apache-2.0
|
|
91
|
+
'''
|
|
92
|
+
from __future__ import annotations
|
|
93
|
+
|
|
94
|
+
from pkgutil import extend_path
|
|
95
|
+
__path__ = extend_path(__path__, __name__)
|
|
96
|
+
|
|
97
|
+
import abc
|
|
98
|
+
import builtins
|
|
99
|
+
import datetime
|
|
100
|
+
import enum
|
|
101
|
+
import typing
|
|
102
|
+
|
|
103
|
+
import jsii
|
|
104
|
+
import publication
|
|
105
|
+
import typing_extensions
|
|
106
|
+
|
|
107
|
+
from jsii._type_checking import cached_type_hints, check_type
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
from ._jsii import *
|
|
111
|
+
|
|
112
|
+
class _LazyImport:
|
|
113
|
+
def __init__(self, module_name: str) -> None:
|
|
114
|
+
self._module_name = module_name
|
|
115
|
+
self._module: typing.Any = None
|
|
116
|
+
def __getattr__(self, name: str) -> typing.Any:
|
|
117
|
+
if self._module is None:
|
|
118
|
+
import importlib
|
|
119
|
+
self._module = importlib.import_module(self._module_name)
|
|
120
|
+
return getattr(self._module, name)
|
|
121
|
+
|
|
122
|
+
if typing.TYPE_CHECKING:
|
|
123
|
+
|
|
124
|
+
import constructs as _constructs_77d1e7e8
|
|
125
|
+
else:
|
|
126
|
+
|
|
127
|
+
_constructs_77d1e7e8 = _LazyImport("constructs")
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class Preflight(metaclass=jsii.JSIIMeta, jsii_type="cdk-preflight.Preflight"):
|
|
131
|
+
'''cdk-preflight: catch deploy-time CloudFormation failures at synth time.
|
|
132
|
+
|
|
133
|
+
Injects a curated Rego rule pack (constraints that resource provider schemas
|
|
134
|
+
do not express: doc-only value limits, cross-property and cross-resource
|
|
135
|
+
rules) into the AWS CDK built-in CloudFormation validator.
|
|
136
|
+
|
|
137
|
+
Example::
|
|
138
|
+
|
|
139
|
+
declare const app: App;
|
|
140
|
+
Preflight.apply(app);
|
|
141
|
+
'''
|
|
142
|
+
|
|
143
|
+
@jsii.member(jsii_name="apply")
|
|
144
|
+
@builtins.classmethod
|
|
145
|
+
def apply(
|
|
146
|
+
cls,
|
|
147
|
+
scope: "_constructs_77d1e7e8.IConstruct",
|
|
148
|
+
*,
|
|
149
|
+
enforce: typing.Optional[builtins.bool] = None,
|
|
150
|
+
exclude: typing.Optional[typing.Sequence[builtins.str]] = None,
|
|
151
|
+
include_upstream_pending: typing.Optional[builtins.bool] = None,
|
|
152
|
+
strict: typing.Optional[builtins.bool] = None,
|
|
153
|
+
) -> None:
|
|
154
|
+
'''Register the cdk-preflight rules on an App or Stage.
|
|
155
|
+
|
|
156
|
+
:param scope: -
|
|
157
|
+
:param enforce: Fail synthesis (instead of reporting warnings) when a bundled rule is violated. In the default (warn) mode, findings are reported through the CDK built-in CloudFormation validator and surface as synth warnings with construct traces. With ``enforce: true``, cdk-preflight evaluates its rules with its own validation plugin and a violation makes ``cdk synth`` fail. Default: false
|
|
158
|
+
:param exclude: Rule ids to disable (see ``Preflight.ruleIds()`` or docs/rules.md). Default: - all bundled rules are enabled
|
|
159
|
+
:param include_upstream_pending: Include rules that are marked ``pending-engine`` (candidates that have been proposed to the upstream cloudformation-validate engine but are not merged yet). Disable this if you run a newer engine that already covers them. Default: true
|
|
160
|
+
:param strict: In enforce mode, additionally fail synthesis on error-class findings (severity ERROR/FATAL) of the built-in validation engine itself, e.g. schema violations like ``F3034``. This is the workaround for the CDK behavior where all built-in findings are downgraded to warnings. Only effective together with ``enforce: true``. Default: false
|
|
161
|
+
'''
|
|
162
|
+
if __debug__:
|
|
163
|
+
type_hints = cached_type_hints(_typecheckingstub__5b535ea6056dfabd62239bba1185a75fb43155b62d18b3cbb69ca8a01b7edfa8)
|
|
164
|
+
check_type(argname="argument scope", value=scope, expected_type=type_hints["scope"])
|
|
165
|
+
options = PreflightOptions(
|
|
166
|
+
enforce=enforce,
|
|
167
|
+
exclude=exclude,
|
|
168
|
+
include_upstream_pending=include_upstream_pending,
|
|
169
|
+
strict=strict,
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
return typing.cast(None, jsii.sinvoke(cls, "apply", [scope, options]))
|
|
173
|
+
|
|
174
|
+
@jsii.member(jsii_name="ruleIds")
|
|
175
|
+
@builtins.classmethod
|
|
176
|
+
def rule_ids(cls) -> typing.List[builtins.str]:
|
|
177
|
+
'''The ids of all bundled rules.'''
|
|
178
|
+
return typing.cast(typing.List[builtins.str], jsii.sinvoke(cls, "ruleIds", []))
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
@jsii.data_type(
|
|
182
|
+
jsii_type="cdk-preflight.PreflightOptions",
|
|
183
|
+
jsii_struct_bases=[],
|
|
184
|
+
name_mapping={
|
|
185
|
+
"enforce": "enforce",
|
|
186
|
+
"exclude": "exclude",
|
|
187
|
+
"include_upstream_pending": "includeUpstreamPending",
|
|
188
|
+
"strict": "strict",
|
|
189
|
+
},
|
|
190
|
+
)
|
|
191
|
+
class PreflightOptions:
|
|
192
|
+
def __init__(
|
|
193
|
+
self,
|
|
194
|
+
*,
|
|
195
|
+
enforce: typing.Optional[builtins.bool] = None,
|
|
196
|
+
exclude: typing.Optional[typing.Sequence[builtins.str]] = None,
|
|
197
|
+
include_upstream_pending: typing.Optional[builtins.bool] = None,
|
|
198
|
+
strict: typing.Optional[builtins.bool] = None,
|
|
199
|
+
) -> None:
|
|
200
|
+
'''Options for {@link Preflight.apply}.
|
|
201
|
+
|
|
202
|
+
:param enforce: Fail synthesis (instead of reporting warnings) when a bundled rule is violated. In the default (warn) mode, findings are reported through the CDK built-in CloudFormation validator and surface as synth warnings with construct traces. With ``enforce: true``, cdk-preflight evaluates its rules with its own validation plugin and a violation makes ``cdk synth`` fail. Default: false
|
|
203
|
+
:param exclude: Rule ids to disable (see ``Preflight.ruleIds()`` or docs/rules.md). Default: - all bundled rules are enabled
|
|
204
|
+
:param include_upstream_pending: Include rules that are marked ``pending-engine`` (candidates that have been proposed to the upstream cloudformation-validate engine but are not merged yet). Disable this if you run a newer engine that already covers them. Default: true
|
|
205
|
+
:param strict: In enforce mode, additionally fail synthesis on error-class findings (severity ERROR/FATAL) of the built-in validation engine itself, e.g. schema violations like ``F3034``. This is the workaround for the CDK behavior where all built-in findings are downgraded to warnings. Only effective together with ``enforce: true``. Default: false
|
|
206
|
+
'''
|
|
207
|
+
if __debug__:
|
|
208
|
+
type_hints = cached_type_hints(_typecheckingstub__12ab0dc6052d00feef3e218547f7a8add8c0a9bd629d0362a30a71aa52b7cab1)
|
|
209
|
+
check_type(argname="argument enforce", value=enforce, expected_type=type_hints["enforce"])
|
|
210
|
+
check_type(argname="argument exclude", value=exclude, expected_type=type_hints["exclude"])
|
|
211
|
+
check_type(argname="argument include_upstream_pending", value=include_upstream_pending, expected_type=type_hints["include_upstream_pending"])
|
|
212
|
+
check_type(argname="argument strict", value=strict, expected_type=type_hints["strict"])
|
|
213
|
+
self._values: typing.Dict[builtins.str, typing.Any] = {}
|
|
214
|
+
if enforce is not None:
|
|
215
|
+
self._values["enforce"] = enforce
|
|
216
|
+
if exclude is not None:
|
|
217
|
+
self._values["exclude"] = exclude
|
|
218
|
+
if include_upstream_pending is not None:
|
|
219
|
+
self._values["include_upstream_pending"] = include_upstream_pending
|
|
220
|
+
if strict is not None:
|
|
221
|
+
self._values["strict"] = strict
|
|
222
|
+
|
|
223
|
+
@builtins.property
|
|
224
|
+
def enforce(self) -> typing.Optional[builtins.bool]:
|
|
225
|
+
'''Fail synthesis (instead of reporting warnings) when a bundled rule is violated.
|
|
226
|
+
|
|
227
|
+
In the default (warn) mode, findings are reported through the CDK built-in
|
|
228
|
+
CloudFormation validator and surface as synth warnings with construct traces.
|
|
229
|
+
With ``enforce: true``, cdk-preflight evaluates its rules with its own
|
|
230
|
+
validation plugin and a violation makes ``cdk synth`` fail.
|
|
231
|
+
|
|
232
|
+
:default: false
|
|
233
|
+
'''
|
|
234
|
+
result = self._values.get("enforce")
|
|
235
|
+
return typing.cast(typing.Optional[builtins.bool], result)
|
|
236
|
+
|
|
237
|
+
@builtins.property
|
|
238
|
+
def exclude(self) -> typing.Optional[typing.List[builtins.str]]:
|
|
239
|
+
'''Rule ids to disable (see ``Preflight.ruleIds()`` or docs/rules.md).
|
|
240
|
+
|
|
241
|
+
:default: - all bundled rules are enabled
|
|
242
|
+
'''
|
|
243
|
+
result = self._values.get("exclude")
|
|
244
|
+
return typing.cast(typing.Optional[typing.List[builtins.str]], result)
|
|
245
|
+
|
|
246
|
+
@builtins.property
|
|
247
|
+
def include_upstream_pending(self) -> typing.Optional[builtins.bool]:
|
|
248
|
+
'''Include rules that are marked ``pending-engine`` (candidates that have been proposed to the upstream cloudformation-validate engine but are not merged yet).
|
|
249
|
+
|
|
250
|
+
Disable this if you run a newer engine that already covers them.
|
|
251
|
+
|
|
252
|
+
:default: true
|
|
253
|
+
'''
|
|
254
|
+
result = self._values.get("include_upstream_pending")
|
|
255
|
+
return typing.cast(typing.Optional[builtins.bool], result)
|
|
256
|
+
|
|
257
|
+
@builtins.property
|
|
258
|
+
def strict(self) -> typing.Optional[builtins.bool]:
|
|
259
|
+
'''In enforce mode, additionally fail synthesis on error-class findings (severity ERROR/FATAL) of the built-in validation engine itself, e.g. schema violations like ``F3034``. This is the workaround for the CDK behavior where all built-in findings are downgraded to warnings.
|
|
260
|
+
|
|
261
|
+
Only effective together with ``enforce: true``.
|
|
262
|
+
|
|
263
|
+
:default: false
|
|
264
|
+
'''
|
|
265
|
+
result = self._values.get("strict")
|
|
266
|
+
return typing.cast(typing.Optional[builtins.bool], result)
|
|
267
|
+
|
|
268
|
+
def __eq__(self, rhs: typing.Any) -> builtins.bool:
|
|
269
|
+
return isinstance(rhs, self.__class__) and rhs._values == self._values
|
|
270
|
+
|
|
271
|
+
def __ne__(self, rhs: typing.Any) -> builtins.bool:
|
|
272
|
+
return not (rhs == self)
|
|
273
|
+
|
|
274
|
+
def __repr__(self) -> str:
|
|
275
|
+
return "PreflightOptions(%s)" % ", ".join(
|
|
276
|
+
k + "=" + repr(v) for k, v in self._values.items()
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
__all__ = [
|
|
281
|
+
"Preflight",
|
|
282
|
+
"PreflightOptions",
|
|
283
|
+
]
|
|
284
|
+
|
|
285
|
+
publication.publish()
|
|
286
|
+
|
|
287
|
+
def _typecheckingstub__5b535ea6056dfabd62239bba1185a75fb43155b62d18b3cbb69ca8a01b7edfa8(
|
|
288
|
+
scope: _constructs_77d1e7e8.IConstruct,
|
|
289
|
+
*,
|
|
290
|
+
enforce: typing.Optional[builtins.bool] = None,
|
|
291
|
+
exclude: typing.Optional[typing.Sequence[builtins.str]] = None,
|
|
292
|
+
include_upstream_pending: typing.Optional[builtins.bool] = None,
|
|
293
|
+
strict: typing.Optional[builtins.bool] = None,
|
|
294
|
+
) -> None:
|
|
295
|
+
"""Type checking stubs"""
|
|
296
|
+
pass
|
|
297
|
+
|
|
298
|
+
def _typecheckingstub__12ab0dc6052d00feef3e218547f7a8add8c0a9bd629d0362a30a71aa52b7cab1(
|
|
299
|
+
*,
|
|
300
|
+
enforce: typing.Optional[builtins.bool] = None,
|
|
301
|
+
exclude: typing.Optional[typing.Sequence[builtins.str]] = None,
|
|
302
|
+
include_upstream_pending: typing.Optional[builtins.bool] = None,
|
|
303
|
+
strict: typing.Optional[builtins.bool] = None,
|
|
304
|
+
) -> None:
|
|
305
|
+
"""Type checking stubs"""
|
|
306
|
+
pass
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from pkgutil import extend_path
|
|
2
|
+
__path__ = extend_path(__path__, __name__)
|
|
3
|
+
|
|
4
|
+
import abc
|
|
5
|
+
import builtins
|
|
6
|
+
import datetime
|
|
7
|
+
import enum
|
|
8
|
+
import typing
|
|
9
|
+
|
|
10
|
+
import jsii
|
|
11
|
+
import publication
|
|
12
|
+
import typing_extensions
|
|
13
|
+
|
|
14
|
+
from jsii._type_checking import cached_type_hints, check_type
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
import aws_cdk._jsii
|
|
18
|
+
import constructs._jsii
|
|
19
|
+
|
|
20
|
+
__jsii_assembly__ = jsii.JSIIAssembly.load(
|
|
21
|
+
"cdk-preflight", "0.0.0", __name__[0:-6], "cdk-preflight@0.0.0.jsii.tgz"
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"__jsii_assembly__",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
publication.publish()
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
import jsii
|
|
4
|
+
import sys
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
if "JSII_RUNTIME_PACKAGE_CACHE" not in os.environ:
|
|
8
|
+
os.environ["JSII_RUNTIME_PACKAGE_CACHE"] = "disabled"
|
|
9
|
+
|
|
10
|
+
__jsii_assembly__ = jsii.JSIIAssembly.load(
|
|
11
|
+
"cdk-preflight", "0.0.0", "cdk_preflight", "cdk-preflight@0.0.0.jsii.tgz"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
exit_code = __jsii_assembly__.invokeBinScript(
|
|
15
|
+
"cdk-preflight", "cdk-preflight", sys.argv[1:]
|
|
16
|
+
)
|
|
17
|
+
exit(exit_code)
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: cdk-preflight
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Catch deploy-time CloudFormation failures at synth time: a Rego rule pack for constraints that resource schemas miss, injected into the AWS CDK built-in validator
|
|
5
|
+
Home-page: https://github.com/badmintoncryer/cdk-preflight.git
|
|
6
|
+
Author: Kazuho CryerShinozuka<malaysia.cryer@gmail.com>
|
|
7
|
+
License: Apache-2.0
|
|
8
|
+
Project-URL: Source, https://github.com/badmintoncryer/cdk-preflight.git
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: JavaScript
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
20
|
+
Classifier: License :: OSI Approved
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: aws-cdk-lib<3.0.0,>=2.267.0
|
|
25
|
+
Requires-Dist: constructs<11.0.0,>=10.5.1
|
|
26
|
+
Requires-Dist: jsii<2.0.0,>=1.140.0
|
|
27
|
+
Requires-Dist: publication>=0.0.3
|
|
28
|
+
|
|
29
|
+
# cdk-preflight
|
|
30
|
+
|
|
31
|
+
**Catch deploy-time CloudFormation failures at `cdk synth` time.**
|
|
32
|
+
|
|
33
|
+
Some CloudFormation constraints are not expressed in resource provider schemas — they live only in documentation, in service API validation, or across multiple properties. Templates that violate them pass `cdk synth`, pass CloudFormation pre-deployment validation, and then fail minutes into a deployment, burning a rollback cycle.
|
|
34
|
+
|
|
35
|
+
cdk-preflight is a curated [Rego rule pack](docs/rules.md) for exactly those constraints. It injects the rules into the AWS CDK built-in CloudFormation validator (`aws-cdk-lib` >= 2.267.0), so violations surface at synth with construct-level traces — before you deploy.
|
|
36
|
+
|
|
37
|
+
Every bundled rule is backed by a `fail`/`pass` template pair, and the failure has been reproduced against real AWS (or is explicitly marked `doc-only`). Rules that the built-in validation engine already covers are deliberately **not** duplicated — a test suite enforces this.
|
|
38
|
+
|
|
39
|
+
## Quick start
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm i -D cdk-preflight
|
|
43
|
+
npx cdk-preflight init # inserts Preflight.apply(app) into your CDK app
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
or add one line yourself:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import { Preflight } from 'cdk-preflight';
|
|
50
|
+
|
|
51
|
+
const app = new App();
|
|
52
|
+
Preflight.apply(app);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`cdk synth` then reports violations like:
|
|
56
|
+
|
|
57
|
+
```text
|
|
58
|
+
WARNING idle_timeout.timeout_seconds is 5000 but must be between 1 and 4000 seconds (CloudFormation Validate)
|
|
59
|
+
MyStack/Alb (Alb) aws-cdk-lib.aws_elasticloadbalancingv2.CfnLoadBalancer
|
|
60
|
+
Acknowledge with 'CloudFormation-Validate::pf-elbv2-lb-idle-timeout-range'
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Failing the build
|
|
64
|
+
|
|
65
|
+
By default findings are warnings (matching the CDK built-in validator behavior). To make violations fail `cdk synth`:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
Preflight.apply(app, { enforce: true });
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
| Option | Default | Effect |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| `enforce` | `false` | Violations of bundled rules fail synthesis instead of warning |
|
|
74
|
+
| `strict` | `false` | With `enforce`: also fail on error-class findings (`ERROR`/`FATAL`, e.g. `F3034`) of the built-in validation engine itself, which the CDK currently downgrades to warnings |
|
|
75
|
+
| `exclude` | `[]` | Rule ids to disable |
|
|
76
|
+
| `includeUpstreamPending` | `true` | Include rules already proposed to the upstream engine but not yet merged |
|
|
77
|
+
|
|
78
|
+
Individual findings can also be suppressed with the CDK acknowledge mechanism shown in the warning text.
|
|
79
|
+
|
|
80
|
+
## Bundled rules
|
|
81
|
+
|
|
82
|
+
See [docs/rules.md](docs/rules.md) for the generated rule table. Highlights:
|
|
83
|
+
|
|
84
|
+
* **ELBv2**: `idle_timeout` / `deregistration_delay` / `slow_start` attribute ranges (stringly-typed Key/Value attributes are invisible to schema validation)
|
|
85
|
+
* **IAM**: managed (6,144 chars) and inline (role/group/user) policy document size limits
|
|
86
|
+
* **CloudFront**: `MinTTL <= DefaultTTL <= MaxTTL` ordering, ACM certificates must live in `us-east-1`
|
|
87
|
+
* **Step Functions**: `StartAt`/`Next`/`Default`/`Choices` must reference defined states
|
|
88
|
+
* **EC2**: security group TCP/UDP port ranges and `FromPort <= ToPort`
|
|
89
|
+
|
|
90
|
+
## For AI agents
|
|
91
|
+
|
|
92
|
+
To add cdk-preflight to a CDK app:
|
|
93
|
+
|
|
94
|
+
1. `npm i -D cdk-preflight`
|
|
95
|
+
2. `npx cdk-preflight init` (finds the entry point via `cdk.json` and inserts `Preflight.apply(app)`; use `--dry-run` to preview)
|
|
96
|
+
3. Run `cdk synth` and read the warnings; each carries a rule id, a suggested fix, and a construct trace
|
|
97
|
+
4. If the user wants synthesis to fail on violations, change the call to `Preflight.apply(app, { enforce: true })`
|
|
98
|
+
|
|
99
|
+
The machine-readable findings are written to `cdk.out/validation-report.json` when synthesizing with `-c @aws-cdk/core:validationReportJson=true`.
|
|
100
|
+
|
|
101
|
+
## How it works
|
|
102
|
+
|
|
103
|
+
`Preflight.apply()` registers the rules with the CDK built-in `CloudFormationValidatePlugin` (the [cloudformation-validate](https://github.com/aws-cloudformation/cloudformation-validate) Rust/WASM engine that ships inside `aws-cdk-lib`). No extra binaries, no network access at synth time. In `enforce` mode the same engine is invoked through a dedicated validation plugin so that violations fail synthesis.
|
|
104
|
+
|
|
105
|
+
Constraints that *can* be expressed in schemas or generic engine rules are contributed upstream instead of living here; each rule's `meta.yaml` tracks its upstream status, and rules retire once the engine covers them.
|
|
106
|
+
|
|
107
|
+
## Requirements
|
|
108
|
+
|
|
109
|
+
* `aws-cdk-lib` >= 2.267.0 (the first release that bundles the built-in CloudFormation validator)
|
|
110
|
+
|
|
111
|
+
## Contributing
|
|
112
|
+
|
|
113
|
+
Rule authoring, the verification gates (including real-deploy reproduction), and the test layout are documented in [AGENTS.md](AGENTS.md) — written for AI coding agents and humans alike.
|
|
114
|
+
|
|
115
|
+
## License
|
|
116
|
+
|
|
117
|
+
Apache-2.0
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
setup.py
|
|
6
|
+
src/cdk_preflight/__init__.py
|
|
7
|
+
src/cdk_preflight/py.typed
|
|
8
|
+
src/cdk_preflight.egg-info/PKG-INFO
|
|
9
|
+
src/cdk_preflight.egg-info/SOURCES.txt
|
|
10
|
+
src/cdk_preflight.egg-info/dependency_links.txt
|
|
11
|
+
src/cdk_preflight.egg-info/requires.txt
|
|
12
|
+
src/cdk_preflight.egg-info/top_level.txt
|
|
13
|
+
src/cdk_preflight/_jsii/__init__.py
|
|
14
|
+
src/cdk_preflight/_jsii/cdk-preflight@0.0.0.jsii.tgz
|
|
15
|
+
src/cdk_preflight/_jsii/bin/cdk-preflight
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cdk_preflight
|