How AWS WAF works with IAM - AWS WAF, AWS Firewall Manager, and AWS Shield Advanced

How AWS WAF works with IAM

This section explains how to use the features of IAM with AWS WAF.

Before you use IAM to manage access to AWS WAF, learn what IAM features are available to use with AWS WAF.

To get a high-level view of how AWS WAF and other AWS services work with most IAM features, see AWS services that work with IAM in the IAM User Guide.

Identity-based policies for AWS WAF

Supports identity-based policies: Yes

Identity-based policies are JSON permissions policy documents that you can attach to an identity, such as an IAM user, group of users, or role. These policies control what actions users and roles can perform, on which resources, and under what conditions. To learn how to create an identity-based policy, see Define custom IAM permissions with customer managed policies in the IAM User Guide.

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. You can't specify the principal in an identity-based policy because it applies to the user or role to which it is attached. To learn about all of the elements that you can use in a JSON policy, see IAM JSON policy elements reference in the IAM User Guide.

To view examples of AWS WAF identity-based policies, see Identity-based policy examples for AWS WAF.

Resource-based policies within AWS WAF

Supports resource-based policies: Yes

Resource-based policies are JSON policy documents that you attach to a resource. Examples of resource-based policies are IAM role trust policies and Amazon S3 bucket policies. In services that support resource-based policies, service administrators can use them to control access to a specific resource. For the resource where the policy is attached, the policy defines what actions a specified principal can perform on that resource and under what conditions. You must specify a principal in a resource-based policy. Principals can include accounts, users, roles, federated users, or AWS services.

To enable cross-account access, you can specify an entire account or IAM entities in another account as the principal in a resource-based policy. Adding a cross-account principal to a resource-based policy is only half of establishing the trust relationship. When the principal and the resource are in different AWS accounts, an IAM administrator in the trusted account must also grant the principal entity (user or role) permission to access the resource. They grant permission by attaching an identity-based policy to the entity. However, if a resource-based policy grants access to a principal in the same account, no additional identity-based policy is required. For more information, see Cross account resource access in IAM in the IAM User Guide.

AWS WAF uses resource based policies to support the sharing of rule groups across accounts. You share a rule group that you own with another AWS account by providing the resource-based policy settings to the AWS WAF API call PutPermissionPolicy or to an equivalent CLI or SDK call. For additional information, including examples and links to documentation for the other available languages, see PutPermissionPolicy in the AWS WAF API Reference. This functionality isn't available through other means, such as the console or AWS CloudFormation.

Policy actions for AWS WAF

Supports policy actions: Yes

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.

To see a list of AWS WAF actions and permissions for each, see Actions defined by AWS WAF V2 in the Service Authorization Reference.

Policy actions in AWS WAF use the following prefix before the action:

wafv2

To specify multiple actions in a single statement, separate them with commas.

"Action": [ "wafv2:action1", "wafv2:action2" ]

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

"Action": "wafv2:List*"

To view examples of AWS WAF identity-based policies, see Identity-based policy examples for AWS WAF.

Actions that require additional permissions settings

Some actions require permissions that can't be completely described in Actions defined by AWS WAF V2 in the Service Authorization Reference. This section provides additional permissions information.

Permissions for AssociateWebACL

This section lists the permissions required to associate a web ACL to a resource using the AWS WAF action AssociateWebACL.

For Amazon CloudFront distributions, instead of this action, use the CloudFront action UpdateDistribution. For information, see UpdateDistribution in the Amazon CloudFront API Reference.

Amazon API Gateway REST API

Requires permission to call API Gateway SetWebACL on the REST API resource type and to call AWS WAF AssociateWebACL on a web ACL.

{ "Sid": "AssociateWebACL1", "Effect": "Allow", "Action": [ "wafv2:AssociateWebACL" ], "Resource": [ "arn:aws:wafv2:region:account-id:regional/webacl/*/*" ] }, { "Sid": "AssociateWebACL2", "Effect": "Allow", "Action": [ "apigateway:SetWebACL" ], "Resource": [ "arn:aws:apigateway:*::/restapis/*/stages/*" ] }
Application Load Balancer

Requires permission to call elasticloadbalancing:SetWebACL action on the Application Load Balancer resource type and to call AWS WAF AssociateWebACL on a web ACL.

{ "Sid": "AssociateWebACL1", "Effect": "Allow", "Action": [ "wafv2:AssociateWebACL" ], "Resource": [ "arn:aws:wafv2:region:account-id:regional/webacl/*/*" ] }, { "Sid": "AssociateWebACL2", "Effect": "Allow", "Action": [ "elasticloadbalancing:SetWebACL" ], "Resource": [ "arn:aws:elasticloadbalancing:*:account-id:loadbalancer/app/*/*" ] }
AWS AppSync GraphQL API

Requires permission to call AWS AppSync SetWebACL on the GraphQL API resource type and to call AWS WAF AssociateWebACL on a web ACL.

{ "Sid": "AssociateWebACL1", "Effect": "Allow", "Action": [ "wafv2:AssociateWebACL" ], "Resource": [ "arn:aws:wafv2:region:account-id:regional/webacl/*/*" ] }, { "Sid": "AssociateWebACL2", "Effect": "Allow", "Action": [ "appsync:SetWebACL" ], "Resource": [ "arn:aws:appsync:*:account-id:apis/*" ] }
Amazon Cognito user pool

Requires permission to call the Amazon Cognito AssociateWebACL action on the user pool resource type and to call AWS WAF AssociateWebACL on a web ACL.

{ "Sid": "AssociateWebACL1", "Effect": "Allow", "Action": [ "wafv2:AssociateWebACL" ], "Resource": [ "arn:aws:wafv2:region:account-id:regional/webacl/*/*" ] }, { "Sid": "AssociateWebACL2", "Effect": "Allow", "Action": [ "cognito-idp:AssociateWebACL" ], "Resource": [ "arn:aws:cognito-idp:*:account-id:userpool/*" ] }
AWS App Runner service

Requires permission to call the App Runner AssociateWebACL action on the App Runner service resource type and to call AWS WAF AssociateWebACL on a web ACL.

{ "Sid": "AssociateWebACL1", "Effect": "Allow", "Action": [ "wafv2:AssociateWebACL" ], "Resource": [ "arn:aws:wafv2:region:account-id:regional/webacl/*/*" ] }, { "Sid": "AssociateWebACL2", "Effect": "Allow", "Action": [ "apprunner:AssociateWebAcl" ], "Resource": [ "arn:aws:apprunner:*:account-id:service/*/*" ] }
AWS Verified Access instance

Requires permission to call the ec2:AssociateVerifiedAccessInstanceWebAcl action on the Verified Access instance resource type and to call AWS WAF AssociateWebACL on a web ACL.

{ "Sid": "AssociateWebACL1", "Effect": "Allow", "Action": [ "wafv2:AssociateWebACL" ], "Resource": [ "arn:aws:wafv2:region:account-id:regional/webacl/*/*" ] }, { "Sid": "AssociateWebACL2", "Effect": "Allow", "Action": [ "ec2:AssociateVerifiedAccessInstanceWebAcl" ], "Resource": [ "arn:aws:ec2:*:account-id:verified-access-instance/*" ] }

Permissions for DisassociateWebACL

This section lists the permissions required to disassociate a web ACL from a resource using the AWS WAF action DisassociateWebACL.

For Amazon CloudFront distributions, instead of this action, use the CloudFront action UpdateDistribution with an empty web ACL ID. For information, see UpdateDistribution in the Amazon CloudFront API Reference.

Amazon API Gateway REST API

Requires permission to call API Gateway SetWebACL on the REST API resource type. Does not require permission to call AWS WAF DisassociateWebACL.

{ "Sid": "DisassociateWebACL", "Effect": "Allow", "Action": [ "apigateway:SetWebACL" ], "Resource": [ "arn:aws:apigateway:*::/restapis/*/stages/*" ] }
Application Load Balancer

Requires permission to call the elasticloadbalancing:SetWebACL action on the Application Load Balancer resource type. Does not require permission to call AWS WAF DisassociateWebACL.

{ "Sid": "DisassociateWebACL", "Effect": "Allow", "Action": [ "elasticloadbalancing:SetWebACL" ], "Resource": [ "arn:aws:elasticloadbalancing:*:account-id:loadbalancer/app/*/*" ] }
AWS AppSync GraphQL API

Requires permission to call AWS AppSync SetWebACL on the GraphQL API resource type. Does not require permission to call AWS WAF DisassociateWebACL.

{ "Sid": "DisassociateWebACL", "Effect": "Allow", "Action": [ "appsync:SetWebACL" ], "Resource": [ "arn:aws:appsync:*:account-id:apis/*" ] }
Amazon Cognito user pool

Requires permission to call the Amazon Cognito DisassociateWebACL action on the user pool resource type and to call AWS WAF DisassociateWebACL.

{ "Sid": "DisassociateWebACL1", "Effect": "Allow", "Action": "wafv2:DisassociateWebACL", "Resource": "*" }, { "Sid": "DisassociateWebACL2", "Effect": "Allow", "Action": [ "cognito-idp:DisassociateWebACL" ], "Resource": [ "arn:aws:cognito-idp:*:account-id:userpool/*" ] }
AWS App Runner service

Requires permission to call the App Runner DisassociateWebACL action on the App Runner service resource type and to call AWS WAF DisassociateWebACL.

{ "Sid": "DisassociateWebACL1", "Effect": "Allow", "Action": "wafv2:DisassociateWebACL", "Resource": "*" }, { "Sid": "DisassociateWebACL2", "Effect": "Allow", "Action": [ "apprunner:DisassociateWebAcl" ], "Resource": [ "arn:aws:apprunner:*:account-id:service/*/*" ] }
AWS Verified Access instance

Requires permission to call the ec2:DisassociateVerifiedAccessInstanceWebAcl action on the Verified Access instance resource type and to call AWS WAF DisassociateWebACL.

{ "Sid": "DisassociateWebACL1", "Effect": "Allow", "Action": "wafv2:DisassociateWebACL", "Resource": "*" }, { "Sid": "DisassociateWebACL2", "Effect": "Allow", "Action": [ "ec2:DisassociateVerifiedAccessInstanceWebAcl" ], "Resource": [ "arn:aws:ec2:*:account-id:verified-access-instance/*" ] }

Permissions for GetWebACLForResource

This section lists the permissions required to get the web ACL for a protected resource using the AWS WAF action GetWebACLForResource.

For Amazon CloudFront distributions, instead of this action, use the CloudFront action GetDistributionConfig. For information, see GetDistributionConfig in the Amazon CloudFront API Reference.

Note

GetWebACLForResource requires the permission to call GetWebACL. In this context, AWS WAF uses GetWebACL only to verify that your account has the permission it needs to access the web ACL that GetWebACLForResource returns. When you call GetWebACLForResource, you might get an error indicating that your account is not authorized to perform wafv2:GetWebACL on the resource. AWS WAF doesn't add this type of error to the AWS CloudTrail event history.

Amazon API Gateway REST API, Application Load Balancer, and AWS AppSync GraphQL API

Require permission to call AWS WAF GetWebACLForResource and GetWebACL for a web ACL.

{ "Sid": "GetWebACLForResource", "Effect": "Allow", "Action": [ "wafv2:GetWebACLForResource", "wafv2:GetWebACL" ], "Resource": [ "arn:aws:wafv2:region:account-id:regional/webacl/*/*" ] }
Amazon Cognito user pool

Requires permission to call the Amazon Cognito GetWebACLForResource action on the user pool resource type and to call AWS WAF GetWebACLForResource and GetWebACL.

{ "Sid": "GetWebACLForResource1", "Effect": "Allow", "Action": [ "wafv2:GetWebACLForResource", "wafv2:GetWebACL" ], "Resource": [ "arn:aws:wafv2:region:account-id:regional/webacl/*/*" ] }, { "Sid": "GetWebACLForResource2", "Effect": "Allow", "Action": [ "cognito-idp:GetWebACLForResource" ], "Resource": [ "arn:aws:cognito-idp:*:account-id:userpool/*" ] }
AWS App Runner service

Requires permission to call the App Runner DescribeWebAclForService action on the App Runner service resource type and to call AWS WAF GetWebACLForResource and GetWebACL.

{ "Sid": "GetWebACLForResource1", "Effect": "Allow", "Action": [ "wafv2:GetWebACLForResource", "wafv2:GetWebACL" ], "Resource": [ "arn:aws:wafv2:region:account-id:regional/webacl/*/*" ] }, { "Sid": "GetWebACLForResource2", "Effect": "Allow", "Action": [ "apprunner:DescribeWebAclForService" ], "Resource": [ "arn:aws:apprunner:*:account-id:service/*/*" ] }
AWS Verified Access instance

Requires permission to call the ec2:GetVerifiedAccessInstanceWebAcl action on the Verified Access instance resource type and to call AWS WAF GetWebACLForResource and GetWebACL.

{ "Sid": "GetWebACLForResource1", "Effect": "Allow", "Action": [ "wafv2:GetWebACLForResource", "wafv2:GetWebACL" ], "Resource": [ "arn:aws:wafv2:region:account-id:regional/webacl/*/*" ] }, { "Sid": "GetWebACLForResource2", "Effect": "Allow", "Action": [ "ec2:GetVerifiedAccessInstanceWebAcl" ], "Resource": [ "arn:aws:ec2:*:account-id:verified-access-instance/*" ] }

Permissions for ListResourcesForWebACL

This section lists the permissions required to retrieve the list of protected resources for a web ACL using the AWS WAF action ListResourcesForWebACL.

For Amazon CloudFront distributions, instead of this action, use the CloudFront action ListDistributionsByWebACLId. For information, see ListDistributionsByWebACLId in the Amazon CloudFront API Reference.

Amazon API Gateway REST API, Application Load Balancer, and AWS AppSync GraphQL API

Require permission to call AWS WAF ListResourcesForWebACL for a web ACL.

{ "Sid": "ListResourcesForWebACL", "Effect": "Allow", "Action": [ "wafv2:ListResourcesForWebACL" ], "Resource": [ "arn:aws:wafv2:region:account-id:regional/webacl/*/*" ] }
Amazon Cognito user pool

Requires permission to call the Amazon Cognito ListResourcesForWebACL action on the user pool resource type and to call AWS WAF ListResourcesForWebACL.

{ "Sid": "ListResourcesForWebACL1", "Effect": "Allow", "Action": [ "wafv2:ListResourcesForWebACL" ], "Resource": [ "arn:aws:wafv2:region:account-id:regional/webacl/*/*" ] }, { "Sid": "ListResourcesForWebACL2", "Effect": "Allow", "Action": [ "cognito-idp:ListResourcesForWebACL" ], "Resource": [ "arn:aws:cognito-idp:*:account-id:userpool/*" ] }
AWS App Runner service

Requires permission to call the App Runner ListAssociatedServicesForWebAcl action on the App Runner service resource type and to call AWS WAF ListResourcesForWebACL.

{ "Sid": "ListResourcesForWebACL1", "Effect": "Allow", "Action": [ "wafv2:ListResourcesForWebACL" ], "Resource": [ "arn:aws:wafv2:region:account-id:regional/webacl/*/*" ] }, { "Sid": "ListResourcesForWebACL2", "Effect": "Allow", "Action": [ "apprunner:ListAssociatedServicesForWebAcl" ], "Resource": [ "arn:aws:apprunner:*:account-id:service/*/*" ] }
AWS Verified Access instance

Requires permission to call the ec2:DescribeVerifiedAccessInstanceWebAclAssociations action on the Verified Access instance resource type and to call AWS WAF ListResourcesForWebACL.

{ "Sid": "ListResourcesForWebACL1", "Effect": "Allow", "Action": [ "wafv2:ListResourcesForWebACL" ], "Resource": [ "arn:aws:wafv2:region:account-id:regional/webacl/*/*" ] }, { "Sid": "ListResourcesForWebACL2", "Effect": "Allow", "Action": [ "ec2:DescribeVerifiedAccessInstanceWebAclAssociations" ], "Resource": [ "arn:aws:ec2:*:account-id:verified-access-instance/*" ] }

Policy resources for AWS WAF

Supports policy resources: Yes

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": "*"

To see the list of AWS WAF resource types and their ARNs, see Resources defined by AWS WAF V2 in the Service Authorization Reference. To learn with which actions you can specify the ARN of each resource, see Actions defined by AWS WAF V2. To allow or deny access to a subset of AWS WAF resources, include the ARN of the resource in the resource element of your policy.

The ARNs of AWS WAF wafv2 resources have the following format:

arn:partition:wafv2:region:account-id:scope/resource-type/resource-name/resource-id

For general information about ARN specifications, see Amazon Resource Names (ARNs) in the Amazon Web Services General Reference.

The following lists requirements that are specific to the ARNs of wafv2 resources:

  • region: For AWS WAF resources that you use to protect Amazon CloudFront distributions, set this to us-east-1. Otherwise, set this to the Region you're using with your protected regional resources.

  • scope: Set the scope to global for use with an Amazon CloudFront distribution or regional for use with any of the regional resources that AWS WAF supports. The regional resources are an Amazon API Gateway REST API, an Application Load Balancer, an AWS AppSync GraphQL API, an Amazon Cognito user pool, an AWS App Runner service, and an AWS Verified Access instance.

  • resource-type: Specify one of the following values: webacl, rulegroup, ipset, regexpatternset, or managedruleset.

  • resource-name: Specify the name that you gave the AWS WAF resource, or specify a wildcard (*) to indicate all resources that satisfy the other specifications in the ARN. You must either specify the resource name and resource ID or specify a wildcard for both.

  • resource-id: Specify the ID of the AWS WAF resource, or specify a wildcard (*) to indicate all resources that satisfy the other specifications in the ARN. You must either specify the resource name and resource ID or specify a wildcard for both.

For example, the following ARN specifies all web ACLs with regional scope for the account 111122223333 in Region us-west-1:

arn:aws:wafv2:us-west-1:111122223333:regional/webacl/*/*

The following ARN specifies the rule group named MyIPManagementRuleGroup with global scope for the account 111122223333 in Region us-east-1:

arn:aws:wafv2:us-east-1:111122223333:global/rulegroup/MyIPManagementRuleGroup/1111aaaa-bbbb-cccc-dddd-example-id

To view examples of AWS WAF identity-based policies, see Identity-based policy examples for AWS WAF.

Policy condition keys for AWS WAF

Supports service-specific policy condition keys: Yes

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.

In addition, AWS WAF supports the following condition keys that you can use to provide fine-grained filtering for your IAM policies:

  • wafv2:LogDestinationResource

    This condition key takes an Amazon Resource Name (ARN) specification for the logging destination. This is the ARN that you provide for the logging destination when you use the REST API call PutLoggingConfiguration.

    You can explicitly specify an ARN and you can specify filtering for the ARN. The following example specifies filtering for Amazon S3 bucket ARNs that have a specific location and prefix.

    "Condition": { "ArnLike": { "wafv2:LogDestinationResource": "arn:aws:s3:::aws-waf-logs-suffix/custom-prefix/*" } }
  • wafv2:LogScope

    This condition key defines the source of the logging configuration in a string. Currently, this is always set to the default of Customer, which indicates that the logging destination is owned and managed by you.

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

To view examples of AWS WAF identity-based policies, see Identity-based policy examples for AWS WAF.

ACLs in AWS WAF

Supports ACLs: No

Access control lists (ACLs) control which principals (account members, users, or roles) have permissions to access a resource. ACLs are similar to resource-based policies, although they do not use the JSON policy document format.

ABAC with AWS WAF

Supports ABAC (tags in policies): Partial

Attribute-based access control (ABAC) is an authorization strategy that defines permissions based on attributes. In AWS, these attributes are called tags. You can attach tags to IAM entities (users or roles) and to many AWS resources. Tagging entities and resources is the first step of ABAC. Then you design ABAC policies to allow operations when the principal's tag matches the tag on the resource that they are trying to access.

ABAC is helpful in environments that are growing rapidly and helps with situations where policy management becomes cumbersome.

To control access based on tags, you provide tag information in the condition element of a policy using the aws:ResourceTag/key-name, aws:RequestTag/key-name, or aws:TagKeys condition keys.

If a service supports all three condition keys for every resource type, then the value is Yes for the service. If a service supports all three condition keys for only some resource types, then the value is Partial.

For more information about ABAC, see Define permissions with ABAC authorization in the IAM User Guide. To view a tutorial with steps for setting up ABAC, see Use attribute-based access control (ABAC) in the IAM User Guide.

Using temporary credentials with AWS WAF

Supports temporary credentials: Yes

Some AWS services don't work when you sign in using temporary credentials. For additional information, including which AWS services work with temporary credentials, see AWS services that work with IAM in the IAM User Guide.

You are using temporary credentials if you sign in to the AWS Management Console using any method except a user name and password. For example, when you access AWS using your company's single sign-on (SSO) link, that process automatically creates temporary credentials. You also automatically create temporary credentials when you sign in to the console as a user and then switch roles. For more information about switching roles, see Switch from a user to an IAM role (console) in the IAM User Guide.

You can manually create temporary credentials using the AWS CLI or AWS API. You can then use those temporary credentials to access AWS. AWS recommends that you dynamically generate temporary credentials instead of using long-term access keys. For more information, see Temporary security credentials in IAM.

Forward access sessions for service AWS WAF

Supports forward access sessions (FAS): Yes

When you use an IAM user or role to perform actions in AWS, you are considered a principal. When you use some services, you might perform an action that then initiates another action in a different service. FAS uses the permissions of the principal calling an AWS service, combined with the requesting AWS service to make requests to downstream services. FAS requests are only made when a service receives a request that requires interactions with other AWS services or resources to complete. In this case, you must have permissions to perform both actions. For policy details when making FAS requests, see Forward access sessions.

Service roles for AWS WAF

Supports service roles: Yes

A service role is an IAM role that a service assumes to perform actions on your behalf. An IAM administrator can create, modify, and delete a service role from within IAM. For more information, see Create a role to delegate permissions to an AWS service in the IAM User Guide.

Warning

Changing the permissions for a service role might break AWS WAF functionality. Edit service roles only when AWS WAF provides guidance to do so.

Service-linked roles for AWS WAF

Supports service-linked roles: Yes

A service-linked role is a type of service role that is linked to an AWS service. The service can assume the role to perform an action on your behalf. Service-linked roles appear in your AWS account and are owned by the service. An IAM administrator can view, but not edit the permissions for service-linked roles.

For details about creating or managing AWS WAF service-linked roles, see Using service-linked roles for AWS WAF.