Chapter 2. Configuring GitHub Actions for external integration by using the CLI
このコンテンツは選択した言語では利用できません。
Chapter 2. Configuring GitHub Actions for external integration by using the CLI
Configure GitHub Actions for external integration with Red Hat Advanced Developer Suite - software supply chain using the command-line interface (CLI) to automate security checks and artifact management.
Prerequisites
Before you configure GitHub Actions, ensure you have the following:
Admin access to your GitHub repository and CI/CD settings.
Container registry credentials for pulling container images from Quay, JFrog Artifactory, or Sonatype Nexus Repository.
Authentication details for specific GitHub Actions tasks:
For ACS security tasks:
ROX Central server endpoint
ROX API token
For SBOM and artifact signing tasks:
Cosign signing key password, private key and public key
Trustification API and issuer URL, client ID, client secret, and supported CycloneDX version
Note
The credentials and other details are already Base64-encoded, so you do not need to encode them again. You can find these credentials in your private.env file, which you created during RHADS - SSC installation.
Procedure
Create a project with two files in your preferred text editor, such as Visual Studio Code:
env_vars.sh
ghub-set-vars
Update the env_vars.sh file with the following environment variables:
env_vars.sh
export GITOPS_AUTH_PASSWORD="your_github_token_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"
# env_vars.shexportGITOPS_AUTH_PASSWORD="your_github_token_here"# Image registry variablesexportIMAGE_REGISTRY_USER="your_registry_username_here"exportIMAGE_REGISTRY_PASSWORD="your_registry_password_here"
// Add credentials for an image repository that you use
# Quay.io credentialsexportQUAY_IO_CREDS_USR="your_quay_username_here"exportQUAY_IO_CREDS_PSW="your_quay_password_here"# or JFrog Artifactory credenditalsexportARTIFACTORY_IO_CREDS_USR="your_artifactory_username_here"exportARTIFACTORY_IO_CREDS_PSW="your_artifactory_password_here"# or Sonatype Nexus credentialsexportNEXUS_IO_CREDS_USR="your_nexus_username_here"exportNEXUS_IO_CREDS_PSW="your_nexus_password_here"
// Variables required for ACS tasks
# ROX variablesexportROX_CENTRAL_ENDPOINT="your_rox_central_endpoint_here"exportROX_API_TOKEN="your_rox_api_token_here"
// Variables required for SBOM tasks.
# Cosign secretsexportCOSIGN_SECRET_PASSWORD="your_cosign_secret_password_here"exportCOSIGN_SECRET_KEY="your_cosign_secret_key_here"exportCOSIGN_PUBLIC_KEY="your_cosign_public_key_here"# Trustification credentialsexportTRUSTIFICATION_BOMBASTIC_API_URL="your__BOMBASTIC_API_URL_here"exportTRUSTIFICATION_OIDC_ISSUER_URL="your_OIDC_ISSUER_URL_here"exportTRUSTIFICATION_OIDC_CLIENT_ID="your_OIDC_CLIENT_ID_here"exportTRUSTIFICATION_OIDC_CLIENT_SECRET="your_OIDC_CLIENT_SECRET_here"exportTRUSTIFICATION_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 routesexportREKOR_HOST="your rekor server url here"exportTUF_MIRROR="your tuf service url here"
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Update the ghub-set-vars file with the following information:
#!/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."
#!/bin/bash# Helper script used to simplify setting variables and secrets in a GitHub repositoryset-euo pipefail
functionecho_usage(){echo"Usage: $0 OWNER/REPO"echo" $0 https://github.com/OWNER/REPO"}if[$#-ne1];thenecho"Invalid number of arguments"echo
echo_usage
exit1figithub_repository=$1# Naive check that the provided repository in the argument matches# the expected format (see usage)if![["$github_repository"=~ ^(https://github.com/)?(.+/.+)$ ]];thenecho"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 logsfunctionset_variable(){echo"Setting variable '$1' in $github_repository..."
gh variable set"$1"--body"$2"--repo"$github_repository"}# Set repository secret via GitHub CLIfunctionset_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"echoecho"All variables and secrets are set."
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Load the environment variables into your current shell session:
source env_vars.sh
$ source env_vars.sh
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Make the ghub-set-vars script executable, and run it with your repository name to set the variables in your GitHub repository.
chmod +x ghub-set-vars
$ chmod +x ghub-set-vars
Copy to ClipboardCopied!Toggle word wrapToggle overflow
./ghub-set-vars your_repository_name
$ ./ghub-set-vars your_repository_name
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Rerun the last pipeline run to verify the secrets are applied correctly. Alternatively, switch to you application’s source repository in GitHub, make a minor change, and commit it to trigger a new pipeline run.