# Webhooks

A Webhook is a Hook type that sends an HTTP POST request to the configured URL. Any non `2XX` response by the responding endpoint will fail the Hook, cancel the execution of the following Hooks under the same Action. For `pre-*` hooks, the triggering operation will also be aborted.

> [!WARNING]
>
> You should not use `pre-*` webhooks for long-running tasks, since they block the performed operation. Moreover, the branch is locked during the execution of `pre-*` hooks, so the webhook server cannot perform any write operations on the branch (like uploading or commits).

## Restricting webhook destinations

To limit where hooks are allowed to connect, list the IP addresses or CIDR ranges to block under the `actions.network.blocked_addresses` [configuration](<https://docs.lakefs.io/reference/configuration/index.md#actions>):

```yaml
actions:
  network:
    blocked_addresses: ["169.254.169.254", "10.0.0.0/8"]
```

Blocked addresses are enforced on every connection, including redirects, and hook requests connect directly without using proxy environment variables.

## Action File Webhook properties

*See the [Action configuration](<https://docs.lakefs.io/guides/hooks/index.md#action-files>) for overall configuration schema and details.*

| Property | Description | Data Type | Required | Default Value | Env Vars Support |
| --- | --- | --- | --- | --- | --- |
| url | The URL address of the request | String | true |  | no |
| timeout | Time to wait for response before failing the hook | String (golang's [Duration](<https://golang.org/pkg/time/#Duration.String>) representation) | false | 1 minute | no |
| query\_params | List of query params that will be added to the request | Dictionary(String:String or String:List(String) | false |  | yes |
| headers | Headers to add to the request | Dictionary(String:String) | false |  | yes |

**Secrets &amp; Environment Variables**

lakeFS Actions supports secrets by using environment variables. The format `{% raw %}{{{% endraw %} ENV.SOME_ENV_VAR {% raw %}}}{% endraw %}` will be replaced with the value of `$SOME_ENV_VAR` during the execution of the action. If that environment variable doesn't exist in the lakeFS server environment, the action run will fail.

> [!NOTE]
>
> **Info**
>
> All environment variables need to begin with "LAKEFSACTIONS\_". Otherwise, they will be blocked. Additionally, the `actions.env.enabled` configuration parameter can be set to `false` to block access to all environment variables.

> [!NOTE]
>
> **Example**
>
> ```yaml
> ...
> hooks:
> - id: prevent_user_columns
>     type: webhook
>     description: Ensure no user_* columns under public/
>     properties:
>     url: "http://<host:port>/webhooks/schema"
>     timeout: 1m30s
>     query_params:
>         disallow: ["user_", "private_"]
>         prefix: public/
>     headers:
>         secret_header: "{% raw %}{{{% endraw %} ENV.MY_SECRET {% raw %}}}{% endraw %}"
> ...
> ```

## Request body schema

Upon execution, a webhook will send a request containing a JSON object with the following fields:

| Field | Description | Type |
| --- | --- | --- |
| event\_type | Type of the event that triggered the *Action* | string |
| event\_time | Time of the event that triggered the *Action* (RFC3339 formatted) | string |
| action\_name | Containing *Hook* Action's Name | string |
| hook\_id | ID of the *Hook* | string |
| repository\_id | ID of the Repository | string |
| branch\_id[^/guides/hooks/webhooks/#1] | ID of the Branch | string |
| source\_ref | Reference to the source on which the event was triggered | string |
| commit\_message[^/guides/hooks/webhooks/#2] | The message for the commit (or merge) that is taking place | string |
| committer[^/guides/hooks/webhooks/#2] | Name of the committer | string |
| commit\_metadata[^/guides/hooks/webhooks/#2] | The metadata for the commit that is taking place | string |
| commit\_id[^/guides/hooks/webhooks/#3] | The ID of the commit that is being created | string |
| tag\_id | The ID of the created/deleted tag (available for Tag events) | string |
| merge\_source | The source branch/tag/ref on merge (available for Merge events) | string |

> [!NOTE]
>
> **Example**
>
> ```json
> {
>     "event_type": "pre-merge",
>     "event_time": "2021-02-28T14:03:31Z",
>     "action_name": "test action",
>     "hook_id": "prevent_user_columns",
>     "repository_id": "repo1",
>     "branch_id": "feature-1",
>     "source_ref": "feature-1",
>     "commit_message": "merge commit message",
>     "commit_id": "5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03",
>     "committer": "committer",
>     "commit_metadata": {
>         "key": "value"
>     }
> }
> ```

[^/guides/hooks/webhooks/#1]: N/A for Tag events

[^/guides/hooks/webhooks/#2]: N/A for Tag and Create/Delete Branch events

[^/guides/hooks/webhooks/#3]: Available for Commit/Merge events only. In Merge, this represents the merge commit ID to be created if the merge operation succeeds.
