cdk-preflight 1.20.1 → 1.20.3
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.
- package/.jsii +2 -2
- package/AGENTS.md +2 -2
- package/lib/index.js +1 -1
- package/lib/rules.generated.js +285 -281
- package/package.json +1 -1
package/.jsii
CHANGED
|
@@ -10111,6 +10111,6 @@
|
|
|
10111
10111
|
"symbolId": "src/index:PreflightOptions"
|
|
10112
10112
|
}
|
|
10113
10113
|
},
|
|
10114
|
-
"version": "1.20.
|
|
10115
|
-
"fingerprint": "
|
|
10114
|
+
"version": "1.20.3",
|
|
10115
|
+
"fingerprint": "7NvKIQjkChWrXex3D1lfXwQNV4D8dFvU+60T39PIHzI="
|
|
10116
10116
|
}
|
package/AGENTS.md
CHANGED
|
@@ -160,7 +160,7 @@ If you are a subagent running one of these phases, do not spawn further agents.
|
|
|
160
160
|
- `package cdk_preflight`, `import rego.v1`
|
|
161
161
|
- Emit via `make_diag_full("<rule-id>", "ERROR", name, <property-path>, <message with actual value>, <fix>, <doc url>)`
|
|
162
162
|
- Use the engine builtins (`resources_of_type`, `resolve`, `flatten_list`, `object.get`). **Read numbers through `rules/_lib/value.rego`, never with `to_number`**: `_pf_tonum(v)` and `_pf_onum(obj, key)` are undefined for an omitted key, `null` (an `Fn::If` that became `AWS::NoValue`), booleans, intrinsic markers and non-numeric strings, so the rule skips instead of reading "0". `to_number` itself turns `null` into 0 and booleans into 0/1 (#392, #396). `scripts/lint-rules.ts` (run by `test/structure.test.ts`) fails on any `to_number` call outside the value lib.
|
|
163
|
-
- **An omitted property stays undefined.** Do not give `object.get` a default that is a value the service could have (`"V1"`, `"GENEVE"`, `0`, `false`, `""`): that reads "the user left it out" as "the user chose this", and it is the most common source of false positives (#393, #402, #403, #405). Safe defaults are `null`, the `"__pf_absent"` sentinel, `[]` / `{}` for traversal, and display names such as `"<unnamed>"`. The lint rejects any other literal default
|
|
163
|
+
- **An omitted property stays undefined.** Do not give `object.get` a default that is a value the service could have (`"V1"`, `"GENEVE"`, `0`, `false`, `""`): that reads "the user left it out" as "the user chose this", and it is the most common source of false positives (#393, #402, #403, #405). Safe defaults are `null`, the `"__pf_absent"` sentinel, `[]` / `{}` for traversal, and display names such as `"<unnamed>"`. The lint rejects any other literal default, with no baseline. For a comparison that is false on omission, use `_pf_oval(obj, key)`. If the service really fills in a default and the rule depends on it, declare it in `rules/_defaults.yaml` under the rule id (or `_lib/<name>`) with `basis` (`deploy` / `docs` / `test`) and a `source` (the evidence location, or the doc URL plus the sentence), and read it with `object.get(o, "K", _pf_default("<owner>", "<key>"))`. Without a declaration the omission stays undefined and the rule does not judge it. `scripts/bundle-rules.ts` rejects an undeclared `_pf_default` call and a declaration no rule reads.
|
|
164
164
|
- **Conditional resources are handled for you.** The enforce plugin evaluates every resource `Condition` on the raw template (`src/private/conditions.ts`, three-valued: parameter defaults, the stack's region/account, `Fn::Equals/Not/And/Or/Select/Split/Join/FindInMap`) and drops findings on resources whose condition is proven false under those defaults (#408) — the same defaults the engine resolves properties with. A condition it cannot decide keeps the resource. Rules must not try to read conditions themselves: `input.conditions` only carries a lossy summary (`Not(Equals(?, ""))`).
|
|
165
165
|
- `resolve()` resolves a Ref-to-resource to the target's **logical ID as a string**, and resolves template-parameter defaults (measured 2026-09-02, 1.7.0-beta). Two consequences: an `is_string` guard alone does not prove a user literal — add a shape guard (ARN prefix, pattern, known constant) before comparing values; and cross-resource rules need no private API — test the resolved string for membership in `resources_of_type(...)`, then `resolve(<that id>, "Properties....")` reads the target resource (`pf-route53-apex-cname` is the reference implementation).
|
|
166
166
|
- The standard OPA `walk` builtin is NOT available in this engine. Write explicit traversals.
|
|
@@ -194,7 +194,7 @@ If you are a subagent running one of these phases, do not spawn further agents.
|
|
|
194
194
|
- **An unreadable value taken as absent**: a number where the helper reads strings, a `Fn::Join` that does not `resolve()`. Test presence on the raw properties, not on the resolved value.
|
|
195
195
|
The engine also resolves a parameter of an SSM type (`AWS::SSM::Parameter::Value<...>`) to its `Default`, which is the parameter name; the plugins drop those defaults before validating (`specializeTemplate`). New corpus findings that are not false positives (placeholder accounts, a runtime retired since the snapshot) go in `rules/_corpus-accepted.txt` with the reason; the file is a ratchet like the other baselines. Corpus templates that make a rule error at run time fail the check outright.
|
|
196
196
|
|
|
197
|
-
**Reference sweep.** `npx projen reference-sweep` (`scripts/reference-sweep.ts`, a step of the `corpus` job) takes each rule's pass template and replaces the string leaves of the rule's resource types, one at a time, with a `Ref` and a `Fn::GetAtt` to a resource no rule reads (strings, numbers and booleans). The value of a reference is unknown until deploy, so a rule that fires on one of these mutants and not on the pass template is reading the reference as a literal. `rules/_lib/value.rego` has the readers: `_pf_lit(name, path)` is the value only when it is a literal (a string that is not a logical id, a number, a boolean), `_pf_is_lit(v)` tests a value already read, `_pf_unknown(name, path)` / `_pf_list_unknown(name, path)` hold when the template writes something there that cannot be read. A rule that fires on an absence or a mismatch (`not x in {...}`, `x != "Y"`, "the list does not contain Z") must add `not _pf_unknown(...)` for the value it compares; a size limit counts `_pf_json_size_min(doc)`. `rules/_reference-baseline.txt` is a ratchet that may only shrink (empty since 2026-11-26: every firing found was fixed). A mutant that makes a rule error at run time fails regardless: one runtime error stops every rule of its service on that template (enforce mode then skips that service with a `pf-engine-error` warning rather than blocking synth, but its rules are lost).
|
|
197
|
+
**Reference sweep.** `npx projen reference-sweep` (`scripts/reference-sweep.ts`, a step of the `corpus` job) takes each rule's pass template and replaces the string leaves of the rule's resource types, one at a time, with a `Ref` and a `Fn::GetAtt` to a resource no rule reads (strings, numbers and booleans). The value of a reference is unknown until deploy, so a rule that fires on one of these mutants and not on the pass template is reading the reference as a literal. `rules/_lib/value.rego` has the readers: `_pf_lit(name, path)` is the value only when it is a literal (a string that is not a logical id, a number, a boolean), `_pf_is_lit(v)` tests a value already read, `_pf_unknown(name, path)` / `_pf_list_unknown(name, path)` hold when the template writes something there that cannot be read. A rule that fires on an absence or a mismatch (`not x in {...}`, `x != "Y"`, "the list does not contain Z") must add `not _pf_unknown(...)` for the value it compares; a size limit counts `_pf_json_size_min(doc)`. To read a key whose omission has no measured meaning, use `_pf_oval(o, k)` (undefined when absent, so the judgement drops) instead of an `object.get` default. `rules/_reference-baseline.txt` is a ratchet that may only shrink (empty since 2026-11-26: every firing found was fixed). A mutant that makes a rule error at run time fails regardless: one runtime error stops every rule of its service on that template (enforce mode then skips that service with a `pf-engine-error` warning rather than blocking synth, but its rules are lost).
|
|
198
198
|
4. **Real-deploy gate**: `bash bench/verify-rule.sh <rule-id>` deploys the fail template (expects CREATE to fail; records the service error message) and, where cheap, the pass template (expects success, then deletes). Paste the observed error into `meta.yaml#repro.evidence` with the date, then copy the part of it that names the constraint into `meta.yaml#repro.expect` — one line, `expect: "<fragment>"`, no `"` or `\` inside (the monthly runner reads it with `sed`), verbatim from the evidence (`bundle-rules` checks). Every monthly run matches the fail stack's reason against it, so a stack that falls over for anything else is INCONCLUSIVE rather than verified. Required for `real-deploy` rules added on or after 2026-09-27; when the service only ever says something generic (`GeneralServiceException`), quote that. Only `doc-only` rules may skip this, with justification.
|
|
199
199
|
|
|
200
200
|
**A rule about runs after the deploy needs a probe to fail the deploy.** Most resources give CloudFormation nothing to wait on, so the fail template adds a custom resource (logical id `Probe`, type `Custom::CdkpfProbe`) backed by an inline Python function (`ProbeFn`, with its own `ProbeRole`) that, on Create only, runs the resource once — invokes the function, publishes and reads back from the queue, sets the alarm state and reads its history — and answers `FAILED` with what it observed, or `SUCCESS`. The pass template carries the same probe, so the pair differs only in the property the rule judges. `pf-lambda-zipfile-handler-module` and `pf-sns-aws-managed-key-delivery` are the reference implementations. The contract:
|
package/lib/index.js
CHANGED
|
@@ -19,7 +19,7 @@ const rules_generated_1 = require("./rules.generated");
|
|
|
19
19
|
* Preflight.apply(app);
|
|
20
20
|
*/
|
|
21
21
|
class Preflight {
|
|
22
|
-
static [JSII_RTTI_SYMBOL_1] = { fqn: "cdk-preflight.Preflight", version: "1.20.
|
|
22
|
+
static [JSII_RTTI_SYMBOL_1] = { fqn: "cdk-preflight.Preflight", version: "1.20.3" };
|
|
23
23
|
/**
|
|
24
24
|
* Register the cdk-preflight rules on an App or Stage.
|
|
25
25
|
*/
|