Cette page explique comment sécuriser une instance Google Kubernetes Engine (GKE) avec Identity-Aware Proxy (IAP).
Présentation
IAP est intégré via l'objet Entrée pour GKE. Cette intégration permet de contrôler l'accès des employés au niveau de la ressource au lieu d'utiliser un VPN.
Dans un cluster GKE, le trafic entrant est géré par l'équilibrage de charge HTTP(S), un composant de Cloud Load Balancing. L'équilibreur de charge HTTP(S) est généralement configuré par le contrôleur Ingress Kubernetes. Le contrôleur d'entrée obtient les informations de configuration à partir d'un objet Ingress Kubernetes associé à un ou plusieurs objets Service. Chaque objet Service contient des informations de routage qui permettent de diriger une requête entrante vers un pod et un port particuliers.
À partir de la version 1.10.5-gke.3 de Kubernetes, vous pouvez ajouter une configuration pour l'équilibreur de charge en associant un service à un objet BackendConfig. BackendConfig est une définition de ressource personnalisée (CRD, Custom Resource Definition) spécifiée dans le dépôt kubernetes/ingress-gce.
Le contrôleur Kubernetes Ingress lit les informations de configuration à partir de BackendConfig et configure l'équilibreur de charge en conséquence. BackendConfig contient les informations de configuration propres à Cloud Load Balancing et permet de définir une configuration distincte pour chaque service de backend de l'équilibrage de charge HTTP(S).
Avant de commencer
Pour activer IAP pour GKE, vous avez besoin des éléments suivants :
- Un projet de console Google Cloud avec la facturation activée
- Un groupe d'une ou de plusieurs instances GKE desservies par un équilibreur de charge HTTPS. L'équilibreur de charge doit se créer automatiquement lorsque vous créez un objet Ingress dans un cluster GKE.
- Découvrez comment créer un objet Ingress pour HTTPS.
- 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.
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 IAP. Si vous souhaitez autoriser l'accès à des utilisateurs externes à votre organisation, consultez la section Activer IAP pour les applications externes.
Activer IAP
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.
Configuring BackendConfig
You can configure a BackendConfig for IAP by adding an iap
block.
Adding an iap
block to the BackendConfig
To configure the BackendConfig for IAP, you need to specify the
enabled
value. Ensure
that you have the compute.backendServices.update
permission and add the
iap
block to BackendConfig.
For GKE versions 1.16.8-gke.3 and higher, use the cloud.google.com/v1
API version.
If you are using an earlier GKE version, use cloud.google.com/v1beta1
.
apiVersion: cloud.google.com/v1 kind: BackendConfig metadata: name: CONFIG_DEFAULT namespace: my-namespace spec: iap: enabled: true
Associate a service port with a BackendConfig
You also need to associate Service ports with your BackendConfig to trigger turning on IAP. One way to make this association is to make all ports for the service default to your BackendConfig, which you can do by adding the following annotation to your Service resource:
metadata: annotations: beta.cloud.google.com/backend-config: '{"default": "CONFIG_DEFAULT"}'
Verify the BackendConfig
To test the configuration, run kubectl get event
. If you see the message
"no BackendConfig for service port exists
", then you successfully
associated a service port with your BackendConfig, but the BackendConfig
resource wasn't found. This error can occur if you haven't created the BackendConfig resource,
created it in the wrong namespace, or misspelled the reference in the Service annotation.
Turning IAP off
To turn IAP off, you must set enabled
to
false
in the BackendConfig. If you delete the IAP
block from BackendConfig, the settings will persist. For example, if IAP is
enabled and you delete the block then IAP will still be turned on.
Étape suivante
- Apprenez à configurer Cloud CDN sur GKE.
- Apprenez à configurer Cloud Armor pour GKE.
- Obtenez plus d'informations sur la ressource BackendConfig.