Authorization best practices
To protect data in a MaxCompute project, the project owner or an authorized user must manage member access following the principle of least privilege. This topic provides common permission management use cases.
Permission evaluation priority overview
-
Deny takes precedence over Allow.
-
Project Owner and Super_Administrator are not subject to any restrictions.
-
ACL authorization and Policy authorization are evaluated independently. A Condition only constrains the Policy it belongs to.
Policy-based access control use cases
Grant role permissions via a policy
-
Use case:
Grant a group of project members permissions to create tables, upload resources, create functions, and run tasks. Access is restricted to read-only for tables whose names start with the prefix
t_app_. -
Procedure:
Use the MaxCompute client
-
Create a new role.
create role <role_name>;<role_name> is the name of the role.
-
In the
bindirectory of the MaxCompute client, create a file namedpolicy_1.jsonand paste the following content into it:{ "Statement": [ { "Action": ["odps:List", "odps:CreateTable", "odps:CreateInstance", "odps:CreateResource", "odps:CreateFunction"], "Effect": "Allow", "Resource": ["acs:odps:*:projects/<project_name>"]}, { "Action": ["odps:*"], "Effect": "Allow", "Resource": [ "acs:odps:*:projects/<project_name>/tables/t_app_*", "acs:odps:*:projects/<project_name>/registration/functions/*", "acs:odps:*:projects/<project_name>/instances/*", "acs:odps:*:projects/<project_name>/resources/*"]}], "Version": "1"}<project_name> is the name of the MaxCompute project.
-
Apply the policy and grant the role.
-- Attach the policy to the new role. put policy policy_1.json on role <role_name>; -- Grant the role to the target user. grant <role_name> to <user_name>;<user_name> is the target user account. For an Alibaba Cloud account, use the format
ALIYUN$<account_email>. For a RAM user, use the formatRAM$<parent_account_email>:<ram_user_name>.
Use the console
-
Log in to the MaxCompute console and select a region in the upper-left corner.
-
In the left-side navigation pane, choose .
-
On the Projects page, click Manage in the Actions column for the target project.
-
On the Project Settings page, click the Role Permissions tab.
-
Click Create Project-level Role to create a project role with the required MaxCompute permissions.
-
In the Create Role dialog box, create a Resource-type role, enter a Role Name, and paste the policy content.
{ "Statement": [ { "Action": ["odps:List", "odps:CreateTable", "odps:CreateInstance", "odps:CreateResource", "odps:CreateFunction"], "Effect": "Allow", "Resource": ["acs:odps:*:projects/<project_name>"]}, { "Action": ["odps:*"], "Effect": "Allow", "Resource": [ "acs:odps:*:projects/<project_name>/tables/t_app_*", "acs:odps:*:projects/<project_name>/registration/functions/*", "acs:odps:*:projects/<project_name>/instances/*", "acs:odps:*:projects/<project_name>/resources/*"]}], "Version": "1"} -
Select the target project-level role and click Manage Members in the Actions column. Select the Alibaba Cloud account or RAM user you want to authorize, and click OK. If you cannot find the account when you first try to grant permissions, you can add it in the Add Member Manually section below.
-
Deny role permissions via a policy
-
Use case: Some tables are critical to the business and must be protected from accidental deletion. Specific users must be prevented from deleting any table whose name starts with the prefix
tb_. -
Procedure:
Use the MaxCompute client
-
Create a new role.
create role <role_name>;<role_name> is the name of the role.
-
In the
bindirectory of the MaxCompute client, create a file namedpolicy_2.jsonand paste the following content into it:{ "Version": "1", "Statement": [{ "Effect": "Deny", "Action": "odps:Drop", "Resource": "acs:odps:*:projects/<project_name>/tables/tb_*" }] }<project_name> is the name of the MaxCompute project.
-
Apply the policy and grant the role.
-- Attach the policy to the new role. put policy policy_2.json on role <role_name>; -- Grant the role to the target user. grant <role_name> to <user_name>;<user_name> is the target user account. For an Alibaba Cloud account, use the format
ALIYUN$<account_email>. For a RAM user, use the formatRAM$<parent_account_email>:<ram_user_name>.
Use the console
-
Log in to the MaxCompute console and select a region in the upper-left corner.
-
In the left-side navigation pane, choose .
-
On the Projects page, click Manage in the Actions column for the target project.
-
On the Project Settings page, click the Role Permissions tab.
-
In the Create Role dialog box, create a Resource-type role, enter a Role Name, and paste the policy content.
Enter the following policy content:
{ "Version": "1", "Statement": [{ "Effect": "Deny", "Action": "odps:Drop", "Resource": "acs:odps:*:projects/<project_name>/tables/tb_*" }] } -
Select the target project-level role and click Manage Members in the Actions column. Select the Alibaba Cloud account or RAM user you want to authorize, and click OK. If you cannot find the account when you first try to grant permissions, you can add it in the Add Member Manually section below.
-
Grant conditional permissions via a policy
-
A Condition in a Policy only constrains the permissions granted by that specific Policy. It does not affect permissions obtained through ACL (GRANT commands) or role inheritance.
-
If a user also has other unconditional permission sources (such as the admin role or direct ACL grants), the IP restriction in the Condition does not take effect.
-
Example 1:
-
Use case:
Grant a user (
a****@aliyunid.com) a set of permissions with specific conditions. The user can performCreateInstance,CreateTable, andListactions in the test_project project only if the request is made before23:59:59 on November 11, 2026and originates from the IP address range10.32.180.0/23. The user must also be denied permission to delete any table in that project. -
Procedure:
Use the MaxCompute client
-
Create a new role.
create role policy_3; -
In the
bindirectory of the MaxCompute client, create a file namedpolicy_3.jsonand paste the following content into it:{ "Version": "1", "Statement": [{ "Effect":"Allow", "Action":["odps:CreateTable","odps:CreateInstance","odps:List"], "Resource":"acs:odps:*:projects/<project_name>", "Condition":{ "DateLessThan": { "acs:CurrentTime":"2026-11-11T23:59:59Z" }, "IpAddress": { "acs:SourceIp":"10.32.180.0/23" } } }, { "Effect":"Deny", "Action":"odps:Drop", "Resource":"acs:odps:*:projects/<project_name>/tables/*" }] }<project_name> is the name of the MaxCompute project.
-
Apply the policy and grant the role.
-- Attach the policy to the new role. put policy policy_3.json on role policy_3; -- Grant the role to the target user. grant policy_3 to ALIYUN$a****@aliyunid.com;
Use the console
-
Log in to the MaxCompute console and select a region in the upper-left corner.
-
In the left-side navigation pane, choose .
-
On the Projects page, click Manage in the Actions column for the target project.
-
On the Project Settings page, click the Role Permissions tab.
-
In the Create Role dialog box, create a Resource-type role, enter a Role Name, and paste the policy content.
Enter the following policy content:
{ "Version": "1", "Statement": [{ "Effect":"Allow", "Action":["odps:CreateTable","odps:CreateInstance","odps:List"], "Resource":"acs:odps:*:projects/<project_name>", "Condition":{ "DateLessThan": { "acs:CurrentTime":"2026-11-11T23:59:59Z" }, "IpAddress": { "acs:SourceIp":"10.32.180.0/23" } } }, { "Effect":"Deny", "Action":"odps:Drop", "Resource":"acs:odps:*:projects/<project_name>/tables/*" }] } -
Select the target project-level role and click Manage Members in the Actions column. Select the Alibaba Cloud account or RAM user you want to authorize, and click OK. If you cannot find the account when you first try to grant permissions, you can add it in the Add Member Manually section below.
-
-
-
Example 2: Enforce IP access control via a Deny Policy
-
Use case:
Restrict specific users to access the project only from a designated IP range, regardless of how the users obtained their permissions.
-
Core approach:
Create a Deny Policy that rejects all requests from IP addresses outside the designated range. Because Deny takes precedence over
Allow, even if the user has permissions through ACL or other roles, access from a non-designated IP address is denied.
-
Policy content:
{ "Version": "1", "Statement": [{ "Effect": "Deny", "Action": "odps:*", "Resource": "acs:odps:*:projects/<project_name>/*", "Condition": { "NotIpAddress": { "acs:SourceIp": "10.32.180.0/23" } } }] }
-
Package authorization use cases
Cross-project resource sharing via a package
-
Use case:
A business analyst needs to view data in production tables without seeing the production task code, and requires access to a specific subset of tables from multiple production projects.
-
Solution:
Because the analyst must not see production tasks, create a separate project for analysis. In each production project, create a package containing the tables to share, then allow the analysis project to install it. After installation, grant permissions to the analyst. This approach eliminates the need to add the analyst to every production project and ensures that the analyst can only view the shared production tables from within the analysis project.
In this example, a
packagenamedPackage_testis created in a production project (Project_a). A productiontable(table_a) is added to thispackage. Thepackageis then installed in an analysis project (Project_analyze), and a user (A*****@aliyunid.com) is granted permission to query the table through the package. -
Procedure:
-
In the production project, create a package.
USE Project_a; CREATE PACKAGE Package_test; -
In the production project, add the resource to share to the package.
ADD table table_a TO PACKAGE Package_test; -
In the production project, allow the analysis project to install the package.
ALLOW PROJECT Project_analyze TO INSTALL PACKAGE Package_test; -
In the analysis project, install the package.
USE Project_analyze; INSTALL PACKAGE Project_a.Package_test; -
Grant the analyst read permission on the package.
GRANT read on package Package_test TO USER ALIYUN$A*****@aliyunid.com; -
The analyst can now query data from the table.
select * from Project_a.table_a;
-
Cross-account resource sharing via a package
-
Use case
Within a single enterprise, different departments may use separate Alibaba Cloud accounts to manage their MaxCompute resources for billing or organizational reasons. When these departments need to share data, they require a secure, fine-grained access control mechanism that allows users in one account to read only specific tables from another account, enforcing the principle of least privilege.
Note-
A RAM user from one Alibaba Cloud account cannot be added to a MaxCompute project owned by another. For example, Account A cannot add a RAM user from Account B to a project it owns.
-
To grant only read permissions on a table, resource, or function, use a package to share the resource across projects that belong to different Alibaba Cloud accounts.
-
-
Solution
Assume two Alibaba Cloud accounts exist, Account A and Account B. Account A owns a project named
Project_a, and Account B owns a project namedProject_b. A RAM user from Account B,b_user1, needs read permission on tablest1andt2inProject_a. Another RAM user from Account B,b_user2, needs read permission on tablet3inProject_a.ImportantAlthough data can be shared between different Alibaba Cloud accounts by using authorization, tasks in DataWorks workspaces that belong to different Alibaba Cloud accounts cannot communicate with each other. This means it is not possible to configure scheduling dependencies between these tasks.
-
Procedure:
-
In
Project_a, use Alibaba Cloud Account A to create a package nameda_to_b_pkgand add tablest1,t2, andt3to the package.USE Project_a; CREATE PACKAGE a_to_b_pkg; ADD table t1 TO PACKAGE a_to_b_pkg; ADD table t2 TO PACKAGE a_to_b_pkg; ADD table t3 TO PACKAGE a_to_b_pkg; -
Allow project Project_b (owned by Account B) to install the
a_to_b_pkgpackage.ALLOW PROJECT Project_b TO INSTALL PACKAGE a_to_b_pkg; -
In project Project_b, use Alibaba Cloud Account B to install the
a_to_b_pkgpackage.INSTALL PACKAGE Project_a.a_to_b_pkg; -
Grant the RAM users from Account B permissions on the tables in the package.
add user ram$B:b_user1; add user ram$B:b_user2; GRANT Describe , Select ON TABLE t1 TO USER ram$B:b_user1 PRIVILEGEPROPERTIES ("refobject" = "true", "refproject"="project_a", "package"="project_a.a_to_b_pkg");--Grant read permissions on table t1 to b_user1 GRANT Describe , Select ON TABLE t2 TO USER ram$B:b_user1 PRIVILEGEPROPERTIES ("refobject" = "true", "refproject"="project_a", "package"="project_a.a_to_b_pkg");--Grant read permissions on table t2 to b_user1 GRANT Describe , Select ON TABLE t3 TO USER ram$B:b_user2 PRIVILEGEPROPERTIES ("refobject" = "true", "refproject"="project_a", "package"="project_a.a_to_b_pkg");--Grant read permissions on table t3 to b_user2
-
Row-level access control via a package
-
Use case:
A table named
table_orderin projectProjectAcontains order information for all merchants. This table must be shared with the merchants, but each merchant must only be able to see the orders corresponding to their own store. -
Solution:
The
table_ordertable contains a merchant ID column that can be used to filter data. Although MaxCompute does not directly support row-level access control, you can achieve it by creating a separate view for each merchant based on thetable_ordertable, then granting each merchant permissions to their corresponding view through a package. -
Procedure:
-
In ProjectA, create a dedicated view for each merchant.
CREATE VIEW <viewname> as select * from table_order WHERE sellerid='xxxx';<viewname> is the name of the view to create.
-
In ProjectA, create a package and share the view with the merchant.
create package <packagename>; add table <viewname> to package <packagename>; allow project <Projectname_seller> to install package <packagename>;<packagename> is the name of the package. <Projectname_seller> is the name of the merchant's MaxCompute project.
-
The merchant installs the package in their project and queries the view.
USE <Projectname_seller>; install package <ProjectA>.<packagename>; grant read on package <ProjectA>.<packagename> to user <username>; select * from <ProjectA>.<viewname>;<username> is the user in the merchant's project who needs to query the view.
-