From Granting a User Permissions to Pass a Role to an AWS Service:
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:
To attach a managed policy (console)
Sign in to the AWS Management Console and open the IAM console at https://console.aws.amazon.com/iam/.
In the navigation pane, choose Policies.
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.
Choose Policy actions, and then choose Attach.
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)
Sign in to the AWS Management Console and open the IAM console at https://console.aws.amazon.com/iam/.
In the navigation pane, choose Users or Roles.
In the list, choose the name of the user or role to embed a policy in.
Choose the Permissions tab.
Scroll to the bottom of the page and choose Add inline policy.
Note
You cannot embed an inline policy in a 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 and choose Yes in the Service-Linked Role column for
your service.
Choose from the following methods to view the steps required to create your policy:
Import an Existing Managed Policy – 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 – 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 – 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.
After you create an inline policy, it is automatically embedded in your user or role.