Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(toolkit): scrutiny dialog should fail with no tty #1382

Merged
merged 8 commits into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/aws-cdk/bin/cdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,14 @@ async function initCommandLine() {
if (requireApproval !== RequireApproval.Never) {
const currentTemplate = await readCurrentTemplate(stack);
if (printSecurityDiff(currentTemplate, stack, requireApproval)) {

// only talk to user if we STDIN is a terminal (otherwise, fail)
if (!process.stdin.isTTY) {
throw new Error(
'"--require-approval" is enabled and stack includes security-sensitive updates, ' +
'but terminal (TTY) is not attached so we are unable to get a confirmation from the user');
}

const confirmed = await confirm(`Do you wish to deploy these changes (y/n)?`);
if (!confirmed) { throw new Error('Aborted by user'); }
}
Expand Down
1 change: 1 addition & 0 deletions packages/aws-cdk/integ-tests/common.bash
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function cleanup_stack() {
function cleanup() {
cleanup_stack cdk-toolkit-integration-test-1
cleanup_stack cdk-toolkit-integration-test-2
cleanup_stack cdk-toolkit-integration-iam-test
}

function setup() {
Expand Down
16 changes: 16 additions & 0 deletions packages/aws-cdk/integ-tests/test-cdk-deploy-no-tty.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -euo pipefail
scriptdir=$(cd $(dirname $0) && pwd)
source ${scriptdir}/common.bash
# ----------------------------------------------------------

setup

# redirect /dev/null to stdin, which means there will not be tty attached
# since this stack includes security-related changes, the deployment should
# immediately fail because we can't confirm the changes
if cdk deploy cdk-toolkit-integration-iam-test < /dev/null; then
fail "test failed. we expect 'cdk deploy' to fail if there are security-related changes and no tty"
fi

echo "✅ success"