# IAM Trust Policies

## Abusing Vulnerable Trust Policies

* Poorly written IAM Trust Policies can lead to compromise

***

## AWS Service Trust Policy

### Bad policy

* This policy allows the Lambda service in **any** AWS account to assume the role. An attacker only needs to know the ARN of the role

{% code overflow="wrap" %}

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
	  "AWS": "*",
	  "Service": "lambda.amazonaws.com"
	},
      "Action": "sts:AssumeRole"
    }
  ]
}
```

{% endcode %}

### Better policy

* The role assumption is restricted to a particular lambda function within a particular AWS account but [other conditions](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html) can be specified too

{% code overflow="wrap" %}

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "lambda.amazonaws.com"
      },
      "Action": "sts:AssumeRole",
      "Condition": {
        "ArnLike": {
          "aws:SourceArn": "arn:aws:lambda:<Region>:<AwsAccountId>:function:<LambdaFunction>"
        }
      }
    }
  ]
}
```

{% endcode %}

***

## Resources

{% embed url="<https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html>" %}

{% embed url="<https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_iam-condition-keys.html>" %}

{% embed url="<https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements.html>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.techwithtyler.dev/cloud-security/aws/aws-offensive-security/aws-privilege-escalation/attacks-techniques-and-tools.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
