GitHub Actions の設定


Red Hat Trusted Application Pipeline 1.5

セキュアな CI/CD ワークフロー用に GitHub Actions を設定する方法を学ぶ

Red Hat Trusted Application Pipeline Documentation Team

概要

このドキュメントでは、脆弱性スキャン、イメージ署名、アテステーション生成などの重要なセキュリティータスクを実行するために GitHub Actions を設定する手順を説明します。

はじめに

アプリケーションに GitHub Actions を使用している場合、シークレットが欠落しているためにパイプラインの実行が失敗する可能性があります。シークレットがないと、Quay、JFrog、Red Hat Advanced Cluster Security (ACS) との統合が機能せず、脆弱性スキャン、イメージ署名、コンプライアンスのための SBOM 生成などのセキュリティータスクが機能しなくなります。

これを防ぐには、GitHub Actions にシークレットをセキュアに保存する必要があります。このガイドでは、パイプラインをスムーズかつセキュアに実行するためのプロセスを順を追って説明します。

第1章 外部ツールとの統合のために GitHub Actions にシークレットと変数を追加する

前提条件

GitHub Actions を設定する前に、次のものがあることを確認してください。

  • GitHub リポジトリーと CI/CD 設定への 管理者 アクセス権。
  • Quay.io、JFrog Artifactory、または Sonatype Nexus からコンテナーイメージをプルするための コンテナーレジストリー認証情報
  • 特定の GitHub Actions タスクの 認証の詳細:

    • ACS セキュリティータスクの場合:

      • ROX Central サーバーエンドポイント
      • ROX API トークン
    • SBOM およびアーティファクト署名タスクの場合:

      • 署名鍵のパスワード、秘密鍵、公開鍵に署名する
      • Trustification API と発行者 URL、クライアント ID、クライアントシークレット、サポートされている CycloneDX バージョン
    注記

    認証情報やその他の詳細は、すでに Base64 でエンコードされているため、再度エンコードする必要はありません。これらの認証情報は、RHTAP のインストール中に作成した private.env ファイルにあります。

1.1. オプション 1: UI を使用して GitHub Actions にシークレットと変数を追加する

手順

  1. GitHub にログインし、ソースリポジトリーに移動します。
  2. Settings タブに移動します。
  3. 左側のナビゲーションペインで、Secrets and variables を選択し、Actions を選択します。
  4. Actions secrets and variables ページで、Secrets タブを選択します。

    1. New repository secret を選択します。
    2. Name フィールドに MY_GITHUB_TOKEN を入力します。
    3. Secret フィールドに、GitHub アカウントに関連付けられた トークン を入力します。
    4. Add secret を選択します。
  5. 手順 4 を繰り返して、必要なシークレットを追加します。

    表1.1 イメージレジストリーおよび GitOps シークレット
    変数説明

    IMAGE_REGISTRY_PASSWORD

    コンテナーイメージレジストリーにアクセスするためのパスワード。

    GITOPS_AUTH_PASSWORD

    新しくビルドされたイメージの GitOps リポジトリーを更新するためにシステムが使用するトークン。

    表1.2 ACS および SBOM タスクに必要なシークレット
    変数説明

    ROX_API_TOKEN

    ROX サーバーにアクセスするための API トークン。

    COSIGN_SECRET_PASSWORD

    Cosign 署名鍵のパスワード。

    COSIGN_SECRET_KEY

    Cosign の秘密鍵。

    TRUSTIFICATION_OIDC_CLIENT_SECRET

    Trustification Bombastic API への認証にクライアント ID と一緒に使用されるクライアントシークレット。

  1. Actions secrets and variables ページで、Variables タブに切り替えます。

    1. New repository variable を選択します。
    2. Name フィールドに IMAGE_REGISTRY_USER を入力します。
    3. Value フィールドに、コンテナーイメージレジストリーにアクセスするためのユーザー名を入力します。
    4. Add variable を選択します。
  2. 手順 6 を繰り返して、必要な変数を追加します。

    表1.3 イメージレジストリー変数
    変数説明

    IMAGE_REGISTRY_USER

    コンテナーイメージレジストリーにアクセスするためのユーザー名

    表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 バージョンを指定します。

    オプション: CI プロバイダーランナーが RHTAP インスタンスと同じクラスター上で実行されていない場合は、Rekor および TUF 変数を設定します。

    表1.5 Rekor および TUF 変数
    変数説明

    REKOR_HOST

    Rekor サーバーの URL。

    TUF_MIRROR

    TUF サービスの URL。

  1. 最後のパイプライン実行を再実行して、シークレットが正しく適用されていることを確認します。

    1. または、GitHub でアプリケーションのソースリポジトリーに切り替えて、小さな変更を加え、コミットして新しいパイプラインの実行をトリガーします。

1.2. オプション 2: CLI を使用して GitHub Actions にシークレットと変数を追加する

手順

  1. Visual Studio Code などの任意のテキストエディターで、次の 2 つのファイルを含むプロジェクトを作成します。

    • env_vars.sh
    • ghub-set-vars
  2. 次の環境変数を使用して env_vars.sh ファイルを更新します。

    # env_vars.sh
    
    # GitHub credentials
    export MY_GITHUB_TOKEN="your_github_token_here"
    export MY_GITHUB_USER="your_github_username_here"
    
    export GITOPS_AUTH_PASSWORD="your_OpenShift_GitOps_password_here"
    
    # Image registry variables
    export IMAGE_REGISTRY_USER="your_registry_username_here"
    export IMAGE_REGISTRY_PASSWORD="your_registry_password_here"
    
    // Add credentials for an image repository that you use
    # Quay.io credentials
    export QUAY_IO_CREDS_USR="your_quay_username_here"
    export QUAY_IO_CREDS_PSW="your_quay_password_here"
    
    # or JFrog Artifactory credenditals
    export ARTIFACTORY_IO_CREDS_USR="your_artifactory_username_here"
    export ARTIFACTORY_IO_CREDS_PSW="your_artifactory_password_here"
    
    # or Sonatype Nexus credentials
    export NEXUS_IO_CREDS_USR="your_nexus_username_here"
    export NEXUS_IO_CREDS_PSW="your_nexus_password_here"
    
    // Variables required for ACS tasks
    # ROX variables
    export ROX_CENTRAL_ENDPOINT="your_rox_central_endpoint_here"
    export ROX_API_TOKEN="your_rox_api_token_here"
    
    // Variables required for SBOM tasks.
    # Cosign secrets
    export COSIGN_SECRET_PASSWORD="your_cosign_secret_password_here"
    export COSIGN_SECRET_KEY="your_cosign_secret_key_here"
    export COSIGN_PUBLIC_KEY="your_cosign_public_key_here"
    
    # Trustification credentials
    export TRUSTIFICATION_BOMBASTIC_API_URL="your__BOMBASTIC_API_URL_here"
    export TRUSTIFICATION_OIDC_ISSUER_URL="your_OIDC_ISSUER_URL_here"
    export TRUSTIFICATION_OIDC_CLIENT_ID="your_OIDC_CLIENT_ID_here"
    export TRUSTIFICATION_OIDC_CLIENT_SECRET="your_OIDC_CLIENT_SECRET_here"
    export TRUSTIFICATION_SUPPORTED_CYCLONEDX_VERSION="your_SUPPORTED_CYCLONEDX_VERSION_here"
    
    // Set these variables if your CI provider runners do not run
    on the same cluster as the {ProductShortName} instance.
    # Rekor and TUF routes
    export REKOR_HOST="your rekor server url here"
    export TUF_MIRROR="your tuf service url here"
  3. ghub-set-vars ファイルを次の情報で更新します。

    #!/bin/bash
    
    # Helper script used to simplify setting variables and secrets in a GitHub repository
    
    set -euo pipefail
    
    function echo_usage() {
        echo "Usage: $0 OWNER/REPO"
        echo "       $0 https://github.com/OWNER/REPO"
    }
    
    if [ $# -ne 1 ]; then
        echo "Invalid number of arguments"
        echo
        echo_usage
        exit 1
    fi
    
    github_repository=$1
    
    # Naive check that the provided repository in the argument matches
    # the expected format (see usage)
    if ! [[ "$github_repository" =~ ^(https://github.com/)?(.+/.+)$ ]]; then
        echo "Invalid format of the provided argument '${github_repository}'"
        echo
        echo_usage
    fi
    
    # Set repository variable via GitHub CLI
    # The value of the variable will NOT be hidden in the logs
    function set_variable() {
        echo "Setting variable '$1' in $github_repository..."
        gh variable set "$1" --body "$2" --repo "$github_repository"
    }
    
    # Set repository secret via GitHub CLI
    function set_secret() {
        echo "Setting secret '$1' in $github_repository..."
        gh secret set "$1" --body "$2" --repo "$github_repository"
    }
    
    # Set the minimum required variables and secrets
    
    # Depending on which image repository you use, set:
    set_variable IMAGE_REGISTRY quay.io/"$QUAY_IO_CREDS_USR"
    set_variable IMAGE_REGISTRY_USER "$QUAY_IO_CREDS_USR"
    set_secret IMAGE_REGISTRY_PASSWORD "$QUAY_IO_CREDS_PSW"
    # or
    set_variable IMAGE_REGISTRY_USER "$ARTIFACTORY_IO_CREDS_USR"
    set_secret IMAGE_REGISTRY_PASSWORD "$ARTIFACTORY_IO_CREDS_PSW"
    # or
    set_variable IMAGE_REGISTRY_USER "$NEXUS_IO_CREDS_USR"
    set_secret IMAGE_REGISTRY_PASSWORD "$NEXUS_IO_CREDS_PSW"
    
    set_variable ROX_CENTRAL_ENDPOINT "$ROX_CENTRAL_ENDPOINT"
    set_secret ROX_API_TOKEN "$ROX_API_TOKEN"
    
    set_secret GITOPS_AUTH_PASSWORD "$GITOPS_AUTH_PASSWORD"
    
    set_variable QUAY_IO_CREDS_USR "$QUAY_IO_CREDS_USR"
    set_secret QUAY_IO_CREDS_PSW "$QUAY_IO_CREDS_PSW"
    
    set_secret COSIGN_SECRET_PASSWORD "$COSIGN_SECRET_PASSWORD"
    set_secret COSIGN_SECRET_KEY "$COSIGN_SECRET_KEY"
    set_variable COSIGN_PUBLIC_KEY "$COSIGN_PUBLIC_KEY"
    
    set_variable TRUSTIFICATION_BOMBASTIC_API_URL "$TRUSTIFICATION_BOMBASTIC_API_URL"
    set_variable TRUSTIFICATION_OIDC_ISSUER_URL "$TRUSTIFICATION_OIDC_ISSUER_URL"
    set_variable TRUSTIFICATION_OIDC_CLIENT_ID "$TRUSTIFICATION_OIDC_CLIENT_ID"
    set_variable TRUSTIFICATION_SUPPORTED_CYCLONEDX_VERSION "$TRUSTIFICATION_SUPPORTED_CYCLONEDX_VERSION"
    set_secret TRUSTIFICATION_OIDC_CLIENT_SECRET "$TRUSTIFICATION_OIDC_CLIENT_SECRET"
    
    # If you need to use the Rekor and TUF variables and you've added them to env_vars.sh,
    # set them here too:
    set_variable REKOR_HOST "$REKOR_HOST"
    set_variable TUF_MIRROR "$TUF_MIRROR"
    
    echo
    echo "All variables and secrets are set."
  4. 現在のシェルセッションに環境変数を読み込みます。

    source env_vars.sh
  5. ghub-set-vars スクリプトを実行可能にして、リポジトリー名で実行し、GitHub リポジトリーに変数を設定します。

    chmod +x ghub-set-vars
    
    ./ghub-set-vars your_repository_name
  6. 最後のパイプライン実行を再実行して、シークレットが正しく適用されていることを確認します。

    1. または、GitHub でアプリケーションのソースリポジトリーに切り替えて、小さな変更を加え、コミットして新しいパイプラインの実行をトリガーします。





改訂日時: 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

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

© 2024 Red Hat, Inc.