Gestione del parco risorse con policy dell'organizzazione personalizzate

Puoi utilizzare il servizio Policy dell'organizzazione con vincoli personalizzati per applicare configurazioni specifiche nei cluster Managed Service per Apache Spark della tua organizzazione. Questo approccio centralizzato contribuisce a garantire la conformità, controllare i costi e standardizzare il parco risorse Managed Service per Apache Spark.

Questa guida mostra come creare e applicare una policy dell'organizzazione personalizzata per i cluster Managed Service per Apache Spark. Per saperne di più, consulta la pagina Introduzione alla policy dell'organizzazione.

Prima di iniziare

  1. Accedi al tuo Google Cloud account. Se non conosci Google Cloud, crea un account per valutare le prestazioni dei nostri prodotti in scenari reali. I nuovi clienti ricevono anche 300 $di crediti senza costi per l'esecuzione, il test e il deployment dei workload.
  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. Installa Google Cloud CLI.

  7. Se utilizzi un provider di identità (IdP) esterno, devi prima accedere a gcloud CLI con la tua identità federata.

  8. Per inizializzare gcloud CLI, esegui questo comando:

    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. Installa Google Cloud CLI.

  14. Se utilizzi un provider di identità (IdP) esterno, devi prima accedere a gcloud CLI con la tua identità federata.

  15. Per inizializzare gcloud CLI, esegui questo comando:

    gcloud init

Applica un vincolo personalizzato

I passaggi seguenti mostrano come applicare un requisito di sicurezza comune: assicurarsi che tutti i nuovi cluster Managed Service per Apache Spark abbiano Kerberos abilitato.

  1. Definisci il vincolo personalizzato.

    1. Crea un file YAML con i seguenti contenuti:
    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.
    

    Sostituisci ORGANIZATION_ID con l'ID della tua organizzazione.

  2. Imposta il vincolo personalizzato in modo che sia disponibile per la tua organizzazione.

    gcloud org-policies set-custom-constraint CONSTRAINT_PATH
    

    Sostituisci CONSTRAINT_PATH con il percorso del file YAML del vincolo.

  3. Crea una policy dell'organizzazione che applichi il vincolo.

    1. Crea un altro file YAML con i seguenti contenuti:
    name: projects/PROJECT_ID/policies/custom.dataprocKerberos
    spec:
      rules:
        -   enforce: true
    

    Sostituisci PROJECT_ID con l'ID del progetto a cui applicare la policy. Puoi applicare questa policy anche a livello di cartella o organizzazione.

  4. Applica la policy.

    gcloud org-policies set-policy POLICY_PATH
    

    Sostituisci POLICY_PATH con il percorso del file YAML della policy.

Dopo aver applicato la policy, un tentativo di creare un cluster Managed Service per Apache Spark nella risorsa specificata senza Kerberos abilitato non riesce.

Casi d'uso per i vincoli personalizzati

Puoi creare vincoli personalizzati per applicare un'ampia gamma di policy per il tuo parco risorse Managed Service per Apache Spark. L'applicazione delle policy del parco risorse contribuisce al controllo dei costi, alla standardizzazione e alla sicurezza.

Esempio: puoi richiedere tipi di macchine specifici o impedire gli indirizzi IP pubblici sui nodi del cluster.

Passaggi successivi