All Products
Search
Document Center

ApsaraMQ for RocketMQ:Custom policies for ApsaraMQ for RocketMQ

Last Updated:Mar 10, 2026

When the predefined system policies for ApsaraMQ for RocketMQ do not meet your access control requirements, create custom Resource Access Management (RAM) policies to enforce least-privilege access at the instance, topic, or group level.

System policies vs. custom policies

RAM policies fall into two categories:

TypeCreated byEditableVersion control
System policiesAlibaba CloudNoNo
Custom policiesYouYesYes, through RAM version management

After you create a custom policy, attach it to a RAM user, RAM user group, or RAM role to grant the specified permissions. You can directly delete a custom policy that is not attached to any principal. To delete a custom policy that is attached to a principal, detach it first.

Actions and resource scope

The following table lists the actions available for ApsaraMQ for RocketMQ custom policies and the resource types each action applies to.

ActionDescriptionApplicable resource types
mq:QueryInstanceBaseInfoQuery instance detailsInstance
mq:PUBPublish messages to a topicTopic
mq:SUBSubscribe to messages from a topic or groupTopic, Group
mq:*All actionsAll

Resource ARN formats

ApsaraMQ for RocketMQ supports two resource scoping models depending on whether your instance uses namespaces. The scoping hierarchy from broadest to narrowest is: Instance > Topic/Group.

  • With namespaces -- Topics and groups are scoped to an instance. The instance ID is part of the topic and group ARN.

  • Without namespaces -- Topics and groups are globally scoped. The ARN contains only the topic or group name.

ResourceARN (with namespace)ARN (without namespace)
Instanceacs:mq:*:*:{instanceId}acs:mq:*:*:{instanceId}
Topicacs:mq:*:*:{instanceId}%{topic}acs:mq:*:*:{topic}
Groupacs:mq:*:*:{instanceId}%{groupId}acs:mq:*:*:{groupId}
All resources on an instanceacs:mq:*:*:{instanceId}*N/A
Important

Before you grant permissions on a topic or group, grant mq:QueryInstanceBaseInfo on the corresponding instance.

Create and apply a custom policy

  1. Create a custom policy in the RAM console. For detailed steps, see Create a custom policy.

  2. Attach the policy to a RAM user, RAM user group, or RAM role.

  3. Verify that the principal can access only the intended resources.

To use a custom policy, you must understand the permission management requirements of your business and the authorization information about ApsaraMQ for RocketMQ. For the full list of actions and resource definitions, see RAM authorization.

Policy examples

Important

The JSON examples below contain // comments for explanation only. Remove all comments before you use the code. JSON does not support inline comments.

Grant publish and subscribe permissions on a specific topic and group

This policy grants a RAM user permission to publish messages to and subscribe to messages from a specific topic and group on a single instance.

Replace the following placeholders with your values:

PlaceholderDescriptionExample
{instanceId}RocketMQ instance IDMQ_INST_abc123
{topic}Topic nameorder-topic
{groupId}Consumer group IDGID_order-consumer

Instances with namespaces:

{
    "Version": "1",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "mq:QueryInstanceBaseInfo"
            ],
            "Resource": [
                "acs:mq:*:*:{instanceId}"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "mq:PUB",
                "mq:SUB"
            ],
            "Resource": [
                "acs:mq:*:*:{instanceId}%{topic}"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "mq:SUB"
            ],
            "Resource": [
                "acs:mq:*:*:{instanceId}%{groupId}"
            ]
        }
    ]
}

The policy contains three statements:

  • Statement 1 -- Grants mq:QueryInstanceBaseInfo on the instance. Required before granting topic-level or group-level permissions.

  • Statement 2 -- Grants mq:PUB and mq:SUB on a specific topic, scoped to the instance by the {instanceId}%{topic} ARN format.

  • Statement 3 -- Grants mq:SUB on a specific group.

Instances without namespaces:

{
    "Version": "1",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "mq:QueryInstanceBaseInfo"
            ],
            "Resource": [
                "acs:mq:*:*:{instanceId}"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "mq:PUB",
                "mq:SUB"
            ],
            "Resource": [
                "acs:mq:*:*:{topic}"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "mq:SUB"
            ],
            "Resource": [
                "acs:mq:*:*:{groupId}"
            ]
        }
    ]
}

The difference: topic and group ARNs do not include the instance ID prefix. The resource field uses acs:mq:*:*:{topic} instead of acs:mq:*:*:{instanceId}%{topic}.

Grant full permissions on all resources of an instance

This policy grants all permissions on every resource (topics, groups) within a single instance. It applies only to instances with namespaces.

{
    "Version": "1",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "mq:*"
            ],
            "Resource": [
                "acs:mq:*:*:{instanceId}*"
            ]
        }
    ]
}

The wildcard * after {instanceId} matches all topics and groups on that instance. Replace {instanceId} with your instance ID.

References