Identity-based policy examples for Amazon Bedrock
By default, users and roles don't have permission to create or modify Amazon Bedrock resources. They also can't perform tasks by using the AWS Management Console, AWS Command Line Interface (AWS CLI), or AWS API. To grant users permission to perform actions on the resources that they need, an IAM administrator can create IAM policies. The administrator can then add the IAM policies to roles, and users can assume the roles.
To learn how to create an IAM identity-based policy by using these example JSON policy documents, see Create IAM policies (console) in the IAM User Guide.
For details about actions and resource types defined by Amazon Bedrock, including the format of the ARNs for each of the resource types, see Actions, Resources, and Condition Keys for Amazon Bedrock in the Service Authorization Reference.
Topics
- Policy best practices
- Use the Amazon Bedrock console
- Allow users to view their own permissions
- Allow access to third-party model subscriptions
- Deny access for inference on specific models
- Allow users to invoke a provisioned model
- Identity-based policy examples for Amazon Bedrock Agents
- Identity-based policy examples for Amazon Bedrock Studio
Policy best practices
Identity-based policies determine whether someone can create, access, or delete Amazon Bedrock resources in your account. These actions can incur costs for your AWS account. When you create or edit identity-based policies, follow these guidelines and recommendations:
-
Get started with AWS managed policies and move toward least-privilege permissions – To get started granting permissions to your users and workloads, use the AWS managed policies that grant permissions for many common use cases. They are available in your AWS account. We recommend that you reduce permissions further by defining AWS customer managed policies that are specific to your use cases. For more information, see AWS managed policies or AWS managed policies for job functions in the IAM User Guide.
-
Apply least-privilege permissions – When you set permissions with IAM policies, grant only the permissions required to perform a task. You do this by defining the actions that can be taken on specific resources under specific conditions, also known as least-privilege permissions. For more information about using IAM to apply permissions, see Policies and permissions in IAM in the IAM User Guide.
-
Use conditions in IAM policies to further restrict access – You can add a condition to your policies to limit access to actions and resources. For example, you can write a policy condition to specify that all requests must be sent using SSL. You can also use conditions to grant access to service actions if they are used through a specific AWS service, such as AWS CloudFormation. For more information, see IAM JSON policy elements: Condition in the IAM User Guide.
-
Use IAM Access Analyzer to validate your IAM policies to ensure secure and functional permissions – IAM Access Analyzer validates new and existing policies so that the policies adhere to the IAM policy language (JSON) and IAM best practices. IAM Access Analyzer provides more than 100 policy checks and actionable recommendations to help you author secure and functional policies. For more information, see Validate policies with IAM Access Analyzer in the IAM User Guide.
-
Require multi-factor authentication (MFA) – If you have a scenario that requires IAM users or a root user in your AWS account, turn on MFA for additional security. To require MFA when API operations are called, add MFA conditions to your policies. For more information, see Secure API access with MFA in the IAM User Guide.
For more information about best practices in IAM, see Security best practices in IAM in the IAM User Guide.
Use the Amazon Bedrock console
To access the Amazon Bedrock console, you must have a minimum set of permissions. These permissions must allow you to list and view details about the Amazon Bedrock resources in your AWS account. If you create an identity-based policy that is more restrictive than the minimum required permissions, the console won't function as intended for entities (users or roles) with that policy.
You don't need to allow minimum console permissions for users that are making calls only to the AWS CLI or the AWS API. Instead, allow access to only the actions that match the API operation that they're trying to perform.
To ensure that users and roles can still use the Amazon Bedrock console, also attach the Amazon Bedrock AmazonBedrockFullAccess or AmazonBedrockReadOnly AWS managed policy to the entities. For more information, see Adding permissions to a user in the IAM User Guide.
Allow users to view their own permissions
This example shows how you might create a policy that allows IAM users to view the inline and managed policies that are attached to their user identity. This policy includes permissions to complete this action on the console or programmatically using the AWS CLI or AWS API.
{ "Version": "2012-10-17", "Statement": [ { "Sid": "ViewOwnUserInfo", "Effect": "Allow", "Action": [ "iam:GetUserPolicy", "iam:ListGroupsForUser", "iam:ListAttachedUserPolicies", "iam:ListUserPolicies", "iam:GetUser" ], "Resource": ["arn:aws:iam::*:user/${aws:username}"] }, { "Sid": "NavigateInConsole", "Effect": "Allow", "Action": [ "iam:GetGroupPolicy", "iam:GetPolicyVersion", "iam:GetPolicy", "iam:ListAttachedGroupPolicies", "iam:ListGroupPolicies", "iam:ListPolicyVersions", "iam:ListPolicies", "iam:ListUsers" ], "Resource": "*" } ] }
Allow access to third-party model subscriptions
To access the Amazon Bedrock models for the first time, you use the Amazon Bedrock console to subscribe to third-party models. Your IAM user or role requires permission to access the subscription API operations.
For the aws-marketplace:Subscribe
action only, you can use the aws-marketplace:ProductId
condition key to restrict subscription to specific models. To see a list of product IDs and which
foundation models they correspond to, see the table in Grant IAM permissions to request access to
Amazon Bedrock foundation models.
Note
You can't remove request access from the Amazon Titan, Mistral AI, and Meta Llama 3 Instruct models. You can prevent users from making inference calls to these models by using an IAM policy and specifying the model ID. For more information, see Deny access for inference on specific models.
The following example shows an identity-based policy to allow a role to subscribe to the Amazon Bedrock foundation models listed in the Condition
field and to unsubscribe to and view subscriptions to foundation models:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "aws-marketplace:Subscribe" ], "Resource": "*", "Condition": { "ForAnyValue:StringEquals": { "aws-marketplace:ProductId": [ "1d288c71-65f9-489a-a3e2-9c7f4f6e6a85", "cc0bdd50-279a-40d8-829c-4009b77a1fcc", "c468b48a-84df-43a4-8c46-8870630108a7", "99d90be8-b43e-49b7-91e4-752f3866c8c7", "b0eb9475-3a2c-43d1-94d3-56756fd43737", "d0123e8d-50d6-4dba-8a26-3fed4899f388", "a61c46fe-1747-41aa-9af0-2e0ae8a9ce05", "216b69fd-07d5-4c7b-866b-936456d68311", "b7568428-a1ab-46d8-bab3-37def50f6f6a", "38e55671-c3fe-4a44-9783-3584906e7cad", "prod-ariujvyzvd2qy", "prod-2c2yc2s3guhqy", "prod-6dw3qvchef7zy", "prod-ozonys2hmmpeu", "prod-fm3feywmwerog", "prod-tukx4z3hrewle", "prod-nb4wqmplze2pm", "prod-m5ilt4siql27k", "prod-cx7ovbu5wex7g" ] } } }, { "Effect": "Allow", "Action": [ "aws-marketplace:Unsubscribe", "aws-marketplace:ViewSubscriptions" ], "Resource": "*" } ] }
Deny access for inference on specific models
To deny all inference access to a resource, such as a foundation model, you need to deny
access to the bedrock:InvokeModel
and
bedrock:InvokeModelWithResponseStream
actions. Doing this also denies access to
the resource through the Converse API actions (Converse and
ConverseStream).
The following example shows an identity-based policy that denies access to running inference on a specific model. For a list of model IDs, see Supported foundation models in Amazon Bedrock.
{ "Version": "2012-10-17", "Statement": { "Sid": "DenyInference", "Effect": "Deny", "Action": [ "bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream" ], "Resource": "arn:aws:bedrock:*::foundation-model/
model-id
" } }
Allow users to invoke a provisioned model
The following is a sample policy that you can attach to an IAM role to allow it to use a provisioned model in model inference. For example, you could attach this policy to a role that you want to only have permissions to use a provisioned model. The role won't be able to manage or see information about the Provisioned Throughput.
{ "Version": "2012-10-17", "Statement": [ { "Sid": "
ProvisionedThroughputModelInvocation
", "Effect": "Allow", "Action": [ "bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream" ], "Resource": "arn:aws:bedrock:aws-region
:111122223333
:provisioned-model/${my-provisioned-model}
" } ] }