generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 54
feat(cli): gc can ignore user-verified unauthorized non-cdk stacks #850
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
Open
dgandhi62
wants to merge
7
commits into
aws:main
Choose a base branch
from
dgandhi62:feat-ignore-skip-stacks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
248ad08
feat(cli): add skip-unauthorized-stacks-when-noncdk option for garbag…
gandhya 140fcd9
feat(gc): improve unauthorized stack handling with batch prompts and …
dgandhi62 7aed817
Add environment variable to test for ci environments
dgandhi62 698f26d
fix(test): add CI detection for garbage collection tests
dgandhi62 dd4cf80
Merge branch 'aws:main' into feat-ignore-skip-stacks
dgandhi62 eb74966
feat(gc): change default to 'no' for unauthorized stacks and rename o…
dgandhi62 87054d9
fix: add option to cli-config and remove it from parse-command-line-a…
dgandhi62 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
packages/@aws-cdk/toolkit-lib/lib/api/garbage-collection/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| # CDK Garbage Collection - Skip Unauthorized Native CloudFormation Stacks | ||
|
|
||
| This document describes the `--unauth-native-cfn-stacks-to-skip` option that allows users to provide patterns to automatically skip unauthorized native CloudFormation stacks. | ||
|
|
||
| ## Overview | ||
|
|
||
| When CDK Garbage Collection scans CloudFormation stacks to determine which assets are still in use, it may encounter stacks that it cannot access due to insufficient permissions. | ||
|
|
||
| **Without skip patterns configured:** | ||
| 1. **Prompt the user** asking whether to skip the unauthorized stacks | ||
| 2. **Default to 'no'** - the operation will be cancelled unless the user explicitly chooses to skip | ||
| 3. **List the unauthorized stacks** that were found | ||
|
|
||
| **With skip patterns configured:** | ||
| - Stacks matching the patterns are automatically skipped without prompting | ||
| - Only non-matching unauthorized stacks will prompt the user | ||
|
|
||
| The user needs to ensure that the stacks they intend to skip are native CloudFormation stacks (not CDK-managed). The option does NOT check this. Attempting to skip CDK stacks during gc can be hazardous | ||
|
|
||
| Example prompt: | ||
| ``` | ||
| Found 3 unauthorized stack(s): Legacy-App-Stack, | ||
| Legacy-DB-Stack, | ||
| ThirdParty-Service | ||
| Do you want to skip all these stacks? Default is 'no' [y]es/[n]o | ||
| ``` | ||
|
|
||
| ## Skip Patterns Configuration | ||
|
|
||
| Users can provide glob patterns to automatically skip unauthorized stacks using the `--unauth-native-cfn-stacks-to-skip` option: | ||
|
|
||
| ```bash | ||
| cdk gc --unstable=gc --unauth-native-cfn-stacks-to-skip "Legacy-*" "ThirdParty-*" | ||
| ``` | ||
|
|
||
| **How it works:** | ||
| - Patterns are checked against unauthorized stack names | ||
| - Matching stacks are automatically skipped | ||
| - Non-matching unauthorized stacks still prompt the user with default 'no' | ||
|
|
||
| ### Pattern Matching | ||
|
|
||
| - Supports glob patterns (`*`, `**`) | ||
| - Extracts stack names from ARNs automatically | ||
| - Case-sensitive matching | ||
|
|
||
| Examples: | ||
| - `Legacy-*` matches `Legacy-App-Stack`, `Legacy-DB-Stack` | ||
| - `*-Prod` matches `MyApp-Prod`, `Database-Prod` | ||
| - `ThirdParty-*` matches `ThirdParty-Service`, `ThirdParty-API` | ||
|
|
||
| ## Security Considerations | ||
|
|
||
| The default behavior of requiring explicit user confirmation to skip stacks helps prevent: | ||
|
|
||
| - Accidentally skipping important stacks | ||
| - Missing assets that might be referenced by inaccessible stacks | ||
| - Unintended deletion of assets in shared environments | ||
|
|
||
| ## CI/CD Environments | ||
|
|
||
| In CI/CD environments where user interaction is not possible: | ||
|
|
||
| - The default 'no' response will cause the operation to fail | ||
| - Consider implementing proper IAM permissions instead of skipping stacks | ||
|
|
||
|
|
||
| ## Implementation Details | ||
|
|
||
| The skip patterns feature is implemented in `stack-refresh.ts`: | ||
|
|
||
| 1. Attempt to access each stack template | ||
| 2. Catch `AccessDenied` errors | ||
| 3. Check if stack name matches any user-provided skip patterns | ||
| 4. **If pattern matches:** automatically skip without prompting | ||
| 5. **If no pattern matches:** prompt user whether to skip (defaults to 'no') | ||
|
|
||
| This ensures that only stacks matching user-specified patterns are skipped automatically, maintaining security by default. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/@aws-cdk/toolkit-lib/test/api/aws-auth/__snapshots__/sdk-logger.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.