配置 Jenkins


Red Hat Trusted Application Pipeline 1.5

了解如何为安全 CI/CD 工作流配置 Jenkins。

Red Hat Trusted Application Pipeline Documentation Team

摘要

本文档提供了有关设置 Jenkins 以执行基本安全任务的说明,如漏洞扫描、镜像签名和测试生成。

前言

要让 Jenkins 管道能够执行基本任务,如漏洞扫描、镜像签名和测试,请按照以下步骤操作。该表概述了您需要采取的操作以及完成这些操作时。

Expand
操作何时完成

在 Jenkins 中添加 secret 以便与外部工具安全集成

在使用安全软件模板来创建应用之前,请将 secret 添加到 Jenkins 中。这样可确保与 ACS、Quay 和 GitOps 无缝集成。

将应用程序添加到 Jenkins

创建应用和源存储库后,将它们添加到 Jenkins 中。这可让您查看 Red Hat Developer Hub 平台上 Jenkins 管道的各个方面。

通过完成以下步骤,您可以让 Jenkins 与 ACS (高级集群安全)、Quay 和 GitOps 无缝集成,并使用 Cosign 签名和验证容器镜像。

在创建应用程序时,当您将 Jenkins 选择为 CI 供应商时,您必须将 secret 和环境变量添加到 Jenkins 中,以便与外部工具进行集成。这可让 Jenkins 执行基本任务,如漏洞扫描、镜像签名和测试生成。

先决条件

  • 您必须具有创建和管理 Jenkins 任务、变量和 CI 管道所需的权限。
  • 您必须具有镜像 registry 的用户名和密码,如 Quay.io、Jfrog Artifactory 或 Sonatype Nexus。
  • 您必须具有适当的 GitOps 凭证。
  • 您必须具有 Jenkins 管道执行的特定任务的以下信息:

    • 对于 ACS 任务:

      • ROX Central 服务器端点和令牌
    • 对于 SBOM 任务:

      • Cosign 签名密钥密码、私钥和公钥
      • Trustification API 和 issuer URL, client ID, client secret, and supported CycloneDX version
    注意

    用于这些凭证的值已经经过 Base64 编码,因此您不需要转换它们。您可以在 private.env 文件中找到这些凭证。

1.1. 在 Jenkins 中添加 secret

按照以下步骤,使用 Jenkins 服务器上的 UI 添加所需的凭证。

流程

  1. 在 Web 浏览器中打开 Jenkins 实例,并使用您的管理员凭据登录。
  2. 选择 Jenkins 仪表板右上角的用户名。
  3. 从左侧边栏,选择 Manage Jenkins
  4. Security 部分中,选择 Credentials
  5. Stores 范围下,选择 System
  6. 选择您要添加凭证的域。通常,它是 全局凭据(无限制), 单击此域名。
  7. 选择 Add Credentials
  8. Kind 下拉列表中,选择 Secret 文本
  9. Scope 下拉列表中的默认值保留为 Global (Jenkins…​)
  10. 在 UI 字段中输入与 secret 相关的信息。
  11. 选择 Create
  12. 重复步骤 7-11 以添加以下凭证:

    注意

    对于镜像 registry,Quay 是默认选项。要使用 JFrog Artifactory 或 Sonatype Nexus,请在克隆的 tssc-sample-templates GitHub 仓库中的 gitops-templatesource-repo 文件夹中取消注释 2 Jenkinsfiles 中的对应变量的行。

    Expand
    表 1.1. 镜像 registry 和 GitOps secret
    变量描述

    QUAY_IO_CREDS

    用于访问 Quay.io 存储库的用户名和密码。这是在 Jenkinsfile 中取消注释的默认选项。

    RTIFACTORY_IO_CREDS

    用于访问 JFrog Artifactory 存储库的用户名和密码。

    NEXUS_IO_CREDS

    用于访问 Sonatype Nexus 存储库的用户名和密码。

    GITOPS_AUTH_PASSWORD

    系统用来为新构建镜像更新 GitOps 存储库的令牌。

    Expand
    表 1.2. ACS 和 SBOM 任务所需的 secret
    变量描述

    ROX_API_TOKEN

    用于访问 ROX 服务器的 API 令牌。

    COSIGN_SECRET_PASSWORD

    Cosign 签名密钥的密码。

    COSIGN_SECRET_KEY

    Cosign 的私钥。

    TRUSTIFICATION_OIDC_CLIENT_SECRET

    与客户端 ID 一起使用的客户端 secret,以向 Trustification Bombastic API 进行身份验证。

  13. 重新运行最后的管道运行。

    1. 或者,切换到 GitHub 中应用的源存储库,进行次要更改,并提交它以触发新的管道运行。

1.2. 在 Jenkins 中添加环境变量

添加所有所需的 secret 后,按照以下步骤使用 Jenkins 服务器上的 UI 添加环境变量。

流程

  1. 从左侧边栏,选择 Manage Jenkins
  2. "系统配置"部分中,选择" 系统 "。
  3. System 页面中,向下滚动以查找 Global properties 部分。
  4. 选择 Environment variables > Add
  5. 为以下环境变量添加键值对:

    Expand
    表 1.3. GitOps variable
    变量描述

    GITOPS_AUTH_USERNAME (可选)

    使用 GitLab 所需的变量。

    Expand
    表 1.4. ACS 和 SBOM 任务所需的变量
    变量描述

    ROX_CENTRAL_ENDPOINT

    ROX Central 服务器的端点。

    COSIGN_PUBLIC_KEY

    Cosign 的公钥。

    TRUSTIFICATION_BOMBASTIC_API_URL

    SBOM 生成中使用的 Trustification Bombastic API 的 URL。

    TRUSTIFICATION_OIDC_ISSUER_URL

    与 Trustification Bombastic API 交互时用于身份验证的 OIDC 签发者 URL。

    TRUSTIFICATION_OIDC_CLIENT_ID

    用于使用 OIDC 向 Trustification Bombastic API 进行身份验证的客户端 ID。

    TRUSTIFICATION_SUPPORTED_CYCLONEDX_VERSION

    指定系统支持并生成的 CycloneDX SBOM 版本。

    可选 :如果 Jenkins 没有在本地 OpenShift 实例上运行,则设置 Rekor 和 TUF 变量,且 Rekor 和 TUF 服务在不同的集群中。另外,在克隆的 tssc-sample-templates 存储库中的 Jenkinsfile 中取消对带有 Rekor 和 TUF 变量的行的注释。

    Expand
    表 1.5. Rekor 和 TUF 变量
    变量描述

    REKOR_HOST

    您的 Rekor 服务器的 URL。

    TUF_MIRROR

    您的 TUF 服务的 URL。

  1. 添加所有变量时,选择 Save
  2. 重新运行最后的管道运行。

第 2 章 将应用程序添加到 Jenkins

在创建应用程序时将 Jenkins 选择为 CI 供应商时,您必须将应用添加到 Jenkins 中。正确的集成可确保您的管道与您的 CI/CD 工作流一致,并无缝运行。

先决条件

  • 您必须在您的环境中安装和配置 Jenkins。
  • 您必须具有创建和管理 Jenkins 任务所需的权限。
  • 您必须在 post RHTAP 安装阶段为 Jenkins 管道 添加正确的凭证
  • 检查 Jenkinsfile,并确保它与您的 Jenkins 配置一致。例如,您可能需要更新代理设置,以限制管道运行的位置。
  • 确保 Jenkins 代理安装了必要的二进制文件: gitcurljqyqbuildahsyftcosignpython3tree。如果管道运行在启动时失败,这可能表示缺少一个或多个二进制文件。

流程

  1. 登录 Jenkins 实例。
  2. 从 Jenkins 控制面板,选择 New Item
  3. 输入管道作业的名称并选择 Pipeline 项目(如 secure-jenkins)。

    注意

    管道任务的名称必须与您要添加 Jenkins CI 的应用的名称匹配。如果名称不匹配,管道将在 Jenkins 上运行,但对 RHDH 不可见。

    1. (可选)如果要使用不同的管道名称,请使用您选择的管道名称更新 source 存储库中的 catalog-info.yaml 文件中的 jenkins.io/job-full-name 字段。
  4. 选择 OK 以创建该作业。
  5. 在 Configure > General 页面上,进入 Pipeline 部分,从 Definition 下拉列表中选择 Pipeline 脚本
  6. SCM 下拉列表中,选择 Git
  7. Repository URL 字段中,输入 Jenkins 源存储库 URL。

    1. 在 Red Hat Developer Hub 平台上,从 Catalog 中选择一个适当的应用程序。
    2. 前往 Overview 选项卡,再选择 View Source 以打开托管应用程序的源代码的存储库。
  8. Branches to build 部分中,输入 */main
  9. 选择 Save。系统显示 live-jenkins (作业名称)页面。
  10. 选择 Build Now。系统启动构建管道。等待构建完成。

    1. Stage View 部分中,选择 Pipeline Overview 来视觉化管道运行。
    2. 选择 Pipeline Console 来查看管道运行的每个阶段的实时日志。

验证

将应用程序与 Jenkins 集成后,请在 Red Hat Developer Hub 平台上查看 Jenkins 管道的各个方面。

  1. 从 Catalog 中,选择适当的应用程序或组件。

    • 前往 CI 选项卡,以查看 Jenkins 项目。对于适当的 Jenkins 任务,使用 Actions 列,您可以查看、重新运行和查看作业历史记录。系统显示作业概述,状态为 latest run。
    • 进入 CD 选项卡并选择适当的卡来查看部署详情,如提交消息、作者名称和由 ArgoCD 和 GitOps 管理的部署历史记录。
    • 在目录中,从 Kind 下拉列表中选择 Resource。系统显示 Jenkins GitOps 任务。选择并查看适当的 GitOps 资源。
    • 进入 Topology 选项卡,在 development 命名空间中视觉化应用程序的部署。

完成这些步骤可确保应用程序与 Jenkins 的无缝集成,实现高效可靠的 CI/CD 工作流。





更新于 2025-05-01

法律通告

Copyright © 2025 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat