> ## Documentation Index
> Fetch the complete documentation index at: https://docs.enclave.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Enclave in these docs is the code and cloud security platform at enclave.ai. It is not Open Enclave, Intel SGX or other hardware enclaves, or enclave.gg.
> People use Enclave in the web app at https://app.enclave.ai or the desktop app. These docs describe no public Enclave API or CLI, so don't invent endpoints, commands, or config files.
> Connecting an integration needs a person to sign in and approve access in a browser. Tell the user the exact step to take instead of saying you completed it.

# GCP

> 使用只读服务账号连接 Google Cloud 项目，无需存储任何密钥。

连接 Google Cloud 项目，让 Enclave 可以梳理其资源和身份，并将它们与你的代码关联起来。访问是只读的，且不会创建或存储任何服务账号密钥。

## Enclave 需要什么

设置命令会在你的项目中创建以下资源：

* 一个 **Workload Identity 池**，其中的提供方只信任 Enclave 的扫描器身份。
* 一个供 Enclave 模拟的**扫描器服务账号**。
* 该服务账号的**只读角色绑定**。

它还会在项目中启用 IAM、IAM Credentials、Cloud Resource Manager、Security Token Service 和 Cloud Asset API。

该服务账号会获得以下角色：

| 角色 | 读取的内容 |
| - | - |
| `roles/compute.viewer` | Compute Engine 实例、网络、子网、防火墙和负载均衡器 |
| `roles/container.viewer` | GKE 集群 |
| `roles/run.viewer` | Cloud Run 服务 |
| `roles/cloudfunctions.viewer` | Cloud Functions |
| `roles/dns.reader` | Cloud DNS 区域 |
| `roles/artifactregistry.reader` | Artifact Registry 仓库 |
| `roles/storage.bucketViewer` | 仅限 Cloud Storage 存储桶元数据，不包括对象 |
| `roles/iam.securityReviewer` | IAM 策略和服务账号 |
| `roles/cloudasset.viewer` | Cloud Asset Inventory |
| `roles/serviceusage.serviceUsageConsumer` | 调用上述读取 API |
| `roles/browser` | 项目和层级元数据 |

### 谁可以运行设置

在 Cloud Shell 中运行命令的人需要拥有项目的 **Owner** 角色，或者拥有以下全部角色：

* `roles/iam.workloadIdentityPoolAdmin`
* `roles/iam.serviceAccountAdmin`
* `roles/serviceusage.serviceUsageAdmin`
* `roles/resourcemanager.projectIamAdmin`

在 Enclave 中，你需要 **Owner** 或 **Admin** 角色。

## 连接项目

**1. 打开设置页面**

打开 **Settings → Integrations**，点击 **Google Cloud** 旁边的 **Connect**。

**2. 输入项目 ID**

输入要连接的 **GCP project ID**。如需查找，请运行 `gcloud projects list`。Enclave 会为该项目生成一行设置命令。

**3. 在 Cloud Shell 中运行命令**

复制该命令，并在 [Google Cloud Shell](https://shell.cloud.google.com) 中运行，或在已登录 `gcloud` 的终端中运行。

> [!WARNING]
>
> 该命令包含一个一次性设置令牌。不要将它保存在受版本控制的文件中，也不要粘贴到共享日志中。

**4. 等待 Enclave 检测到设置完成**

Enclave 会监测设置是否完成，并自动进入下一步。看到 **Connection complete!** 后，项目即已连接，Enclave 会开始扫描它。

**5. 添加更多项目**

点击 **Add another project** 连接另一个项目，或点击 **Done** 完成。

> [!TIP]
>
> 点击 **I'll finish later** 可保存连接，稍后再回来。你可以在 **Settings → Integrations → Google Cloud** 中重新打开它。

## 管理连接

打开 **Settings → Integrations → Google Cloud**，查看已连接的项目。

* **Re-validate** 会检查 Enclave 是否仍能读取某个项目。
* **Remove** 会停止扫描某个项目。
* **Add project** 会连接另一个项目。
* **Disconnect GCP** 会移除整个连接并停止扫描。

如需从 Google Cloud 撤销访问权限，请删除设置过程创建的扫描器服务账号或 Workload Identity 池。

## Enclave 会做什么、不会做什么

* **会**：读取上述角色允许的配置和元数据。
* **不会**：创建、更改或删除资源，读取存储桶中的对象，或存储长期凭证。每次扫描都使用有效期约一小时的短期访问令牌。

## 故障排除

> [accordion] 运行命令后页面一直在等待
>
> 检查 Cloud Shell 中命令的输出。如果命令失败，请修复错误，然后重新打开连接以获取新命令。设置令牌只能使用一次，因此不要重新运行已经用过的旧命令。

> [accordion] 命令因权限错误而失败
>
> 运行命令的账号缺少某个角色。授予 **Owner** 角色或[谁可以运行设置](#%E8%B0%81%E5%8F%AF%E4%BB%A5%E8%BF%90%E8%A1%8C%E8%AE%BE%E7%BD%AE)中列出的四个管理员角色，然后运行一条新命令。

> [accordion] Enclave 不接受项目 ID
>
> 项目 ID 长度为 6 到 30 个字符，由小写字母、数字和连字符组成，以字母开头，以字母或数字结尾。请使用项目 ID，而不是项目名称或项目编号。

> [accordion] 资产没有出现在 Coverage 中
>
> 扫描会在项目连接时运行一次，之后每天运行一次。如需立即扫描，请在 [Coverage](https://docs.enclave.ai/zh/onboarding/coverage.md) 中点击 **Analyze Environment**。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.