Fleet management with custom organization policies
You can use the Organization Policy Service with custom constraints to enforce specific configurations across your organization's Dataproc clusters. This centralized approach helps ensure compliance, control costs, and standardize your Dataproc fleet.
This guide shows you how to create and enforce a custom organization policy for Dataproc clusters. For more information, see the Introduction to the Organization Policy.
Before you begin
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
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 theserviceusage.services.enablepermission. Learn how to grant roles. -
Make sure that you have the following role or roles on the project: Organization Policy Administrator
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
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.
- 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
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
- Click Grant access.
-
In the New principals field, enter your user identifier. This is typically the email address for a Google Account.
- Click Select a role, then search for the role.
- To grant additional roles, click Add another role and add each additional role.
- Click Save.
-
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init -
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
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 theserviceusage.services.enablepermission. Learn how to grant roles. -
Make sure that you have the following role or roles on the project: Organization Policy Administrator
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
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.
- 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
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
- Click Grant access.
-
In the New principals field, enter your user identifier. This is typically the email address for a Google Account.
- Click Select a role, then search for the role.
- To grant additional roles, click Add another role and add each additional role.
- Click Save.
-
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
Enforce a custom constraint
The following steps show you how to enforce a common security requirement: ensuring that all new Dataproc clusters have Kerberos enabled.
Define the custom constraint.
- Create a YAML file with the following content:
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.Replace
ORGANIZATION_IDwith your organization ID.Set the custom constraint to make it available to your organization.
gcloud org-policies set-custom-constraint CONSTRAINT_PATHReplace
CONSTRAINT_PATHwith the path to your YAML constraint file.Create an organization policy that enforces the constraint.
- Create another YAML file with the following content:
name: projects/PROJECT_ID/policies/custom.dataprocKerberos spec: rules: - enforce: trueReplace
PROJECT_IDwith the ID of the project to apply the policy to. You can also apply this policy at a folder or organization level.Apply the policy.
gcloud org-policies set-policy POLICY_PATHReplace
POLICY_PATHwith the path to the YAML policy file.
After you apply the policy, an attempt to create a Dataproc cluster in the specified resource without Kerberos enabled fails.
Use cases for custom constraints
You can create custom constraints to enforce a wide range of policies for your Dataproc fleet. Applying fleet policies helps with cost control, standardization, and security.
Example: You can require specific machine types or prevent public IP addresses on cluster nodes.
What's next
- Read the Introduction to the Organization Policy
- Learn more about custom constraints.