cdk-real-drift 0.29.0 → 0.30.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.
@@ -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,29 @@ 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
+
700
+ ```yaml
701
+ ignore:
702
+ # the CI read role is deliberately not granted secretsmanager:GetSecretValue
703
+ - path: Database/Cluster/Secret/Attachment
704
+ resourceType: AWS::SecretsManager::SecretTargetAttachment
705
+ # the CDK lookup role denies kms:Decrypt, so this function's env is unreadable
706
+ - path: ClusterRestorer/Verifier.Environment
707
+ ```
708
+
661
709
  - Matching findings move to the informational `ignored` tier: visible under
662
710
  `--verbose`, never exit-affecting, excluded from `revert` and `record`. A
663
711
  **deleted resource is never ignorable**.
@@ -760,6 +808,12 @@ the secret never lands in a committed file while a later change still re-surface
760
808
  drift (an unchanged one stays recorded). Older baselines holding a plaintext value keep
761
809
  comparing correctly and migrate to the hashed form on the next `record` (#798).
762
810
 
811
+ **Coverage-gap fields.** A `readGap` finding whose read FAILED carries `"readFailed": true`
812
+ (a by-nature one — write-only, not returned — never does; an unconfirmable `alias/aws/*`
813
+ KMS key carries `"compareOnly": true`); both, like a `skipped` finding, fail `--strict`. A
814
+ `skipped` / failed-read finding an `ignore.yaml` rule acknowledged keeps its tier and
815
+ carries `"acknowledgedBy": "<rule>"` — it no longer fails `--strict` (#1969/#1970).
816
+
763
817
  A **stack that errored or was skipped** before it could be checked still appears as an
764
818
  element so a consumer sees which stacks ran: it carries `"error": "<reason>"` alongside
765
819
  `"drifted": 0` and an empty `"findings": []`. (`error` is absent on a
@@ -885,6 +939,9 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
885
939
  `DescribeType`; `DescribeStackResources` (the sibling-ownership check for the
886
940
  `added` tier — see the `added`-tier entry below); `ListExports` (only for
887
941
  templates using `Fn::ImportValue`)
942
+ - with `--assume-role`: `sts:AssumeRole` on that role for the CALLING
943
+ identity (and the role's trust policy must allow it); everything else on this
944
+ list is then needed by the ROLE
888
945
  - `sts:GetCallerIdentity` (resolves the current account so every verb can tell a
889
946
  stack never deployed in THIS account from one deleted out of band, under the
890
947
  multi-account baseline pattern — `check`/`record`/`ignore` skip a stack pinned
@@ -1069,6 +1126,13 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
1069
1126
  code bytes are gone, so it is detect-only (not revertable — redeploy with a
1070
1127
  forced code update). Without the permission the signal is skipped, never
1071
1128
  false-flagged.
1129
+ - `kms:Decrypt` on a function's environment key (the AWS-managed `aws/lambda`
1130
+ key by default) lets cdkrd read `AWS::Lambda::Function` environment variables.
1131
+ A caller denied it — notably the CDK bootstrap **lookup role**, whose policy
1132
+ explicitly denies `kms:Decrypt` — gets an `Environment.Error` instead of the
1133
+ variables, so cdkrd reports `Environment` as an unverifiable `readGap`
1134
+ (counted in the `info:` footer) with a stderr warning, never as declared
1135
+ drift.
1072
1136
  - Optional: `glue:GetJob` + `s3:GetObject` (on the script bucket) record a content
1073
1137
  hash of an `AWS::Glue::Job`'s ETL script (`ScriptSha256`, fetched from
1074
1138
  `Command.ScriptLocation`) so an out-of-band script swap at the **same S3 key**
@@ -1088,9 +1152,10 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
1088
1152
  really differ there (`cdk deploy` skips the upload because the key already exists),
1089
1153
  but the cause is the unchanged hash, not an edit made out of band.
1090
1154
  - Optional: `kms:ListAliases` enables strict verification that a declared
1091
- `alias/aws/*` key was not swapped for a customer-managed key. Without it that case
1092
- is conservatively suppressed AND cdkrd prints a one-line warning per region (the
1093
- swap would otherwise go undetected), so the reduced coverage is never silent.
1155
+ `alias/aws/*` key was not swapped for a customer-managed key. Without it that
1156
+ comparison is reported as a `readGap` (and cdkrd prints a one-line warning per
1157
+ region), which `--strict` counts as incomplete coverage, so the reduced coverage is
1158
+ never silent.
1094
1159
  - **`added` tier (out-of-band resource detection).** The `added` tier — cdkrd's
1095
1160
  detection of live child resources that exist in AWS but were never declared in
1096
1161
  your template (a headline differentiator) — enumerates each declared parent's