Generic secrets store sensitive data such as passwords, AccessKey pairs, OAuth keys, and tokens in KMS. Multiple versions let you rotate values without hard-coding credentials.
Generic secret rotation
KMS does not support periodic rotation for generic secrets. To set up periodic rotation, use Use Function Compute to rotate a generic secret. To rotate immediately, store a new version in the console or call the PutSecretValue OpenAPI operation.
Each generic secret supports up to 10 versions. KMS automatically deletes the oldest version when this limit is exceeded.
Prerequisites
A KMS instance is created and enabled. For more information, see Purchase and enable a KMS instance.
A symmetric key has been created in the KMS instance to encrypt secrets. For detailed instructions, see Create a key.
Step 1: Create a secret
When you create a generic secret, KMS assigns the built-in stage label ACSCurrent to the initial version.
Log on to the Key Management Service console. In the top navigation bar, select a region. In the left-side navigation pane, choose .
Click the Generic Secrets tab, select an Instance ID, and then click Create Secret. Configure the parameters and click OK.
Parameter
Description
Secret Name
A custom credential name. Must be unique within the current region.
Secret Value
Select Secret Key/Value or Plain Text and enter the sensitive data to store. The value must be up to 30,720 bytes (30 KB) in length.
Initial Version
The initial version number. Default value: v1. Custom values are supported.
CMK
Select the symmetric key used to encrypt the credential value. The key and the credential must belong to the same KMS instance.
ImportantThe key and the credential must belong to the same KMS instance, and the key must be a symmetric key. For more information about the symmetric keys supported by KMS, see Key types and specifications.
If a RAM user or RAM role is used, it must have permissions to perform the GenerateDataKey operation using the encryption master key.
Description
An optional description of the credential for identification and management.
Set the access policy for the credential to control which RAM users or roles can read or modify it.
You can select the default policy first and modify it later as needed.
Step 2: Integrate the secret into your application
Retrieve generic secret values through the GetSecretValue OpenAPI or GetSecretValue KMS Instance API (not recommended). Select a method by priority:
We recommend that you implement an error retry mechanism to improve service stability.
KMS supports multiple authentication methods. For higher security, we recommend that you use an ECS instance RAM role or a RAM role.
Endpoints:
For a shared gateway, see Endpoints.
For a dedicated gateway, use the following format:
{Instance-ID}.cryptoservice.kms.aliyuncs.com.
Priority | Scenarios | Supported gateway types |
Priority 1: Secrets Client | Applications in Java 8+, Go, or Python. |
|
Priority 2: Alibaba Cloud SDK | Applications in Java 6+, PHP, Go, Python, .NET (C#), C++, or Node.js. |
|
Priority 3: KMS Agent |
|
|
Priority 4: KMS Instance SDK (not recommended) | Applications in Java 8+, PHP, Go, Python, or .NET (C#). | Dedicated gateway |
Additional operations
Rotate a generic secret
Rotation cannot be configured during secret creation. To rotate immediately, store a new version in the console or call the PutSecretValue OpenAPI operation.
Log on to the Key Management Service console. In the top navigation bar, select a region. In the left-side navigation pane, choose .
Click the Generic Secrets tab, select an Instance ID, find the target secret, and then click Details in the Actions column.
On the secret details page, in the Versions section, click Store Secret Value.
In the Store Secret Value dialog box, enter values for Version and Secret Value, and then click OK.
ImportantStoring a new version rotates the secret immediately. The GetSecretValue API returns the latest version by default.
Delete a generic secret
Delete a generic secret by scheduling deletion or removing it immediately.
Verify that the secret is no longer in use before deletion. Active references to a deleted secret may cause service failures.
Log on to the KMS console. In the top navigation bar, select the required region. In the left-side navigation pane, click Secrets.
Click the Generic Secrets tab, select an Instance ID, find the target secret, and then click Schedule Deletion in the Actions column.
In the Schedule Deletion dialog box, select a deletion method for the secret and click OK.
Schedule Deletion: Specify a recovery period of 7 to 30 days. The system deletes the secret after the recovery period ends.
Delete Immediately: The system immediately deletes the secret.
During the recovery period, you can find the secret and click Restore Secret in the Actions column to cancel the deletion.
Configure tags for secrets
Tags classify secrets as key-value pairs.
Format of a tag key and a tag value: A tag key or a tag value can be up to 128 characters in length and can contain letters, digits, forward slashes (/), backslashes (\), underscores (_), hyphens (-), periods (.), plus signs (+), equal signs (=), colons (:), at signs (@), and spaces.
A tag key cannot start with
aliyunoracs:.Each credential supports up to 20 tag key-value pairs.
Configure tags for a single secret
Method | Operation |
Method 1: Configure tags on the Secret Management page |
|
Method 2: Configure tags on the Secret Details page |
|
Configure tags for multiple secrets in a batch
Log on to the Key Management Service console. In the top navigation bar, select a region. In the left-side navigation pane, choose .
Click the tab for the secret type, select an Instance ID, and then select the secrets that you want to manage.
Add tags: At the bottom of the secret list, click Add Tag. Enter one or more Tag Key and Tag Value pairs, click OK, and then click Close.
Remove tags: At the bottom of the secret list, click Remove Tag. In the Batch Remove dialog box, select the tags that you want to detach, click Cancel, and then click Close.