# Sub-Account Data Permission Management

This document describes how a primary account configures data permissions for sub-accounts to control the data scope that sub-accounts can view and operate on each Astraflow feature page.

Sub-accounts that already have project permissions can still view all API Keys under the project and their associated data by default, without needing re-authorization. Only configure according to this document when you need to restrict a sub-account's data scope or when you need to use the "Share API Key" feature.

# Scope of Application

Astraflow's data permissions are based on API Key granularity and apply to the following three pages:

| **Page** | **Content Controlled by Data Permissions** |
|----------|-------------------------------------------|
| API Key Management | API Key list, API Key details, sharing relationships |
| Model Logs | Invocation logs generated by each API Key, log analysis tasks |
| Model Monitoring | Invocation volume, Token, latency, cache, and other monitoring metrics generated by each API Key |

Each page's data permissions are controlled by their respective APIs. The policy templates provided in this document already include all interfaces for the three pages. When using the templates directly, the API Keys visible to the sub-account in API Key Management will determine the data shown in Model Logs and Model Monitoring.

If you need to customize policies, please configure the interfaces for each page separately according to the [API Permission Comparison: "All" vs "My" Data](api-permission-comparison.md), and keep the data scope consistent across pages.

> Whether a page can be entered is controlled by [Page Access Permission](page-access-permission.md). Data permissions are configured separately from page access permissions, and both must be satisfied. A sub-account needs both page access permission and data permission to view the corresponding data.

# Data Permission Description

### "All" vs "My"

The API Key Management page is divided into "All" and "My" views based on data scope:

- **All**: All API Keys under the current project.
- **My**: API Keys created by the current account under the current project, and API Keys shared to the current account by other accounts.


The primary account can configure data permissions for sub-accounts according to the following table:

| **Configuration Goal** | **Visible Scope in API Key Management** | **Permitted Operations** |
|------------------------|----------------------------------------|--------------------------|
| Manage all API Keys under the project | "All" and "My" | Create, edit, delete any API Key in the project, share and manage sharing relationships |
| Manage only own created and shared API Keys | Only "My", "All" not shown | Own created API Keys can be created, edited, deleted, shared; shared API Keys are view-only |

### API Key Sharing

- API Keys can be shared with **sub-accounts within the same project**.
- The recipient can view the API Key and its data in Model Logs, Model Monitoring, and Consumer Center, but cannot edit, delete, or share it again.
- Existing API Keys are uniformly owned by the primary account, with the creator displayed as "root". The primary account can share existing keys to sub-accounts to make them visible (API key plaintext is not displayed). API Keys created after the new version goes live will record the actual creator.

# Operation Guide

For the meaning of interfaces in each scenario, see [API Permission Comparison: "All" vs "My" Data](api-permission-comparison.md).

## General Step: Create Share Object Query Policy (Global Level)

In the following three scenarios, if you need to use the "Share API Key" feature, you must first create this policy. The share dialog needs to list sub-accounts in the same project, which depends on interfaces such as `iam:ListUsers`; **without this policy, the share dialog cannot list selectable sub-accounts.**

1. Go to **Access Control > Policy Management**, and click **Create Custom Policy**.
2. Fill in the policy name as `Astraflow-APIKey-ShareUserList`, and the policy description as "Allow selecting sub-accounts in the same project when sharing API Keys".
3. Select **Global Level** for the policy level, select **Script Edit** for the edit mode, paste the following script, and save.

```plain
{
  "Version": "1",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "label:ListLabelsByResourceIds"
      ],
      "Resource": [
        "*"
      ],
      "Condition": {}
    },
    {
      "Effect": "Allow",
      "Action": [
        "iam:ListUsers",
        "iam:ListEntitiesForProject"
      ],
      "Resource": [
        "*"
      ],
      "Condition": {}
    }
  ]
}
```

> **Global Policy Impact Scope**: Astraflow shares the account and access control system with UCloud. Global-level policies take effect across the entire UCloud primary account scope, not distinguishing projects; interfaces such as `iam:ListUsers` and `label:ListLabelsByResourceIds` may also apply to other UCloud products that call the same interfaces. Please confirm the impact scope before authorizing, and only grant to sub-accounts who genuinely need sharing. This policy itself does not grant permission to view other sub-accounts' API Keys.

## Scenario A: Grant Only API Key Sharing Permission

### Create Project-Level Policy

1. In the Astraflow console, click **Account and Permission Management** in the account menu at the top right.


2. Go to **Access Control > Policy Management**, and click **Create Custom Policy**.


3. Fill in the policy name and description. Suggested name and description: Astraflow-APIKey-ShareProjectKey, policy description: Sub-account can share the current project's API Keys to sub-accounts in the same project.
4. Select **Project Level** for the policy level, select **Script Edit** for the edit mode, paste the following script, and save.

```plain
{
  "Version": "1",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "uai_modelverse:AddUMInferAPIKeyShareUsersProject",
        "uai_modelverse:DeleteUMInferAPIKeyShareUsersProject",
        "uai_modelverse:ListUMInferAPIKeyShareUsersProject"
      ],
      "Resource": [
        "*"
      ],
      "Condition": {}
    }
  ]
}
```

### Bind to Sub-Account

1. Go to **Access Control > User Management**, and click **Add Permission** in the operation column of the target sub-account.
2. Select both `Astraflow-APIKey-ShareProjectKey` and `Astraflow-APIKey-ShareUserList`.
3. Select **Specified Project** for the project-level policy and save.

## Scenario B: Sub-Account Manages All API Keys Under the Project

**Applicable Scenario**: The sub-account needs to manage all API Keys within the project and view the data generated by all API Keys in Model Logs and Model Monitoring.

### Permission Effect

After configuration, the sub-account in the target project:

- The API Key Management page shows both "All" and "My" views.
- Can view all API Keys under the project, and can create, batch create, edit, batch update, and delete any API Key in the project.
- Can share API Keys to sub-accounts in the same project and manage sharing relationships.
- Model Logs and Model Monitoring show data generated by all API Keys under the project.

### Configuration Steps

#### (1) Create Project-Level Policy

1. In the Astraflow console, click **Account and Permission Management** in the account menu at the top right.
2. Go to **Access Control > Policy Management**, and click **Create Custom Policy**.
3. Fill in the policy name and description. Suggested name and description: Astraflow-APIKey-ProjectFullAccess, policy description: Sub-account can manage all API Keys under the project.
4. Select **Project Level** for the policy level, select **Script Edit** for the edit mode.
5. Paste the script and save.

```plain
{
  "Version": "1",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "uai_modelverse:AddUMInferAPIKeyShareUsers",
        "uai_modelverse:AddUMInferAPIKeyShareUsersProject",
        "uai_modelverse:BatchCreateUMInferAPIKey",
        "uai_modelverse:BatchUpdateUMInferAPIKey",
        "uai_modelverse:BatchUpdateUMInferUserAPIKey",
        "uai_modelverse:CancelLogAnalysisJob",
        "uai_modelverse:CancelUMInferExportTask",
        "uai_modelverse:CancelUMInferUserExportTask",
        "uai_modelverse:CancelUserLogAnalysisJob",
        "uai_modelverse:CheckLogAnalysisLogCount",
        "uai_modelverse:CheckUMInferAPIKeyQuotaAlertContact",
        "uai_modelverse:CheckUserLogAnalysisLogCount",
        "uai_modelverse:CreateLogAnalysisJob",
        "uai_modelverse:CreateUMInferAPIKey",
        "uai_modelverse:CreateUserLogAnalysisJob",
        "uai_modelverse:DeleteUMInferAPIKey",
        "uai_modelverse:DeleteUMInferAPIKeyShareUsers",
        "uai_modelverse:DeleteUMInferAPIKeyShareUsersProject",
        "uai_modelverse:DownloadUMInferExportTask",
        "uai_modelverse:DownloadUMInferUserExportTask",
        "uai_modelverse:GetLogAnalysisJob",
        "uai_modelverse:GetLogAnalysisReport",
        "uai_modelverse:GetUMInferAPIKeyPlaintext",
        "uai_modelverse:GetUMInferLog",
        "uai_modelverse:GetUMInferLogPermissionStatus",
        "uai_modelverse:GetUMInferPlaintext",
        "uai_modelverse:GetUMInferRequestLogDetail",
        "uai_modelverse:GetUMInferUserLog",
        "uai_modelverse:GetUMInferUserRequestLogDetail",
        "uai_modelverse:GetUMMonitorBasicMetrics",
        "uai_modelverse:GetUMMonitorCacheMetrics",
        "uai_modelverse:GetUMMonitorLatencyMetrics",
        "uai_modelverse:GetUMMonitorModelMetrics",
        "uai_modelverse:GetUMMonitorThroughputMetrics",
        "uai_modelverse:GetUMMonitorTokenMetrics",
        "uai_modelverse:GetUMMonitorUserBasicMetrics",
        "uai_modelverse:GetUMMonitorUserCacheMetrics",
        "uai_modelverse:GetUMMonitorUserLatencyMetrics",
        "uai_modelverse:GetUMMonitorUserModelMetrics",
        "uai_modelverse:GetUMMonitorUserThroughputMetrics",
        "uai_modelverse:GetUMMonitorUserTokenMetrics",
        "uai_modelverse:GetUserLogAnalysisJob",
        "uai_modelverse:GetUserLogAnalysisReport",
        "uai_modelverse:ListLogAnalysisJobs",
        "uai_modelverse:ListUMInferAPIKey",
        "uai_modelverse:ListUMInferAPIKeyShareUsers",
        "uai_modelverse:ListUMInferAPIKeyShareUsersProject",
        "uai_modelverse:ListUMInferAPIKeyTags",
        "uai_modelverse:ListUMInferAPIKeyV2",
        "uai_modelverse:ListUMInferExportTasks",
        "uai_modelverse:ListUMInferExportUserTasks",
        "uai_modelverse:ListUMInferRequestLogModels",
        "uai_modelverse:ListUMInferRequestLogs",
        "uai_modelverse:ListUMInferUserRequestLogModels",
        "uai_modelverse:ListUMInferUserRequestLogs",
        "uai_modelverse:ListUMInferUserShareAPIKey",
        "uai_modelverse:ListUserLogAnalysisJobs",
        "uai_modelverse:RemoveUMInferApikeys",
        "uai_modelverse:RemoveUMInferUserAPIKeys",
        "uai_modelverse:RestartLogAnalysisJob",
        "uai_modelverse:RestartUMInferExportTask",
        "uai_modelverse:RestartUMInferUserExportTask",
        "uai_modelverse:RestartUserLogAnalysisJob",
        "uai_modelverse:SendUMInferAPIKeyQuotaAlertVerifyCode",
        "uai_modelverse:UpdateUMInferAPIKey",
        "uai_modelverse:UpdateUMInferExportTaskTime",
        "uai_modelverse:UpdateUMInferUserExportTaskTime"
      ],
      "Resource": [
        "*"
      ],
      "Condition": {}
    }
  ]
}
```

### Bind Policy to Sub-Account

1. Go to **Access Control > User Management**, and click **Add Permission** in the operation column of the target sub-account.
2. Select the created project-level policy Astraflow-APIKey-ProjectFullAccess; if you need to use the sharing feature, also select Astraflow-APIKey-ShareUserList.
3. Select **Specified Project** for the project-level policy and save. Only select "All Projects" when you confirm the need to cover all existing and future projects.

> Note: This policy only covers data permissions for the API Key Management, Model Logs, and Model Monitoring pages. If you need to grant other Astraflow feature permissions to the sub-account, you need to configure the corresponding policies separately.

## Scenario C: Sub-Account Manages Only Own Created and Shared API Keys

**Applicable Scenario**: The sub-account should only see API Keys they created and API Keys shared with them by other accounts, and should not see other API Keys under the project and their data.

### Permission Effect

After configuration, the sub-account in the target project:

- The API Key Management page only shows the "My" view, not "All".
- The list contains API Keys created by the user and API Keys shared with the user.
- For own created API Keys: can view, create, edit, delete, and share.
- For shared API Keys: can view and their data in Model Logs, Model Monitoring, and Consumer Center; cannot edit, delete, or share again.
- Model Logs and Model Monitoring only show data generated by own created and shared API Keys.
- Cannot view other API Keys in the project that are not shared with them and their data.

### Create Project-Level Policy

1. In the Astraflow console, click **Account and Permission Management** in the account menu at the top right.
2. Go to **Access Control > Policy Management**, and click **Create Custom Policy**.
3. Fill in the policy name and description. Suggested name and description: Astraflow-APIKey-OwnAndShared, policy description: Sub-account can only manage own created and shared API Keys.
4. Select **Project Level** for the policy level, select **Script Edit** for the edit mode.
5. Paste the script and save.

```plain
{
  "Version": "1",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "uai_modelverse:CreateUMInferAPIKey",
        "uai_modelverse:BatchCreateUMInferAPIKey",
        "uai_modelverse:SendUMInferAPIKeyQuotaAlertVerifyCode",
        "uai_modelverse:AddUMInferAPIKeyShareUsers",
        "uai_modelverse:RemoveUMInferUserAPIKeys",
        "uai_modelverse:DeleteUMInferAPIKeyShareUsers",
        "uai_modelverse:BatchUpdateUMInferUserAPIKey",
        "uai_modelverse:CheckUMInferAPIKeyQuotaAlertContact",
        "uai_modelverse:ListUMInferAPIKeyTags",
        "uai_modelverse:GetUMInferAPIKeyPlaintext",
        "uai_modelverse:GetUMInferPlaintext",
        "uai_modelverse:ListUMInferUserShareAPIKey",
        "uai_modelverse:ListUMInferAPIKeyShareUsers",
        "uai_modelverse:GetUMInferLogPermissionStatus",
        "uai_modelverse:ListUMInferUserRequestLogs",
        "uai_modelverse:GetUMInferUserRequestLogDetail",
        "uai_modelverse:ListUMInferUserRequestLogModels",
        "uai_modelverse:GetUMInferUserLog",
        "uai_modelverse:ListUMInferExportUserTasks",
        "uai_modelverse:DownloadUMInferUserExportTask",
        "uai_modelverse:CreateUserLogAnalysisJob",
        "uai_modelverse:CheckUserLogAnalysisLogCount",
        "uai_modelverse:GetUserLogAnalysisJob",
        "uai_modelverse:ListUserLogAnalysisJobs",
        "uai_modelverse:CancelUserLogAnalysisJob",
        "uai_modelverse:RestartUserLogAnalysisJob",
        "uai_modelverse:GetUserLogAnalysisReport",
        "uai_modelverse:GetUMMonitorUserBasicMetrics",
        "uai_modelverse:GetUMMonitorUserTokenMetrics",
        "uai_modelverse:GetUMMonitorUserThroughputMetrics",
        "uai_modelverse:GetUMMonitorUserLatencyMetrics",
        "uai_modelverse:GetUMMonitorUserCacheMetrics",
        "uai_modelverse:GetUMMonitorUserModelMetrics",
        "uai_modelverse:CancelUMInferUserExportTask",
        "uai_modelverse:RestartUMInferUserExportTask",
        "uai_modelverse:UpdateUMInferUserExportTaskTime"

      ],
      "Resource": [
        "*"
      ],
      "Condition": {}
    },    
    {
      "Effect": "Deny",
      "Action": [
        "uai_modelverse:AddUMInferAPIKeyShareUsersProject",
        "uai_modelverse:RemoveUMInferApikeys",
        "uai_modelverse:DeleteUMInferAPIKey",
        "uai_modelverse:DeleteUMInferAPIKeyShareUsersProject",
        "uai_modelverse:BatchUpdateUMInferAPIKey",
        "uai_modelverse:UpdateUMInferAPIKey",
        "uai_modelverse:ListUMInferAPIKeyShareUsersProject",
        "uai_modelverse:ListUMInferAPIKeyV2",
        "uai_modelverse:ListUMInferAPIKey",
        "uai_modelverse:ListUMInferRequestLogs",
        "uai_modelverse:GetUMInferRequestLogDetail",
        "uai_modelverse:ListUMInferRequestLogModels",
        "uai_modelverse:GetUMInferLog",
        "uai_modelverse:ListUMInferExportTasks",
        "uai_modelverse:DownloadUMInferExportTask",
        "uai_modelverse:CreateLogAnalysisJob",
        "uai_modelverse:CheckLogAnalysisLogCount",
        "uai_modelverse:GetLogAnalysisJob",
        "uai_modelverse:ListLogAnalysisJobs",
        "uai_modelverse:CancelLogAnalysisJob",
        "uai_modelverse:RestartLogAnalysisJob",
        "uai_modelverse:GetLogAnalysisReport",
        "uai_modelverse:GetUMMonitorBasicMetrics",
        "uai_modelverse:GetUMMonitorTokenMetrics",
        "uai_modelverse:GetUMMonitorThroughputMetrics",
        "uai_modelverse:GetUMMonitorLatencyMetrics",
        "uai_modelverse:GetUMMonitorCacheMetrics",
        "uai_modelverse:GetUMMonitorModelMetrics",
        "uai_modelverse:CancelUMInferExportTask",
        "uai_modelverse:RestartUMInferExportTask",
        "uai_modelverse:UpdateUMInferExportTaskTime"
      ],
      "Resource": [
        "*"
      ],
      "Condition": {}
    }
  ]
}
```

### Bind Policy to Sub-Account

1. Go to **Access Control > User Management**, and click **Add Permission** in the operation column of the target sub-account.
2. Select the created project-level policy Astraflow-APIKey-OwnAndShared; if you need to use the sharing feature, also select Astraflow-APIKey-ShareUserList.
3. Select **Specified Project** for the project-level policy and save. Only select "All Projects" when you confirm the need to cover all existing and future projects.

Note: This policy only covers data permissions for the API Key Management, Model Logs, and Model Monitoring pages. If you need to grant other Astraflow feature permissions to the sub-account, you need to configure the corresponding policies separately.

# FAQ

**1. Sub-account still shows "No Access Permission" after configuration?**

First check whether the sub-account has the corresponding page access permission (menu permission). Data permissions control which data can be viewed; page access permissions control whether the page can be entered. Both are required for normal use.

**2. Still see the "All" tab after configuring Scenario C?**

Please check whether the sub-account is also bound to other policies that contain full project query permissions. If so, please adjust the existing authorization first, or unbind the policy that conflicts with this one.

**3. Why can't the sub-account see API Keys shared with them?**

Please check in order:

- Whether the sharer has shared the Key to this sub-account.
- Whether both parties are in the **same project**.
- Whether the recipient has configured the project-level policy `ModelVerse-APIKey-OwnAndShared`.
- Whether the recipient has the corresponding page menu permission.

**4. Do Model Logs, Model Monitoring, and Consumer Center need separate data permission configuration?**

It depends on the configuration method:

- **Using the templates in this document directly**: No separate configuration is needed. The templates for Scenario B and Scenario C already include the relevant interfaces for Model Logs, Model Monitoring, and Consumer Center.
- **Custom policies**: Separate configuration is needed. The "All" and "My" data for each page are controlled by different interfaces; unauthorized pages will not be able to view data. Please refer to [API Permission Comparison: "All" vs "My" Data](api-permission-comparison.md) to add them one by one.

When customizing, it is recommended to use the same data scope for all pages. For example, if API Key Management only authorizes "My" interfaces, but Model Monitoring authorizes "All" interfaces, the sub-account will be able to see invocation data for all API Keys under the project in Model Monitoring.

**5. Will the global-level policy allow sub-accounts to see other sub-accounts' Keys?**

No. This global policy is used to open the interfaces needed to select sub-accounts; API Key data is still determined by project-level policies and sharing relationships.

**6. Do you need to configure a separate policy for the recipient of a shared Key?**

Yes. The recipient must at least be able to enter the API Key Management page and have a project-level policy configured to stably view the shared Key and its associated data in "My".
