The Organization Policy API uses Kubernetes custom resources and relies on the
Kubernetes Resource Model (KRM). It is used to manage the lifecycle of
organization policies such as creating, updating, deleting.

To use the Organization Policy API, we recommend that you use the Kubernetes CLI
`kubectl`. If your application needs to use its own libraries to call this API,
use the following example, the [full API definition](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/gdcag/apis/service/org-policy/org-policy-krm-api.md.txt), and
the dedicated [policy match page](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/gdcag/apis/service/org-policy/policy-match-section.md.txt) to build your requests.

> [!WARNING]
> **Warning:** While organization policies use an open-source API that's marked as beta (`constraints.gatekeeper.sh/v1beta1`), the organization policy system itself is in alpha. Additional APIs may be introduced in the future to facilitate the management of organisation policies.

## Service endpoint and discovery document

The API endpoint for the Organization Policy API is:
`https://MANAGEMENT_API_SERVER_ENDPOINT/apis/constraints.gatekeeper.sh/v1beta1`
where `MANAGEMENT_API_SERVER_ENDPOINT` is the endpoint of the
Management API server.

Using the `kubectl proxy` command, you can access that URL in your browser or
with a tool such as `curl` to get the discovery document for the Organization
Policy API. The `kubectl proxy` command opens up a proxy to the Kubernetes API
server on your local machine. After that command is running, you can access the
document at the following URL:
`http://127.0.0.1:8001/apis/constraints.gatekeeper.sh/v1beta1`.

## Example KRM

The following is an example of a `GDCHRestrictedServices` object in the
Organization Policy API to restrict the use of the Database Services to projects
that have the label `owner: dba-team`.

```yaml
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: GDCHRestrictedService
metadata:
  name: db-restricted-to-dbas
spec:
  match:
    scope: Namespaced
    namespaceSelector:
      matchExpressions:
      # We are restricting the use of the service in namespaces that
      # DON'T have the owner: dba-team label
      - key: owner
        operator: NotIn
        values:
        - dba-team
    kinds:
    - apiGroups:
      - "postgresql.dbadmin.gdc.goog"
      kinds:
      - Dbclusters
      - Backupplans
      - Imports
      - Restores
    - apiGroups:
      - "oracle.dbadmin.gdc.goog"
      kinds:
      - Dbclusters
      - Backupplans
      - Imports
  parameters:
    disabledOperations:
      - "UPDATE"
      - "CREATE"
```