Skip to content

Commit 9b57462

Browse files
authored
Merge pull request #17 from toricls/check-initprocessenabled
Add check on "initProcessEnabled" flag
2 parents 98d1c33 + cbc544b commit 9b57462

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,26 +84,29 @@ The IAM user/role you used for the `check-ecs-exec.sh` are not allowed to use th
8484
Note that the `Condition` element of the IAM policy is not currently supported to evaluate by `check-ecs-exec.sh`.
8585

8686
7. **_🟡 Can I ExecuteCommand? | ssm:StartSession denied?: allowed_**
87-
The result means your IAM user/role is allowed to do `ssm:StartSession` action to the ECS task. This check item won't block you to use ECS Exec, but we recommend you to limit access to the `ssm:StartSession` API, from the security and the principle of least privilege perspectives. See [the official documentation](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html#ecs-exec-limit-access-start-session) for further details.
87+
The result means your IAM user/role is allowed to do `ssm:StartSession` action to the ECS task. This check item won't block you to use ECS Exec, but we recommend you to limit access to the `ssm:StartSession` API, from the security and the principle of least privilege perspectives. See [the ECS official documentation](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html#ecs-exec-limit-access-start-session) for further details.
8888
Note that the `Condition` element of the IAM policy is not currently supported to evaluate by `check-ecs-exec.sh`.
8989

9090
8. **_🔴 Platform Version | 1.3.0 (Required: >= 1.4.0)_**
9191
On AWS Fargate, `ECS Exec` requires the Platform version 1.4.0 or newer. If your ECS task is part of an ECS service, then you can update the platform version by specifying the `PlatformVersion` parameter for the `UpdateService` API. If your ECS task is a standalone task, then you need to re-run the ECS task with the `PlatformVersion` parameter specified for the `RunTask` API. See also [the migration guide from the previous PVs](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/platform_versions.html#platform-version-migration).
9292

9393
9. **_🔴 ECS Agent Version | x.y.z (Required: >= 1.50.2)_**
94-
You need to update the version of the ECS Container Agent for your EC2 instance where your ECS task runs. See [the official documentation](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-agent-update.html) for the details and how to update.
94+
You need to update the version of the ECS Container Agent for your EC2 instance where your ECS task runs. See [the ECS official documentation](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-agent-update.html) for the details and how to update.
9595

9696
10. **_🔴 Exec Enabled for Task | NO_**
9797
You need to enable the ECS Exec feature for your ECS service or your ECS standalone task. If your ECS task is part of an ECS service, then you can update the ECS by specifying the `EnableExecuteCommand` parameter for the `UpdateService` API. If your ECS task is a standalone task, then you need to re-run the ECS task with the `EnableExecuteCommand` parameter specified for the `RunTask` API.
9898

9999
11. **_🔴 Managed Agent Status | STOPPED (Reason: stopped-reason-here)_**
100100
The managed agent for a container in your Task has stopped for some reasons. If you see this error again and again even after re-running your ECS task, then make sure you have other results from `check-ecs-exec.sh` are all green.
101101

102-
12. **_🔴 EC2 or Task Role | Not Configured"_ or _{serviceName}:{ActionName}: implicitDeny_**
102+
12. **_🟡 Init Process Enabled | Disabled_**
103+
This check item won't block you to use ECS Exec, but we recommend you to add the `initProcessEnabled` flag to your ECS task definition for each container to avoid having orphaned and zombie processes. See the "Considerations for using ECS Exec" in [the ECS official documentation](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html#ecs-exec-considerations) for more details.
104+
105+
13. **_🔴 EC2 or Task Role | Not Configured"_ or _{serviceName}:{ActionName}: implicitDeny_**
103106
Your ECS task needs a task role or an instance role of the underlying EC2 instance with some permissions for using SSM Session Manager at least. See the [IAM permissions required for ECS Exec](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html#ecs-exec-enabling-and-using) section and the [Enabling logging and auditing in your tasks and services](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html#ecs-exec-logging) section in the official documentation for the details.
104107
Note that the `Condition` element of the IAM policy is not currently supported to evaluate by `check-ecs-exec.sh`.
105108

106-
13. **_🟡 SSM PrivateLink "com.amazonaws.(region).ssmmessages" not found_**
109+
14. **_🟡 SSM PrivateLink "com.amazonaws.(region).ssmmessages" not found_**
107110
The `check-ecs-exec.sh` found one or more VPC endpoints configured in the VPC for your task, so you **may** want to add an additional SSM PrivateLink for your VPC. Make sure your ECS task has proper outbound internet connectivity, and if it doesn't, then you **need** to configure an additional SSM PrivateLink for your VPC.
108111

109112
## Security

check-ecs-exec.sh

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,15 @@ fi
182182
## 3. CHECK CLUSTER AND TASK CONFIGURATIONS ##############################################
183183
printf "\n"
184184
printSectionHeaderLine
185-
printf "${COLOR_DEFAULT}Configurations for ECS task and other resources\n"
185+
printf "${COLOR_DEFAULT}Checks on ECS task and other resources\n"
186186
printSectionHeaderLine
187187
printf "${COLOR_DEFAULT}Region : ${AWS_REGION}\n"
188188
printf "${COLOR_DEFAULT}Cluster: ${CLUSTER_NAME}\n"
189189
printf "${COLOR_DEFAULT}Task : ${TASK_ID}\n"
190190
printSectionHeaderLine
191191
##########################################################################################
192192

193-
# 1. Checks on the cluster configurations
193+
# 1. Checks on the cluster configurations (yellow)
194194
describedClusterJson=$(${AWS_CLI_BIN} ecs describe-clusters \
195195
--clusters "${CLUSTER_NAME}" \
196196
--include CONFIGURATIONS \
@@ -279,7 +279,7 @@ if [[ ! "x${kmsKeyId}" = "xnull" ]]; then
279279
| jq -r ".EvaluationResults[0].EvalDecision")
280280
showEvalResult "${kmsGenerateDataKeyResult}" "${kmsGenerateDataKey}"
281281
fi
282-
## Check for ensuring "I cannot" call ssm:StartSession
282+
## Check for ensuring "I cannot" call ssm:StartSession (yellow)
283283
### See the "Limiting access to the Start Session action" section at https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html#ecs-exec-limit-access-start-session
284284
ssmStartSession="ssm:StartSession"
285285
printf "${COLOR_DEFAULT} ${ssmStartSession} denied?: "
@@ -345,7 +345,7 @@ printf "${COLOR_DEFAULT}\n"
345345
# 5. Check the managed agents' status
346346
printf "${COLOR_DEFAULT} Managed Agent Status | "
347347
if [[ "x${executeCommandEnabled}" = "xfalse" ]]; then
348-
printf "${COLOR_DEFAULT}SKIPPED\n"
348+
printf "${COLOR_YELLOW}SKIPPED\n"
349349
else
350350
printf "\n"
351351
agentsStatus=$(echo "${describedTaskJson}" | jq -r ".tasks[0].containers[].managedAgents[].lastStatus")
@@ -365,11 +365,27 @@ else
365365
done
366366
fi
367367

368-
# 6. Check the task role permissions
368+
# 6. Check the "initProcessEnabled" flag added in the task definition (yellow)
369369
taskDefArn=$(echo "${describedTaskJson}" | jq -r ".tasks[0].taskDefinitionArn")
370370
taskDefJson=$(${AWS_CLI_BIN} ecs describe-task-definition \
371371
--task-definition "${taskDefArn}" \
372372
--output json)
373+
initEnabledList=$(echo "${taskDefJson}" | jq -r ".taskDefinition.containerDefinitions[].linuxParameters.initProcessEnabled")
374+
idx=0
375+
printf "${COLOR_DEFAULT} Init Process Enabled | ${taskDefArn}\n"
376+
for enabled in $initEnabledList; do
377+
containerName=$(echo "${taskDefJson}" | jq -r ".taskDefinition.containerDefinitions[${idx}].name")
378+
printf " $((idx+1)). "
379+
case "${enabled}" in
380+
*true* ) printf "${COLOR_GREEN}Enabled";;
381+
*false* ) printf "${COLOR_YELLOW}Disabled";;
382+
* ) printf "${COLOR_YELLOW}Disabled";;
383+
esac
384+
printf "${COLOR_DEFAULT} for \"${containerName}\" container\n"
385+
idx=$((idx+1))
386+
done
387+
388+
# 7. Check the task role permissions
373389
taskRoleArn=$(echo "${taskDefJson}" | jq -r ".taskDefinition.taskRoleArn")
374390

375391
hasRole=true
@@ -499,8 +515,8 @@ else
499515
fi
500516
fi
501517

502-
# 7. Check existing VPC Endpoints (PrivateLinks) in the task VPC.
503-
# If there is any VPC Endpoints configured for the task VPC, we assume you would need an additional SSM PrivateLink to be configured.
518+
# 8. Check existing VPC Endpoints (PrivateLinks) in the task VPC.
519+
# If there is any VPC Endpoints configured for the task VPC, we assume you would need an additional SSM PrivateLink to be configured. (yellow)
504520
# TODO: In the ideal world, the script should simply check if the task can reach to the internet or not :)
505521
taskNetworkingAttachment=$(echo "${describedTaskJson}" | jq -r ".tasks[0].attachments[0]")
506522
taskVpcId=""

0 commit comments

Comments
 (0)