---
schema_version: "1"
id: e65cd6dd68fa5c885c3aac476e58af5e877141425576b9e5c97614309633dade
title: Applying Custom Policies
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/pdk/1.5/policies-pdk-apply-policies.md
canonical_url: https://docs.mulesoft.com/pdk/1.5/policies-pdk-apply-policies
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 1b40acbd753731a66836c02a4373179c6de6fb8c0d4ea2b68bb929f76820ed4a
description: MuleSoft Documentation Site
release: "1.5"
latest: false
---
---
product: Omni Gateway Policy Development Kit (PDK)
version: 1.5
---

# Applying Custom Policies

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Applying custom policies is the same as applying
[included policies](https://docs.mulesoft.com/gateway/latest/policies-included-directory).

When applying custom policies, the configuration parameters are defined in `definition/gcl.yaml`.

To learn more about defining configuration parameters, see
[Defining a Policy Schema Definition](https://docs.mulesoft.com/pdk/1.5/policies-pdk-create-schema-definition).

## Before You Begin

- [Compile your custom policy](https://docs.mulesoft.com/pdk/1.5/policies-pdk-compile-policies).

- If applying your custom policy to Flex Gateway running in Connected Mode,
  [upload your custom policy to Exchange](https://docs.mulesoft.com/pdk/1.5/policies-pdk-publish-policies).

## Apply Policies in Connected Mode

When you apply a custom policy in Connected Mode, the configuration parameters and metadata defined
in `gcl.yaml` appear in the API Manager UI.

To apply a custom policy in Connected Mode, see
[Applying Policies for Managed Omni Gateways and Connected Mode](https://docs.mulesoft.com/gateway/latest/gateway-secure-conn).

### Update Policies in Connected Mode

To update a custom policy in API Manager:

1.  Go to **Anypoint Platform > API Manager**.

2.  In **API Administration** click the name of the API to which to apply a policy.

3.  From the left navigation menu, click **Policies**.

4.  Click the more options button (![1%](/mulesoft/current/en-us/pdk/1.5/_images/more-options-menu.png)) of the policy you want to
    update, and then click **Edit configuration**.

5.  Select the **latest** version for **Policy version** configuration parameter.

6.  Click **Save**.

7.  Click the more options button (![1%](/mulesoft/current/en-us/pdk/1.5/_images/more-options-menu.png)) of the policy you want to
    update, and then click **Check for implementation updates**.

    For more information about implementation updates, see
    [Update Policy Implementations](https://docs.mulesoft.com/exchange/manage-versions#update-policy-implementations).

8.  In the confirmation dialog box, click **Update all**.

## Apply Policies in Local Mode

For Flex Gateway running in Local Mode, you apply custom policies using
[local declarative configuration files](https://docs.mulesoft.com/gateway/latest/local-configuration-reference-guide).
You specify the location of these configuration files when you first run Flex Gateway.

To create the local declarative files:

1.  In the `target/wasm32-wasip1/release` PDK directory, copy both of the following files:

    - `<your_custom_policy>_definition.yaml`

    - `<your_custom_policy>_implementation.yaml`

2.  Paste the two files in the `/etc/mulesoft/flex-gateway/conf.d/` Flex Gateway configuration
    directory.

3.  Create a policy binding configuration file with a `.yaml` file extension to bind the policy to
    an API instance:

    - Give the file a custom name.

    - Save the file in the Flex Gateway configuration directory
      `/etc/mulesoft/flex-gateway/conf.d/custom`. This directory can contain multiple configuration
      files.

4.  Copy and paste the following YAML snippet into the file, substituting your values where
    indicated:

    ```yaml
    apiVersion: gateway.mulesoft.com/v1alpha1
    kind: PolicyBinding
    metadata:
      name: <custom-policy-id>
    spec:
      targetRef:
        kind: ApiInstance
        name: <your-api-instance>
      policyRef:
        kind: Extension
        name: <your_custom_policy>-<version>-impl
      config:
        <custom-cofiguration-parameters>: "your parameter"
    ```

    - `metadata.name`: The custom policy instance name.

    - `spec.targetRef.name`: The name of the API instance of which to apply the custom policy. The
      API instance must already have been defined and applied.

    - `spec.policyRef.name`: The custom policy implementation ID. To get the policy ID, run the
      `make show-policy-ref-name` command from the policy’s root directory.

    - `spec.config`: Your policy configuration data.

5.  Save the file. The gateway automatically refreshes the configuration.

### Update Policies in Local Mode

To update a custom policy for Flex Gateway running in Local Mode:

- If you did not edit the configuration parameters, replace your old
  `<your_custom_policy>_implementation.yaml` in your Flex Gateway configuration directory with the
  implementation file from your `target/wasm32-wasip1/release` PDK directory.

- If you did edit the configuration parameters, repeat the steps in
  [Apply Policies in Local Mode](#apply-policies-in-local-mode) to update your configuration
  parameters.

## Reorder Custom Policies

Reordering custom policies is the same as reordering included policies.

To reorder policies, see [Ordering Policies](https://docs.mulesoft.com/gateway/latest/policies-reorder).

Polices execute in order on the request and then in inverse order on the response. However, some
policies do not execute on both the request and the response.

For example, policies ordered:

1.  Policy X

2.  Policy Y

Execute Policy X then Policy Y on the request, and Policy Y then Policy X on the response.

## See Also

- [Declarative Configuration Reference Guide](https://docs.mulesoft.com/gateway/latest/local-configuration-reference-guide)
