Nesta página, documentamos como ativar o Login do SO e configurar uma política da organização para aplicá-la a clusters e nós particulares do GKE. O Login do SO não está disponível para clusters do modo Autopilot do GKE porque o GKE gerencia os nós.
Configure uma restrição de Login do SO na organização para garantir que todos os novos projetos e as instâncias de VM criadas neles tenham esse recurso ativado. O Login do SO se tornou rapidamente uma
prática recomendada de segurança do Google Cloud, recomendando a aplicação do uso
por meio de uma política da organização.
Nas instruções a seguir, detalhamos como ativar o Login do SO usando uma política da organização no GKE.
Antes de começar
Antes de começar, verifique se você realizou as tarefas a seguir:
Se você quiser usar a Google Cloud CLI para essa tarefa,
instale e, em seguida,
inicialize a
CLI gcloud. Se você instalou a CLI gcloud anteriormente, instale a versão
mais recente executando gcloud components update.
Atualizar projetos existentes para usar o login do SO
Antes de definir a política da organização, migre todos os clusters particulares atuais para usar o login do SO.
Atualize a versão em todos os pools de nós em um projeto para uma versão compatível:
VERSION: uma versão compatível com o Login do SO, que pode ser a versão 1.10.5 ou posterior.
Ative o Login do SO em todas as instâncias de VM atuais e novas por padrão definindo a sinalização enable-oslogin como TRUE. Não é necessário reinicializar o nó.
Depois que a política da organização for definida, as seguintes condições serão aplicadas:
enable-oslogin é definido como true nos metadados do projeto para todos os novos projetos.
As solicitações de atualização para definir enable-oslogin como false nos metadados da instância ou do projeto são rejeitadas.
Como gerenciar o acesso ao nó
Depois de ativar a política da organização de Login do SO, não será mais necessário gerenciar chaves SSH para tomar decisões de autorização. O Login do SO move o gerenciamento de autorização para o gerenciamento de identidade e acesso. Para gerenciar o acesso SSH aos nós, use o Login do SO. Para
mais detalhes, consulte Como configurar o Login do SO.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2024-11-21 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)."]]