Using manual mode with GCP Workload Identity

Manual mode with GCP Workload Identity is supported for Google Cloud Platform (GCP).

This credentials strategy is supported for only new OKD clusters and must be configured during installation. You cannot reconfigure an existing cluster that uses a different credentials strategy to use this feature.

In manual mode with GCP Workload Identity, the individual OKD cluster components can impersonate IAM service accounts using short-term, limited-privilege credentials.

Requests for new and refreshed credentials are automated by using an appropriately configured OpenID Connect (OIDC) identity provider, combined with IAM service accounts. OKD signs service account tokens that are trusted by GCP, and can be projected into a pod and used for authentication. Tokens are refreshed after one hour by default.

Using manual mode with GCP Workload Identity changes the content of the GCP credentials that are provided to individual OKD components.

GCP secret format

  1. apiVersion: v1
  2. kind: Secret
  3. metadata:
  4. namespace: <target_namespace> (1)
  5. name: <target_secret_name> (2)
  6. data:
  7. service_account.json: <service_account> (3)
1The namespace for the component.
2The name of the component secret.
3The Base64 encoded service account.

Content of the Base64 encoded service_account.json file using long-lived credentials

  1. {
  2. "type": "service_account", (1)
  3. "project_id": "<project_id>",
  4. "private_key_id": "<private_key_id>",
  5. "private_key": "<private_key>", (2)
  6. "client_email": "<client_email_address>",
  7. "client_id": "<client_id>",
  8. "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  9. "token_uri": "https://oauth2.googleapis.com/token",
  10. "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  11. "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/<client_email_address>"
  12. }
1The credential type is service_account.
2The private RSA key that is used to authenticate to GCP. This key must be kept secure and is not rotated.

Content of the Base64 encoded service_account.json file using GCP Workload Identity

  1. {
  2. "type": "external_account", (1)
  3. "audience": "//iam.googleapis.com/projects/123456789/locations/global/workloadIdentityPools/test-pool/providers/test-provider", (2)
  4. "subject_token_type": "urn:ietf:params:oauth:token-type:jwt",
  5. "token_url": "https://sts.googleapis.com/v1/token",
  6. "service_account_impersonation_url": "https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/<client_email_address>:generateAccessToken", (3)
  7. "credential_source": {
  8. "file": "<path_to_token>", (4)
  9. "format": {
  10. "type": "text"
  11. }
  12. }
  13. }
1The credential type is external_account.
2The target audience is the GCP Workload Identity provider.
3The resource URL of the service account that can be impersonated with these credentials.
4The path to the service account token inside the pod. By convention, this is /var/run/secrets/openshift/serviceaccount/token for OKD components.

Installing an OKD cluster configured for manual mode with GCP Workload Identity

To install a cluster that is configured to use the Cloud Credential Operator (CCO) in manual mode with GCP Workload Identity:

  1. Configure the Cloud Credential Operator utility.

  2. Create the required GCP resources.

  3. Run the OKD installer.

  4. Verify that the cluster is using short-lived credentials.

Configuring the Cloud Credential Operator utility

To create and manage cloud credentials from outside of the cluster when the Cloud Credential Operator (CCO) is operating in manual mode with GCP Workload Identity, extract and prepare the CCO utility (ccoctl) binary.

The ccoctl is a Linux binary that must run in a Linux environment.

Procedure

  1. Obtain the OKD release image by running the following command:

    1. $ RELEASE_IMAGE=$(./openshift-install version | awk '/release image/ {print $3}')
  2. Obtain the CCO container image from the OKD release image by running the following command:

    1. $ CCO_IMAGE=$(oc adm release info --image-for='cloud-credential-operator' $RELEASE_IMAGE -a ~/.pull-secret)

    Ensure that the architecture of the $RELEASE_IMAGE matches the architecture of the environment in which you will use the ccoctl tool.

  3. Extract the ccoctl binary from the CCO container image within the OKD release image by running the following command:

    1. $ oc image extract $CCO_IMAGE --file="/usr/bin/ccoctl" -a ~/.pull-secret
  4. Change the permissions to make ccoctl executable by running the following command:

    1. $ chmod 775 ccoctl

Verification

  • To verify that ccoctl is ready to use, display the help file by running the following command:

    1. $ ccoctl --help

    Output of ccoctl --help:

    1. OpenShift credentials provisioning tool
    2. Usage:
    3. ccoctl [command]
    4. Available Commands:
    5. alibabacloud Manage credentials objects for alibaba cloud
    6. aws Manage credentials objects for AWS cloud
    7. gcp Manage credentials objects for Google cloud
    8. help Help about any command
    9. ibmcloud Manage credentials objects for IBM Cloud
    10. nutanix Manage credentials objects for Nutanix
    11. Flags:
    12. -h, --help help for ccoctl
    13. Use "ccoctl [command] --help" for more information about a command.

Creating GCP resources with the Cloud Credential Operator utility

You can use the ccoctl gcp create-all command to automate the creation of GCP resources.

By default, ccoctl creates objects in the directory in which the commands are run. To create the objects in a different directory, use the —output-dir flag. This procedure uses <path_to_ccoctl_output_dir> to refer to this directory.

Prerequisites

You must have:

  • Extracted and prepared the ccoctl binary.

Procedure

  1. Extract the list of CredentialsRequest objects from the OKD release image:

    1. $ oc adm release extract \
    2. --credentials-requests \
    3. --cloud=gcp \
    4. --to=<path_to_directory_with_list_of_credentials_requests>/credrequests \ (1)
    5. quay.io/<path_to>/ocp-release:<version>
    1credrequests is the directory where the list of CredentialsRequest objects is stored. This command creates the directory if it does not exist.

    This command can take a few moments to run.

  2. If your cluster uses cluster capabilities to disable one or more optional components, delete the CredentialsRequest custom resources for any disabled components.

    Example credrequests directory contents for OKD 4.12 on GCP

    1. 0000_26_cloud-controller-manager-operator_16_credentialsrequest-gcp.yaml (1)
    2. 0000_30_machine-api-operator_00_credentials-request.yaml (2)
    3. 0000_50_cloud-credential-operator_05-gcp-ro-credentialsrequest.yaml (3)
    4. 0000_50_cluster-image-registry-operator_01-registry-credentials-request-gcs.yaml (4)
    5. 0000_50_cluster-ingress-operator_00-ingress-credentials-request.yaml (5)
    6. 0000_50_cluster-network-operator_02-cncc-credentials.yaml (6)
    7. 0000_50_cluster-storage-operator_03_credentials_request_gcp.yaml (7)
    1The Cloud Controller Manager Operator CR is required.
    2The Machine API Operator CR is required.
    3The Cloud Credential Operator CR is required.
    4The Image Registry Operator CR is required.
    5The Ingress Operator CR is required.
    6The Network Operator CR is required.
    7The Storage Operator CR is an optional component and might be disabled in your cluster.
  3. Use the ccoctl tool to process all CredentialsRequest objects in the credrequests directory:

    1. $ ccoctl gcp create-all \
    2. --name=<name> \
    3. --region=<gcp_region> \
    4. --project=<gcp_project_id> \
    5. --credentials-requests-dir=<path_to_directory_with_list_of_credentials_requests>/credrequests

    where:

    • <name> is the user-defined name for all created GCP resources used for tracking.

    • <gcp_region> is the GCP region in which cloud resources will be created.

    • <gcp_project_id> is the GCP project ID in which cloud resources will be created.

    • <path_to_directory_with_list_of_credentials_requests>/credrequests is the directory containing the files of CredentialsRequest manifests to create GCP service accounts.

    If your cluster uses Technology Preview features that are enabled by the TechPreviewNoUpgrade feature set, you must include the —enable-tech-preview parameter.

Verification

  • To verify that the OKD secrets are created, list the files in the <path_to_ccoctl_output_dir>/manifests directory:

    1. $ ls <path_to_ccoctl_output_dir>/manifests

You can verify that the IAM service accounts are created by querying GCP. For more information, refer to GCP documentation on listing IAM service accounts.

Running the installer

Prerequisites

  • Configure an account with the cloud platform that hosts your cluster.

  • Obtain the OKD release image.

Procedure

  1. Change to the directory that contains the installation program and create the install-config.yaml file:

    1. $ openshift-install create install-config --dir <installation_directory>

    where <installation_directory> is the directory in which the installation program creates files.

  2. Edit the install-config.yaml configuration file so that it contains the credentialsMode parameter set to Manual.

    Example install-config.yaml configuration file

    1. apiVersion: v1
    2. baseDomain: cluster1.example.com
    3. credentialsMode: Manual (1)
    4. compute:
    5. - architecture: amd64
    6. hyperthreading: Enabled
    1This line is added to set the credentialsMode parameter to Manual.
  3. Create the required OKD installation manifests:

    1. $ openshift-install create manifests
  4. Copy the manifests that ccoctl generated to the manifests directory that the installation program created:

    1. $ cp /<path_to_ccoctl_output_dir>/manifests/* ./manifests/
  5. Copy the private key that the ccoctl generated in the tls directory to the installation directory:

    1. $ cp -a /<path_to_ccoctl_output_dir>/tls .
  6. Run the OKD installer:

    1. $ ./openshift-install create cluster

Verifying the installation

  1. Connect to the OKD cluster.

  2. Verify that the cluster does not have root credentials:

    1. $ oc get secrets -n kube-system gcp-credentials

    The output should look similar to:

    1. Error from server (NotFound): secrets "gcp-credentials" not found
  3. Verify that the components are assuming the service accounts that are specified in the secret manifests, instead of using credentials that are created by the CCO:

    Example command with the Image Registry Operator

    1. $ oc get secrets -n openshift-image-registry installer-cloud-credentials -o json | jq -r '.data."service_account.json"' | base64 -d

    The output should show the role and web identity token that are used by the component and look similar to:

    Example output with the Image Registry Operator

    1. {
    2. "type": "external_account", (1)
    3. "audience": "//iam.googleapis.com/projects/123456789/locations/global/workloadIdentityPools/test-pool/providers/test-provider",
    4. "subject_token_type": "urn:ietf:params:oauth:token-type:jwt",
    5. "token_url": "https://sts.googleapis.com/v1/token",
    6. "service_account_impersonation_url": "https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/<client-email-address>:generateAccessToken", (2)
    7. "credential_source": {
    8. "file": "/var/run/secrets/openshift/serviceaccount/token",
    9. "format": {
    10. "type": "text"
    11. }
    12. }
    13. }
    1The credential type is external_account.
    2The resource URL of the service account used by the Image Registry Operator.

Upgrading an OKD cluster configured for manual mode with GCP Workload Identity

The release image for the version of OKD that you are upgrading to contains a version of the ccoctl binary and list of CredentialsRequest objects specific to that release.

Configuring the Cloud Credential Operator utility

To create and manage cloud credentials from outside of the cluster when the Cloud Credential Operator (CCO) is operating in manual mode with GCP Workload Identity, extract and prepare the CCO utility (ccoctl) binary.

The ccoctl is a Linux binary that must run in a Linux environment.

Procedure

  1. Obtain the OKD release image by running the following command:

    1. $ RELEASE_IMAGE=$(./openshift-install version | awk '/release image/ {print $3}')
  2. Obtain the CCO container image from the OKD release image by running the following command:

    1. $ CCO_IMAGE=$(oc adm release info --image-for='cloud-credential-operator' $RELEASE_IMAGE -a ~/.pull-secret)

    Ensure that the architecture of the $RELEASE_IMAGE matches the architecture of the environment in which you will use the ccoctl tool.

  3. Extract the ccoctl binary from the CCO container image within the OKD release image by running the following command:

    1. $ oc image extract $CCO_IMAGE --file="/usr/bin/ccoctl" -a ~/.pull-secret
  4. Change the permissions to make ccoctl executable by running the following command:

    1. $ chmod 775 ccoctl

Verification

  • To verify that ccoctl is ready to use, display the help file by running the following command:

    1. $ ccoctl --help

    Output of ccoctl --help:

    1. OpenShift credentials provisioning tool
    2. Usage:
    3. ccoctl [command]
    4. Available Commands:
    5. alibabacloud Manage credentials objects for alibaba cloud
    6. aws Manage credentials objects for AWS cloud
    7. gcp Manage credentials objects for Google cloud
    8. help Help about any command
    9. ibmcloud Manage credentials objects for IBM Cloud
    10. nutanix Manage credentials objects for Nutanix
    11. Flags:
    12. -h, --help help for ccoctl
    13. Use "ccoctl [command] --help" for more information about a command.

Updating cloud provider resources with the Cloud Credential Operator utility

The process for upgrading an OKD cluster configured for manual mode with GCP Workload Identity is similar to creating the cloud provider resources during installation.

By default, ccoctl creates objects in the directory in which the commands are run. To create the objects in a different directory, use the —output-dir flag. This procedure uses <path_to_ccoctl_output_dir> to refer to this directory.

Prerequisites

  • Obtain the OKD release image for the version that you are upgrading to.

  • Extract and prepare the ccoctl binary from the release image.

Procedure

  1. Extract the list of CredentialsRequest custom resources (CRs) from the OKD release image by running the following command:

    1. $ oc adm release extract --credentials-requests \
    2. --cloud=gcp \
    3. --to=<path_to_directory_with_list_of_credentials_requests>/credrequests \ (1)
    4. quay.io/<path_to>/ocp-release:<version>
    1credrequests is the directory where the list of CredentialsRequest objects is stored. This command creates the directory if it does not exist.
  2. For each CredentialsRequest CR in the release image, ensure that a namespace that matches the text in the spec.secretRef.namespace field exists in the cluster. This field is where the generated secrets that hold the credentials configuration are stored.

    Sample GCP CredentialsRequest object

    1. apiVersion: cloudcredential.openshift.io/v1
    2. kind: CredentialsRequest
    3. metadata:
    4. annotations:
    5. exclude.release.openshift.io/internal-openshift-hosted: "true"
    6. include.release.openshift.io/self-managed-high-availability: "true"
    7. name: cloud-credential-operator-gcp-ro-creds
    8. namespace: openshift-cloud-credential-operator
    9. spec:
    10. providerSpec:
    11. apiVersion: cloudcredential.openshift.io/v1
    12. kind: GCPProviderSpec
    13. predefinedRoles:
    14. - roles/iam.securityReviewer
    15. - roles/iam.roleViewer
    16. skipServiceCheck: true
    17. secretRef:
    18. name: cloud-credential-operator-gcp-ro-creds
    19. namespace: openshift-cloud-credential-operator (1)
    20. serviceAccountNames:
    21. - cloud-credential-operator
    1This field indicates the namespace which needs to exist to hold the generated secret.
  3. For any CredentialsRequest CR for which the cluster does not already have a namespace with the name specified in spec.secretRef.namespace, create the namespace by running the following command:

    1. $ oc create namespace <component_namespace>
  4. Use the ccoctl tool to process all CredentialsRequest objects in the credrequests directory by running the following command:

    1. $ ccoctl gcp create-service-accounts \
    2. --credentials-requests-dir=<path_to_directory_with_list_of_credentials_requests>/credrequests \
    3. --name=<name> \
    4. --project=<gcp_project_id> \
    5. --workload-identity-pool=<name> \
    6. --workload-identity-provider=<name>

    where:

    • <path_to_directory_with_list_of_credentials_requests>/credrequests is the directory containing the files of CredentialsRequest manifests to create GCP service accounts.

    • <name> is the user-defined name for all created GCP resources used for tracking.

    • <gcp_project_id> is the GCP project ID in which cloud resources will be created.

    If your cluster uses Technology Preview features that are enabled by the TechPreviewNoUpgrade feature set, you must include the —enable-tech-preview parameter.

    For each CredentialsRequest object, ccoctl creates a service account and a permissions policy as defined in each CredentialsRequest object from the OKD release image.

  5. Apply the secrets to your cluster by running the following command:

    1. $ ls <path_to_ccoctl_output_dir>/manifests/*-credentials.yaml | xargs -I{} oc apply -f {}

Verification

You can verify that the service accounts are created by querying GCP. For more information, refer to GCP documentation on listing service accounts.

Upgrading clusters with manually maintained credentials

The Cloud Credential Operator (CCO) Upgradable status for a cluster with manually maintained credentials is False by default.

  • For minor releases, for example, from 4.11 to 4.12, this status prevents you from upgrading until you have addressed any updated permissions and annotated the CloudCredential resource to indicate that the permissions are updated as needed for the next version. This annotation changes the Upgradable status to True.

  • For z-stream releases, for example, from 4.12.0 to 4.12.1, no permissions are added or changed, so the upgrade is not blocked.

Before upgrading a cluster with manually maintained credentials, you must create any new credentials for the release image that you are upgrading to. Additionally, you must review the required permissions for existing credentials and accommodate any new permissions requirements in the new release for those components.

Procedure

  1. Extract and examine the CredentialsRequest custom resource for the new release.

    The “Manually creating IAM” section of the installation content for your cloud provider explains how to obtain and use the credentials required for your cloud.

  2. Update the manually maintained credentials on your cluster:

    • Create new secrets for any CredentialsRequest custom resources that are added by the new release image.

    • If the CredentialsRequest custom resources for any existing credentials that are stored in secrets have changed their permissions requirements, update the permissions as required.

    If your cluster uses cluster capabilities to disable one or more optional components, delete the CredentialsRequest custom resources for any disabled components.

  3. When all of the secrets are correct for the new release, indicate that the cluster is ready to upgrade:

    1. Log in to the OKD CLI as a user with the cluster-admin role.

    2. Edit the CloudCredential resource to add an upgradeable-to annotation within the metadata field:

      1. $ oc edit cloudcredential cluster

      Text to add

      1. ...
      2. metadata:
      3. annotations:
      4. cloudcredential.openshift.io/upgradeable-to: <version_number>
      5. ...

      Where <version_number> is the version you are upgrading to, in the format x.y.z. For example, 4.8.2 for OKD 4.8.2.

      It may take several minutes after adding the annotation for the upgradeable status to change.

Verification

  1. In the Administrator perspective of the web console, navigate to AdministrationCluster Settings.

  2. To view the CCO status details, click cloud-credential in the Cluster Operators list.

    1. If the Upgradeable status in the Conditions section is False, verify that the upgradeable-to annotation is free of typographical errors. When the Upgradeable status in the Conditions section is True, you can begin the OKD upgrade.