Chapter 2. Uploading images to GCP with RHEL image builder With RHEL image builder, you can build a gce image, provide credentials for your user or GCP service account, and then upload the gce image directly to the GCP environment. 2.1. Configuring and uploading a gce image to GCP by using the CLI Set up a configuration file with credentials to upload your gce image to GCP by using the RHEL image builder CLI. Warning You cannot manually import gce image to GCP, because the image will not boot. You must use either gcloud or RHEL image builder to upload it. Prerequisites You have a valid Google account and credentials to upload your image to GCP. The credentials can be from a user account or a service account. The account associated with the credentials must have at least the following IAM roles assigned: roles/storage.admin - to create and delete storage objects roles/compute.storageAdmin - to import a VM image to Compute Engine. You have an existing GCP bucket. Procedure Use a text editor to create a gcp-config.toml configuration file with the following content: GCP_BUCKET points to an existing bucket. It is used to store the intermediate storage object of the image which is being uploaded. GCP_STORAGE_REGION is both a regular Google storage region and a dual or multi region. OBJECT_KEY is the name of an intermediate storage object. It must not exist before the upload, and it is deleted when the upload process is done. If the object name does not end with .tar.gz , the extension is automatically added to the object name. GCP_CREDENTIALS is a Base64 -encoded scheme of the credentials JSON file downloaded from GCP. The credentials determine which project the GCP uploads the image to. Note Specifying GCP_CREDENTIALS in the gcp-config.toml file is optional if you use a different mechanism to authenticate with GCP. For other authentication methods, see Authenticating with GCP . Retrieve the GCP_CREDENTIALS from the JSON file downloaded from GCP. Create a compose with an additional image name and cloud provider profile: The image build, upload, and cloud registration processes can take up to ten minutes to complete. Verification Verify that the image status is FINISHED: Additional resources Identity and Access Management Create storage buckets 2.2. How RHEL image builder sorts the authentication order of different GCP credentials You can use several different types of credentials with RHEL image builder to authenticate with GCP. If RHEL image builder configuration is set to authenticate with GCP using multiple sets of credentials, it uses the credentials in the following order of preference: Credentials specified with the composer-cli command in the configuration file. Credentials configured in the osbuild-composer worker configuration. Application Default Credentials from the Google GCP SDK library, which tries to automatically find a way to authenticate by using the following options: If the GOOGLE_APPLICATION_CREDENTIALS environment variable is set, Application Default Credentials tries to load and use credentials from the file pointed to by the variable. Application Default Credentials tries to authenticate by using the service account attached to the resource that is running the code. For example, Google Compute Engine VM. Note You must use the GCP credentials to determine which GCP project to upload the image to. Therefore, unless you want to upload all of your images to the same GCP project, you always must specify the credentials in the gcp-config.toml configuration file with the composer-cli command. 2.2.1. Specifying GCP credentials with the composer-cli command You can specify GCP authentication credentials in the upload target configuration gcp-config.toml file. Use a Base64 -encoded scheme of the Google account credentials JSON file to save time. Procedure Get the encoded content of the Google account credentials file with the path stored in GOOGLE_APPLICATION_CREDENTIALS environment variable, by running the following command: In the upload target configuration gcp-config.toml file, set the credentials: 2.2.2. Specifying credentials in the osbuild-composer worker configuration You can configure GCP authentication credentials to be used for GCP globally for all image builds. This way, if you want to import images to the same GCP project, you can use the same credentials for all image uploads to GCP. Procedure In the /etc/osbuild-worker/osbuild-worker.toml worker configuration, set the following credential value:

Commands:
provider = "gcp" [settings] bucket = "GCP_BUCKET" region = "GCP_STORAGE_REGION" object = "OBJECT_KEY" credentials = "GCP_CREDENTIALS"
sudo base64 -w 0 cee-gcp-nasa-476a1fa485b7.json
sudo composer-cli compose start BLUEPRINT-NAME gce IMAGE_KEY gcp-config.toml
sudo composer-cli compose status
base64 -w 0 "USD{GOOGLE_APPLICATION_CREDENTIALS}"
provider = "gcp" [settings] provider = "gcp" [settings] credentials = "GCP_CREDENTIALS"
[gcp] credentials = " PATH_TO_GCP_ACCOUNT_CREDENTIALS "