Skip to content

Commit 478a714

Browse files
author
Elad Ben-Israel
authored
fix(toolkit): scrutiny dialog should fail with no tty (#1382)
If STDIN is not connected to a TTY (terminal), and scrutiny is enabled, we expect the program to fail (exit with non-zero exit code). This is especially important for CI/CD scenarios where you wouldn't want to accidentally deploy changes that didn't pass a scrutiny check. Added integration test. Fixes #1380
1 parent 8c733ef commit 478a714

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

packages/aws-cdk/bin/cdk.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,14 @@ async function initCommandLine() {
306306
if (requireApproval !== RequireApproval.Never) {
307307
const currentTemplate = await readCurrentTemplate(stack);
308308
if (printSecurityDiff(currentTemplate, stack, requireApproval)) {
309+
310+
// only talk to user if we STDIN is a terminal (otherwise, fail)
311+
if (!process.stdin.isTTY) {
312+
throw new Error(
313+
'"--require-approval" is enabled and stack includes security-sensitive updates, ' +
314+
'but terminal (TTY) is not attached so we are unable to get a confirmation from the user');
315+
}
316+
309317
const confirmed = await confirm(`Do you wish to deploy these changes (y/n)?`);
310318
if (!confirmed) { throw new Error('Aborted by user'); }
311319
}

packages/aws-cdk/integ-tests/common.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function cleanup_stack() {
2121
function cleanup() {
2222
cleanup_stack cdk-toolkit-integration-test-1
2323
cleanup_stack cdk-toolkit-integration-test-2
24+
cleanup_stack cdk-toolkit-integration-iam-test
2425
}
2526

2627
function setup() {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
scriptdir=$(cd $(dirname $0) && pwd)
4+
source ${scriptdir}/common.bash
5+
# ----------------------------------------------------------
6+
7+
setup
8+
9+
# redirect /dev/null to stdin, which means there will not be tty attached
10+
# since this stack includes security-related changes, the deployment should
11+
# immediately fail because we can't confirm the changes
12+
if cdk deploy cdk-toolkit-integration-iam-test < /dev/null; then
13+
fail "test failed. we expect 'cdk deploy' to fail if there are security-related changes and no tty"
14+
fi
15+
16+
echo "✅ success"

0 commit comments

Comments
 (0)