Configurer l'application de la stratégie d'autorisation binaire
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
L'autorisation binaire pour Google Distributed Cloud est une Google Cloud fonctionnalité qui étend l'application hébergée au moment du déploiement de l'autorisation binaire à vos clusters d'utilisateurs sur site. Le principal cas d'utilisation de l'autorisation binaire sur Google Distributed Cloud consiste à sécuriser les charges de travail sur vos clusters d'utilisateurs. Suivez les étapes de ce guide pour appliquer les règles d'application d'une règle d'autorisation binaire configurée dans votre projet Google Cloud à vos clusters d'utilisateurs. Pour en savoir plus sur les règles et les stratégies d'autorisation binaire, consultez la présentation de l'autorisation binaire.
Prérequis
Avant de pouvoir activer l'application de la règle d'autorisation binaire pour un cluster d'utilisateur, assurez-vous de remplir les critères préalables suivants :
Enregistrer le cluster avec un parc:pour un cluster créé avec gkectl, le cluster est enregistré dans le projet Google Cloud que vous spécifiez dans le champ gkeConnect.projectID du fichier de configuration du cluster. Ce projet est appelé projet hôte du parc.
Pour en savoir plus sur les parcs, y compris sur les cas d'utilisation, les bonnes pratiques et obtenir des exemples, consultez la documentation sur la gestion de parc.
Ajoutez le rôle d'évaluateur de la stratégie d'autorisation binaire à votre projet hôte de parc : pour attribuer le rôle d'évaluateur de la stratégie d'autorisation binaire (roles/binaryauthorization.policyEvaluator) au compte de service Kubernetes sur votre projet hôte du parc, exécutez la commande suivante :
Si votre cluster s'exécute derrière un serveur proxy, assurez-vous que le serveur proxy autorise les connexions à l'API Binary Authorization (binaryauthorization.googleapis.com). Cette API fournit une validation et un contrôle du déploiement basés sur des règles pour les images déployées sur votre cluster. Pour en savoir plus, consultez la page Proxy des règles de proxy et de pare-feu.
Une fois que vous avez rempli les conditions préalables, vous pouvez activer (ou désactiver) la stratégie d'autorisation binaire lorsque vous créez un cluster ou mettez à jour un cluster existant.
Activer la règle d'autorisation binaire lors de la création d'un cluster
Vous pouvez activer l'application de la stratégie d'autorisation binaire avec gkectl ou gcloud CLI.
gkectl
Pour activer l'autorisation binaire lorsque vous créez un cluster avec gkectl, procédez comme suit :
Avant de créer votre cluster, ajoutez binaryAuthorization.evaluationMode au fichier de configuration du cluster utilisateur, comme illustré dans l'exemple suivant:
Les valeurs autorisées pour evaluationMode sont les suivantes :
project_singleton_policy_enforce: appliquez les règles spécifiées dans la règle d'autorisation binaire, également appelée règle Singleton de projet, sur votre Google Cloud projet afin de régir le déploiement des images de conteneurs sur votre cluster.
disabled : désactivez l'utilisation de l'autorisation binaire pour votre cluster.
Il s'agit de la valeur par défaut. Si vous omettez binaryAuthorization, la fonctionnalité est désactivée.
Apportez les autres modifications nécessaires dans le fichier de configuration du cluster, puis exécutez la commande gkectl create cluster.
Activer ou désactiver la règle d'autorisation binaire pour un cluster existant
Si vous disposez d'un cluster de version 1.28 ou ultérieure, vous pouvez activer ou désactiver l'autorisation binaire à tout moment à l'aide de gkectl ou de gcloud CLI.
gkectl
Pour activer :
Modifiez le fichier de configuration du cluster pour ajouter les champs binaryAuthorization :
ADMIN_CLUSTER_KUBECONFIG : chemin d'accès au fichier kubeconfig du cluster d'administrateur
USER_CLUSTER_CONFIG_FILE : chemin d'accès au fichier de configuration du cluster d'utilisateur
Attendez que le déploiement nommé binauthz-module-deployment dans l'espace de noms binauthz-system soit prêt.
Lorsque le déploiement est prêt, l'autorisation binaire applique les règles spécifiées dans la règle d'autorisation binaire, également appelée règle Singleton de projet. Cette stratégie est associée à votre projetGoogle Cloud et spécifie les règles régissant le déploiement des images de conteneur. Pour en savoir plus sur l'utilisation de gkectl pour mettre à jour un cluster, consultez la section Mettre à jour des clusters.
Pour en savoir plus sur les règles et les stratégies d'autorisation binaire, consultez la page Présentation de l'autorisation binaire.
Pour la désactiver :
Modifiez le fichier de configuration du cluster et supprimez la section binaryAuthorization ou définissez evaluationMode sur disabled.
Une fois cette modification effectuée, attendez quelques minutes jusqu'à ce que le déploiement nommé binauthz-module-deployment dans l'espace de noms binauthz-system soit supprimé.
Dépannage
Si vous ne remplissez pas toutes les conditions préalables, un message semblable à celui-ci peut s'afficher, indiquant un problème de configuration de l'autorisation binaire:
failedtovalidateBinaryAuthorizationpolicy
(1)EnsuretheBinaryAuthorizationAPIisenabledforyour Google Cloud project:
gcloudservicesenablebinaryauthorization.googleapis.com--project=PROJECT_ID(2)EnsureanIAMpolicybindingisinplacegrantingbinaryauthorization.policyEvaluatorroletothebinauthz-system/binauthz-agentKubernetesserviceaccount:
gcloudprojectsadd-iam-policy-bindingPROJECT_ID\--member="serviceAccount:PROJECT_ID.svc.id.goog[binauthz-system/binauthz-agent]"\--role=roles/binaryauthorization.policyEvaluator
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/01 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/01 (UTC)."],[],[],null,["Binary Authorization for Google Distributed Cloud is a Google Cloud feature\nthat extends the hosted, deploy-time enforcement of\n[Binary Authorization](/binary-authorization/docs/overview) to your on-premises\nuser clusters. The primary use case for Binary Authorization on\nGoogle Distributed Cloud is to secure workloads on your user clusters. Follow the\nsteps in this guide to apply the enforcement rules of a Binary Authorization\npolicy configured in your Google Cloud project to your user clusters. For more\ninformation about Binary Authorization policies and rules, see\n[Binary Authorizationoverview](/binary-authorization/docs/key-concepts).\n| **Note:** If you enabled the ([Preview](/products#product-launch-stages)) Binary Authorization for Google Distributed Cloud, [disable it and clean up the\n| resources](/binary-authorization/docs/setting-up-on-prem#clean_up) before you enable the GA feature. Use the instructions in this document to enable the GA feature on version 1.28 or higher clusters.\n\nPrerequisites\n\nBefore you can enable Binary Authorization policy enforcement for a user\ncluster, ensure you've met the following prerequisite criteria:\n\n- **Register the cluster with a fleet:** For a cluster created with `gkectl`,\n the cluster is registered to the Google Cloud project that you specify\n in the `gkeConnect.projectID` field in the cluster configuration file. This\n project is referred to as the [fleet host\n project](/anthos/fleet-management/docs/fleet-concepts#fleet-host-project).\n To learn more about fleets, including use cases, best practices, and\n examples, see the [Fleet management](/anthos/fleet-management/docs)\n documentation.\n\n- **Enable the Binary Authorization API in your Google Cloud project:** [enable\n the Binary Authorization service](/binary-authorization/docs/enabling) in\n your fleet host project.\n\n- **Add the Binary Authorization Policy Evaluator role to your fleet host\n project:** To grant the Binary Authorization Policy Evaluator\n (`roles/binaryauthorization.policyEvaluator`) role to the Kubernetes service\n account on your fleet host project, run the following command:\n\n gcloud projects add-iam-policy-binding \u003cvar label=\"ID for the fleet host project\" translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e \\\n --member=\"serviceAccount:\u003cvar scope=\"PROJECT_ID\" translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e.svc.id.goog[binauthz-system/binauthz-agent]\" \\\n --role=\"roles/binaryauthorization.policyEvaluator\"\n\n If your cluster is running behind a proxy server, make sure the proxy server\n allows connections to the Binary Authorization API\n (`binaryauthorization.googleapis.com`). This API provides policy-based\n deployment validation and control for images deployed to your cluster. For\n more information about, see\n [Proxy and firewall rules proxy](/kubernetes-engine/distributed-cloud/vmware/docs/how-to/firewall-rules).\n\nOnce you satisfy the prerequisites, you can enable (or disable) the\nBinary Authorization policy when you create a new cluster or update an existing\ncluster.\n\nEnable the Binary Authorization policy during cluster creation\n\nYou can enable the Binary Authorization policy enforcement with either `gkectl`\nor gcloud CLI. \n\n`gkectl`\n\nTo enable Binary Authorization when you create a cluster with `gkectl`:\n\n1. Before you create your cluster, add\n `binaryAuthorization.evaluationMode` to the user cluster\n configuration file as shown in the following example:\n\n ...\n binaryAuthorization:\n evaluationMode: \"project_singleton_policy_enforce\"\n ...\n\n Allowed values for `evaluationMode` are:\n - `project_singleton_policy_enforce`: enforce the rules specified in the\n Binary Authorization *policy* , also known as a *project-singleton\n policy*, on your Google Cloud project to govern the deployment of\n container images on your cluster.\n\n - `disabled`: disable the use of Binary Authorization for your cluster.\n This is the default value. If you omit `binaryAuthorization`, the\n feature is disabled.\n\n2. Make any other changes needed in the cluster configuration file and then\n run the `gkectl create cluster` command.\n\nFor more information about creating clusters, see\n[Google Distributed Cloud installation overview](/kubernetes-engine/distributed-cloud/vmware/docs/how-to/install-overview).\n\nEnable or disable the Binary Authorization policy for an existing cluster\n\nIf you have an existing version 1.28 or higher cluster, you can enable or\ndisable Binary Authorization at any time, using `gkectl` or\ngcloud CLI. \n\n`gkectl`\n\n- To enable:\n\n 1. Edit the cluster configuration file to add the `binaryAuthorization`\n fields:\n\n ...\n binaryAuthorization:\n evaluationMode: \"project_singleton_policy_enforce\"\n\n 2. Update the cluster:\n\n ```\n gkectl update cluster \\\n --kubeconfig ADMIN_CLUSTER_KUBECONFIG \\\n --config USER_CLUSTER_CONFIG_FILE \\\n --force\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eADMIN_CLUSTER_KUBECONFIG\u003c/var\u003e: the path of the admin cluster kubeconfig file\n - \u003cvar translate=\"no\"\u003eUSER_CLUSTER_CONFIG_FILE\u003c/var\u003e: the path of your user cluster configuration file.\n 3. Wait for the Deployment named `binauthz-module-deployment` in the\n `binauthz-system` namespace to become ready.\n\n When the deployment is ready, Binary Authorization enforces the rules\n specified in the Binary Authorization *policy* , also known as a\n *project-singleton policy* . This policy is associated with your\n Google Cloud project and specifies rules to govern the deployment of\n container images. For more information about using `gkectl` to update a\n cluster, see [Update clusters](/kubernetes-engine/distributed-cloud/vmware/docs/how-to/upgrading).\n For more information about Binary Authorization policies and rules,\n see [Binary Authorization overview](/binary-authorization/docs/key-concepts).\n- To disable:\n\n 1. Edit the cluster configuration file and either remove the\n `binaryAuthorization` section or by set `evaluationMode` to\n `disabled`.\n\n ...\n binaryAuthorization:\n evaluationMode: \"disabled\"\n\n 2. Update the cluster:\n\n ```\n gkectl update cluster \\\n --kubeconfig ADMIN_CLUSTER_KUBECONFIG \\\n --config USER_CLUSTER_CONFIG_FILE \\\n --force\n ```\n\n After you make this change, wait a few minutes until the Deployment named\n `binauthz-module-deployment` in the `binauthz-system` namespace is\n removed.\n\nTroubleshooting\n\nIf you don't complete all of the prerequisites, you may see a message like the\nfollowing indicates there is a problem with the Binary Authorization configuration: \n\n```bash\nfailed to validate Binary Authorization policy\n\n(1) Ensure the Binary Authorization API is enabled for your Google Cloud project:\n gcloud services enable binaryauthorization.googleapis.com --project=PROJECT_ID\n(2) Ensure an IAM policy binding is in place granting binaryauthorization.policyEvaluator role to the binauthz-system/binauthz-agent Kubernetes service account:\n gcloud projects add-iam-policy-binding PROJECT_ID \\\n --member=\"serviceAccount:\u003cvar class=\"readonly\" translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e.svc.id.goog[binauthz-system/binauthz-agent]\" \\\n --role=roles/binaryauthorization.policyEvaluator\n```"]]