AI Gateway Secrets
When AI Gateway connects to large model services (such as Claude, GPT, and Gemini), you must configure an API key for each model for identity verification. Storing these keys in plaintext poses a leakage risk. When you create a key in AI Gateway, the system automatically hosts the API key in Key Management Service (KMS) Secrets Manager for encrypted storage. This eliminates plaintext risks and provides centralized management and fine-grained access control.
Overview
The AI Gateway feature of API Gateway supports connecting to multiple large model services. Each large model service requires an API Key or Token for identity verification. Storing these credentials in plaintext poses a leakage risk. KMS Secrets Manager provides the following security capabilities for this scenario:
-
No plaintext credentials: API Keys are stored in ciphertext in KMS and encrypted by a specified customer master key (CMK).
-
Unified multi-model management: Manage API Keys for multiple large models such as Claude, GPT, and Gemini through KMS, with centralized viewing and updating.
-
Version control: Each time the credential value is updated, a new version is automatically created, supporting version tracing.
-
Access control: Use RAM policies to finely control which services and users can read credential values.
When you create a key in the AI Gateway console, the system automatically creates a corresponding credential in the associated KMS instance. The credential is displayed on the Default Secrets tab in the KMS console and belongs to the Managed Cloud Products type. Managed credentials have their lifecycle managed by AI Gateway and do not support manual rotation or scheduled deletion.
Step 1: Create an encryption CMK
Create a symmetric customer master key (CMK) in the KMS console to encrypt the credentials hosted by AI Gateway.
Log on to the Key Management Service console. In the top navigation bar, select a region. In the left-side navigation pane, choose .
-
On the Keys page, click the Customer Master Keys tab, select the KMS instance from the Instance ID drop-down list, and click Create Key.
-
In the Create Key panel, configure the parameters, and then click OK.
Parameter
Description
Key Type
Select Symmetric Key.
Key Specifications
Select a key algorithm specification. We recommend that you use Aliyun_AES_256. For more information about key specifications, see Key management types and key specifications.
Key Usage
Select
ENCRYPT/DECRYPT.Key Alias
Enter a custom key alias for subsequent reference. The format is
alias/<alias>. We recommend that you use a name related to AI Gateway, such asai-gateway-cmk.Automatic Rotation
For more information, see key rotation.
Rotation Period
If rotation is enabled, set the key rotation interval based on your business requirements.
Step 2: Create a key in AI Gateway
When you create a key in the AI Gateway console, select KMS as the credential source and associate it with the KMS instance and CMK from Step 1.
-
Go to the AI Gateway console. In the left-side navigation pane, choose Key.
-
In the upper-left corner of the page, click Create key. On the Create Key page, configure the key parameters.
ImportantIf the service-linked role is not authorized, click Authorization to grant AI Gateway the service-linked role
AliyunServiceRoleForNativeApiGwInvokeKms. Reference: Service-linked roles.Parameter
Description
Key Name
The name of the key. The key name must be unique and can contain letters, digits, and underscores (_). The name can be up to 64 characters in length.
Credential Source
The storage location of the key. Default value: KMS.
Select Instance
Select the KMS instance where you created the CMK in Step 1.
Master Key
Select the symmetric encryption CMK that you created in Step 1.
Key Content
The credential information to be encrypted and stored. The information is synchronized to KMS and used as a secret resource.
-
Click OK to create the key.
Step 3: View AI Gateway keys
After the key is created in AI Gateway, the system automatically creates a managed secret in KMS. You can view the secret through the following methods:
-
View from AI Gateway
-
Go to the AI Gateway console. In the left-side navigation pane, choose Key.
-
In the Actions column of the target key, click Edit.
-
In the KMS Credential value section of the edit page, click View value to go to the secret details page (KMS console).
-
-
View from KMS
ImportantManaged secrets created by AI Gateway do not support manual rotation or scheduled deletion. To update the key content, delete the key in the AI Gateway console and create a new one.
Log on to the Key Management Service console. In the top navigation bar, select a region. In the left-side navigation pane, choose .
-
On the Customer-managed Secrets tab, select the KMS instance that you configured when creating the key in AI Gateway, and enter a secret name (
AI Gateway key name) as a search condition.NoteKMS automatically adds a prefix to the managed secret for AI Gateway. The format is
apig!${AI Gateway key name}.
FAQ
-
What is the relationship between AI Gateway keys and KMS secrets?
When you create a key in the AI Gateway console, the system automatically creates a corresponding managed secret through the associated KMS instance. The secret is displayed on the Default Secrets tab in the KMS console. Its lifecycle is managed by AI Gateway.
-
Why do AI Gateway managed secrets not support rotation and scheduled deletion?
Keys created by AI Gateway belong to the Managed Cloud Products type. Their lifecycle is uniformly managed by the AI Gateway service. Therefore, manual rotation (storing credential values) and scheduled deletion operations are not supported in the KMS console. To update the key content, delete the original key in the AI Gateway console and create a new one.
-
What type of CMK should I select?
The encryption CMK selected when creating a secret must be a symmetric key in the same KMS instance, such as Aliyun_AES_128, Aliyun_AES_192, Aliyun_AES_256, or Aliyun_SM4. Asymmetric keys are not supported.