Skip to content

Commit f7d2155

Browse files
committed
Add task status check
1 parent 9b57462 commit f7d2155

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,26 +87,32 @@ Note that the `Condition` element of the IAM policy is not currently supported t
8787
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

90-
8. **_🔴 Platform Version | 1.3.0 (Required: >= 1.4.0)_**
90+
8. **_🔴 Task Status | DEACTIVATING or STOPPING or DEPROVISIONING or STOPPED_**
91+
Your ECS task has already stopped, or is shutting down. ECS Exec requires the task is in the `RUNNING` state. Restart your ECS task if it's a standalone task, or wait for another task if it's a part of an ECS service. See also [the Task lifecycle](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-lifecycle.html) in the ECS documentation for more details.
92+
93+
9. **_🟡 Task Status | PROVISIONING or ACTIVATING or PENDING_**
94+
Your ECS task is in the middle of its starting process. ECS Exec requires the task is in the `RUNNING` state. Wait few more seconds for the task to be ready. See also [the Task lifecycle](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-lifecycle.html) in the ECS documentation for more details.
95+
96+
10. **_🔴 Platform Version | 1.3.0 (Required: >= 1.4.0)_**
9197
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).
9298

93-
9. **_🔴 ECS Agent Version | x.y.z (Required: >= 1.50.2)_**
99+
11. **_🔴 ECS Agent Version | x.y.z (Required: >= 1.50.2)_**
94100
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.
95101

96-
10. **_🔴 Exec Enabled for Task | NO_**
102+
12. **_🔴 Exec Enabled for Task | NO_**
97103
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.
98104

99-
11. **_🔴 Managed Agent Status | STOPPED (Reason: stopped-reason-here)_**
105+
13. **_🔴 Managed Agent Status | STOPPED (Reason: stopped-reason-here)_**
100106
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.
101107

102-
12. **_🟡 Init Process Enabled | Disabled_**
108+
14. **_🟡 Init Process Enabled | Disabled_**
103109
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.
104110

105-
13. **_🔴 EC2 or Task Role | Not Configured"_ or _{serviceName}:{ActionName}: implicitDeny_**
111+
15. **_🔴 EC2 or Task Role | Not Configured"_ or _{serviceName}:{ActionName}: implicitDeny_**
106112
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.
107113
Note that the `Condition` element of the IAM policy is not currently supported to evaluate by `check-ecs-exec.sh`.
108114

109-
14. **_🟡 SSM PrivateLink "com.amazonaws.(region).ssmmessages" not found_**
115+
16. **_🟡 SSM PrivateLink "com.amazonaws.(region).ssmmessages" not found_**
110116
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.
111117

112118
## Security

check-ecs-exec.sh

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,20 @@ else
296296
fi
297297
printf "${ssmSessionEvalResult}\n"
298298

299-
# 3. Check the launch type, platform version, ecs-agent version
299+
# 3. Check the task is running
300+
printf "${COLOR_DEFAULT} Task Status | "
301+
taskStatus=$(echo "${describedTaskJson}" | jq -r ".tasks[0].lastStatus")
302+
stoppedReason=$(echo "${describedTaskJson}" | jq -r ".tasks[0].stoppedReason")
303+
case "${taskStatus}" in
304+
RUNNING ) printf "${COLOR_GREEN}${taskStatus}";;
305+
PROVISIONING|ACTIVATING|PENDING ) printf "${COLOR_YELLOW}${taskStatus}";;
306+
DEACTIVATING|STOPPING|DEPROVISIONING ) printf "${COLOR_RED}${taskStatus}";;
307+
STOPPED ) printf "${COLOR_RED}${taskStatus} (${stoppedReason})";;
308+
* ) printf "${COLOR_RED}${taskStatus}";;
309+
esac
310+
printf "${COLOR_DEFAULT}\n"
311+
312+
# 4. Check the launch type, platform version, ecs-agent version
300313
launchType=$(echo "${describedTaskJson}" | jq -r ".tasks[0].launchType")
301314
describedContainerInstanceJson=""
302315
printf "${COLOR_DEFAULT} Launch Type | "
@@ -333,7 +346,7 @@ else
333346
printf "${COLOR_YELLOW}UNKNOWN\n"
334347
fi
335348

336-
# 4. Check whether the `execute-command` option is enabled for the task
349+
# 5. Check whether the `execute-command` option is enabled for the task
337350
printf "${COLOR_DEFAULT} Exec Enabled for Task | "
338351
if [[ "x${executeCommandEnabled}" = "xtrue" ]]; then
339352
printf "${COLOR_GREEN}OK"
@@ -342,7 +355,7 @@ else
342355
fi
343356
printf "${COLOR_DEFAULT}\n"
344357

345-
# 5. Check the managed agents' status
358+
# 6. Check the managed agents' status
346359
printf "${COLOR_DEFAULT} Managed Agent Status | "
347360
if [[ "x${executeCommandEnabled}" = "xfalse" ]]; then
348361
printf "${COLOR_YELLOW}SKIPPED\n"
@@ -365,7 +378,7 @@ else
365378
done
366379
fi
367380

368-
# 6. Check the "initProcessEnabled" flag added in the task definition (yellow)
381+
# 7. Check the "initProcessEnabled" flag added in the task definition (yellow)
369382
taskDefArn=$(echo "${describedTaskJson}" | jq -r ".tasks[0].taskDefinitionArn")
370383
taskDefJson=$(${AWS_CLI_BIN} ecs describe-task-definition \
371384
--task-definition "${taskDefArn}" \
@@ -385,7 +398,7 @@ for enabled in $initEnabledList; do
385398
idx=$((idx+1))
386399
done
387400

388-
# 7. Check the task role permissions
401+
# 8. Check the task role permissions
389402
taskRoleArn=$(echo "${taskDefJson}" | jq -r ".taskDefinition.taskRoleArn")
390403

391404
hasRole=true
@@ -515,7 +528,7 @@ else
515528
fi
516529
fi
517530

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

0 commit comments

Comments
 (0)