Gestion du parc avec des règles d'administration personnalisées

Vous pouvez utiliser le service de règles d'administration avec des contraintes personnalisées pour appliquer des configurations spécifiques dans les clusters Managed Service for Apache Spark de votre organisation. Cette approche centralisée permet d'assurer la conformité, de contrôler les coûts et de standardiser votre parc Managed Service for Apache Spark.

Ce guide explique comment créer et appliquer une règle d'administration personnalisée pour les clusters Managed Service for Apache Spark. Pour en savoir plus, consultez la présentation des règles d'administration.

Avant de commencer

  1. Connectez-vous à votre Google Cloud compte. Si vous débutez sur Google Cloud, créez un compte pour évaluer les performances de nos produits en conditions réelles. Les nouveaux clients bénéficient également de 300 $de crédits sans frais pour exécuter, tester et déployer des charges de travail.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Resource Manager API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  5. Make sure that you have the following role or roles on the project: Organization Policy Administrator

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. Click Grant access.
    4. In the New principals field, enter your user identifier. This is typically the email address for a Google Account.

    5. Click Select a role, then search for the role.
    6. To grant additional roles, click Add another role and add each additional role.
    7. Click Save.
  6. Installez la Google Cloud CLI.

  7. Si vous utilisez un fournisseur d'identité (IdP) externe, vous devez d'abord vous connecter à la gcloud CLI avec votre identité fédérée.

  8. Pour initialiser la gcloud CLI, exécutez la commande suivante :

    gcloud init
  9. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  10. Verify that billing is enabled for your Google Cloud project.

  11. Enable the Resource Manager API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  12. Make sure that you have the following role or roles on the project: Organization Policy Administrator

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. Click Grant access.
    4. In the New principals field, enter your user identifier. This is typically the email address for a Google Account.

    5. Click Select a role, then search for the role.
    6. To grant additional roles, click Add another role and add each additional role.
    7. Click Save.
  13. Installez la Google Cloud CLI.

  14. Si vous utilisez un fournisseur d'identité (IdP) externe, vous devez d'abord vous connecter à la gcloud CLI avec votre identité fédérée.

  15. Pour initialiser la gcloud CLI, exécutez la commande suivante :

    gcloud init

Appliquer une contrainte personnalisée

Les étapes suivantes vous montrent comment appliquer une exigence de sécurité courante : s'assurer que Kerberos est activé pour tous les nouveaux clusters Managed Service for Apache Spark.

  1. Définissez la contrainte personnalisée.

    1. Créez un fichier YAML avec le contenu suivant :
    name: organizations/ORGANIZATION_ID/customConstraints/custom.dataprocKerberos
    resourceTypes:
    -   dataproc.googleapis.com/Cluster
    methodTypes:
    -   CREATE
    condition: "resource.config.securityConfig.kerberosConfig.enableKerberos == true"
    actionType: ALLOW
    displayName: Cluster must have Kerberos enabled.
    

    Remplacez ORGANIZATION_ID par l'ID de votre organisation.

  2. Définissez la contrainte personnalisée pour la rendre disponible à votre organisation.

    gcloud org-policies set-custom-constraint CONSTRAINT_PATH
    

    Remplacez CONSTRAINT_PATH par le chemin d'accès à votre fichier de contraintes YAML.

  3. Créez une règle d'administration qui applique la contrainte.

    1. Créez un autre fichier YAML avec le contenu suivant :
    name: projects/PROJECT_ID/policies/custom.dataprocKerberos
    spec:
      rules:
        -   enforce: true
    

    Remplacez PROJECT_ID par l'ID du projet auquel appliquer la règle. Vous pouvez également appliquer cette règle au niveau d'un dossier ou d' organisation.

  4. Appliquez la règle.

    gcloud org-policies set-policy POLICY_PATH
    

    Remplacez POLICY_PATH par le chemin d'accès au fichier de règles YAML.

Une fois la règle appliquée, toute tentative de création d'un cluster Managed Service for Apache Spark dans la ressource spécifiée sans Kerberos activé échoue.

Cas d'utilisation des contraintes personnalisées

Vous pouvez créer des contraintes personnalisées pour appliquer un large éventail de règles à votre parc Managed Service for Apache Spark. L'application de règles de parc permet de contrôler les coûts, de standardiser et de sécuriser.

Exemple : Vous pouvez exiger des types de machines spécifiques ou empêcher les adresses IP publiques sur les nœuds de cluster.

Étape suivante