与 Assured OSS 集成以实现代码安全

借助有保障的开源软件 (Assured OSS) 高级层级,您可以使用 Google 用于其自身开发者工作流的 OSS 软件包来增强代码安全性。使用 Assured OSS 时,您的开发者可以利用 Google 为保护自己的开源依赖项而应用的安全专业知识和经验。

将 Assured OSS 与 Security Command Center 集成后,您可以执行以下操作:

  • 从数以千计的精选且最受欢迎的 Java 和 Python 软件包中进行选择,包括 TensorFlow、Pandas 和 Scikit-learn 等常见的机器学习和人工智能项目。
  • 配置安全代理以下载所有带有 Assured OSS 证明的 Java、Python 和 JavaScript 软件包,使 Google 成为知名且值得信赖的供应商。
  • 使用以 SPDX 和 CycloneDX 等业界标准格式提供的 Assured OSS 中的 SBOM 和 VEX,详细了解您的素材。
  • 通过 Google 提供的有签名的防篡改构建来源,提高对您所用软件包完整性的信心。
  • 由于 Google 会主动扫描、查找和修复精选软件包中的新漏洞,因此可降低安全风险。

准备工作

请先完成以下任务,然后再完成本页面上的其余任务。

激活 Security Command Center Enterprise 层级

验证 Security Command Center Enterprise 层级是否已在组织级激活,并且您是否已完成设置指南中的前六个步骤。

在组织级设置权限

您必须在组织级和项目级设置权限。

  1. Make sure that you have the following role or roles on the organization: Security Center Admin, Organization Admin

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the organization.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      前往 IAM
    2. 选择组织。
    3. 点击 授予访问权限
    4. 新的主账号字段中,输入您的用户标识符。 这通常是 Google 账号的电子邮件地址。

    5. 选择角色列表中,选择一个角色。
    6. 如需授予其他角色,请点击 添加其他角色,然后添加其他各个角色。
    7. 点击 Save(保存)。

    在项目级设置权限

    1. Make sure that you have the following role or roles on the project: Service Usage Admin, Service Account Admin, Project IAM Admin

      Check for the roles

      1. In the Google Cloud console, go to the IAM page.

        Go to IAM
      2. Select the project.
      3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

      4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

      Grant the roles

      1. In the Google Cloud console, go to the IAM page.

        前往 IAM
      2. 选择项目。
      3. 点击 授予访问权限
      4. 新的主账号字段中,输入您的用户标识符。 这通常是 Google 账号的电子邮件地址。

      5. 选择角色列表中,选择一个角色。
      6. 如需授予其他角色,请点击 添加其他角色,然后添加其他各个角色。
      7. 点击 Save(保存)。

      设置 Google Cloud CLI

      In the Google Cloud console, activate Cloud Shell.

      Activate Cloud Shell

      At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

      设置 Assured OSS

      控制台

      1. 在 Google Cloud 控制台中,前往 Security Command Center 设置指南

        前往设置指南

      2. 验证您查看的是已激活 Security Command Center Enterprise 层级的组织。

      3. 展开查看安全功能摘要面板。

      4. 依次点击代码安全 > 设置

      5. 设置代码安全性面板中,点击 AOSS 设置

      6. 选择新的服务账号或选择要添加“有保障的开源软件”权限的现有服务账号。

      7. 选择您要将 Assured OSS 资源放在其中的 Google Cloud 项目。

      8. 点击设置 Assured OSS

        设置过程会自动完成以下操作:

        • 如果选择,则创建新的服务账号 assuredoss@PROJECT_ID.gservicesaccount.com
        • 为指定的服务账号分配 Assured OSS User 角色,以便与 Assured OSS 搭配使用。
        • 为已登录的用户账号分配 Assured OSS Admin 角色,以便该账号可以配置服务。
        • 启用 Assured Open Source Software API,如果尚未启用,则启用 Artifact Registry API。
        • 在您所选项目的 Artifact Registry 实例中设置 Assured OSS 代理服务。系统会为每种语言(Java、Python 和 JavaScript)配置一个代码库。这些代码库可以自动从精选组合中提取软件包。如果某个软件包不在精选组合中,存储库会将请求重定向到规范存储库。代理服务仅支持美国区域。
        • 向您和服务账号授予访问 Google 拥有的项目中软件包元数据和通知的权限。
      9. 为每个指定的 Assured OSS 服务账号创建服务账号密钥,并以 JSON 格式下载密钥。

      10. 在本地机器的命令行中,对下载的密钥文件运行以下命令,以获取 base64 编码的字符串:

        base64 KEY_FILENAME.json
        

        KEY_FILENAME.json 替换为您下载的服务账号密钥的名称。

        为 Assured OSS 设置远程代码库时,您需要使用 base64 编码的字符串。

      11. 如需下载软件包,请使用 Assured OSS 为每种语言提供的端点。记下这些端点以备稍后使用。

        • Java:
          https://us-maven.pkg.dev/PROJECT_ID/assuredoss-java
        • Python:
          https://us-python.pkg.dev/PROJECT_ID/assuredoss-python
        • JavaScript:
          https://us-npm.pkg.dev/PROJECT_ID/assuredoss-javascript

        PROJECT_ID 替换为您在设置 Assured OSS 时选择的项目 ID。

      12. 点击下一步。使用贵组织的 Artifact 存储库管理器(例如 JFrog Artifactory 或 Sonatype Nexus)配置 Assured OSS

      gcloud

      1. 使用您要用来启用 Assured OSS 的用户账号对 Google Cloud 进行身份验证:

        gcloud auth revoke
        gcloud auth application-default revoke
        gcloud auth login
        
      2. 搜索您要查找 Assured OSS 资源的项目:

        gcloud alpha projects search --query="displayName=PROJECT_NAME"
        

        PROJECT_NAME 替换为项目名称。

      3. 设置要在其中查找 Assured OSS 资源的项目:

        gcloud config set project PROJECT_ID
        

        PROJECT_ID 替换为项目标识符。

      4. 向用户账号授予角色以设置 Assured OSS:

        gcloud projects add-iam-policy-binding PROJECT_ID \
          --member=user:email@domain.com \
          --role=roles/assuredoss.admin
        
        gcloud projects add-iam-policy-binding PROJECT_ID \
          --member=user:email@domain.com \
          --role=roles/serviceusage.serviceUsageAdmin
        
        gcloud projects add-iam-policy-binding PROJECT_ID \
          --member=user:email@domain.com \
          --role=roles/iam.serviceAccountAdmin
        

        其中,email@domain.com 是您的用户账号的邮箱。

      5. 在项目中启用 Assured OSS。启用 Assured OSS 也会启用 Artifact Registry API。

        gcloud services enable assuredoss.googleapis.com
        
      6. 如需为 Assured OSS 创建新的服务账号,而不是使用现有的服务账号,请完成以下操作:

        gcloud iam service-accounts create SERVICE_ACCOUNT_NAME \
          --description="Service account for using Assured OSS"
          --display-name="Assured OSS service account"
        

        SERVICE_ACCOUNT_NAME 替换为服务账号的名称(例如 assuredoss)。

      7. 为 Assured OSS 配置服务账号:

        gcloud projects add-iam-policy-binding PROJECT_ID \
          --member=serviceAccount:SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com \
          --role roles/assuredoss.user
        

        替换以下内容:

        • SERVICE_ACCOUNT_NAME:服务账号的名称(例如 assuredoss)。
        • PROJECT_ID:项目标识符。
      8. 通过创建 Assured OSS 代码库,在 Artifact Registry 实例中设置 Assured OSS 代理服务。您必须为所有语言创建代码库。用于配置代码库的 Assured OSS 代理服务仅支持美国区域。

        alias gcurlj='curl -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" -X'
        
        gcurlj POST https://artifactregistry.googleapis.com/v1/projects/PROJECT_ID/locations/us/repositories\?repositoryId\=assuredoss-java   -d '{"format": "MAVEN", "mode": "AOSS_REPOSITORY"}'
        
        gcurlj POST https://artifactregistry.googleapis.com/v1/projects/PROJECT_ID/locations/us/repositories\?repositoryId\=assuredoss-javascript   -d '{"format": "NPM", "mode": "AOSS_REPOSITORY"}'
        
        gcurlj POST https://artifactregistry.googleapis.com/v1/projects/PROJECT_ID/locations/us/repositories\?repositoryId\=assuredoss-python   -d '{"format": "PYTHON", "mode": "AOSS_REPOSITORY"}'
        

        PROJECT_ID 替换为您在设置 Assured OSS 时选择的项目 ID。

        这些代码库可以自动从精选组合中提取软件包。如果某个软件包不在精选组合中,存储库会将请求重定向到规范存储库。

      9. 为每个 Assured OSS 服务账号创建服务账号密钥,并以 JSON 格式下载密钥。

      10. 在命令行中,对下载的密钥文件运行以下命令,以获取 base64 编码的字符串:

        base64 KEY_FILENAME.json
        

        KEY_FILENAME.json 替换为您下载的服务账号密钥的名称。

        为 Assured OSS 设置远程代码库时,您需要使用 base64 编码的字符串。

      11. 如需下载软件包,请使用 Assured OSS 为每种语言配置的端点。请记下以下端点:

        • Java:
          https://us-maven.pkg.dev/PROJECT_ID/assuredoss-java
        • Python:
          https://us-python.pkg.dev/PROJECT_ID/assuredoss-python
        • JavaScript:
          https://us-npm.pkg.dev/PROJECT_ID/assuredoss-javascript

        PROJECT_ID 替换为您在设置 Assured OSS 时选择的项目 ID。

      12. 使用贵组织的 Artifact 存储库管理器(例如 JFrog Artifactory 或 Sonatype Nexus)配置 Assured OSS 以下载软件包。

      13. 您可以选择查看可用的 Java、Python 和 JavaScript 软件包:

        gcloud auth revoke
        gcloud auth application-default revoke
        gcloud auth login --cred-file=KEY_FILENAME.json
        

        KEY_FILENAME.json 替换为您下载的服务账号密钥的名称。

        export GOOGLE_APPLICATION_CREDENTIALS=KEY_FILENAME.json
        

        KEY_FILENAME.json 替换为您下载的服务账号密钥的名称。

        gcurlj GET "https://artifactregistry.googleapis.com/v1/projects/PROJECT_ID/locations/us/repositories/assuredoss-java/packages"
        gcurlj GET "https://artifactregistry.googleapis.com/v1/projects/PROJECT_ID/locations/us/repositories/assuredoss-python/packages"
        gcurlj GET "https://artifactregistry.googleapis.com/v1/projects/PROJECT_ID/locations/us/repositories/assuredoss-javascript/packages"
        

        PROJECT_ID 替换为您在设置 Assured OSS 时选择的项目 ID。

      后续步骤