Skip to content

feat(core): explain denied deploy requests without risking sandbox data - #1163

Draft
xyos wants to merge 1 commit into
aws:mainfrom
xyos:feat/deploy-denial-guidance
Draft

xyos wants to merge 1 commit into
aws:mainfrom
xyos:feat/deploy-denial-guidance

Conversation

@xyos

@xyos xyos commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When AWS denies a request of the deployment itself, for example a CloudFormation resource that an AWS Organizations policy (SCP or RCP) denies, the credential check before the deploy passes, and the deploy commands print nothing beyond the CDK output:

  • Production deploy: the first CREATE_FAILED arrives early, but the command only fails after the rollback, minutes later.
  • Sandbox: it prints its Express Mode note recommending npm run sandbox:destroy. That deletes an existing sandbox and its data, for a failure a redeploy cannot get past.
  • Expired credentials: credentials that expire or are rejected after the pre-deploy check (for example during cdk watch) get no sign-in guidance at all.

Issue #, if available:

Changes

  • Reading CDK's failure output.

    • Only failure output counts: the reason column of CloudFormation events ending in _FAILED, the CDK error block (read by paragraph, because CDK hard-wraps it mid-phrase), and failed asset uploads (<stack>: fail:), since cdk watch swallows the error block.
    • Left out: stack-name banners, resource headings, source locations, and app log lines from cdk watch.
    • The classifier in denial-guidance.ts (from feat(core): explain denied credential checks and the aws login Region #839) now tolerates ANSI codes, CRLF and wrapped phrases; accepts AuthorizationError and UnauthorizedOperation; and no longer treats CDK's (e.g. AccessDenied) note about cdk diagnose as a denial.
  • When it reports.

    • An explicit Organizations deny is explained as soon as its line arrives, before the rollback.
    • Any other denial is explained once the attempt is known to have failed.
    • At most once per deployment, including each deployment in watch mode.
    • Output, errors and exit codes are otherwise unchanged.
  • Credential expiry in npm run sandbox. Expired or rejected credentials print the credential check's source-aware sign-in guidance, once per deployment. Order of precedence:

    1. an explicit Organizations deny, which signing in again cannot get past;
    2. the IAM Identity Center or aws login provider's own sign-in instruction;
    3. a generic denial or a credential error name in an error position.

    RequestExpired alone is not read as expiry, because it also means clock skew. In watch mode the last line says to save a file for credentials the CDK reloads (IAM Identity Center, aws login, roles via source_profile), or to restart for credentials it keeps for the life of the process (access keys, credential_process). No prompts, no automatic login.

  • Sandbox recovery after a denial. Fixed two-case guidance replaces the Express Mode note: after a first deploy, sandbox:destroy removes the empty failed stack; a sandbox that existed before must not be destroyed. Other failures keep the Express Mode note byte for byte.

  • Capture strategy.

    • Production already streams both pipes; every line reaches the monitor whether or not the output is curated.
    • The initial sandbox deploy runs through the CDK output runner (cdk-output.ts). Under cdk-blocks at quiet and normal (the curated levels), each line is observed after the curated relay handles it. At verbose and debug, and when no level is set, stdin and stdout are inherited (stdout follows BLOCKS_LOG_STREAM as before) and only stderr is piped to the observer, relayed unchanged as it arrives. This runner uses the same cross-spawn helper and bounded drain as the existing curated runner.
    • With CI set, CDK prints events to stdout, so the denial is explained from the stderr error block when the deploy fails.
    • Watch output keeps its existing relay; the monitor reads its lines at every level.
  • Output channel and wording: the notice, credential guidance and recovery text are printed like errors, so no log level hides them, and they name the command that was run (for example npx --no -- cdk-blocks sandbox deploy). Because curated levels print the full CDK output only after a failure, the notice says "The CDK output has the details" rather than "above".

  • Visible change: the initial sandbox deploy passes --progress events, like npm run deploy, because its stderr is no longer a terminal. It prints one line per CloudFormation event instead of a progress bar.

  • Docs: packages/blocks/README.md and create-blocks-app/resources/AGENTS.md. Changeset: core, blocks, create-blocks-app (patch). No public API change (check:api passes).

Not in this PR: credential-expiry guidance during a production deploy (the pre-deploy check already covers expiry at start), and naming a spend limit as the cause of a denial (there is no supported signal for that yet).

Validation

  • Tests written first for each behavior. Before the corresponding fixes, the new monitor, classifier and sandbox tests failed.
  • Fixtures use sanitized CDK output (documentation example IDs only).
  • Covered:
    • denial evidence on stdout and stderr, in event text and error blocks;
    • a chunk split inside the explicit-deny line through a real child pipe;
    • hard-wrapped lines, ANSI and CRLF, and a trailing line without a newline;
    • ordinary failures next to the CDK notes;
    • resources, paths or stacks named AccessDenied or ExpiredToken, and app log lines shaped like deploy events;
    • CI-shaped output;
    • repeated watch errors and attempt boundaries;
    • provider-refresh wraps with and without an explicit deny;
    • IAM Identity Center, aws login, environment-key and role-chain credential messages;
    • no IDs, ARNs, keys or secrets in any added output.
  • Checks on Node 22, one commit rebased onto main c672712 (no merge commit; import and placement conflicts with the deploy-history recorder from feat(admin-ui): add the Blocks Admin UI, a local dashboard for Blocks apps #843 in deploy.ts and sandbox.ts resolved by keeping both sides): npm install, npm run build, npm run lint (two existing useAwaitThenable nursery warnings), npm run lint:deps and npm run check:api pass.
  • New tests: the real startSandbox with a fake CDK at normal, quiet and verbose (with BLOCKS_LOG_STREAM=stderr). It reports one notice naming the CLI command before the verdict, plus the recovery text; it fails if the curated wiring is removed. The production monitor is also tested with curated streams at normal and quiet.
  • npm test (all workspaces, after npm run build:force): 13203 passed, 0 failed, 10 skipped. An earlier run on the same commit failed one file, packages/blocks/dist/conditional-exports.test.js, because the local checkout still held ignored build leftovers of the removed bb-auth-basic, bb-auth-cognito and bb-auth-oidc package directories; with those moved aside, the full rerun passed.
  • npm run test:e2e:local: 522 passed, 6 skipped; 12/12; 2/2; 1/1; 14/14; 0 failed.
  • Manual: replayed recorded CDK output from real deploys that an Organizations SCP denied (two production deploys, one sandbox, two more deploys) through the built monitor. Each reported the explicit deny exactly once, at or within three lines of the first CREATE_FAILED; in one production run that is about 2.5 minutes before CDK's own failure message. Recorded dev, destroy and sandbox:destroy output produced no notice.

Checklist

  • PR description included
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@changeset-bot

changeset-bot Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7bcb024

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@aws-blocks/core Patch
@aws-blocks/blocks Patch
@aws-blocks/create-blocks-app Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@xyos
xyos force-pushed the feat/deploy-denial-guidance branch 2 times, most recently from e0eef08 to 5ff3132 Compare November 11, 2026 15:59
When AWS denied a request of the deployment itself, for example a
CloudFormation resource that an AWS Organizations policy denies, the deploy
commands printed nothing beyond the CDK output: the credential check before
the deploy passes in that case. A production deploy then waited for the
rollback, minutes after the first failure, and a sandbox printed its Express
Mode note recommending sandbox:destroy, which deletes an existing sandbox's
data, for a failure that a redeploy cannot get past.

The deploy commands now read the CDK CLI's failure output while it runs: the
reason column of CloudFormation events whose status ends in _FAILED, and the
CDK CLI's error block, read by paragraph because it hard-wraps the reason
mid-phrase (the stack name in its banner, resource headings and source
locations are left out). App log lines that cdk watch prints are skipped
before anything else. An explicit
deny by a service or resource control policy is explained as soon as its line
arrives; any other denial once the deploy is known to fail, so that it is not
explained as missing IAM permissions just before an explicit deny of another
resource. Each is explained at most once per deployment, including each
deployment of the sandbox's watch mode. The notice adds no details from the
error, and output, errors and exit codes are unchanged.

The classifier now tolerates terminal colors, CRLF and line breaks inside a
phrase, accepts the AuthorizationError (SNS) and UnauthorizedOperation (EC2)
error names, and no longer treats the CDK CLI's note "(e.g. AccessDenied)"
about cdk diagnose as a denial.

Capture: the production deploy already streams both pipes. The initial
sandbox deploy, which inherited all stdio synchronously at the default log
level, now keeps stdin and stdout there (where the CDK CLI decides its
terminal behavior) and pipes only stderr, where it writes progress and
errors without --ci; each chunk is relayed unchanged as it arrives and read
line by line on the side. Because that stderr is no longer a terminal, the
sandbox deploy passes --progress events, as the production deploy does.
With CI set, the CDK CLI prints its events to the inherited stdout, and the
denial is explained from the error block on stderr when the deploy fails.
At BLOCKS_LOG_LEVEL=quiet|normal (the blocks CLI's --quiet and default),
where both streams are already piped and curated, each line of the deploy
and of cdk watch is read once the curated relay has handled it. The
notices and guidance are not log lines, so no level hides them, and they
name the command that ran (for example `npx --no -- cdk-blocks sandbox`).

After a denial, a failed sandbox deploy prints fixed recovery guidance
instead of the Express Mode note: a first deploy's failed stack holds no data
and sandbox:destroy removes it, while a sandbox that existed before must not
be destroyed. Other failures keep the Express Mode note unchanged.

Credentials that expire or are rejected while the sandbox deploys, which the
pre-deploy check cannot catch, are now explained from the same failure
output, never as a denial: the sign-in instructions of the bundled IAM
Identity Center and aws login credential providers (which take precedence
over an AccessDeniedException that they wrap, though not over an explicit
Organizations deny, which signing in again cannot get past), the SDK error names
ExpiredToken, ExpiredTokenException, TokenRefreshRequired,
InvalidClientTokenId and UnrecognizedClientException where the output names
an error, and STS's expired or invalid security token wording. RequestExpired
alone is not read as expiry, since it also means a clock that is off. cdk
watch does not print the error block of a failed deployment, so a failed
asset upload (`<stack>: fail:`) also counts as failure output. Once per
deployment, the sandbox prints the pre-deploy check's source-aware sign-in
guidance for its deployment target; in watch mode its last line says to save
a file for credentials that the CDK CLI loads again on expiry (IAM Identity
Center, aws login, roles assumed with source_profile), or to restart for
credentials that it keeps for the life of the process (access keys,
credential_process).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant