AWS bedrock high security documentation change
Summary
Complete rewrite of API keys documentation: Added distinction between short-term and long-term keys, detailed generation methods for multiple languages, usage examples, auto-refresh mechanisms for short-term keys, compromised key handling procedures, and granular permission controls with IAM policy examples.
Security assessment
The changes explicitly address security best practices: 1) Discourages long-term keys in favor of short-term keys, 2) Adds procedures for handling compromised keys (deactivation/reset), 3) Introduces IAM condition keys (bedrock:bearerTokenType) to restrict key usage, 4) Provides security-focused policy examples to control key generation/usage. These directly mitigate risks of credential exposure and privilege escalation.
Diff
diff --git a/bedrock/latest/userguide/api-keys.md b/bedrock/latest/userguide/api-keys.md index eb4a43ac4..4f0f028a2 100644 --- a//bedrock/latest/userguide/api-keys.md +++ b//bedrock/latest/userguide/api-keys.md @@ -6,0 +7,2 @@ +Generate a short-term API keyGenerate a long-term API keyUse an API keyAuto-refresh short-term keysModify permissionsCompromised keysControl permissions + @@ -9 +11,8 @@ -You can easily make calls to the Amazon Bedrock API by generating an Amazon Bedrock API key and using it to authenticate your identity when making requests to the Amazon Bedrock API. +Amazon Bedrock API keys let you authenticate API requests using a bearer token instead of AWS credentials. There are two types: + + * **Short-term** – Lasts up to 12 hours (or the duration of your session, whichever is shorter). Inherits permissions from the IAM principal used to generate it. Recommended for production use. + + * **Long-term** – Lasts until a configured expiration date. Creates an IAM user with attached policies. Recommended only for exploration. + + + @@ -13 +22,32 @@ You can easily make calls to the Amazon Bedrock API by generating an Amazon Bedr -For audit and compliance purposes, all API calls are logged in AWS CloudTrail. Amazon Bedrock API keys are passed as authorization headers to API requests and aren’t logged. +All API calls are logged in AWS CloudTrail. API keys are passed as authorization headers and are not logged. + +## Generate a short-term API key + +Choose the tab for your preferred method, and then follow the steps: + +Console + + + 1. Sign in to the AWS Management Console with an IAM identity that has permissions to use the Amazon Bedrock console. Then, open the Amazon Bedrock console at [https://console.aws.amazon.com/bedrock](https://console.aws.amazon.com/bedrock). + + 2. In the left navigation pane, select **API keys**. + + 3. In the **Short-term API keys** tab, choose **Generate short-term API keys**. + + + + +The key expires when your console session expires (max 12 hours). To generate a key for a different Region, switch Regions in the console first. + +Python + + +Install the token generator: + + + pip install aws-bedrock-token-generator + +Generate a token: + + + from aws_bedrock_token_generator import provide_token @@ -15 +55,2 @@ For audit and compliance purposes, all API calls are logged in AWS CloudTrail. A -Amazon Bedrock API keys are limited to [Amazon Bedrock](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_Operations_Amazon_Bedrock.html) and [Amazon Bedrock Runtime](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_Operations_Amazon_Bedrock_Runtime.html) actions. You can't use them with the following API operations: + token = provide_token() + print(f"Token: {token}") @@ -17 +58 @@ Amazon Bedrock API keys are limited to [Amazon Bedrock](https://docs.aws.amazon. - * [InvokeModelWithBidirectionalStream](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModelWithBidirectionalStream.html). +Javascript @@ -19 +59,0 @@ Amazon Bedrock API keys are limited to [Amazon Bedrock](https://docs.aws.amazon. - * [Agents for Amazon Bedrock](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_Operations_Agents_for_Amazon_Bedrock.html) or [Agents for Amazon Bedrock Runtime](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_Operations_Agents_for_Amazon_Bedrock.html) API operations. @@ -21 +61 @@ Amazon Bedrock API keys are limited to [Amazon Bedrock](https://docs.aws.amazon. - * [Data Automation for Amazon Bedrock](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_Operations_Data_Automation_for_Amazon_Bedrock.html) or [Runtime for Amazon Bedrock Data Automation](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_Operations_Runtime_for_Amazon_Bedrock_Data_Automation) API operations. +Install the token generator: @@ -23,0 +64 @@ Amazon Bedrock API keys are limited to [Amazon Bedrock](https://docs.aws.amazon. + npm install @aws/bedrock-token-generator @@ -24,0 +66 @@ Amazon Bedrock API keys are limited to [Amazon Bedrock](https://docs.aws.amazon. +Generate a token: @@ -26 +67,0 @@ Amazon Bedrock API keys are limited to [Amazon Bedrock](https://docs.aws.amazon. -Amazon Bedrock allows you to generate the following kinds of Amazon Bedrock API keys: @@ -28 +69 @@ Amazon Bedrock allows you to generate the following kinds of Amazon Bedrock API - * **Short-term** – Create an Amazon Bedrock API key that lasts as long as your session (and no longer than 12 hours). You should already have an [IAM principal](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction_identity-management.html#intro-structure-terms) set up with the proper permissions to use Amazon Bedrock. This option is preferred over long-term keys for production environments that require regular changing of credentials for greater security. + import { getTokenProvider } from "@aws/bedrock-token-generator"; @@ -30 +71,3 @@ Amazon Bedrock allows you to generate the following kinds of Amazon Bedrock API -Short term keys have the following properties: + const provideToken = getTokenProvider(); + const token = await provideToken(); + console.log(`Bearer Token: ${token}`); @@ -32 +75 @@ Short term keys have the following properties: - * Valid for the shorter of the following values: +Java @@ -34 +76,0 @@ Short term keys have the following properties: - * 12 hours @@ -36 +78 @@ Short term keys have the following properties: - * The duration of the session generated by the IAM principal used to generate the key. +Add the dependency (Maven): @@ -38 +79,0 @@ Short term keys have the following properties: - * Inherit the permissions attached to the principal used to generate the key. @@ -40 +81,5 @@ Short term keys have the following properties: - * Can be used only in the AWS Region from which you generated it. + <dependency> + <groupId>software.amazon.bedrock</groupId> + <artifactId>aws-bedrock-token-generator</artifactId> + <version>1.1.0</version> + </dependency> @@ -42 +87,9 @@ Short term keys have the following properties: - * **Long-term** – Create an Amazon Bedrock API key with permissions to make basic API requests in Amazon Bedrock. This easy one-click option lets you quickly begin exploring the Amazon Bedrock API without needing to understand the underlying security infrastructure or manually configuring AWS Identity and Access Management permissions. If you're trying out Amazon Bedrock for the first time, you can try out the example at [Get started with Amazon Bedrock API keys: Generate a 30-day key and make your first API call](./getting-started-api-keys.html) for an easy tutorial to create a long-term key and get started using Amazon Bedrock. +Generate a token: + + + import software.amazon.bedrock.token.BedrockTokenGenerator; + + BedrockTokenGenerator tokenGenerator = BedrockTokenGenerator.builder().build(); + String token = tokenGenerator.getToken(); + +## Generate a long-term API key @@ -46 +99,169 @@ Short term keys have the following properties: -We strongly recommend restricting the use of Amazon Bedrock API keys for exploration of Amazon Bedrock. When you're ready to incorporate Amazon Bedrock into applications with greater security requirements, you should switch to short-term credentials. For more information, see [Alternatives to long-term access keys](https://docs.aws.amazon.com/IAM/latest/UserGuide/security-creds-programmatic-access.html#security-creds-alternatives-to-long-term-access-keys) in the IAM User Guide. +Long-term keys are for exploration only. For production, use short-term keys. For more information, see [Alternatives to long-term access keys](https://docs.aws.amazon.com/IAM/latest/UserGuide/security-creds-programmatic-access.html#security-creds-alternatives-to-long-term-access-keys). + +Choose the tab for your preferred method, and then follow the steps: + +Console + + + 1. Sign in to the AWS Management Console with an IAM identity that has permissions to use the Amazon Bedrock console. Then, open the Amazon Bedrock console at [https://console.aws.amazon.com/bedrock](https://console.aws.amazon.com/bedrock). + + 2. In the left navigation pane, select **API keys**. + + 3. In the **Long-term API keys** tab, choose **Generate long-term API keys**. + + 4. Choose an expiration time and optionally add permissions in **Advanced permissions**. + + 5. Choose **Generate**. + + + + +CLI + + + + # Create an IAM user + aws iam create-user --user-name bedrock-api-user + + # Attach permissions + aws iam attach-user-policy --user-name bedrock-api-user \ + --policy-arn arn:aws:iam::aws:policy/AmazonBedrockLimitedAccess + + # Generate the API key (replace NUMBER-OF-DAYS) + aws iam create-service-specific-credential \ + --user-name bedrock-api-user \ + --service-name bedrock.amazonaws.com \ + --credential-age-days ${NUMBER-OF-DAYS} + +The `ServiceApiKeyValue` in the response is your API key. + +Python + + + + import boto3 + + iam_client = boto3.client("iam") + + # Create IAM user + iam_client.create_user(UserName="bedrock-api-user") + + # Attach permissions + iam_client.attach_user_policy( + UserName="bedrock-api-user", + PolicyArn="arn:aws:iam::aws:policy/AmazonBedrockLimitedAccess" + ) + + # Generate API key + response = iam_client.create_service_specific_credential( + UserName="bedrock-api-user", + ServiceName="bedrock.amazonaws.com", + CredentialAgeDays=30 + ) + api_key = response["ServiceSpecificCredential"]["ServiceApiKeyValue"] + print(api_key) + +## Use an API key + +Set the key as an environment variable: + + + # macOS/Linux + export AWS_BEARER_TOKEN_BEDROCK=${api-key} + + # Windows + setx AWS_BEARER_TOKEN_BEDROCK "${api-key}" + +Or pass it directly in the `Authorization` header: + + + Authorization: Bearer ${api-key} + +###### Example: Make a Converse request + +choose the tab for your preferred method, and then follow the steps: + +cURL + + + + curl -X POST "https://bedrock-runtime.us-east-1.amazonaws.com/model/us.anthropic.claude-sonnet-4-6/converse" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $AWS_BEARER_TOKEN_BEDROCK" \ + -d '{