Skip to content

Commit 1cdcfeb

Browse files
authored
Merge pull request #7 from aws-containers/add-ssm-startsession-check
Implement check for ssm:StartSession
2 parents 4401e82 + 0518e68 commit 1cdcfeb

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,27 @@ Note that the `Condition` element of the IAM policy is not currently supported t
8383
The IAM user/role you used for the `check-ecs-exec.sh` are not allowed to use the `kms:GenerateDataKey` API with the given KMS Key ID which you're using for the logging and auditing configuration for ECS exec. See the "[IAM permissions required for encryption using your own KMS customer master key (CMK)](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html#ecs-exec-logging) section under the "Logging and Auditing using ECS Exec" section in the official documenation to add the required permission to the IAM user/role.
8484
Note that the `Condition` element of the IAM policy is not currently supported to evaluate by `check-ecs-exec.sh`.
8585

86-
7. **_🔴 Platform Version | 1.3.0 (Required: >= 1.4.0)_**
86+
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.
88+
Note that the `Condition` element of the IAM policy is not currently supported to evaluate by `check-ecs-exec.sh`.
89+
90+
8. **_🔴 Platform Version | 1.3.0 (Required: >= 1.4.0)_**
8791
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).
8892

89-
8. **_🔴 ECS Agent Version | x.y.z (Required: >= 1.50.2)_**
93+
9. **_🔴 ECS Agent Version | x.y.z (Required: >= 1.50.2)_**
9094
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.
9195

92-
9. **_🔴 Exec Enabled for Task | NO_**
96+
10. **_🔴 Exec Enabled for Task | NO_**
9397
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.
9498

95-
10. **_🔴 Managed Agent Status | STOPPED (Reason: stopped-reason-here)_**
99+
11. **_🔴 Managed Agent Status | STOPPED (Reason: stopped-reason-here)_**
96100
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.
97101

98-
11. **_🔴 EC2 or Task Role | Not Configured"_ or _{serviceName}:{ActionName}: implicitDeny_**
102+
12. **_🔴 EC2 or Task Role | Not Configured"_ or _{serviceName}:{ActionName}: implicitDeny_**
99103
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.
100104
Note that the `Condition` element of the IAM policy is not currently supported to evaluate by `check-ecs-exec.sh`.
101105

102-
12. **_🟡 SSM PrivateLink "com.amazonaws.(region).ssmmessages" not found_**
106+
13. **_🟡 SSM PrivateLink "com.amazonaws.(region).ssmmessages" not found_**
103107
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.
104108

105109
## Security

check-ecs-exec.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,22 @@ if [[ ! "x${kmsKeyId}" = "xnull" ]]; then
250250
| jq -r ".EvaluationResults[0].EvalDecision")
251251
showEvalResult "${kmsGenerateDataKeyResult}" "${kmsGenerateDataKey}"
252252
fi
253+
## Check for ensuring "I cannot" call ssm:StartSession
254+
### 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
255+
ssmStartSession="ssm:StartSession"
256+
printf "${COLOR_DEFAULT} ${ssmStartSession} denied?: "
257+
ssmSessionEvalResult=$(${AWS_CLI_BIN} iam simulate-principal-policy \
258+
--policy-source-arn "${MY_IAM_ARN}" \
259+
--action-names "${ssmStartSession}" \
260+
--resource-arns "arn:aws:ecs:${AWS_REGION}:${ACCOUNT_ID}:task/${CLUSTER_NAME}/${TASK_ID}" \
261+
--output json \
262+
| jq -r ".EvaluationResults[0].EvalDecision")
263+
if [[ "x${ssmSessionEvalResult}" = "xallowed" ]]; then
264+
printf "${COLOR_YELLOW}"
265+
else
266+
printf "${COLOR_GREEN}"
267+
fi
268+
printf "${ssmSessionEvalResult}\n"
253269

254270
# 3. Check the launch type, platform version, ecs-agent version
255271
launchType=$(echo "${describedTaskJson}" | jq -r ".tasks[0].launchType")
@@ -314,7 +330,7 @@ else
314330
*STOPPED* ) printf "${COLOR_RED}STOPPED (Reason: ${reason})";;
315331
*PENDING* ) printf "${COLOR_YELLOW}PENDING";;
316332
* ) printf "${COLOR_GREEN}RUNNING";;
317-
esac
333+
esac
318334
printf "${COLOR_DEFAULT} for \"${containerName}\" container\n"
319335
idx=$((idx+1))
320336
done

0 commit comments

Comments
 (0)