All Products
Search
Document Center

MaxCompute:Authorization best practices

Last Updated:Jun 23, 2026

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 describes common use cases for permission management in MaxCompute.

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

    1. Create a new role.

      create role <role_name>;

      <role_name> is the name of the role.

    2. In the bin directory of the MaxCompute client, create a file named policy_1.json and 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.

    3. 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 format RAM$<parent_account_email>:<ram_user_name>.

    Use the console

    1. Log in to the MaxCompute console and select a region in the upper-left corner.

    2. In the left-side navigation pane, choose Manage Configurations > Projects.

    3. On the Projects page, click Manage in the Actions column for the target project.

    4. On the Project Settings page, click the Role Permissions tab.

    5. Click Create Project-level Role to create a project role with the required MaxCompute permissions.

    6. 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"}
    7. 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. The goal is to prevent specific users from deleting any table whose name starts with the prefix tb_.

  • Procedure:

    Use the MaxCompute client

    1. Create a new role.

      create role <role_name>;

      <role_name> is the name of the role.

    2. In the bin directory of the MaxCompute client, create a file named policy_2.json and 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.

    3. 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 format RAM$<parent_account_email>:<ram_user_name>.

    Use the console

    1. Log in to the MaxCompute console and select a region in the upper-left corner.

    2. In the left-side navigation pane, choose Manage Configurations > Projects.

    3. On the Projects page, click Manage in the Actions column for the target project.

    4. On the Project Settings page, click the Role Permissions tab.

    5. 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_*" }]
      }
    6. 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

Important
  • 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 perform CreateInstance, CreateTable, and List actions in the test_project project, only if the request is made before 23:59:59 on November 11, 2026 and originates from the IP address range 10.32.180.0/23. The user must also be denied permission to delete any table in that project.

    • Procedure:

      Use the MaxCompute client

      1. Create a new role.

        create role policy_3;
      2. In the bin directory of the MaxCompute client, create a file named policy_3.json and 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.

      3. 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

      1. Log in to the MaxCompute console and select a region in the upper-left corner.

      2. In the left-side navigation pane, choose Manage Configurations > Projects.

      3. On the Projects page, click Manage in the Actions column for the target project.

      4. On the Project Settings page, click the Role Permissions tab.

      5. 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/*"
        }]
        }
      6. 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. This analyst needs 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, add the tables to share to the package, and then allow the analysis project to install it. After the package is installed in the analysis project, grant permissions to the analyst. This approach reduces management overhead by removing the need to add the analyst to every production project, and it ensures that the analyst can only view the shared production tables from within the analysis project.

    This example demonstrates the workflow: a package named Package_test is created in a production project (Project_a). A production table (table_a) is added to this package. The package is 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:

    1. In the production project, create a package.

      USE Project_a;
      CREATE PACKAGE Package_test;
    2. In the production project, add the resource to share to the package.

      ADD table table_a TO PACKAGE Package_test;
    3. In the production project, allow the analysis project to install the package.

      ALLOW PROJECT Project_analyze TO INSTALL PACKAGE Package_test;
    4. In the analysis project, install the package.

      USE Project_analyze;
      INSTALL PACKAGE Project_a.Package_test;
    5. Grant the analyst read permission on the package.

      GRANT read on package Package_test TO USER ALIYUN$A*****@aliyunid.com;
    6. 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 business reasons. When these departments need to share data, they require a secure, fine-grained access control mechanism. This ensures that users in one account can only read 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 named Project_b. A RAM user from Account B, b_user1, read permission on tables t1 and t2 in Project_a. Another RAM user from Account B, b_user2, read permission on table t3 in Project_a.

    Important

    Although 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:

    1. In Project_a, use Alibaba Cloud Account A to create a package named a_to_b_pkg and add tables t1, t2, and t3 to 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;
    2. Allow project Project_b (owned by Account B) to install the a_to_b_pkg package.

      ALLOW PROJECT Project_b TO INSTALL PACKAGE a_to_b_pkg;
    3. In project Project_b, use Alibaba Cloud Account B to install the a_to_b_pkg package.

      INSTALL PACKAGE Project_a.a_to_b_pkg;
    4. 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_order in project ProjectA contains 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_order table contains a merchant ID column that can be used to filter data. While MaxCompute does not directly support row-level access control, implement this by creating a separate view for each merchant based on the table_order table. Then grant each merchant permissions to their corresponding view by using a package. This method effectively achieves row-level access control.

  • Procedure:

    1. 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.

    2. 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.

    3. 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.