Answers: <p>To create (and assign) IAM roles and permissions that user needs to have Administrator level rights within the AWS Account. You can search <code>admin</code> in <code>Attach existing policies directly</code> window in the Add permissions to &lt;&lt; user name >>` of the IAM Module accessible via the Console.</p>
  
  <p>From there look at the different levels of Administrator accounts offered by default and you can further look at the JSON provided examples to better understand the specific access rights you could begin to assign to lock down the user to only specific functions.</p>
  
  <p>Edit 2018-01-26
  From the AWS Console Page:
  - Click Services, type in IAM
  - From the IAM Console Click Users
  - Select the user then via the Permissions Tab, Click Add Permissions
  - Locate "AdministratorAccess"</p>
  
Answers: CC BY-SA 3.0
Answers: 2018-01-25T04:41:33.923Z
Answers: Could you specify the policy?
Answers: hawkeye
Answers: CC BY-SA 3.0
Answers: 2018-01-26T18:51:47.497Z
Answers: Please reference my edit for instructions on setting AdminstratorAccess.
Answers: Steven K7FAQ
Answers: CC BY-SA 3.0
Answers: 2018-01-26T18:53:23.343Z
Answers: Are you wanting your coworker to simply attach a role to an EC2 (for example) or are you wanting him/her to create roles to attach? Simply attaching possibly the other answer would be more appropriate. Creation of roles is another matter.
Answers: Steven K7FAQ
Answers: CC BY-SA 3.0
Answers: 2018-01-26T22:48:25.323Z
Answers: Just attaching - I’d prefer something more specific than administrator access.
Answers: hawkeye
Answers: CC BY-SA 3.0
Answers: 2018-01-17T23:27:28.740Z
Answers: 2018-01-26T18:49:53.793Z
Answers: 2018-01-26T18:49:53.793Z
Answers: Steven K7FAQ
Answers: <p>I hope you've figured it out yourself. In case you (or some other people) have that issue:</p>
  
  <p>The user that needs to attach / detach the instance profile to an instance needs:</p>
  
  <ul>
  <li>EC2 actions to perform that. That includes:</li>
  </ul>
  
  <pre><code>{
      "Sid": "InstanceProfileAccess",
      "Effect": "Allow",
      "Action": [
          "iam:GetInstanceProfile",
          "iam:ListInstanceProfiles",
          "iam:ListInstanceProfilesForRole",
          "iam:AddRoleToInstanceProfile",
          "iam:RemoveRoleFromInstanceProfile"
      ],
      "Resource": "*"
  }
  </code></pre>
  
  <ul>
  <li>The <code>passRole</code> action to pass the role to the specific resource.</li>
  </ul>
  
  <pre><code>{
      "Sid": "PassDefaultInstanceProfileToEC2",
      "Effect":"Allow",
      "Action":"iam:PassRole",
      "Resource":"arn:aws:iam::&lt;ID&gt;:role/&lt;ROLE_NAME&gt;"
  }
  </code></pre>
  
  <p>That user can gain access via policies or roles or group.
  I hope this helps.</p>
  
  <p>You can read more here:</p>
  
  <ul>
  <li><a href="https://aws.amazon.com/blogs/security/granting-permission-to-launch-ec2-instances-with-iam-roles-passrole-permission/" rel="nofollow noreferrer">Granting Permission to Launch EC2 Instances with IAM Roles</a>.</li>
  <li><a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2_instance-profiles.html" rel="nofollow noreferrer">Using Instance Profiles</a>.</li>
  <li><a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html" rel="nofollow noreferrer">IAM Roles for Amazon EC2</a>.</li>
  <li><a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_passrole.html" rel="nofollow noreferrer">Granting a User Permissions to Pass a Role to an AWS Service</a>.</li>
  </ul>
  
Answers: CC BY-SA 4.0
Answers: 2020-03-24T16:11:21.517Z
Answers: 2020-03-24T16:11:21.517Z
Answers: Viet
Answers: <p>From <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_passrole.html" rel="noreferrer">Granting a User Permissions to Pass a Role to an AWS Service</a>:</p>
  
  <blockquote>
    <p>To pass a role (and its permissions) to an AWS service, a user must
    have permissions to <em>pass the role</em> to the service. This helps
    administrators ensure that only approved users can configure a service
    with a role that grants permissions. To allow a user to pass a role to
    an AWS service, you must grant the <code>PassRole</code> permission to the user's
    IAM user, role, or group.</p>
    
    <p>When a user passes a role ARN as a parameter to any API that uses the
    role to assign permissions to the service, the service checks whether
    that user has the <code>iam:PassRole</code> permission. To limit the user to
    passing only approved roles, you can filter the <code>iam:PassRole</code>
    permission with the <code>Resources</code> element of the IAM policy statement.</p>
  </blockquote>
  
  <p>Is this what you're looking for? </p>
  
  <p>An example from the above-metioned page:</p>
  
  <blockquote>
    <p>Example 1</p>
    
    <p>Imagine that you want to grant a user the ability to pass any of an
    approved set of roles to the Amazon EC2 service upon launching an
    instance. You need three elements:</p>
    
    <ul>
    <li><p>An IAM <em>permissions policy</em> attached to the role that determines what the role can do. Scope permissions to only the actions that the role
    needs to perform, and to only the resources that the role needs for
    those actions. You can use AWS managed or customer-created IAM
    permissions policy.</p>
  
  <pre><code>{
      "Version": "2012-10-17",
      "Statement": {
          "Effect": "Allow",
          "Action": [ "A list of the permissions the role is allowed to use" ],
          "Resource": [ "A list of the resources the role is allowed to access" ]
      }
  } 
  </code></pre></li>
    <li><p>A <em>trust policy</em> for the role that allows the service to assume the role. For example, you could attach the following trust policy to the
    role with the <code>UpdateAssumeRolePolicy</code> action. This trust policy allows
    Amazon EC2 to use the role and the permissions attached to the role.</p>
  
  <pre><code>{
      "Version": "2012-10-17",
      "Statement": {
          "Sid": "TrustPolicyStatementThatAllowsEC2ServiceToAssumeTheAttachedRole",
          "Effect": "Allow",
          "Principal": { "Service": "ec2.amazonaws.com" },
         "Action": "sts:AssumeRole"
      }
  }       
  </code></pre></li>
    <li><p>An IAM <em>permissions policy</em> attached to the IAM user that allows the user to pass only those policies that are approved. <code>iam:PassRole</code>
    usually is accompanied by <code>iam:GetRole</code> so that the user can get the
    details of the role to be passed. In this example, the user can pass
    only roles that exist in the specified account with names that begin
    with <code>EC2-roles-for-XYZ-</code>:</p>
  
  <pre><code>{
      "Version": "2012-10-17",
      "Statement": [{
          "Effect": "Allow",
          "Action": [
              "iam:GetRole",
              "iam:PassRole"
          ],
          "Resource": "arn:aws:iam::&lt;account-id&gt;:role/EC2-roles-for-XYZ-*"
      }]
  }
  </code></pre></li>
    </ul>
    
    <p>Now the user can start an Amazon EC2 instance with an assigned role.
    Applications running on the instance can access temporary credentials
    for the role through the instance profile metadata. The permission
    policies attached to the role determine what the instance can do.</p>
  </blockquote>
  
  <p>The procedure(s) to attach a policy to a user/role (inlining it might work as well) are described in <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-attach-detach.html" rel="noreferrer">Attaching and Detaching IAM Policies</a>:</p>
  
  <blockquote>
    <p><strong>To attach a managed policy (console)</strong></p>
    
    <ol>
    <li><p>Sign in to the AWS Management Console and open the IAM console at <a href="https://console.aws.amazon.com/iam/" rel="noreferrer">https://console.aws.amazon.com/iam/</a>.</p></li>
    <li><p>In the navigation pane, choose <strong>Policies</strong>.</p></li>
    <li><p>In the list of policies, select the check box next to the name of the policy to attach. You can use the <strong>Filter</strong> menu and the search
    box to filter the list of policies.</p></li>
    <li><p>Choose <strong>Policy actions</strong>, and then choose <strong>Attach</strong>.</p></li>
    <li><p>Select one or more identities to attach the policy to. You can use the <strong>Filter</strong> menu and the search box to filter the list of principal
    entities. After selecting the identities, choose <strong>Attach policy</strong>.</p></li>
    </ol>
  </blockquote>
  
  <p>...</p>
  
  <blockquote>
    <p><strong>To embed an inline policy for a user or role (console)</strong></p>
    
    <ol>
    <li><p>Sign in to the AWS Management Console and open the IAM console at <a href="https://console.aws.amazon.com/iam/" rel="noreferrer">https://console.aws.amazon.com/iam/</a>.</p></li>
    <li><p>In the navigation pane, choose <strong>Users</strong> or <strong>Roles</strong>.</p></li>
    <li><p>In the list, choose the name of the user or role to embed a policy in.</p></li>
    <li><p>Choose the <strong>Permissions</strong> tab.</p></li>
    <li><p>Scroll to the bottom of the page and choose <strong>Add inline policy</strong>.</p>
    
    <p><strong>Note</strong></p>
    
    <p>You cannot embed an inline policy in a <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_terms-and-concepts.html#iam-term-service-linked-role" rel="noreferrer">service-linked role</a> in IAM. Because the linked service defines whether you can modify the
    permissions of the role, you might be able to add additional policies
    from the service console, API, or AWS CLI. To view the service-linked
    role documentation for a service, see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-services-that-work-with-iam.html" rel="noreferrer">AWS Services That Work with
    IAM</a> and choose <strong>Yes</strong> in the <strong>Service-Linked Role</strong> column for
    your service.</p></li>
    <li><p>Choose from the following methods to view the steps required to create your policy:</p>
    
    <ul>
    <li><p><a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html#access_policies_create-copy" rel="noreferrer">Import an Existing Managed Policy</a> – You can import a managed policy within your account and then edit the policy to customize it to
    your specific requirements. A managed policy can be an AWS managed
    policy or a customer managed policy that you created previously.</p></li>
    <li><p><a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html#access_policies_create-visual-editor" rel="noreferrer">Create a Policy with the Visual Editor</a> – You can construct a new policy from scratch in the visual editor. If you use the visual
    editor, you do not have to understand JSON syntax.</p></li>
    <li><p><a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html#access_policies_create-json-editor" rel="noreferrer">Create a Policy on the JSON Tab</a> – In the JSON tab, you can use <strong>JSON</strong> syntax to create a policy. You can type a new JSON policy document or paste an <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_examples.html" rel="noreferrer">example policy</a>.</p></li>
    </ul></li>
    <li><p>After you create an inline policy, it is automatically embedded in your user or role.</p></li>
    </ol>
  </blockquote>
  
Answers: CC BY-SA 3.0
Answers: 2018-01-17T23:45:00.280Z
Answers: Could you expand on the procedure to set this?
Answers: hawkeye
Answers: CC BY-SA 3.0
Answers: 2018-01-25T04:41:08.597Z
Answers: This is nice - but you haven’t said what the actual policy I need is.
Answers: hawkeye
Answers: CC BY-SA 3.0
Answers: 2018-01-26T01:39:00.770Z
Answers: I don't know of a managed one with `iam:PassRole`, you may need to create one (or more) - you need 3 according to the quotes.
Answers: Dan Cornilescu
Answers: CC BY-SA 3.0
Answers: 2018-01-17T22:39:00.873Z
Answers: 2018-01-18T03:55:40.463Z
Answers: 2018-01-18T03:55:40.463Z
Answers: Dan Cornilescu
Body: <p>My coworker is trying to attach IAM roles to EC2 instances and doesn’t have permissions. I’m trying to work out which permissions to give him.</p>
  
  <p>My question is: <strong>What is the AWS user permission that allows attaching and detaching IAM Roles to instances?</strong></p>
  
  <p><a href="https://i.sstatic.net/RqqKB.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/RqqKB.png" alt="enter image description here"></a></p>
  
Tags: <amazon-ec2><aws-iam>
Title: What is the AWS user permission that allows attaching and detaching IAM Roles to instances?
UserDisplayName: hawkeye
ThreadText: # What is the AWS user permission that allows attaching and detaching IAM Roles to instances?
  
  (Asked by: username_0 on 2018-01-17)
  
  My coworker is trying to attach IAM roles to EC2 instances and doesn’t have permissions. I’m trying to work out which permissions to give him.
  
  My question is: **What is the AWS user permission that allows attaching and detaching IAM Roles to instances?**
  
  [![enter image description here](https://i.sstatic.net/RqqKB.png)](https://i.sstatic.net/RqqKB.png)
  
  **Tags:** amazon-ec2, aws-iam
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_3 on 2018-01-17. Score: 5 | Accepted answer
  
  From [Granting a User Permissions to Pass a Role to an AWS Service](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_passrole.html):
  
  > To pass a role (and its permissions) to an AWS service, a user must
  > have permissions to *pass the role* to the service. This helps
  > administrators ensure that only approved users can configure a service
  > with a role that grants permissions. To allow a user to pass a role to
  > an AWS service, you must grant the `PassRole` permission to the user's
  > IAM user, role, or group.
  >
  > When a user passes a role ARN as a parameter to any API that uses the
  > role to assign permissions to the service, the service checks whether
  > that user has the `iam:PassRole` permission. To limit the user to
  > passing only approved roles, you can filter the `iam:PassRole`
  > permission with the `Resources` element of the IAM policy statement.
  
  Is this what you're looking for?
  
  An example from the above-metioned page:
  
  > Example 1
  >
  > Imagine that you want to grant a user the ability to pass any of an
  > approved set of roles to the Amazon EC2 service upon launching an
  > instance. You need three elements:
  >
  > * An IAM *permissions policy* attached to the role that determines what the role can do. Scope permissions to only the actions that the role
  >   needs to perform, and to only the resources that the role needs for
  >   those actions. You can use AWS managed or customer-created IAM
  >   permissions policy.
  >
  >   ```
  >   {
  >       "Version": "2012-10-17",
  >       "Statement": {
  >           "Effect": "Allow",
  >           "Action": [ "A list of the permissions the role is allowed to use" ],
  >           "Resource": [ "A list of the resources the role is allowed to access" ]
  >       }
  >   } 
  >
  >   ```
  > * A *trust policy* for the role that allows the service to assume the role. For example, you could attach the following trust policy to the
  >   role with the `UpdateAssumeRolePolicy` action. This trust policy allows
  >   Amazon EC2 to use the role and the permissions attached to the role.
  >
  >   ```
  >   {
  >       "Version": "2012-10-17",
  >       "Statement": {
  >           "Sid": "TrustPolicyStatementThatAllowsEC2ServiceToAssumeTheAttachedRole",
  >           "Effect": "Allow",
  >           "Principal": { "Service": "ec2.amazonaws.com" },
  >          "Action": "sts:AssumeRole"
  >       }
  >   }       
  >
  >   ```
  > * An IAM *permissions policy* attached to the IAM user that allows the user to pass only those policies that are approved. `iam:PassRole`
  >   usually is accompanied by `iam:GetRole` so that the user can get the
  >   details of the role to be passed. In this example, the user can pass
  >   only roles that exist in the specified account with names that begin
  >   with `EC2-roles-for-XYZ-`:
  >
  >   ```
  >   {
  >       "Version": "2012-10-17",
  >       "Statement": [{
  >           "Effect": "Allow",
  >           "Action": [
  >               "iam:GetRole",
  >               "iam:PassRole"
  >           ],
  >           "Resource": "arn:aws:iam::<account-id>:role/EC2-roles-for-XYZ-*"
  >       }]
  >   }
  >
  >   ```
  >
  > Now the user can start an Amazon EC2 instance with an assigned role.
  > Applications running on the instance can access temporary credentials
  > for the role through the instance profile metadata. The permission
  > policies attached to the role determine what the instance can do.
  
  The procedure(s) to attach a policy to a user/role (inlining it might work as well) are described in [Attaching and Detaching IAM Policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-attach-detach.html):
  
  > **To attach a managed policy (console)**
  >
  > 1. Sign in to the AWS Management Console and open the IAM console at <https://console.aws.amazon.com/iam/>.
  > 2. In the navigation pane, choose **Policies**.
  > 3. In the list of policies, select the check box next to the name of the policy to attach. You can use the **Filter** menu and the search
  >    box to filter the list of policies.
  > 4. Choose **Policy actions**, and then choose **Attach**.
  > 5. Select one or more identities to attach the policy to. You can use the **Filter** menu and the search box to filter the list of principal
  >    entities. After selecting the identities, choose **Attach policy**.
  
  ...
  
  > **To embed an inline policy for a user or role (console)**
  >
  > 1. Sign in to the AWS Management Console and open the IAM console at <https://console.aws.amazon.com/iam/>.
  > 2. In the navigation pane, choose **Users** or **Roles**.
  > 3. In the list, choose the name of the user or role to embed a policy in.
  > 4. Choose the **Permissions** tab.
  > 5. Scroll to the bottom of the page and choose **Add inline policy**.
  >
  >    **Note**
  >
  >    You cannot embed an inline policy in a [service-linked role](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_terms-and-concepts.html#iam-term-service-linked-role) in IAM. Because the linked service defines whether you can modify the
  >    permissions of the role, you might be able to add additional policies
  >    from the service console, API, or AWS CLI. To view the service-linked
  >    role documentation for a service, see [AWS Services That Work with
  >    IAM](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-services-that-work-with-iam.html) and choose **Yes** in the **Service-Linked Role** column for
  >    your service.
  > 6. Choose from the following methods to view the steps required to create your policy:
  >
  >    * [Import an Existing Managed Policy](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html#access_policies_create-copy) – You can import a managed policy within your account and then edit the policy to customize it to
  >      your specific requirements. A managed policy can be an AWS managed
  >      policy or a customer managed policy that you created previously.
  >    * [Create a Policy with the Visual Editor](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html#access_policies_create-visual-editor) – You can construct a new policy from scratch in the visual editor. If you use the visual
  >      editor, you do not have to understand JSON syntax.
  >    * [Create a Policy on the JSON Tab](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html#access_policies_create-json-editor) – In the JSON tab, you can use **JSON** syntax to create a policy. You can type a new JSON policy document or paste an [example policy](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_examples.html).
  > 7. After you create an inline policy, it is automatically embedded in your user or role.
  
  > **Comments:**
  > **username_0**: Could you expand on the procedure to set this?  
  > **username_0**: This is nice - but you haven’t said what the actual policy I need is.  
  > **username_3**: I don't know of a managed one with `iam:PassRole`, you may need to create one (or more) - you need 3 according to the quotes.  
  
  ---
  
  ### Answer by username_1 on 2018-01-17. Score: 1
  
  To create (and assign) IAM roles and permissions that user needs to have Administrator level rights within the AWS Account. You can search `admin` in `Attach existing policies directly` window in the Add permissions to << user name >>` of the IAM Module accessible via the Console.
  
  From there look at the different levels of Administrator accounts offered by default and you can further look at the JSON provided examples to better understand the specific access rights you could begin to assign to lock down the user to only specific functions.
  
  Edit 2018-01-26
  From the AWS Console Page:
  - Click Services, type in IAM
  - From the IAM Console Click Users
  - Select the user then via the Permissions Tab, Click Add Permissions
  - Locate "AdministratorAccess"
  
  > **Comments:**
  > **username_0**: Could you specify the policy?  
  > **username_1**: Please reference my edit for instructions on setting AdminstratorAccess.  
  > **username_1**: Are you wanting your coworker to simply attach a role to an EC2 (for example) or are you wanting him/her to create roles to attach? Simply attaching possibly the other answer would be more appropriate. Creation of roles is another matter.  
  > **username_0**: Just attaching - I’d prefer something more specific than administrator access.  
  
  ---
  
  ### Answer by username_2 on 2020-03-24. Score: 0
  
  I hope you've figured it out yourself. In case you (or some other people) have that issue:
  
  The user that needs to attach / detach the instance profile to an instance needs:
  
  * EC2 actions to perform that. That includes:
  
  ```
  {
      "Sid": "InstanceProfileAccess",
      "Effect": "Allow",
      "Action": [
          "iam:GetInstanceProfile",
          "iam:ListInstanceProfiles",
          "iam:ListInstanceProfilesForRole",
          "iam:AddRoleToInstanceProfile",
          "iam:RemoveRoleFromInstanceProfile"
      ],
      "Resource": "*"
  }
  
  ```
  
  * The `passRole` action to pass the role to the specific resource.
  
  ```
  {
      "Sid": "PassDefaultInstanceProfileToEC2",
      "Effect":"Allow",
      "Action":"iam:PassRole",
      "Resource":"arn:aws:iam::<ID>:role/<ROLE_NAME>"
  }
  
  ```
  
  That user can gain access via policies or roles or group.
  I hope this helps.
  
  You can read more here:
  
  * [Granting Permission to Launch EC2 Instances with IAM Roles](https://aws.amazon.com/blogs/security/granting-permission-to-launch-ec2-instances-with-iam-roles-passrole-permission/).
  * [Using Instance Profiles](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2_instance-profiles.html).
  * [IAM Roles for Amazon EC2](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html).
  * [Granting a User Permissions to Pass a Role to an AWS Service](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_passrole.html).
  
  
  ---
  
  