Skip to content

Conversation

@aemada-aws
Copy link
Contributor

Improve subprocess handling in EKS Helm custom resource handler.

Same PR as: #35141

Reason for this change

The EKS Helm custom resource handler used shell=True with subprocess calls, which is not aligned with security best practices. Following Python's recommended approach for subprocess execution improves code robustness and follows secure coding guidelines.

Description of changes

Refactor subprocess execution to follow Python best practices
https://docs.python.org/3/library/subprocess.html#replacing-shell-pipeline

  • Replaced shell command strings with array-based commands: Refactored get_oci_cmd() to return structured command objects instead of shell strings
  • Implemented proper subprocess pipelines: Used Popen with PIPE to chain aws ecr get-login-password and helm registry login commands following Python documentation recommendations
  • Removed shell=True: Adopted array-based command execution as recommended by Python subprocess documentation
  • Maintained functionality: Preserved all existing behavior for private ECR, public ECR, and fallback scenarios

Files modified:

  • packages/@aws-cdk/custom-resource-handlers/lib/aws-eks/kubectl-handler/helm/__init__.py
  • packages/@aws-cdk/aws-eks-v2-alpha/lib/kubectl-handler/helm/__init__.py
  • packages/@aws-cdk/aws-eks-v2-alpha/test/integ.alb-controller.js.snapshot/asset.*/helm/__init__.py

Technical approach:

  • Commands are now built as arrays: ['helm', 'pull', repository, '--version', version, '--untar']
  • Pipeline implementation follows Python subprocess best practices using Popen with proper PIPE connections
  • User inputs are passed as separate array elements, ensuring proper argument handling

Describe any new or updated permissions being added

No new IAM permissions required. The change maintains the same AWS API calls and functionality.

Description of how you validated changes

  • Functionality testing: Confirmed that ECR authentication and Helm chart pulling continues to work correctly for all scenarios
  • Code review: Verified implementation follows Python subprocess best practices as documented in the Python documentation
  • Compatibility testing: Ensured backward compatibility with existing CDK Helm chart deployments

Checklist


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

@aws-cdk-automation aws-cdk-automation requested a review from a team August 4, 2025 22:24
@github-actions github-actions bot added the p2 label Aug 4, 2025
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Aug 4, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter fails with the following errors:

❌ Fixes must contain a change to an integration test file and the resulting snapshot.

If you believe this pull request should receive an exemption, please comment and provide a justification. A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed, add Clarification Request to a comment.

@aemada-aws aemada-aws force-pushed the remove-shell-v1 branch 3 times, most recently from 1bf66b1 to bb6b571 Compare August 4, 2025 22:32
@aemada-aws aemada-aws added the pr/do-not-merge This PR should not be merged at this time. label Aug 5, 2025
@vishaalmehrishi vishaalmehrishi self-assigned this Aug 5, 2025
@aemada-aws aemada-aws removed the pr/do-not-merge This PR should not be merged at this time. label Aug 5, 2025
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 08f2ee9
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aemada-aws aemada-aws added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Aug 5, 2025
@mergify
Copy link
Contributor

mergify bot commented Aug 5, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 918593d into aws:main Aug 5, 2025
26 of 27 checks passed
@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2025

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

contribution/core This is a PR that came from AWS. p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants