# API Key, Model Logs, and Model Monitoring Permission Configuration

## Scenario 1: 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 with 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

#### 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 as `Astraflow-APIKey-ProjectFullAccess`, and the policy description as "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 following 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",
        "uai_modelverse:CheckMenuModelLog",
        "uai_modelverse:CheckMenuModelMonitor",
        "uai_modelverse:CheckMenuAPIKey",
        "uai_modelverse:CheckMenuExportRecord"
      ],
      "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 2: 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 the API Keys and their data in Model Logs and Model Monitoring; cannot edit, delete, or share them 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 as `Astraflow-APIKey-OwnAndShared`, and the policy description as "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 following 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",
        "uai_modelverse:CheckMenuModelLog",
        "uai_modelverse:CheckMenuModelMonitor",
        "uai_modelverse:CheckMenuAPIKey",
        "uai_modelverse:CheckMenuExportRecord"

      ],
      "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.
