O IAP usa um cliente OAuth gerenciado pelo Google para autenticar usuários.
Somente os usuários da organização podem acessar o aplicativo
ativado para IAPs. Se você quiser permitir o acesso a usuários de fora da sua organização,
consulte Ativar o IAP para aplicativos externos.
É possível ativar o IAP em um serviço de back-end do Compute Engine ou em uma regra de encaminhamento do Compute Engine.
Quando você ativa o IAP em um serviço de back-end do Compute Engine,
somente esse serviço de back-end é protegido pelo IAP. Quando você ativa o IAP em uma regra de encaminhamento do Compute Engine, todas as instâncias do Compute Engine por trás da regra de encaminhamento são protegidas pelo IAP.
Ativar o IAP em uma regra de encaminhamento
É possível ativar o IAP em uma regra de encaminhamento usando o
framework de políticas de autorização
do balanceador de carga.
gcloud
Execute o comando a seguir para preparar um arquivo policy.yaml.
$ cat << EOF > policy.yamlaction:CUSTOMdescription:authz policy with Cloud IAPname:AUTHZ_POLICY_NAMEcustomProvider:cloudIap:{}target:loadBalancingScheme:EXTERNAL_MANAGEDresources:-https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/LOCATION/forwardingRules/FORWARDING_RULE_IDEOF
Execute o comando a seguir para ativar o IAP em uma regra de encaminhamento.
Ativar o IAP em um serviço de back-end do Compute Engine
É possível ativar o IAP em um serviço de back-end do Compute Engine
por esse serviço de back-end.
Console
O cliente OAuth gerenciado pelo Google não está disponível ao ativar o IAP usando o console Google Cloud .
Se você ainda não tiver configurado a tela de consentimento do OAuth do seu projeto, precisará
fazer isso. Para configurar a tela de consentimento do OAuth, consulte
Como configurar a tela de consentimento do OAuth.
Se você estiver executando clusters do GKE na versão 1.24 ou mais recente, será possível configurar
o IAP e o GKE usando a API Kubernetes Gateway. Para fazer isso, siga
as etapas abaixo e depois as instruções em
Configurar o IAP.
Não configure BackendConfig.
Selecione o projeto que você quer proteger com o IAP.
Marque a caixa de seleção ao lado do recurso que você quer conceder acesso.
Se você não encontrar um recurso, verifique se ele foi criado e se o controlador de entrada do Compute Engine BackendConfig foi sincronizado.
Para verificar se o serviço de back-end está disponível, execute o seguinte comando gcloud:
gcloud compute backend-services list
No painel à direita, clique em Adicionar principal.
Na caixa de diálogo Adicionar membros que é exibida, insira os endereços de e-mail de grupos ou
indivíduos que terão o papel Usuário do app da Web protegido pelo IAP no projeto.
Os seguintes tipos de administradores podem ter esse papel:
Conta do Google: user@gmail.com
grupo do Google: admins@googlegroups.com
Conta de serviço: server@example.gserviceaccount.com
Domínio do Google Workspace: example.com
Inclua uma Conta do Google a que você tenha acesso.
Selecione Cloud IAP > Usuário do app da Web protegido pelo IAP na lista suspensa Papéis.
Clique em Salvar.
Como ativar o IAP
Na página Identity-Aware Proxy, em APLICATIVOS,
encontre o balanceador de carga que exibe o instance group a que você quer restringir o acesso. Para ativar o IAP para um recurso, alterne a chave para ativado ou desativado na coluna IAP. Para ativar o IAP:
É necessário que pelo menos um protocolo na configuração de front-end do balanceador de carga seja HTTPS. Saiba mais sobre como configurar um balanceador de carga.
Você precisa ter as permissões compute.backendServices.update, clientauthconfig.clients.create e clientauthconfig.clients.getWithSecret. Elas são concedidas por alguns papéis, como o de editor do projeto. Para saber mais, consulte Como gerenciar o acesso a recursos protegidos pelo IAP.
Na janela Ativar IAP que é exibida, clique em Ativar para confirmar que você quer proteger seu recurso com o IAP. Depois disso, será necessário usar credenciais de login para todas as conexões com o balanceador de carga.
O acesso será concedido apenas às contas com o papel usuário do app da Web protegido pelo IAP no projeto.
gcloud
Antes de configurar o projeto e o IAP, você precisa de uma versão atualizada da
CLI gcloud. Para instruções sobre como instalar a CLI gcloud,
consulte Instalar a CLI gcloud.
Para fazer a autenticação, use a CLI do Google Cloud e execute o comando a seguir.
gcloud auth login
Para fazer login, siga o URL que aparece.
Depois de fazer login, copie o código de verificação que aparece e cole-o na linha de comando.
Execute o comando abaixo para especificar o projeto que contém o recurso que você quer proteger com o IAP.
gcloud config set project PROJECT_ID
Para ativar o IAP, execute o comando com escopo global ou regional.
Depois de ativar o IAP, será possível usar a CLI gcloud para modificar
a política de acesso do IAP usando o papel roles/iap.httpsResourceAccessor do IAM. Saiba mais sobre como gerenciar papéis e permissões.
API
Execute o comando a seguir para preparar um arquivo settings.json.
Depois de ativar o IAP, será possível usar a CLI do Google Cloud para modificar a
política de acesso do IAP usando o papel do IAM
roles/iap.httpsResourceAccessor. Saiba mais sobre como gerenciar papéis e permissões.
[[["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 2025-08-18 UTC."],[[["\u003cp\u003eThis guide outlines the process of securing Compute Engine instances using Identity-Aware Proxy (IAP), which involves enabling IAP on either a backend service or a forwarding rule.\u003c/p\u003e\n"],["\u003cp\u003eTo enable IAP, you'll need a Google Cloud project with billing enabled, a load balancer serving Compute Engine instances, a registered domain name, and code to verify user identity.\u003c/p\u003e\n"],["\u003cp\u003eIAP utilizes a Google-managed OAuth client for user authentication, primarily allowing access to users within the organization, but can be configured for external users.\u003c/p\u003e\n"],["\u003cp\u003eIAP can be enabled on a Compute Engine forwarding rule using load balancer authorization policies, or directly on a backend service using the console, gcloud CLI, or API.\u003c/p\u003e\n"],["\u003cp\u003eOnce enabled, access to IAP-protected resources is managed by assigning the "IAP-Secured Web App User" role to specific Google accounts, groups, service accounts, or Google Workspace domains.\u003c/p\u003e\n"]]],[],null,["# Enable IAP for Compute Engine\n\nThis page explains how to secure a Compute Engine instance with\n[Identity-Aware Proxy (IAP)](/iap/docs/concepts-overview).\n\nBefore you begin\n----------------\n\nTo enable IAP for Compute Engine, you need the\nfollowing:\n\n- A Google Cloud console project with billing enabled.\n- A group of one or more Compute Engine instances, served by a load balancer.\n - Learn about [Setting up an external HTTPS load balancer](/load-balancing/docs/https/setting-up-https).\n - Learn about [setting up an internal HTTP load balancer](/load-balancing/docs/l7-internal/setting-up-l7-internal).\n- A domain name registered to the address of your load balancer.\n- Application code to verify that all requests have an identity.\n - Learn about [Getting the user's identity](/iap/docs/identity-howto).\n\nIf you don't have your Compute Engine instance set up already, see\n[Setting up IAP for Compute Engine](/iap/docs/tutorial-gce)\nfor a complete walkthrough.\n\nIAP uses a Google-managed OAuth client to authenticate users.\nOnly users within the organization can access the IAP-enabled\napplication. If you want to allow access to users outside of your organization,\nsee [Enable IAP for external applications](/iap/docs/custom-oauth-configuration).\n| **Note:** The ability to authenticate users with a Google-managed OAuth client is available in [Preview](/products#product-launch-stages).\n\nYou can enable IAP on a Compute Engine\n[backend service](/load-balancing/docs/backend-service) or on a\nCompute Engine [forwarding rule](/load-balancing/docs/forwarding-rule-concepts).\nWhen you enable IAP on a Compute Engine backend service,\nonly that backend service is protected by IAP. When you enable\nIAP on a Compute Engine forwarding rule, all of the\nCompute Engine instances behind the forwarding rule are protected by\nIAP.\n\nEnable IAP on a forwarding rule\n-------------------------------\n\nYou can enable IAP on a forwarding rule by using the\nload balancer [authorization policies](/load-balancing/docs/auth-policy/auth-policy-overview)\nframework. \n\n### gcloud\n\n1. Run the following command to prepare a `policy.yaml` file.\n\n $ cat \u003c\u003c EOF \u003e policy.yaml\n action: CUSTOM\n description: authz policy with Cloud IAP\n name: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eAUTHZ_POLICY_NAME\u003c/span\u003e\u003c/var\u003e\n customProvider:\n cloudIap: {}\n target:\n loadBalancingScheme: EXTERNAL_MANAGED\n resources:\n - https://www.googleapis.com/compute/v1/projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/regions/\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e/forwardingRules/\u003cvar translate=\"no\"\u003eFORWARDING_RULE_ID\u003c/var\u003e\n EOF\n\n1. Run the following command to enable IAP on a forwarding rule.\n\n```\ngcloud beta network-security authz-policies import AUTHZ_POLICY_NAME \\\n--source=policy.yaml \\\n--location=LOCATION \\\n--project=PROJECT_ID\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: The Google Cloud project ID.\n- \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: The region that the resource is located in.\n- \u003cvar translate=\"no\"\u003eFORWARDING_RULE_ID\u003c/var\u003e: The ID of the forwarding rule resource.\n- \u003cvar translate=\"no\"\u003eAUTHZ_POLICY_NAME\u003c/var\u003e: The name of the authorization policy.\n\n### API\n\n1. Run the following command to prepare a `policy.json` file. \n\n ```\n cat \u003c\u003c EOF \u003e policy.json\n {\n \"name\": \"AUTHZ_POLICY_NAME\",\n \"target\": {\n \"loadBalancingScheme\": \"INTERNAL_MANAGED\",\n \"resources\": [\n \"https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/LOCATION/forwardingRules/FORWARDING_RULE_ID\"\n ],\n },\n \"action\": \"CUSTOM\",\n \"httpRules\": [],\n \"customProvider\": {\n \"cloudIap\": {}\n }\n }\n EOF\n ```\n2. Run the following command to enable IAP on a forwarding rule.\n\n ```\n curl -X PATCH \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n -H \"Accept: application/json\" \\\n -H \"Content-Type: application/json\" \\\n -d @policy.json \\\n \"https://networksecurity.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/authzPolicies\"\n ```\n\n \u003cbr /\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: The Google Cloud project ID.\n - \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: The region that the resource is located in.\n - \u003cvar translate=\"no\"\u003eFORWARDING_RULE_ID\u003c/var\u003e: The ID of the forwarding rule resource.\n - \u003cvar translate=\"no\"\u003eAUTHZ_POLICY_NAME\u003c/var\u003e: The name of the authorization policy.\n\nAfter you enable IAP on a forwarding rule, you can\n[apply permissions to resources](/iap/docs/auth-policies#apply_permissions_to_resources).\n\nEnable IAP on a Compute Engine backend service\n----------------------------------------------\n\nYou can enable IAP on a Compute Engine backend service\nthrough that backend service. \n\n### console\n\nThe Google-managed OAuth client is not available when enabling IAP using the Google Cloud console.\n\nIf you haven't configured your project's OAuth consent screen, you'll be\nprompted to do so. To configure your OAuth consent screen, see\n[Setting up your OAuth consent screen](https://support.google.com/cloud/answer/10311615).\n\nIf you are running GKE clusters version 1.24 or later, you can configure\nIAP and GKE by using the Kubernetes Gateway API. To do so, complete\nthe following steps and then follow the instructions in\n[Configure IAP](/kubernetes-engine/docs/how-to/configure-gateway-resources#configure_iap).\nDo not configure `BackendConfig`.\n\n### Setting up IAP access\n\n1. Go to the [Identity-Aware Proxy page](https://console.cloud.google.com/security/iap). \n [Go to the Identity-Aware Proxy page](https://console.cloud.google.com/security/iap)\n2. Select the project you want to secure with IAP.\n3. Select the checkbox next to the resource you want to grant access to.\n\n If you don't see a resource, ensure that the resource is created and that\n the BackendConfig Compute Engine ingress controller is synced.\n\n To verify that the backend service is available, run the following\n gcloud command:\n `gcloud compute backend-services list`\n4. On the right side panel, click **Add principal**.\n5. In the **Add principals** dialog that appears, enter the email addresses of groups or individuals who should have the **IAP-secured Web App User** role for the project.\n\n The following kinds of principals can have this role:\n - **Google Account**: user@gmail.com\n - **Google Group**: admins@googlegroups.com\n - **Service account**: server@example.gserviceaccount.com\n - **Google Workspace domain**: example.com\n\n Make sure to add a Google Account that you have access to.\n6. Select **Cloud IAP \\\u003e IAP-secured Web App User** from the **Roles** drop-down list.\n7. Click **Save**.\n\n### Turning on IAP\n\n1. On the **Identity-Aware Proxy** page, under **APPLICATIONS** , find the load balancer that serves the instance group you want to restrict access to. To turn on IAP for a resource, toggle the on/off switch in the **IAP** column. \n To enable IAP:\n - At least one protocol in the load balancer frontend configuration must be HTTPS. Learn about [setting up\n a load balancer](/iap/docs/load-balancer-howto).\n - You need the `compute.backendServices.update`, `clientauthconfig.clients.create`, and `clientauthconfig.clients.getWithSecret` permissions. These permissions are granted by roles, such as the Project Editor role. To learn more, see [Managing access to IAP-secured resources](/iap/docs/managing-access#turning_on_and_off).\n2. In the **Turn on IAP** window that appears, click **Turn On** to confirm that you want IAP to secure your resource. After you turn on IAP, it requires login credentials for all connections to your load balancer. Only accounts with the **IAP-Secured Web App User** role on the project will be given access.\n\n### gcloud\n\nBefore you set up your project and IAP, you need an up-to-date version of the\ngcloud CLI. For instructions on how to install the gcloud CLI,\nsee [Install the gcloud CLI](/sdk/downloads).\n\n1. To authenticate, use the Google Cloud CLI and run the following command. \n\n gcloud auth login\n\n2. To sign in, follow the URL that appears.\n3. After you sign in, copy the verification code that appears and paste it in the command line.\n4. Run the following command to specify the project that contains the resource that you want to protect with IAP. \n\n gcloud config set project \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e\n\n5. To enable IAP, run either the globally or regionally scoped command. \n\n Global scope \n\n gcloud compute backend-services update \u003cvar translate=\"no\"\u003eBACKEND_SERVICE_NAME\u003c/var\u003e --global --iap=enabled\n\n Regional scope \n\n gcloud compute backend-services update \u003cvar translate=\"no\"\u003eBACKEND_SERVICE_NAME\u003c/var\u003e --region \u003cvar translate=\"no\"\u003eREGION_NAME\u003c/var\u003e --iap=enabled\n\nAfter you enable IAP, you can use the gcloud CLI to modify\nthe IAP access policy using the IAM role\n`roles/iap.httpsResourceAccessor`. Learn more about\n[managing roles and permissions](/iam/docs/granting-changing-revoking-access).\n\n### API\n\n1. Run the following command to prepare a `settings.json` file.\n\n ```\n cat \u003c\u003c EOF \u003e settings.json\n {\n \"iap\":\n {\n \"enabled\":true\n }\n }\n EOF\n ```\n\n \u003cbr /\u003e\n\n2. Run the following command to enable IAP.\n\n ```\n curl -X PATCH \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n -H \"Accept: application/json\" \\\n -H \"Content-Type: application/json\" \\\n -d @settings.json \\\n \"https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/REGION/backendServices/BACKEND_SERVICE_NAME\"\n ```\n\n \u003cbr /\u003e\n\nAfter you enable IAP, you can use the Google Cloud CLI to modify the\nIAP access policy using the IAM role\n`roles/iap.httpsResourceAccessor`. Learn more about\n[managing roles and permissions](/iam/docs/granting-changing-revoking-access)."]]