# Fleet management with custom organization policies

You can use the
[Organization Policy Service](https://docs.cloud.google.com/resource-manager/docs/organization-policy/overview) with
[custom constraints](https://docs.cloud.google.com/managed-spark/docs/concepts/custom-constraints.md.txt) to
enforce specific configurations across your organization's Managed Service for Apache Spark
clusters. This centralized approach helps ensure compliance, control costs, and
standardize your Managed Service for Apache Spark fleet.

This guide shows you how to create and enforce a custom organization policy for
Managed Service for Apache Spark clusters. For more information, see the [Introduction to
the Organization Policy](https://docs.cloud.google.com/resource-manager/docs/organization-policy/overview).

## Before you begin

<br />

## Enforce a custom constraint

The following steps show you how to enforce a common security requirement:
ensuring that all new Managed Service for Apache Spark clusters have Kerberos enabled.

1. Define the custom constraint.

   1. Create a YAML file with the following content:

   ```yaml
   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_ID` with your organization
   ID.
2. Set the custom constraint to make it available to your organization.

   ```bash
   gcloud org-policies set-custom-constraint CONSTRAINT_PATH
   ```

   Replace `CONSTRAINT_PATH` with the path to your
   YAML constraint file.
3. Create an organization policy that enforces the constraint.

   1. Create another YAML file with the following content:

   ```yaml
   name: projects/PROJECT_ID/policies/custom.dataprocKerberos
   spec:
     rules:
       -   enforce: true
   ```

   Replace `PROJECT_ID` with the ID of the project
   to apply the policy to. You can also apply this policy at a folder or
   organization level.
4. Apply the policy.

   ```bash
   gcloud org-policies set-policy POLICY_PATH
   ```

   Replace `POLICY_PATH` with the path to the YAML
   policy file.

After you apply the policy, an attempt to create a Managed Service for Apache Spark
cluster in the specified resource without Kerberos enabled fails.

> [!NOTE]
> **Note:** The policy can take up to 15 minutes to propagate.

## Use cases for custom constraints

You can create custom constraints to enforce a wide range of policies for your
Managed Service for Apache Spark 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](https://docs.cloud.google.com/resource-manager/docs/organization-policy/overview)
- Learn more about [custom
  constraints](https://docs.cloud.google.com/managed-spark/docs/concepts/custom-constraints).