Skip to content

Commit 071555e

Browse files
committed
Implement check for ssm:StartSession
1 parent 7eb24d8 commit 071555e

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

check-ecs-exec.sh

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

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

0 commit comments

Comments
 (0)