Cette page explique comment sécuriser une instance Compute Engine avec Identity-Aware Proxy (IAP).
Avant de commencer
Pour activer IAP pour Compute Engine, vous devez disposer des éléments suivants :
- Un projet de la console Google Cloud avec la facturation activée.
- Un groupe d'une ou plusieurs instances Compute Engine desservies par un équilibreur de charge
- Découvrez comment configurer un équilibreur de charge HTTPS externe.
- Découvrez comment configurer un équilibreur de charge HTTP interne.
- Un nom de domaine enregistré à l'adresse de votre équilibreur de charge
- Un code d'application pour vérifier que toutes les requêtes ont une identité
- Découvrez comment obtenir l'identité de l'utilisateur.
Si votre instance Compute Engine n'est pas déjà configurée, consultez la page Configurer IAP pour Compute Engine pour obtenir une présentation complète.
IAP utilise un client OAuth géré par Google pour authentifier les utilisateurs. Seuls les utilisateurs de l'organisation peuvent accéder à l'application compatible avec les achats via l'application. Si vous souhaitez autoriser l'accès à des utilisateurs extérieurs à votre organisation, consultez Activer IAP pour les applications externes.
Vous pouvez activer IAP sur un service de backend Compute Engine ou sur une règle de transfert Compute Engine. Lorsque vous activez IAP sur un service de backend Compute Engine, seul ce service de backend est protégé par IAP. Lorsque vous activez IAP sur une règle de transfert Compute Engine, toutes les instances Compute Engine derrière la règle de transfert sont protégées par IAP.
Activer IAP sur une règle de transfert
Vous pouvez activer IAP sur une règle de transfert à l'aide du framework des règles d'autorisation de l'équilibreur de charge.
gcloud
- Run the following command to prepare a
policy.yamlfile. The policy allows clients with an IP address range of10.0.0.0/24to enable IAP on a forwarding rule.
$ cat << EOF > policy.yaml
action: CUSTOM
description: authz policy with Cloud IAP
name: AUTHZ_POLICY_NAME
httpRules:
- from:
sources:
- ipBlocks:
- prefix: "10.0.0.0"
length: 24
customProvider:
cloudIap: {}
target:
loadBalancingScheme: EXTERNAL_MANAGED
resources:
- https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/LOCATION/forwardingRules/FORWARDING_RULE_ID
EOF
- Run the following command to enable IAP on a forwarding rule.
gcloud network-security authz-policies import AUTHZ_POLICY_NAME \ --source=policy.yaml \ --location=LOCATION \ --project=PROJECT_ID
Replace the following:
- PROJECT_ID: The Google Cloud project ID.
- LOCATION: The region that the resource is located in.
- FORWARDING_RULE_ID: The ID of the forwarding rule resource.
- AUTHZ_POLICY_NAME: The name of the authorization policy.
API
- Run the following command to prepare a
policy.jsonfile.cat << EOF > policy.json { "name": "AUTHZ_POLICY_NAME", "target": { "loadBalancingScheme": "INTERNAL_MANAGED", "resources": [ "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/LOCATION/forwardingRules/FORWARDING_RULE_ID" ], }, "action": "CUSTOM", "httpRules": [ { "from": { "sources": { "ipBlocks": [ { "prefix": "10.0.0.0", "length": 24 } ] } } } ], "customProvider": { "cloudIap": {} } } EOF Run the following command to enable IAP on a forwarding rule.
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d @policy.json \ "https://networksecurity.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/authzPolicies"
Replace the following:
- PROJECT_ID: The Google Cloud project ID.
- LOCATION: The region that the resource is located in.
- FORWARDING_RULE_ID: The ID of the forwarding rule resource.
- AUTHZ_POLICY_NAME: The name of the authorization policy.
Une fois que vous avez activé IAP sur une règle de transfert, vous pouvez appliquer des autorisations aux ressources.
Activer IAP sur un service de backend Compute Engine
Vous pouvez activer IAP sur un service de backend Compute Engine via ce service de backend.
Console
Le client OAuth géré par Google n'est pas disponible lorsque vous activez IAP à l'aide de la console Google Cloud .
If you haven't configured your project's OAuth consent screen, you'll be prompted to do so. To configure your OAuth consent screen, see Setting up your OAuth consent screen.
If you are running GKE clusters version 1.24 or later, you can configure
IAP and GKE by using the Kubernetes Gateway API. To do so, complete
the following steps and then follow the instructions in
Configure IAP.
Do not configure BackendConfig.
Setting up IAP access
-
Go to the
Identity-Aware Proxy page.
Go to the Identity-Aware Proxy page - Select the project you want to secure with IAP.
-
Select the checkbox next to the resource you want to grant access to.
If you don't see a resource, ensure that the resource is created and that the BackendConfig Compute Engine ingress controller is synced.
To verify that the backend service is available, run the following gcloud command:
gcloud compute backend-services list - On the right side panel, click Add principal.
-
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.
The following kinds of principals can have this role:
- Google Account: user@gmail.com
- Google Group: admins@googlegroups.com
- Service account: server@example.gserviceaccount.com
- Google Workspace domain: example.com
Make sure to add a Google Account that you have access to.
- Select Cloud IAP > IAP-secured Web App User from the Roles drop-down list.
- Click Save.
Turning on IAP
-
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,
To enable IAP:- At least one protocol in the load balancer frontend configuration must be HTTPS. Learn about setting up a load balancer.
-
You need the
compute.backendServices.update,clientauthconfig.clients.create,clientauthconfig.clients.update, andclientauthconfig.clients.getWithSecretpermissions. These permissions are granted by roles, such as the Project Editor role. To learn more, see Managing access to IAP-secured resources.
- 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.
gcloud
Pour pouvoir configurer votre projet et IAP, vous devez disposer d'une version à jour de la gcloud CLI. Pour obtenir des instructions sur l'installation de la gcloud CLI, consultez la page Installer la gcloud CLI.
-
Pour vous authentifier, utilisez la Google Cloud CLI et exécutez la commande suivante.
gcloud auth login - Pour vous connecter, suivez l'URL qui s'affiche.
- Une fois la connexion effectuée, copiez le code de validation qui s'affiche et collez-le dans la ligne de commande.
-
Exécutez la commande suivante pour spécifier le projet contenant la ressource que vous souhaitez protéger avec IAP.
gcloud config set project PROJECT_ID -
Pour activer IAP, exécutez la commande à champ d'application global ou régional.
Champ d'application global Champ d'application régionalgcloud compute backend-services update BACKEND_SERVICE_NAME --global --iap=enabledgcloud compute backend-services update BACKEND_SERVICE_NAME --region REGION_NAME --iap=enabled
Une fois que vous avez activé IAP, vous pouvez modifier la stratégie d'accès IAP à l'aide du rôle IAM roles/iap.httpsResourceAccessor via la gcloud CLI. Découvrez comment gérer les rôles et les autorisations.
API
Run the following command to prepare a
settings.jsonfile.cat << EOF > settings.json { "iap": { "enabled":true } } EOFRun the following command to enable IAP.
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d @settings.json \ "https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/REGION/backendServices/BACKEND_SERVICE_NAME"
After you enable IAP, you can use the Google Cloud CLI to modify the
IAP access policy using the IAM role
roles/iap.httpsResourceAccessor. Learn more about
managing roles and permissions.