Este conteúdo não está disponível no idioma selecionado.
Chapter 5. Developing Operators
5.1. Token authentication Copiar o linkLink copiado para a área de transferência!
5.1.1. Token authentication for Operators on cloud providers Copiar o linkLink copiado para a área de transferência!
Many cloud providers can enable authentication by using account tokens that provide short-term, limited-privilege security credentials.
OpenShift Container Platform includes the Cloud Credential Operator (CCO) to manage cloud provider credentials as custom resource definitions (CRDs). The CCO syncs on CredentialsRequest
custom resources (CRs) to allow OpenShift Container Platform components to request cloud provider credentials with any specific permissions required.
Previously, on clusters where the CCO is in manual mode, Operators managed by Operator Lifecycle Manager (OLM) often provided detailed instructions in the OperatorHub for how users could manually provision any required cloud credentials.
Starting in OpenShift Container Platform 4.14, the CCO can detect when it is running on clusters enabled to use short-term credentials on certain cloud providers. It can then semi-automate provisioning certain credentials, provided that the Operator author has enabled their Operator to support the updated CCO.
5.1.2. CCO-based workflow for OLM-managed Operators with AWS STS Copiar o linkLink copiado para a área de transferência!
When an OpenShift Container Platform cluster running on AWS is in Security Token Service (STS) mode, it means the cluster is utilizing features of AWS and OpenShift Container Platform to use IAM roles at an application level. STS enables applications to provide a JSON Web Token (JWT) that can assume an IAM role.
The JWT includes an Amazon Resource Name (ARN) for the sts:AssumeRoleWithWebIdentity
IAM action to allow temporarily-granted permission for the service account. The JWT contains the signing keys for the ProjectedServiceAccountToken
that AWS IAM can validate. The service account token itself, which is signed, is used as the JWT required for assuming the AWS role.
The Cloud Credential Operator (CCO) is a cluster Operator installed by default in OpenShift Container Platform clusters running on cloud providers. For the purposes of STS, the CCO provides the following functions:
- Detects when it is running on an STS-enabled cluster
-
Checks the
CredentialsRequest
object for the presence of fields that provide the required information for granting Operators access to AWS resources
The CCO performs this detection even when in manual mode. When properly configured, the CCO projects a Secret
object with the required access information into the Operator namespace.
Starting in OpenShift Container Platform 4.14, the CCO can semi-automate this task through an expanded use of CredentialsRequest
objects, which can request the creation of Secrets
that contain the information required for STS workflows. Users can provide a role ARN when installing the Operator from either the web console or CLI.
Subscriptions with automatic approvals for updates are not recommended because there might be permission changes to make before updating. Subscriptions with manual approvals for updates ensure that administrators have the opportunity to verify the permissions of the later version, take any necessary steps, and then update.
As an Operator author preparing an Operator for use alongside the updated CCO in OpenShift Container Platform 4.14 or later, you should instruct users and add code to handle the divergence from earlier CCO versions, in addition to handling STS token authentication (if your Operator is not already STS-enabled). The recommended method is to provide a CredentialsRequest
object with the correctly filled STS fields and let the CCO create the Secret
for you.
If you plan to support OpenShift Container Platform clusters earlier than version 4.14, consider providing users with instructions on how to manually create a secret with the STS-enabling information by using the CCO utility (ccoctl
). Earlier CCO versions are unaware of STS mode on the cluster and cannot create secrets for you.
Your code should check for secrets that never appear and warn users to follow the fallback instructions you have provided. For more information, see the "Alternative method" subsection.
5.1.2.1. Enabling Operators to support CCO-based workflows with AWS STS Copiar o linkLink copiado para a área de transferência!
As an Operator author designing your project to run on Operator Lifecycle Manager (OLM), you can enable your Operator to authenticate against AWS on STS-enabled OpenShift Container Platform clusters by customizing your project to support the Cloud Credential Operator (CCO).
With this method, the Operator is responsible for and requires RBAC permissions for creating the CredentialsRequest
object and reading the resulting Secret
object.
By default, pods related to the Operator deployment mount a serviceAccountToken
volume so that the service account token can be referenced in the resulting Secret
object.
Prerequisities
- OpenShift Container Platform 4.14 or later
- Cluster in STS mode
- OLM-based Operator project
Procedure
Update your Operator project’s
ClusterServiceVersion
(CSV) object:Ensure your Operator has RBAC permission to create
CredentialsRequests
objects:Example 5.1. Example
clusterPermissions
listCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add the following annotation to claim support for this method of CCO-based workflow with AWS STS:
# ... metadata: annotations: features.operators.openshift.io/token-auth-aws: "true"
# ... metadata: annotations: features.operators.openshift.io/token-auth-aws: "true"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Update your Operator project code:
Get the role ARN from the environment variable set on the pod by the
Subscription
object. For example:// Get ENV var roleARN := os.Getenv("ROLEARN") setupLog.Info("getting role ARN", "role ARN = ", roleARN) webIdentityTokenPath := "/var/run/secrets/openshift/serviceaccount/token"
// Get ENV var roleARN := os.Getenv("ROLEARN") setupLog.Info("getting role ARN", "role ARN = ", roleARN) webIdentityTokenPath := "/var/run/secrets/openshift/serviceaccount/token"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Ensure you have a
CredentialsRequest
object ready to be patched and applied. For example:Example 5.2. Example
CredentialsRequest
object creationCopy to Clipboard Copied! Toggle word wrap Toggle overflow Alternatively, if you are starting from a
CredentialsRequest
object in YAML form (for example, as part of your Operator project code), you can handle it differently:Example 5.3. Example
CredentialsRequest
object creation in YAML formCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteAdding a
CredentialsRequest
object to the Operator bundle is not currently supported.Add the role ARN and web identity token path to the credentials request and apply it during Operator initialization:
Example 5.4. Example applying
CredentialsRequest
object during Operator initializationCopy to Clipboard Copied! Toggle word wrap Toggle overflow Ensure your Operator can wait for a
Secret
object to show up from the CCO, as shown in the following example, which is called along with the other items you are reconciling in your Operator:Example 5.5. Example wait for
Secret
objectCopy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- The
timeout
value is based on an estimate of how fast the CCO might detect an addedCredentialsRequest
object and generate aSecret
object. You might consider lowering the time or creating custom feedback for cluster administrators that could be wondering why the Operator is not yet accessing the cloud resources.
Set up the AWS configuration by reading the secret created by the CCO from the credentials request and creating the AWS config file containing the data from that secret:
Example 5.6. Example AWS configuration creation
Copy to Clipboard Copied! Toggle word wrap Toggle overflow ImportantThe secret is assumed to exist, but your Operator code should wait and retry when using this secret to give time to the CCO to create the secret.
Additionally, the wait period should eventually time out and warn users that the OpenShift Container Platform cluster version, and therefore the CCO, might be an earlier version that does not support the
CredentialsRequest
object workflow with STS detection. In such cases, instruct users that they must add a secret by using another method.Configure the AWS SDK session, for example:
Example 5.7. Example AWS SDK session configuration
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
5.1.2.2. Role specification Copiar o linkLink copiado para a área de transferência!
The Operator description should contain the specifics of the role required to be created before installation, ideally in the form of a script that the administrator can run. For example:
Example 5.8. Example role creation script
5.1.2.3. Troubleshooting Copiar o linkLink copiado para a área de transferência!
5.1.2.3.1. Authentication failure Copiar o linkLink copiado para a área de transferência!
If authentication was not successful, ensure you can assume the role with web identity by using the token provided to the Operator.
Procedure
Extract the token from the pod:
oc exec operator-pod -n <namespace_name> \ -- cat /var/run/secrets/openshift/serviceaccount/token
$ oc exec operator-pod -n <namespace_name> \ -- cat /var/run/secrets/openshift/serviceaccount/token
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Extract the role ARN from the pod:
oc exec operator-pod -n <namespace_name> \ -- cat /<path>/<to>/<secret_name>
$ oc exec operator-pod -n <namespace_name> \ -- cat /<path>/<to>/<secret_name>
1 Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Do not use root for the path.
Try assuming the role with the web identity token:
aws sts assume-role-with-web-identity \ --role-arn $ROLEARN \ --role-session-name <session_name> \ --web-identity-token $TOKEN
$ aws sts assume-role-with-web-identity \ --role-arn $ROLEARN \ --role-session-name <session_name> \ --web-identity-token $TOKEN
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
5.1.2.3.2. Secret not mounting correctly Copiar o linkLink copiado para a área de transferência!
Pods that run as non-root users cannot write to the /root
directory where the AWS shared credentials file is expected to exist by default. If the secret is not mounting correctly to the AWS credentials file path, consider mounting the secret to a different location and enabling the shared credentials file option in the AWS SDK.
5.1.2.4. Alternative method Copiar o linkLink copiado para a área de transferência!
As an alternative method for Operator authors, you can indicate that the user is responsible for creating the CredentialsRequest
object for the Cloud Credential Operator (CCO) before installing the Operator.
The Operator instructions must indicate the following to users:
-
Provide a YAML version of a
CredentialsRequest
object, either by providing the YAML inline in the instructions or pointing users to a download location -
Instruct the user to create the
CredentialsRequest
object
In OpenShift Container Platform 4.14 and later, after the CredentialsRequest
object appears on the cluster with the appropriate STS information added, the Operator can then read the CCO-generated Secret
or mount it, having defined the mount in the cluster service version (CSV).
For earlier versions of OpenShift Container Platform, the Operator instructions must also indicate the following to users:
-
Use the CCO utility (
ccoctl
) to generate theSecret
YAML object from theCredentialsRequest
object -
Apply the
Secret
object to the cluster in the appropriate namespace
The Operator still must be able to consume the resulting secret to communicate with cloud APIs. Because in this case the secret is created by the user before the Operator is installed, the Operator can do either of the following:
-
Define an explicit mount in the
Deployment
object within the CSV -
Programmatically read the
Secret
object from the API server, as shown in the recommended "Enabling Operators to support CCO-based workflows with AWS STS" method
5.1.3. CCO-based workflow for OLM-managed Operators with Microsoft Entra Workload ID Copiar o linkLink copiado para a área de transferência!
When an OpenShift Container Platform cluster running on Azure is in Workload Identity / Federated Identity mode, it means the cluster is utilizing features of Azure and OpenShift Container Platform to apply user-assigned managed identities or app registrations in Microsoft Entra Workload ID at an application level.
The Cloud Credential Operator (CCO) is a cluster Operator installed by default in OpenShift Container Platform clusters running on cloud providers. Starting in OpenShift Container Platform 4.14.8, the CCO supports workflows for OLM-managed Operators with Workload ID.
For the purposes of Workload ID, the CCO provides the following functions:
- Detects when it is running on an Workload ID-enabled cluster
-
Checks the
CredentialsRequest
object for the presence of fields that provide the required information for granting Operators access to Azure resources
The CCO can semi-automate this process through an expanded use of CredentialsRequest
objects, which can request the creation of Secrets
that contain the information required for Workload ID workflows.
Subscriptions with automatic approvals for updates are not recommended because there might be permission changes to make before updating. Subscriptions with manual approvals for updates ensure that administrators have the opportunity to verify the permissions of the later version, take any necessary steps, and then update.
As an Operator author preparing an Operator for use alongside the updated CCO in OpenShift Container Platform 4.14 and later, you should instruct users and add code to handle the divergence from earlier CCO versions, in addition to handling Workload ID token authentication (if your Operator is not already enabled). The recommended method is to provide a CredentialsRequest
object with the correctly filled Workload ID fields and let the CCO create the Secret
object for you.
If you plan to support OpenShift Container Platform clusters earlier than version 4.14, consider providing users with instructions on how to manually create a secret with the Workload ID-enabling information by using the CCO utility (ccoctl
). Earlier CCO versions are unaware of Workload ID mode on the cluster and cannot create secrets for you.
Your code should check for secrets that never appear and warn users to follow the fallback instructions you have provided.
Authentication with Workload ID requires the following information:
-
azure_client_id
-
azure_tenant_id
-
azure_region
-
azure_subscription_id
-
azure_federated_token_file
The Install Operator page in the web console allows cluster administrators to provide this information at installation time. This information is then propagated to the Subscription
object as environment variables on the Operator pod.
5.1.3.1. Enabling Operators to support CCO-based workflows with Microsoft Entra Workload ID Copiar o linkLink copiado para a área de transferência!
As an Operator author designing your project to run on Operator Lifecycle Manager (OLM), you can enable your Operator to authenticate against Microsoft Entra Workload ID-enabled OpenShift Container Platform clusters by customizing your project to support the Cloud Credential Operator (CCO).
With this method, the Operator is responsible for and requires RBAC permissions for creating the CredentialsRequest
object and reading the resulting Secret
object.
By default, pods related to the Operator deployment mount a serviceAccountToken
volume so that the service account token can be referenced in the resulting Secret
object.
Prerequisities
- OpenShift Container Platform 4.14 or later
- Cluster in Workload ID mode
- OLM-based Operator project
Procedure
Update your Operator project’s
ClusterServiceVersion
(CSV) object:Ensure your Operator has RBAC permission to create
CredentialsRequests
objects:Example 5.9. Example
clusterPermissions
listCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add the following annotation to claim support for this method of CCO-based workflow with Workload ID:
# ... metadata: annotations: features.operators.openshift.io/token-auth-azure: "true"
# ... metadata: annotations: features.operators.openshift.io/token-auth-azure: "true"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Update your Operator project code:
Get the client ID, tenant ID, and subscription ID from the environment variables set on the pod by the
Subscription
object. For example:// Get ENV var clientID := os.Getenv("CLIENTID") tenantID := os.Getenv("TENANTID") subscriptionID := os.Getenv("SUBSCRIPTIONID") azureFederatedTokenFile := "/var/run/secrets/openshift/serviceaccount/token"
// Get ENV var clientID := os.Getenv("CLIENTID") tenantID := os.Getenv("TENANTID") subscriptionID := os.Getenv("SUBSCRIPTIONID") azureFederatedTokenFile := "/var/run/secrets/openshift/serviceaccount/token"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Ensure you have a
CredentialsRequest
object ready to be patched and applied.NoteAdding a
CredentialsRequest
object to the Operator bundle is not currently supported.Add the Azure credentials information and web identity token path to the credentials request and apply it during Operator initialization:
Example 5.10. Example applying
CredentialsRequest
object during Operator initializationCopy to Clipboard Copied! Toggle word wrap Toggle overflow Ensure your Operator can wait for a
Secret
object to show up from the CCO, as shown in the following example, which is called along with the other items you are reconciling in your Operator:Example 5.11. Example wait for
Secret
objectCopy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- The
timeout
value is based on an estimate of how fast the CCO might detect an addedCredentialsRequest
object and generate aSecret
object. You might consider lowering the time or creating custom feedback for cluster administrators that could be wondering why the Operator is not yet accessing the cloud resources.
-
Read the secret created by the CCO from the
CredentialsRequest
object to authenticate with Azure and receive the necessary credentials.
5.1.4. CCO-based workflow for OLM-managed Operators with GCP Workload Identity Copiar o linkLink copiado para a área de transferência!
When an OpenShift Container Platform cluster running on Google Cloud Platform (GCP) is in GCP Workload Identity / Federated Identity mode, it means the cluster is utilizing features of Google Cloud Platform (GCP) and OpenShift Container Platform to apply permissions in GCP Workload Identity at an application level.
The Cloud Credential Operator (CCO) is a cluster Operator installed by default in OpenShift Container Platform clusters running on cloud providers. Starting in OpenShift Container Platform 4.17, the CCO supports workflows for OLM-managed Operators with GCP Workload Identity.
For the purposes of GCP Workload Identity, the CCO provides the following functions:
- Detects when it is running on an GCP Workload Identity-enabled cluster
-
Checks the
CredentialsRequest
object for the presence of fields that provide the required information for granting Operators access to GCP resources
The CCO can semi-automate this process through an expanded use of CredentialsRequest
objects, which can request the creation of Secrets
that contain the information required for GCP Workload Identity workflows.
Subscriptions with automatic approvals for updates are not recommended because there might be permission changes to make before updating. Subscriptions with manual approvals for updates ensure that administrators have the opportunity to verify the permissions of the later version, take any necessary steps, and then update.
As an Operator author preparing an Operator for use alongside the updated CCO in OpenShift Container Platform 4.17 and later, you should instruct users and add code to handle the divergence from earlier CCO versions, in addition to handling GCP Workload Identity token authentication (if your Operator is not already enabled). The recommended method is to provide a CredentialsRequest
object with the correctly filled GCP Workload Identity fields and let the CCO create the Secret
object for you.
If you plan to support OpenShift Container Platform clusters earlier than version 4.17, consider providing users with instructions on how to manually create a secret with the GCP Workload Identity-enabling information by using the CCO utility (ccoctl
). Earlier CCO versions are unaware of GCP Workload Identity mode on the cluster and cannot create secrets for you.
Your code should check for secrets that never appear and warn users to follow the fallback instructions you have provided.
To authenticate with GCP using short-lived tokens via Google Cloud Platform Workload Identity, Operators must provide the following information:
AUDIENCE
Created in GCP by the administrator when they set up GCP Workload Identity, the
AUDIENCE
value must be a preformatted URL in the following format://iam.googleapis.com/projects/<project_number>/locations/global/workloadIdentityPools/<pool_id>/providers/<provider_id>
//iam.googleapis.com/projects/<project_number>/locations/global/workloadIdentityPools/<pool_id>/providers/<provider_id>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow SERVICE_ACCOUNT_EMAIL
The
SERVICE_ACCOUNT_EMAIL
value is a GCP service account email that is impersonated during Operator operation, for example:<service_account_name>@<project_id>.iam.gserviceaccount.com
<service_account_name>@<project_id>.iam.gserviceaccount.com
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
The Install Operator page in the web console allows cluster administrators to provide this information at installation time. This information is then propagated to the Subscription
object as environment variables on the Operator pod.
5.1.4.1. Enabling Operators to support CCO-based workflows with GCP Workload Identity Copiar o linkLink copiado para a área de transferência!
As an Operator author designing your project to run on Operator Lifecycle Manager (OLM), you can enable your Operator to authenticate against Google Cloud Platform Workload Identity on OpenShift Container Platform clusters by customizing your project to support the Cloud Credential Operator (CCO).
With this method, the Operator is responsible for and requires RBAC permissions for creating the CredentialsRequest
object and reading the resulting Secret
object.
By default, pods related to the Operator deployment mount a serviceAccountToken
volume so that the service account token can be referenced in the resulting Secret
object.
Prerequisities
- OpenShift Container Platform 4.17 or later
- Cluster in GCP Workload Identity / Federated Identity mode
- OLM-based Operator project
Procedure
Update your Operator project’s
ClusterServiceVersion
(CSV) object:Ensure Operator deployment in the CSV has the following
volumeMounts
andvolumes
fields so that the Operator can assume the role with web identity:Example 5.12. Example
volumeMounts
andvolumes
fieldsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Ensure your Operator has RBAC permission to create
CredentialsRequests
objects:Example 5.13. Example
clusterPermissions
listCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add the following annotation to claim support for this method of CCO-based workflow with GCP Workload Identity:
# ... metadata: annotations: features.operators.openshift.io/token-auth-gcp: "true"
# ... metadata: annotations: features.operators.openshift.io/token-auth-gcp: "true"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Update your Operator project code:
Get the
audience
and theserviceAccountEmail
values from the environment variables set on the pod by the subscription config:// Get ENV var audience := os.Getenv("AUDIENCE") serviceAccountEmail := os.Getenv("SERVICE_ACCOUNT_EMAIL") gcpIdentityTokenFile := "/var/run/secrets/openshift/serviceaccount/token"
// Get ENV var audience := os.Getenv("AUDIENCE") serviceAccountEmail := os.Getenv("SERVICE_ACCOUNT_EMAIL") gcpIdentityTokenFile := "/var/run/secrets/openshift/serviceaccount/token"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Ensure you have a
CredentialsRequest
object ready to be patched and applied.NoteAdding a
CredentialsRequest
object to the Operator bundle is not currently supported.Add the GCP Workload Identity variables to the credentials request and apply it during Operator initialization:
Example 5.14. Example applying
CredentialsRequest
object during Operator initializationCopy to Clipboard Copied! Toggle word wrap Toggle overflow Ensure your Operator can wait for a
Secret
object to show up from the CCO, as shown in the following example, which is called along with the other items you are reconciling in your Operator:Example 5.15. Example wait for
Secret
objectCopy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- The
timeout
value is based on an estimate of how fast the CCO might detect an addedCredentialsRequest
object and generate aSecret
object. You might consider lowering the time or creating custom feedback for cluster administrators that could be wondering why the Operator is not yet accessing the cloud resources.
Read the
service_account.json
field from the secret and use it to authenticate your GCP client:service_account_json := secret.StringData["service_account.json"]
service_account_json := secret.StringData["service_account.json"]
Copy to Clipboard Copied! Toggle word wrap Toggle overflow