# Share API Key Configuration

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

In Scenario 1 on this page and Scenarios 1 and 2 in [API Key, Model Logs, and Model Monitoring Permission Configuration](api-key-log-monitor.md), 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. 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-ShareUserList`, and the policy description as "Allow selecting sub-accounts in the same project when sharing API Keys".
4. 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 1: 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 as `Astraflow-APIKey-ShareProjectKey`, and the policy description as "Sub-account can share the current project's API Keys with 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.
