Skip to content

Commit ba1685f

Browse files
committed
add check for restartPolicy
1 parent b31bb8c commit ba1685f

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ This check item won't block you to use ECS Exec, but we recommend you to add the
115115
15. **_🔴 Read-Only Root Filesystem | ReadOnly_**
116116
ECS Exec uses the SSM agent as its managed agent, and the agents requires that the container file system is able to be written in order to create the required directories and files. Therefore, you need to set the `readonlyRootFilesystem` flag as `false` in your task definition to exec into the container using ECS Exec. 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.
117117

118+
16. **🟡 RestartPolicy : enabled**
119+
You cannot ECS Exec into the container after restarts now.
120+
118121
16. **_🔴 EC2 or Task Role | Not Configured"_ or _{serviceName}:{ActionName}: implicitDeny_**
119122
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.
120123
Note that the `Condition` element of the IAM policy is not currently supported to evaluate by `check-ecs-exec.sh`.

check-ecs-exec.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,27 @@ for enabled in $readonlyRootFsList; do
483483
idx=$((idx+1))
484484
done
485485

486-
# 9. Check the task role permissions
486+
# 9. Check if restartPolicy is set or not (Cannot exec into the container after the container restarts)
487+
restartPolicyList=$(echo "${taskDefJson}" | jq -r ".taskDefinition.containerDefinitions[].restartPolicy.enabled")
488+
idx=0
489+
490+
printf "${COLOR_DEFAULT} ----------\n"
491+
printf "${COLOR_DEFAULT} RestartPolicy (${taskDefFamily}:${taskDefRevision})\n"
492+
printf "${COLOR_DEFAULT} ----------\n"
493+
494+
for restartPolicy in $restartPolicyList; do
495+
containerName=$(echo "${taskDefJson}" | jq -r ".taskDefinition.containerDefinitions[${idx}].name")
496+
printf " $((idx+1)). "
497+
case "${restartPolicy}" in
498+
*false* ) printf "${COLOR_GREEN}Disabled";;
499+
*true* ) printf "${COLOR_YELLOW}Enabled";;
500+
* ) printf "${COLOR_GREEN}Disabled";;
501+
esac
502+
printf "${COLOR_DEFAULT} - \"${containerName}\"\n"
503+
idx=$((idx+1))
504+
done
505+
506+
# 10. Check the task role permissions
487507
overriddenTaskRole=true
488508
taskRoleArn=$(echo "${describedTaskJson}" | jq -r ".tasks[0].overrides.taskRoleArn")
489509
if [[ "${taskRoleArn}" = "null" ]]; then

0 commit comments

Comments
 (0)