Storage encryption
Simple Message Queue (formerly MNS) provides server-side encryption (SSE) that automatically encrypts message bodies at rest and decrypts them on read for queues and topics. The process is transparent to senders and receivers and requires no code changes, helping you meet data security and compliance requirements.
How it works
Simple Message Queue uses envelope encryption. The service encrypts message bodies by using a data encryption key (DEK), and then protects the DEK with a master key. When you send a message, the service automatically encrypts the message body before writing it to storage. When you receive, subscribe to, or consume a message, the service automatically decrypts the message body and returns the plaintext.
SSE-SMQ and SSE-KMS differ in who manages the master key: Simple Message Queue manages SSE-SMQ keys, while SSE-KMS uses a key that you manage in Key Management Service (KMS).
Supported algorithms
Algorithm | Description |
AES-256-GCM (default) | International standard authenticated encryption |
Encryption scope
Storage encryption only encrypts message bodies (MessageBody). Message attributes, system attributes (MessageId, EnqueueTime, and others), and queue or topic metadata are not encrypted.
Encryption schemes
Encryption scheme | Key manager | Use case | Cost |
SSE-SMQ (service-managed key) | Simple Message Queue | Quickly enable encryption without managing keys | Free |
SSE-KMS (customer-managed key) | User through KMS | Scenarios that require autonomous key control | KMS charges apply. MNS does not charge extra. For more information, see KMS billing. |
When you use SSE-KMS, MNS uses envelope encryption and caches data encryption keys (DEKs). The KMS API call rate is much lower than the message send and receive rate. For detailed billing information, see the KMS billing documentation.
Prerequisites
Submit a ticket to request access. Provide your primary account UID, resource name, and region in the ticket.
To use SSE-KMS, you must also meet the following conditions:
The KMS key must belong to the same account and region as the queue or topic.
The KMS key must be an AES-256 symmetric key (KMS KeySpec:
Aliyun_AES_256).Make sure that the service-linked role
AliyunMNSAccessingKMSRolehas permissions to access the specified KMS key, includingkms:GenerateDataKeyandkms:Decrypt. If the console displays an authorization prompt, follow the on-screen instructions to complete the service-linked role authorization.
Enable storage encryption
Enable through the console
Log on to the Simple Message Queue (formerly MNS) console.
In the left-side navigation pane, choose .
In the top menu bar, select a region.
Create a queue or edit an existing queue. In the Server-Side Encryption section, turn on the Enable Encryption switch, select an encryption scheme (SSE-SMQ or SSE-KMS), and then click OK.
If you select SSE-KMS, a Customer Master Key (CMK) drop-down list appears. Select a KMS key from the list. For other parameters, see Manage queues in the console.
The procedure for topics is the same as for queues. Navigate to to create or edit a topic.
Enable through APIs
You can configure storage encryption when you create a queue or modify queue attributes. The CreateTopic, SetTopicAttributes, and GetTopicAttributes operations for topics use the same encryption parameters.
Parameter | Description |
| Specifies whether to enable storage encryption. Valid values: |
| The encryption type. Valid values: |
| The encryption algorithm. Currently supports |
| The KMS key ID. Required only when |
Create an SSE-SMQ encrypted queue:
PUT /queues/{queueName} HTTP/1.1
<Queue>
<EnableSSE>true</EnableSSE>
<SSEType>SMQ</SSEType>
<SSEAlgorithm>AES-256-GCM</SSEAlgorithm>
</Queue>Create an SSE-KMS encrypted queue:
PUT /queues/{queueName} HTTP/1.1
<Queue>
<EnableSSE>true</EnableSSE>
<SSEType>KMS</SSEType>
<SSEAlgorithm>AES-256-GCM</SSEAlgorithm>
<KMSKeyId>key-xxx</KMSKeyId>
</Queue>Modify queue encryption settings:
PUT /queues/{queueName}?metaoverride=true HTTP/1.1
<Queue>
<EnableSSE>true</EnableSSE>
<SSEType>KMS</SSEType>
<SSEAlgorithm>AES-256-GCM</SSEAlgorithm>
<KMSKeyId>key-xxx</KMSKeyId>
</Queue>Disable queue encryption:
PUT /queues/{queueName}?metaoverride=true HTTP/1.1
<Queue>
<EnableSSE>false</EnableSSE>
</Queue>View encryption status
You can view the storage encryption status of a queue or topic in the console, or call GetQueueAttributes or GetTopicAttributes to view encryption fields.
The following is a response example:
HTTP/1.1 200 OK
<Queue>
<EnableSSE>true</EnableSSE>
<SSEType>KMS</SSEType>
<SSEAlgorithm>AES-256-GCM</SSEAlgorithm>
<KMSKeyId>key-xxx</KMSKeyId>
</Queue>Usage notes
You can enable or disable encryption and switch encryption types at any time. Configuration changes take effect immediately. New messages are processed according to the updated encryption policy.
Encryption applies only to newly written messages. Existing messages are not retroactively encrypted. After you disable encryption, previously encrypted messages can still be decrypted and read as long as the key is available.
A single queue can contain both plaintext and encrypted messages, for example, after you enable, disable, or switch encryption types.
Message body size limits are calculated based on the original size before encryption. Encryption introduces approximately 30 bytes of extra overhead, but this does not affect the maximum message body size available to you.
After you enable storage encryption, message send and receive operations incur additional performance overhead. The specific impact depends on message size, concurrency, and key cache hit rates.
When you use SSE-KMS, after KMS key rotation, new messages are encrypted with the new key version. Old messages can still be decrypted by KMS automatically using the old key version.
If you switch the resource configuration to a different
KMSKeyId, only new messages are encrypted with the new key. Historical messages still rely on the oldKMSKeyIdand encryption metadata recorded at write time. Retain the old key andkms:Decryptpermissions until old messages have all expired, been deleted, or are confirmed as no longer needed.After you switch
KMSKeyId, do not immediately disable or delete the old key. Old messages, old DLQ messages, or messages still in the delivery pipeline may still rely on the old key for decryption.
Cross-resource encryption
When topic messages are pushed to a queue through subscriptions, MNS decrypts the source topic message first, then writes it to the target queue according to the target queue's current storage encryption settings. If the target queue has SSE enabled, the message is re-encrypted with the target queue's encryption configuration. For HTTP and other non-queue push scenarios, the decrypted plaintext message body is returned.
When topic subscription messages are moved to a dead-letter queue (DLQ), they are processed according to the target DLQ's storage encryption settings.
When a queue's own messages are moved to a DLQ, the original message's encryption state and encryption metadata are preserved — the message is not re-encrypted even if the target DLQ has SSE enabled. To consume encrypted messages in a DLQ, the original message's corresponding KMS key must still be available.
Important
Disabling, scheduling deletion, or deleting a KMS key affects message sending and receiving and the ability to read already-encrypted messages.
Key disabled — New messages cannot be sent, and already-encrypted existing messages cannot be decrypted for reading. Re-enabling the key restores normal operations.
Key in PendingDeletion state — Behavior is the same as disabled. If the deletion process completes, data encrypted with that key becomes permanently unrecoverable.
Key deleted — Data encrypted with that key is permanently unrecoverable.
Service-linked role
AliyunMNSAccessingKMSRoledeleted or permissions revoked — SSE-KMS encryption and decryption requests fail due to insufficient permissions.
The following table lists common error codes related to storage encryption:
Error code | Common cause | Suggested action |
| SSE-KMS is enabled but | Configure a same-account, same-region AES-256 symmetric KMS key and try again. |
| The KMS key is disabled or in a state that does not allow encryption or decryption. | Enable the key in the KMS console. If the key is in PendingDeletion state, cancel the deletion first. |
| The | Verify the |
| The service-linked role lacks | Follow the console authorization prompt to fix |
| KMS is temporarily unavailable, throttled, or experiencing a network or internal error. | Try again later. If the issue persists, record the RequestId and contact technical support. |
| The encryption or decryption process failed. This may be related to key state, permissions, or abnormal message encryption metadata. | Check the key state and role permissions first. If the issue cannot be resolved, contact technical support with the RequestId, queue or topic name, and time range. |
FAQ
Do I need to modify my code after I enable encryption?
No. Encryption and decryption are performed transparently on the server side.
Can I switch encryption types?
Yes. New messages are processed with the new encryption type. Old messages can still be decrypted as long as the corresponding key is available.
How do I verify that encryption is active?
View the storage encryption status of the queue or topic in the console, or call GetQueueAttributes or GetTopicAttributes to check the EnableSSE, SSEType, SSEAlgorithm, and KMSKeyId fields.
How do I estimate SSE-KMS costs for KMS API calls?
SSE-KMS incurs KMS charges. MNS uses envelope encryption and caches DEKs, so the KMS API call rate is much lower than the message send and receive rate. For specific costs, see the KMS billing documentation.