Skip to content

Commit bd056d1

Browse files
authored
fix(stepfunctions-tasks): custom resource uses subprocess with Shell=true (#22752)
Using `Shell=true` in `subprocess` functions is considered a [security vulnerability](https://cwe.mitre.org/data/definitions/78.html). To avoid using this argument, the command has to be passed as an array rather than a string. ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent a36f2f0 commit bd056d1

9 files changed

+12
-12
lines changed

packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/utils/role-policy/index.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
def handler(event, context):
77
logger = logging.getLogger()
88
logger.setLevel(logging.INFO)
9-
command = f"/opt/awscli/aws emr-containers update-role-trust-policy --cluster-name {event['ResourceProperties']['eksClusterId']} --namespace {event['ResourceProperties']['eksNamespace']} --role-name {event['ResourceProperties']['roleName']}"
9+
command = ["/opt/awscli/aws", "emr-containers", "update-role-trust-policy", "--cluster-name", f"{event['ResourceProperties']['eksClusterId']}", "--namespace", f"{event['ResourceProperties']['eksNamespace']}", "--role-name", f"{event['ResourceProperties']['roleName']}"]
1010
if event['RequestType'] == 'Create' or event['RequestType'] == 'Update' :
1111
try:
12-
res = sp.check_output(command, shell=True)
12+
res = sp.check_output(command)
1313
logger.info(f"Successfully ran {command}")
1414
except Exception as e:
1515
logger.info(f"ERROR: {str(e)}")
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
def handler(event, context):
77
logger = logging.getLogger()
88
logger.setLevel(logging.INFO)
9-
command = f"/opt/awscli/aws emr-containers update-role-trust-policy --cluster-name {event['ResourceProperties']['eksClusterId']} --namespace {event['ResourceProperties']['eksNamespace']} --role-name {event['ResourceProperties']['roleName']}"
9+
command = ["/opt/awscli/aws", "emr-containers", "update-role-trust-policy", "--cluster-name", f"{event['ResourceProperties']['eksClusterId']}", "--namespace", f"{event['ResourceProperties']['eksNamespace']}", "--role-name", f"{event['ResourceProperties']['roleName']}"]
1010
if event['RequestType'] == 'Create' or event['RequestType'] == 'Update' :
1111
try:
12-
res = sp.check_output(command, shell=True)
12+
res = sp.check_output(command)
1313
logger.info(f"Successfully ran {command}")
1414
except Exception as e:
1515
logger.info(f"ERROR: {str(e)}")

packages/@aws-cdk/aws-stepfunctions-tasks/test/emrcontainers/integ.start-job-run.js.snapshot/aws-stepfunctions-tasks-emr-containers-start-job-run-test.assets.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@
9292
}
9393
}
9494
},
95-
"de2da116e1de2db20dc2bc88a1e97df050dde2917a4122674e054e87ee53e334": {
95+
"3c25783c134c6817b53033bdc57fc404bda6ba93392fcc7d3ca4d92bd072351f": {
9696
"source": {
97-
"path": "asset.de2da116e1de2db20dc2bc88a1e97df050dde2917a4122674e054e87ee53e334",
97+
"path": "asset.3c25783c134c6817b53033bdc57fc404bda6ba93392fcc7d3ca4d92bd072351f",
9898
"packaging": "zip"
9999
},
100100
"destinations": {
101101
"current_account-current_region": {
102102
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
103-
"objectKey": "de2da116e1de2db20dc2bc88a1e97df050dde2917a4122674e054e87ee53e334.zip",
103+
"objectKey": "3c25783c134c6817b53033bdc57fc404bda6ba93392fcc7d3ca4d92bd072351f.zip",
104104
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
105105
}
106106
}
@@ -131,15 +131,15 @@
131131
}
132132
}
133133
},
134-
"da24149302db350010268fabd5306eace023f9bd5f26749e3160db3c82e2a2f2": {
134+
"edffa811caefa503489be039d857f8a7abd33dadadc71461d81240ab0ddca7bc": {
135135
"source": {
136136
"path": "aws-stepfunctions-tasks-emr-containers-start-job-run-test.template.json",
137137
"packaging": "file"
138138
},
139139
"destinations": {
140140
"current_account-current_region": {
141141
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
142-
"objectKey": "da24149302db350010268fabd5306eace023f9bd5f26749e3160db3c82e2a2f2.json",
142+
"objectKey": "edffa811caefa503489be039d857f8a7abd33dadadc71461d81240ab0ddca7bc.json",
143143
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
144144
}
145145
}

packages/@aws-cdk/aws-stepfunctions-tasks/test/emrcontainers/integ.start-job-run.js.snapshot/aws-stepfunctions-tasks-emr-containers-start-job-run-test.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@
14961496
"S3Bucket": {
14971497
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
14981498
},
1499-
"S3Key": "de2da116e1de2db20dc2bc88a1e97df050dde2917a4122674e054e87ee53e334.zip"
1499+
"S3Key": "3c25783c134c6817b53033bdc57fc404bda6ba93392fcc7d3ca4d92bd072351f.zip"
15001500
},
15011501
"Role": {
15021502
"Fn::GetAtt": [

packages/@aws-cdk/aws-stepfunctions-tasks/test/emrcontainers/integ.start-job-run.js.snapshot/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"validateOnSynth": false,
2424
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
2525
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
26-
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/da24149302db350010268fabd5306eace023f9bd5f26749e3160db3c82e2a2f2.json",
26+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/edffa811caefa503489be039d857f8a7abd33dadadc71461d81240ab0ddca7bc.json",
2727
"requiresBootstrapStackVersion": 6,
2828
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
2929
"additionalDependencies": [

packages/@aws-cdk/aws-stepfunctions-tasks/test/emrcontainers/integ.start-job-run.js.snapshot/tree.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3952,7 +3952,7 @@
39523952
"s3Bucket": {
39533953
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
39543954
},
3955-
"s3Key": "de2da116e1de2db20dc2bc88a1e97df050dde2917a4122674e054e87ee53e334.zip"
3955+
"s3Key": "3c25783c134c6817b53033bdc57fc404bda6ba93392fcc7d3ca4d92bd072351f.zip"
39563956
},
39573957
"role": {
39583958
"Fn::GetAtt": [

0 commit comments

Comments
 (0)