How App Runner works with IAM - AWS App Runner

How App Runner works with IAM

Before you use IAM to manage access to AWS App Runner, you should understand what IAM features are available to use with App Runner. To get a high-level view of how App Runner and other AWS services work with IAM, see AWS Services That Work with IAM in the IAM User Guide.

For other App Runner security topics, see Security in App Runner.

App Runner identity-based policies

With IAM identity-based policies, you can specify allowed or denied actions and resources as well as the conditions under which actions are allowed or denied. App Runner supports specific actions, resources, and condition keys. To learn about all of the elements that you use in a JSON policy, see IAM JSON Policy Elements Reference in the IAM User Guide.

Actions

Administrators can use AWS JSON policies to specify who has access to what. That is, which principal can perform actions on what resources, and under what conditions.

The Action element of a JSON policy describes the actions that you can use to allow or deny access in a policy. Policy actions usually have the same name as the associated AWS API operation. There are some exceptions, such as permission-only actions that don't have a matching API operation. There are also some operations that require multiple actions in a policy. These additional actions are called dependent actions.

Include actions in a policy to grant permissions to perform the associated operation.

Policy actions in App Runner use the following prefix before the action: apprunner:. For example, to grant someone permission to run an Amazon EC2 instance with the Amazon EC2 RunInstances API operation, you include the ec2:RunInstances action in their policy. Policy statements must include either an Action or NotAction element. App Runner defines its own set of actions that describe tasks that you can perform with this service.

To specify multiple actions in a single statement, separate them with commas as follows:

"Action": [ "apprunner:CreateService", "apprunner:CreateConnection" ]

You can specify multiple actions using wildcards (*). For example, to specify all actions that begin with the word Describe, include the following action:

"Action": "apprunner:Describe*"

To see a list of App Runner actions, see Actions defined by AWS App Runner in the Service Authorization Reference.

Resources

Administrators can use AWS JSON policies to specify who has access to what. That is, which principal can perform actions on what resources, and under what conditions.

The Resource JSON policy element specifies the object or objects to which the action applies. Statements must include either a Resource or a NotResource element. As a best practice, specify a resource using its Amazon Resource Name (ARN). You can do this for actions that support a specific resource type, known as resource-level permissions.

For actions that don't support resource-level permissions, such as listing operations, use a wildcard (*) to indicate that the statement applies to all resources.

"Resource": "*"

App Runner resources have the following ARN structure:

arn:aws:apprunner:region:account-id:resource-type/resource-name[/resource-id]

For more information about the format of ARNs, see Amazon Resource Names (ARNs) and AWS Service Namespaces in the AWS General Reference.

For example, to specify the my-service service in your statement, use the following ARN:

"Resource": "arn:aws:apprunner:us-east-1:123456789012:service/my-service"

To specify all services that belong to a specific account, use the wildcard (*):

"Resource": "arn:aws:apprunner:us-east-1:123456789012:service/*"

Some App Runner actions, such as those for creating resources, cannot be performed on a specific resource. In those cases, you must use the wildcard (*).

"Resource": "*"

To see a list of App Runner resource types and their ARNs, see Resources defined by AWS App Runner in the Service Authorization Reference. To learn with which actions you can specify the ARN of each resource, see Actions defined by AWS App Runner.

Condition keys

Administrators can use AWS JSON policies to specify who has access to what. That is, which principal can perform actions on what resources, and under what conditions.

The Condition element (or Condition block) lets you specify conditions in which a statement is in effect. The Condition element is optional. You can create conditional expressions that use condition operators, such as equals or less than, to match the condition in the policy with values in the request.

If you specify multiple Condition elements in a statement, or multiple keys in a single Condition element, AWS evaluates them using a logical AND operation. If you specify multiple values for a single condition key, AWS evaluates the condition using a logical OR operation. All of the conditions must be met before the statement's permissions are granted.

You can also use placeholder variables when you specify conditions. For example, you can grant an IAM user permission to access a resource only if it is tagged with their IAM user name. For more information, see IAM policy elements: variables and tags in the IAM User Guide.

AWS supports global condition keys and service-specific condition keys. To see all AWS global condition keys, see AWS global condition context keys in the IAM User Guide.

App Runner supports using some global condition keys. To see all AWS global condition keys, see AWS Global Condition Context Keys in the IAM User Guide.

App Runner defines a set of service-specific condition keys. In addition, App Runner supports tag-based access control, which is implemented using condition keys. For details, see Authorization based on App Runner tags.

To see a list of App Runner condition keys, see Condition keys for AWS App Runner in the Service Authorization Reference. To learn with which actions and resources you can use a condition key, see Actions defined by AWS App Runner.

Examples

To view examples of App Runner identity-based policies, see App Runner identity-based policy examples.

App Runner resource-based policies

App Runner does not support resource-based policies.

Authorization based on App Runner tags

You can attach tags to App Runner resources or pass tags in a request to App Runner. To control access based on tags, you provide tag information in the condition element of a policy using the apprunner:ResourceTag/key-name, aws:RequestTag/key-name, or aws:TagKeys condition keys. For more information about tagging App Runner resources, see Configuring an App Runner service.

To view an example identity-based policy for limiting access to a resource based on the tags on that resource, see Controlling access to App Runner services based on tags.

App Runner user permissions

To use App Runner, IAM users need permissions to App Runner actions. A common way to grant permissions to users is by attaching a policy to IAM users or groups. For more information about managing user permissions, see Changing permissions for an IAM user in the IAM User Guide.

App Runner provides two managed policies that you can attach to your users.

  • AWSAppRunnerReadOnlyAccess – Grants permissions to list and view details about App Runner resources.

  • AWSAppRunnerFullAccess – Grants permissions to all App Runner actions.

For more granular control of user permissions, you can create a custom policy and attach it to your users. For details, see Creating IAM policies in the IAM User Guide.

For examples of user policies, see User policies.

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "apprunner:List*", "apprunner:Describe*" ], "Resource": "*" } ] }
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "iam:CreateServiceLinkedRole", "Resource": [ "arn:aws:iam::*:role/aws-service-role/apprunner.amazonaws.com/AWSServiceRoleForAppRunner", "arn:aws:iam::*:role/aws-service-role/networking.apprunner.amazonaws.com/AWSServiceRoleForAppRunnerNetworking" ], "Condition": { "StringLike": { "iam:AWSServiceName": [ "apprunner.amazonaws.com", "networking.apprunner.amazonaws.com" ] } } }, { "Effect": "Allow", "Action": "iam:PassRole", "Resource": "*", "Condition": { "StringLike": { "iam:PassedToService": "apprunner.amazonaws.com" } } }, { "Sid": "AppRunnerAdminAccess", "Effect": "Allow", "Action": "apprunner:*", "Resource": "*" } ] }

App Runner IAM roles

An IAM role is an entity within your AWS account that has specific permissions.

Service-linked roles

Service-linked roles allow AWS services to access resources in other services to complete an action on your behalf. Service-linked roles appear in your IAM account and are owned by the service. An IAM administrator can view but not edit the permissions for service-linked roles.

App Runner supports service-linked roles. For information about creating or managing App Runner service-linked roles, see Using service-linked roles for App Runner.

Service roles

This feature allows a service to assume a service role on your behalf. This role allows the service to access resources in other services to complete an action on your behalf. Service roles appear in your IAM account and are owned by the account. This means that an IAM user can change the permissions for this role. However, doing so might break the functionality of the service.

App Runner supports a few service roles.

Access role

The access role is a role that App Runner uses for accessing images in Amazon Elastic Container Registry (Amazon ECR) in your account. It's required to access an image in Amazon ECR, and isn't required with Amazon ECR Public. Before creating a service based on an image in Amazon ECR, use IAM to create a service role and use the AWSAppRunnerServicePolicyForECRAccess managed policy in it. You can then pass this role to App Runner when you call the CreateService API in the AuthenticationConfiguration member of the SourceConfiguration parameter, or when you use the App Runner console to create a service.

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ecr:GetDownloadUrlForLayer", "ecr:BatchCheckLayerAvailability", "ecr:BatchGetImage", "ecr:DescribeImages", "ecr:GetAuthorizationToken" ], "Resource": "*" } ] }
Note

If you create your own custom policy for your access role, be sure to specify "Resource": "*" for the ecr:GetAuthorizationToken action. Tokens can be used to access any Amazon ECR registry that you have access to.

When you create your access role, be sure to add a trust policy that declares the App Runner service principal build.apprunner.amazonaws.com as a trusted entity.

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "build.apprunner.amazonaws.com" }, "Action": "sts:AssumeRole" } ] }

If you use the App Runner console to create a service, the console can automatically create an access role for you and choose it for the new service. The console also lists other roles in your account, and you can select a different role if you like.

Instance role

The instance role is an optional role that App Runner uses to provide permissions to AWS service actions that your service's compute instances need. You need to provide an instance role to App Runner if your application code calls AWS actions (APIs). Either embed the required permissions in your instance role or create your own custom policy and use it in the instance role. We have no way to anticipate which calls your code uses. Therefore, we don't provide a managed policy for this purpose.

Before creating an App Runner service, use IAM to create a service role with the required custom or embedded policies. You can then pass this role to App Runner as the instance role when you call the CreateService API in the InstanceRoleArn member of the InstanceConfiguration parameter, or when you use the App Runner console to create a service.

When you create your instance role, be sure to add a trust policy that declares the App Runner service principal tasks.apprunner.amazonaws.com as a trusted entity.

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "tasks.apprunner.amazonaws.com" }, "Action": "sts:AssumeRole" } ] }

If you use the App Runner console to create a service, the console lists the roles in your account, and you can select the role that you created for this purpose.

For information about creating a service, see Creating an App Runner service.