cdk-real-drift 0.29.1 → 0.31.0

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/README.md CHANGED
@@ -225,6 +225,20 @@ tier, and step 3 confirms your declaration matches what's live.
225
225
  Run `npx cdkrd check --fail`. It's read-only, never prompts, and exits 1 on drift;
226
226
  it never writes a baseline (you record locally and commit the file).
227
227
 
228
+ If the CI identity may only assume roles (no permissions of its own), name the
229
+ role with `--assume-role` (or `$CDKRD_ASSUME_ROLE`). cdkrd assumes it from the
230
+ ambient credentials before each stack's first AWS call; `{account}` and
231
+ `{region}` are filled per stack, so one value covers a multi-account app:
232
+
233
+ ```bash
234
+ npx cdkrd check --fail --assume-role 'arn:aws:iam::{account}:role/MyReadRole'
235
+ ```
236
+
237
+ The session is named `cdkrd-<verb>` after the verb you ran (visible in CloudTrail) — a revert / record / ignore picked from `check`'s prompt runs in the `cdkrd-check` session. Synthesis still
238
+ runs with the ambient credentials, as `cdk synth` does. A role that cannot be
239
+ assumed fails that stack (exit 2) with the role ARN in the error. Not named
240
+ `--role-arn`, which in the CDK CLI means the CloudFormation execution role.
241
+
228
242
  ## The model: one verb you run, three it offers
229
243
 
230
244
  `cdkrd check` is the entry point: on a TTY it finds drift and offers the other
@@ -419,9 +433,19 @@ CI (with `--yes`).
419
433
  `Custom::LogRetention`) has no cloud-side model to read, so it is a
420
434
  permanent-by-nature gap that no `record` / `ignore` could clear — it is
421
435
  **informational** and does NOT fail `--strict` (otherwise the flag would exit `1`
422
- forever on nearly every real CDK app). The gap is always surfaced regardless (as
423
- the `skipped=N` footer line or a loud `warning:`); `--strict` only decides whether
424
- an actionable gap fails the build.
436
+ forever on nearly every real CDK app). A **property whose read failed** — a
437
+ supplement read denied (`AccessDenied`), a Lambda's environment unreadable under a
438
+ `kms:Decrypt` deny, an `alias/aws/*` KMS key that cannot be confirmed without
439
+ `kms:ListAliases` — is a coverage gap too and fails `--strict` (`readGap=N (… read
440
+ failed — coverage incomplete …)` in the footer), while a property unreadable **by
441
+ nature** (write-only like `MasterUserPassword`, or not returned by AWS) stays
442
+ informational. The gap is always surfaced regardless (as the `skipped=N` /
443
+ `readGap=N` footer line or a loud `warning:`); `--strict` only decides whether an
444
+ actionable gap fails the build. A gap you **intend** — a role deliberately not
445
+ granted `secretsmanager:GetSecretValue`, so a `SecretTargetAttachment` is skipped —
446
+ can be **acknowledged** in `.cdkrd/ignore.yaml` (see below): it stays listed
447
+ (`acknowledged-skip=N`, or `read failed, acknowledged` on the `readGap` line) but
448
+ no longer fails `--strict`, and the committed rule's comment records why.
425
449
  - Errors always exit `2`; `revert` exits `1` when drift remains after it.
426
450
  - Interrupting a run with **Ctrl-C** (or **ESC** / SIGINT) during the gather/read
427
451
  phase exits `130` (128 + SIGINT) for every verb, and a **SIGTERM** (CI
@@ -448,27 +472,28 @@ CI (with `--yes`).
448
472
  leave cells natural-width. Don't chase pixel alignment at the cost of a
449
473
  readable diff. -->
450
474
 
451
- | option | meaning |
452
- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
453
- | `--region <r>` | a stack's own `env.region` ALWAYS wins; for an env-AGNOSTIC stack (no `env`) it falls back to `--region` (or `$AWS_REGION` / `$AWS_DEFAULT_REGION`), else the AWS-CLI/cdk region chain — the active profile's region, then the `[default]` profile's region, then EC2 IMDS |
454
- | `--profile <p>` | AWS profile (else `$AWS_PROFILE`, else `$AWS_DEFAULT_PROFILE` — same order `aws` and `cdk` use) |
455
- | `-a, --app <cmd\|cdk.out>` | CDK app command or pre-synthesized assembly dir (or `$CDKRD_APP` / cdk.json `"app"`); stack auto-discovery + construct paths |
456
- | `-c, --context key=value` | context for synth (repeatable; cdk.json is the base layer) |
457
- | `--all` | target every stack the app defines (the default when no `<stack>` is named; cannot be combined with named stacks — a `<stack> ... --all` invocation errors) |
458
- | `--json` | machine-readable output (see [JSON contract](#json-output-contract)) |
459
- | `--fail` | (check) exit 1 on drift and never prompt; for scripts/CI. Without it, check reports drift but exits 0 |
460
- | `--no-prompt` | (check) never open the interactive resolve menu (report-only), but keep exit 0 on drift — the exit-0 twin of `--fail`'s prompt suppression, for a report-only script attached to a terminal. Non-TTY never prompts anyway; with `--fail`, `--fail`'s exit 1 wins |
461
- | `--strict` | (check) exit 1 when coverage is incomplete. A coverage gap is always surfaced loudly; `--strict` makes it CI-failing. Orthogonal to `--fail` |
462
- | `--show-all` | (check) inventory mode: show all current undeclared state, ignoring the baseline |
463
- | `--verbose` / `-v` | (check) expand the `info:` footer tiers / (revert) expand the not-revertable summary to full lists; (record) itemizes nested sub-keys in the multiselect. `-v` means `--verbose` **inside a verb** (`check -v`); a bare `cdkrd -v` (no verb) prints the version |
464
- | `--pre-deploy` | (check) compare live vs the LOCAL synth template: the declared drift your next `cdk deploy` would silently overwrite |
465
- | `--undeclared-only` | (check) undeclared drift only: pair cdkrd with `cdk drift` for the declared side |
466
- | `--declared-only` | (check) declared drift vs the deployed template only (undeclared tier skipped; baseline untouched). Not `--pre-deploy` |
467
- | `--dry-run` | (revert) print the plan; make no changes |
468
- | `--wait[=DURATION]` | (revert) on a transient "resource is mid-update" error (e.g. Route53Resolver `RSLVR-00705`) keep retrying until it settles, up to DURATION (default `10m`; e.g. `--wait=5m`, `--wait=90s`). The DURATION is **inline-only** (`--wait=5m`); a separate `--wait 5m` is not read |
469
- | `--remove-unrecorded` | (revert, and check for its inline revert) REMOVE unrecorded values + DELETE unrecorded added resources in a no-prompt run (`--yes`/CI); an interactive revert already lists them |
470
- | `--force` | (revert) proceed even when the stack is **mid-operation** (`*_IN_PROGRESS`). By default revert re-reads the stack right before the write and refuses (to avoid fighting an in-flight deploy); `--force` overrides that for a knowingly-wedged stack. The mid-operation warning still prints; `--force` does **not** skip the confirm (that is `--yes`) |
471
- | `--yes` / `-y` | skip confirmations (revert apply; record records all without the multiselect) |
475
+ | option | meaning |
476
+ | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
477
+ | `--region <r>` | a stack's own `env.region` ALWAYS wins; for an env-AGNOSTIC stack (no `env`) it falls back to `--region` (or `$AWS_REGION` / `$AWS_DEFAULT_REGION`), else the AWS-CLI/cdk region chain — the active profile's region, then the `[default]` profile's region, then EC2 IMDS |
478
+ | `--profile <p>` | AWS profile (else `$AWS_PROFILE`, else `$AWS_DEFAULT_PROFILE` — same order `aws` and `cdk` use) |
479
+ | `--assume-role <arn>` | assume this IAM role from the ambient / `--profile` credentials and make every AWS call for a stack as it (synthesis stays on the ambient credentials) (else `$CDKRD_ASSUME_ROLE`); `{account}` / `{region}` are filled per stack from the CDK app (`env.account`, else the calling identity's account; the stack's region) — see [In CI](#in-ci). Session name `cdkrd-<verb>` |
480
+ | `-a, --app <cmd\|cdk.out>` | CDK app command or pre-synthesized assembly dir (or `$CDKRD_APP` / cdk.json `"app"`); stack auto-discovery + construct paths |
481
+ | `-c, --context key=value` | context for synth (repeatable; cdk.json is the base layer) |
482
+ | `--all` | target every stack the app defines (the default when no `<stack>` is named; cannot be combined with named stacks — a `<stack> ... --all` invocation errors) |
483
+ | `--json` | machine-readable output (see [JSON contract](#json-output-contract)) |
484
+ | `--fail` | (check) exit 1 on drift and never prompt; for scripts/CI. Without it, check reports drift but exits 0 |
485
+ | `--no-prompt` | (check) never open the interactive resolve menu (report-only), but keep exit 0 on drift — the exit-0 twin of `--fail`'s prompt suppression, for a report-only script attached to a terminal. Non-TTY never prompts anyway; with `--fail`, `--fail`'s exit 1 wins |
486
+ | `--strict` | (check) exit 1 when coverage is incomplete. A coverage gap is always surfaced loudly; `--strict` makes it CI-failing. Orthogonal to `--fail` |
487
+ | `--show-all` | (check) inventory mode: show all current undeclared state, ignoring the baseline |
488
+ | `--verbose` / `-v` | (check) expand the `info:` footer tiers / (revert) expand the not-revertable summary to full lists; (record) itemizes nested sub-keys in the multiselect. `-v` means `--verbose` **inside a verb** (`check -v`); a bare `cdkrd -v` (no verb) prints the version |
489
+ | `--pre-deploy` | (check) compare live vs the LOCAL synth template: the declared drift your next `cdk deploy` would silently overwrite |
490
+ | `--undeclared-only` | (check) undeclared drift only: pair cdkrd with `cdk drift` for the declared side |
491
+ | `--declared-only` | (check) declared drift vs the deployed template only (undeclared tier skipped; baseline untouched). Not `--pre-deploy` |
492
+ | `--dry-run` | (revert) print the plan; make no changes |
493
+ | `--wait[=DURATION]` | (revert) on a transient "resource is mid-update" error (e.g. Route53Resolver `RSLVR-00705`) keep retrying until it settles, up to DURATION (default `10m`; e.g. `--wait=5m`, `--wait=90s`). The DURATION is **inline-only** (`--wait=5m`); a separate `--wait 5m` is not read |
494
+ | `--remove-unrecorded` | (revert, and check for its inline revert) REMOVE unrecorded values + DELETE unrecorded added resources in a no-prompt run (`--yes`/CI); an interactive revert already lists them |
495
+ | `--force` | (revert) proceed even when the stack is **mid-operation** (`*_IN_PROGRESS`). By default revert re-reads the stack right before the write and refuses (to avoid fighting an in-flight deploy); `--force` overrides that for a knowingly-wedged stack. The mid-operation warning still prints; `--force` does **not** skip the confirm (that is `--yes`) |
496
+ | `--yes` / `-y` | skip confirmations (revert apply; record records all without the multiselect) |
472
497
 
473
498
  Unknown options (`--apq`) and options missing their value (`--app` at the end of
474
499
  the line) are errors (exit `2`): a typo'd flag never silently becomes a stack name.
@@ -490,7 +515,7 @@ treated as non-interactive: the report is written cleanly with no prompt (which
490
515
  would otherwise deadlock, waiting on stdin for a prompt written into the file) and
491
516
  no spinner frames leaking into the text. `--yes` in a TTY skips the write
492
517
  confirmation AND each verb's selection
493
- multiselect — `record` records ALL, `ignore` ignores ALL, `revert` applies the full
518
+ multiselect — `record` records ALL, `ignore` ignores ALL drift (never a coverage gap), `revert` applies the full
494
519
  plan. `check --yes` never opens the action menu (Record / Revert / Ignore / …) —
495
520
  it just reports (#1054/#1185); use the standalone `record --yes` / `ignore --yes`
496
521
  / `revert --yes` verbs for scripted, non-interactive decisions.
@@ -617,7 +642,7 @@ ignore:
617
642
  region: ap-northeast-1
618
643
  ```
619
644
 
620
- - Every rule is a mapping `{ path, stack?, account?, region? }`. `cdkrd ignore`
645
+ - Every rule is a mapping `{ path, stack?, account?, region?, resourceType? }`. `cdkrd ignore`
621
646
  stamps the current **stack / account / region** onto each rule it writes (the same
622
647
  three identity axes a baseline file is keyed on), so ignoring a within-stack path on
623
648
  one stack never leaks to a same-named twin stack in another account/region — an
@@ -658,6 +683,39 @@ ignore:
658
683
  leaking into a same-named stack in another account (stack-name uniqueness only
659
684
  holds within one account / App); **region** is independent the same way — the same
660
685
  stack in several accounts or regions may drift in only one.
686
+ - **`resourceType`** (optional, glob) narrows a rule to findings on resources of a
687
+ matching CloudFormation type. With an EXACT type (no `*` / `?`) an all-wildcard
688
+ `path` is allowed — `path: "*"` + `resourceType: AWS::SecretsManager::SecretTargetAttachment`
689
+ matches every resource of that type (every finding on it, not only its gaps).
690
+ - **Acknowledging a known coverage gap** (#1969/#1970). A rule that matches a
691
+ `skipped` resource — or a `readGap` whose read failed — does not hide it: the
692
+ finding keeps its tier and stays listed, gains `acknowledgedBy` (the rule) in
693
+ `--json`, and no longer fails `--strict`. A skipped resource has no property, so
694
+ only a **resource-level** rule matches it (`<constructPath>` / `<logicalId>`, or a
695
+ construct-path ancestor; a property glob like `Database/Cluster/Secret/Attachment.*`
696
+ does not); a
697
+ failed-read readGap matches at the resource or the property
698
+ (`ClusterRestorer/Verifier.Environment`). A gap no rule matches keeps failing.
699
+ You need not hand-write the key: the interactive **`cdkrd ignore`** picker lists
700
+ every gap that fails `--strict` as a `[coverage gap — …]` row beside the drift,
701
+ and picking one writes exactly the key form that matches it (the construct path
702
+ on a CDK-synthesized app, the logicalId — `Fn9270CBC0.Environment` — on an
703
+ assembly without `aws:cdk:path` metadata). By-nature readGaps, `Custom::*` skips
704
+ and already-acknowledged gaps are not offered, and `ignore --yes` (or any
705
+ non-interactive run) never acknowledges a gap — it ignores the drift only and
706
+ notes how many gaps it left. The rule is an ordinary ignore rule: once the read
707
+ succeeds (you grant the permission), it ignores drift on that resource / property
708
+ too, so remove it when the gap is fixed.
709
+
710
+ ```yaml
711
+ ignore:
712
+ # the CI read role is deliberately not granted secretsmanager:GetSecretValue
713
+ - path: Database/Cluster/Secret/Attachment
714
+ resourceType: AWS::SecretsManager::SecretTargetAttachment
715
+ # the CDK lookup role denies kms:Decrypt, so this function's env is unreadable
716
+ - path: ClusterRestorer/Verifier.Environment
717
+ ```
718
+
661
719
  - Matching findings move to the informational `ignored` tier: visible under
662
720
  `--verbose`, never exit-affecting, excluded from `revert` and `record`. A
663
721
  **deleted resource is never ignorable**.
@@ -760,6 +818,12 @@ the secret never lands in a committed file while a later change still re-surface
760
818
  drift (an unchanged one stays recorded). Older baselines holding a plaintext value keep
761
819
  comparing correctly and migrate to the hashed form on the next `record` (#798).
762
820
 
821
+ **Coverage-gap fields.** A `readGap` finding whose read FAILED carries `"readFailed": true`
822
+ (a by-nature one — write-only, not returned — never does; an unconfirmable `alias/aws/*`
823
+ KMS key carries `"compareOnly": true`); both, like a `skipped` finding, fail `--strict`. A
824
+ `skipped` / failed-read finding an `ignore.yaml` rule acknowledged keeps its tier and
825
+ carries `"acknowledgedBy": "<rule>"` — it no longer fails `--strict` (#1969/#1970).
826
+
763
827
  A **stack that errored or was skipped** before it could be checked still appears as an
764
828
  element so a consumer sees which stacks ran: it carries `"error": "<reason>"` alongside
765
829
  `"drifted": 0` and an empty `"findings": []`. (`error` is absent on a
@@ -885,6 +949,9 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
885
949
  `DescribeType`; `DescribeStackResources` (the sibling-ownership check for the
886
950
  `added` tier — see the `added`-tier entry below); `ListExports` (only for
887
951
  templates using `Fn::ImportValue`)
952
+ - with `--assume-role`: `sts:AssumeRole` on that role for the CALLING
953
+ identity (and the role's trust policy must allow it); everything else on this
954
+ list is then needed by the ROLE
888
955
  - `sts:GetCallerIdentity` (resolves the current account so every verb can tell a
889
956
  stack never deployed in THIS account from one deleted out of band, under the
890
957
  multi-account baseline pattern — `check`/`record`/`ignore` skip a stack pinned
@@ -1095,9 +1162,10 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
1095
1162
  really differ there (`cdk deploy` skips the upload because the key already exists),
1096
1163
  but the cause is the unchanged hash, not an edit made out of band.
1097
1164
  - Optional: `kms:ListAliases` enables strict verification that a declared
1098
- `alias/aws/*` key was not swapped for a customer-managed key. Without it that case
1099
- is conservatively suppressed AND cdkrd prints a one-line warning per region (the
1100
- swap would otherwise go undetected), so the reduced coverage is never silent.
1165
+ `alias/aws/*` key was not swapped for a customer-managed key. Without it that
1166
+ comparison is reported as a `readGap` (and cdkrd prints a one-line warning per
1167
+ region), which `--strict` counts as incomplete coverage, so the reduced coverage is
1168
+ never silent.
1101
1169
  - **`added` tier (out-of-band resource detection).** The `added` tier — cdkrd's
1102
1170
  detection of live child resources that exist in AWS but were never declared in
1103
1171
  your template (a headline differentiator) — enumerates each declared parent's