Cette page explique comment activer OS Login et configurer une règle d'administration afin d'appliquer OS Login pour les clusters et les nœuds privés du mode GKE Standard. OS Login n'est pas disponible pour les clusters GKE en mode Autopilot, car GKE gère les nœuds.
Vous pouvez configurer une contrainte OS Login au sein de votre organisation afin que tous les nouveaux projets et les instances de VM créées dans ces nouveaux projets soient activés. OS Login est rapidement devenue une bonne pratique de sécurité Google Cloud. Nous vous recommandons son utilisation via des règles d'administration.
Les instructions suivantes expliquent comment activer OS Login à l'aide de règles d'administration dans GKE.
Avant de commencer
Avant de commencer, effectuez les tâches suivantes :
Si vous souhaitez utiliser Google Cloud CLI pour cette tâche, installez puis initialisez gcloud CLI. Si vous avez déjà installé gcloud CLI, assurez-vous de disposer de la dernière version en exécutant la commande gcloud components update.
Mettre à jour des projets existants pour utiliser OS Login
Avant de définir les règles d'administration, migrez tous les clusters privés existants pour qu'ils utilisent OS Login.
Mettez à jour la version de tous les pools de nœuds d'un projet vers une version compatible :
VERSION : version compatible avec OS Login, 1.20.5 ou ultérieure
Activez OS Login sur toutes les instances de VM existantes et nouvelles en définissant par défaut l'option enable-oslogin sur TRUE. Vous n'avez pas besoin de redémarrer le nœud.
Une fois les règles d'administration définies, les conditions suivantes sont appliquées :
enable-oslogin est défini sur true dans les métadonnées du projet pour tous les nouveaux projets.
Les demandes de mise à jour pour définir enable-oslogin sur false dans les métadonnées d'instance ou de projet sont rejetées.
Gérer l'accès aux nœuds
Une fois que vous avez activé la règle d'administration d'OS Login, vous n'avez plus besoin de gérer les clés SSH pour prendre des décisions d'autorisation. OS Login déplace la gestion des autorisations vers Identity and Access Management. Pour gérer l'accès SSH aux nœuds, utilisez OS Login. Pour en savoir plus, consultez la page Configurer OS Login.
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 2024/11/22 (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 2024/11/22 (UTC)."],[],[],null,["# Enable and configure OS Login in GKE\n\n[Standard](/kubernetes-engine/docs/concepts/choose-cluster-mode)\n\n*** ** * ** ***\n\nThis page explains how to enable [OS Login](/compute/docs/oslogin) and\nconfigure an organization policy to enforce OS Login for\nGKE Standard mode clusters and nodes. You can use\nOS Login to manage SSH access to your instances using IAM\nwithout having to create and manage individual SSH keys.\n\nOS Login isn't available for GKE\nAutopilot mode clusters because GKE manages the nodes.\n\nClusters that use public nodes don't support OS Login. If this constraint is applied to a project that runs clusters with public nodes, VM instances that are running in that project might not function properly.\n\nThis page is for\nSecurity specialists who\nwant to add OS Login policies on GKE Standard clusters\nto ensure that all VM instances have OS Login by default.\nTo learn more about\ncommon roles and example tasks that we reference in Google Cloud content, see\n[Common GKE user roles and tasks](/kubernetes-engine/enterprise/docs/concepts/roles-tasks).\n\nBefore reading this page, ensure that you're familiar with the [general overview of OS Login](/compute/docs/oslogin).\n\nOverview\n--------\n\nYou can set up an [OS Login](/compute/docs/oslogin) constraint in your\norganization to ensure that all new projects, and the VM instances created in\nthese new projects, have OS Login enabled. OS Login has quickly become a\nGoogle Cloud security best practice, recommending that you enforce its use\nthrough an [organization policy](/compute/docs/oslogin/manage-oslogin-in-an-org#set-org-policy).\n\nThe following instructions detail how to enable OS Login using an organization\npolicy in GKE.\n\nBefore you begin\n----------------\n\nBefore you start, make sure that you have performed the following tasks:\n\n- Enable the Google Kubernetes Engine API.\n[Enable Google Kubernetes Engine API](https://console.cloud.google.com/flows/enableapi?apiid=container.googleapis.com)\n- If you want to use the Google Cloud CLI for this task, [install](/sdk/docs/install) and then [initialize](/sdk/docs/initializing) the gcloud CLI. If you previously installed the gcloud CLI, get the latest version by running `gcloud components update`. **Note:** For existing gcloud CLI installations, make sure to set the `compute/region` [property](/sdk/docs/properties#setting_properties). If you use primarily zonal clusters, set the `compute/zone` instead. By setting a default location, you can avoid errors in the gcloud CLI like the following: `One of [--zone, --region] must be supplied: Please specify location`. You might need to specify the location in certain commands if the location of your cluster differs from the default that you set.\n\nUpdate existing projects to use OS Login\n----------------------------------------\n\nBefore setting the organization policy, migrate any existing clusters to use OS\nLogin.\n\n1. Update the version in all node pools in a project to a supported version:\n\n gcloud container clusters upgrade \u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e \\\n --node-pool=\u003cvar translate=\"no\"\u003eNODE_POOL_NAME\u003c/var\u003e \\\n --cluster-version \u003cvar translate=\"no\"\u003eVERSION\u003c/var\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e: the name of your existing cluster.\n - \u003cvar translate=\"no\"\u003eNODE_POOL_NAME\u003c/var\u003e: the name of the node pool.\n - \u003cvar translate=\"no\"\u003eVERSION\u003c/var\u003e: A version compatible with OS Login, which can be versions 1.20.5 or later.\n2. Enable OS Login on all existing and new VM instances by default by setting\n the `enable-oslogin` flag to `TRUE`. You don't need to reboot the node.\n\n gcloud compute project-info add-metadata --metadata enable-oslogin=TRUE\n\n | **Caution:** Enabling OS Login on instances disables metadata-based SSH key configurations on those instances. Disabling OS Login restores SSH keys that you have [configured in project or instance metadata](/compute/docs/connect/add-ssh-keys#metadata).\n\nSet the OS Login organization policy\n------------------------------------\n\nTo set the OS Login constraint at the organization level, perform the following:\n\n1. Find your organization ID by running the following command:\n\n gcloud organizations list\n\n2. Set the OS Login organization policy. Replace \u003cvar translate=\"no\"\u003eORGANIZATION_ID\u003c/var\u003e\n with your organization ID.\n\n gcloud resource-manager org-policies enable-enforce \\\n compute.requireOsLogin \\\n --organization=\u003cvar translate=\"no\"\u003eORGANIZATION_ID\u003c/var\u003e\n\nAfter the organization policy is set, the following conditions are applied:\n\n- `enable-oslogin` is set to `true` in the project metadata for all new projects.\n- Update requests to set `enable-oslogin` to `false` in instance or project metadata are rejected.\n\n| **Important:** Once you set the OS Login organization policy, unsupported clusters (clusters in versions older than 1.20.5) in the organization will no longer be able to create new nodes. You can choose to [exclude those projects from\n| enforcement](/resource-manager/docs/organization-policy/creating-managing-policies#boolean_constraints).\n\nManage node access\n------------------\n\nOnce you have enabled the OS Login organization policy, you no longer need to\nmanage SSH keys to make authorization decisions. OS Login moves authorization\nmanagement to Identity and Access Management. To manage SSH access to nodes, use OS Login. For\nmore details, see [Setting up OS Login](/compute/docs/instances/managing-instance-access).\n\nWhat's next\n-----------\n\n- Learn about the [OS Login service](/compute/docs/oslogin).\n- Learn to [troubleshoot OS Login](/compute/docs/oslogin/troubleshoot-os-login)."]]