Secret Key Management
Credential leaks are a major data security threat. Use key encryption, credential hosting, rotation, and access control to protect general keys and cloud account keys.
Credential leaks — including database passwords, server passwords, SSH keys, and access keys — are among the top threats to data security. In a cloud environment, keys fall into two categories: general keys (database and server passwords, SSH keys) and cloud account keys (RAM AccessKey/SecretKey). Effective protection measures include key encryption, credential hosting (dynamically retrieving keys as credentials), credential rotation, access control, and auditing. Common unsafe practices include:
-
Storing key plaintext in code;
-
Directly using AccessKey/SecretKey;
-
AccessKey/SecretKey is not rotated regularly.
Best Practices
Enable KMS and Configure Managed Keys and Credentials
Alibaba Cloud provides Key Management Service for key protection, offering encrypted storage, regular rotation, secure distribution, and centralized management through Credential Management. This helps applications avoid storing credentials in plaintext and supports rotation to reduce the impact of credential leaks.
The following figure shows a standard credential management workflow:

-
An administrator configures the username and password necessary for MyApp to access the target database.
-
The administrator creates a credential object named MyDbCreds in KMS to encrypt and store the above-mentioned username and password.
-
When MyApp needs to access the database, it requests the credential MyDbCreds from KMS.
-
KMS reads the stored encrypted credential and decrypts it, then returns the plaintext to MyApp via HTTPS.
-
MyApp reads and parses the decrypted credential returned by KMS, obtains the username and password, and uses this account to access the target database.
To enable KMS and configure managed keys and credentials:
-
Activate and Manage KMS instances.
-
After you activate KMS, follow the standard steps for key protection: create a common credential, enter the credential value (the key plaintext), and select the master key to encrypt it (the master key is generated by KMS or imported by you and handles data encryption within KMS). Then use the KMS SDK or API to call the credential from your application.
-
Protect RAM keys (AccessKey/SecretKey) by using credential management to manage and use RAM secrets without configuring AccessKey in the application. Install the RAM credential plugin so the application can securely retrieve managed keys.
Use Credential Rotation to Improve Key Security Level
Regularly rotate keys stored in KMS to strengthen the security of sensitive information. KMS supports different rotation schemes based on the type of stored key: generic credentials or RAM credentials.
-
Alibaba Cloud supports rotating generic credentials using Function Compute.
-
RAM credentials, ECS, and RDS credentials support automatic rotation.
Set Access Control Policies for Key Access
To prevent unauthorized access, restrict who can access keys and under what conditions. In cloud environments, limit the authorization scope and authorized identities for key access.
-
Use RAM to implement access control for KMS resources.
-
Use KMS application access points to implement access control for application access to KMS.
-
Application access points let you control which credentials are granted to specific applications and define access network and authentication rules for fine-grained authorization.
Enable Security Auditing for Key Usage
Security auditing for KMS supports post-event tracing and compliance verification. Use ActionTrail to query KMS operation events and view supported audit events of KMS.