# Security rule

This subsection is focused on virtual machines and enables the configuration of Firewall policy rules for VMs.

## Create rule

<mark style="color:green;">`POST`</mark> `{{BASE_URL}}/api/security-rules`

Create a firewall policy rule for a specific virtual machine.

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer Token |

#### Request Body

| Name                                   | Type   | Description |
| -------------------------------------- | ------ | ----------- |
| data<mark style="color:red;">\*</mark> | Object |             |

{% tabs %}
{% tab title="201: Created " %}

```json
{
    "_id": "6549fdb370c99a149c7919f4",
    "virtualMachine": "6549fc8570c99a149c79193f",
    "direction": "Inbound",
    "name": "SSH",
    "description": "",
    "createdAt": "2023-11-07T09:04:51.342Z",
    "updatedAt": "2023-11-07T09:04:51.342Z"
}
```

{% endtab %}
{% endtabs %}

<details>

<summary>Request payload ( Azure )</summary>

```json
{
    "source": "*",
    "sourcePortRange": "*",
    "sourceAddressPrefix": "*",
    "destination": "*",
    "destinationPortRange": "8080",
    "destinationAddressPrefix": "*",
    "protocol": "*",
    "access": "Allow",
    "priority": 100,
    "direction": "Inbound",
    "name": "Any",
    "description": "",
    "virtualMachine": "6549fc7a70c99a149c7918e8"
}
```

</details>

<details>

<summary>Request payload ( AWS )</summary>

```json
{
    "protocol": "Tcp",
    "direction": "Inbound",
    "portRange": [
        "22"
    ],
    "name": "SSH",
    "description": "",
    "source": "*",
    "cidrBlock": "0.0.0.0/0",
    "virtualMachine": "6549fc8570c99a149c79193f"
}
```

</details>

***

## Get rules

<mark style="color:blue;">`GET`</mark> `{{BASE_URL}}/api/virtual-machines/{id}/security-rules`

Get firewall policy rules for a specific virtual machine.

#### Path Parameters

| Name                                 | Type   | Description |
| ------------------------------------ | ------ | ----------- |
| id<mark style="color:red;">\*</mark> | String | VM ID       |

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer Token |

{% tabs %}
{% tab title="200: OK " %}

```json
[
    {
        "_id": "6549fcb270c99a149c791978",
        "portRange": [
            "22"
        ],
        "source": "*",
        "cidrBlock": "0.0.0.0/0",
        "protocol": "Tcp",
        "rule": "6549fcb270c99a149c791978",
        "virtualMachine": "6549fc8570c99a149c79193f",
        "direction": "Inbound",
        "name": "AllowAnySSHInbound",
        "createdAt": "2023-11-07T09:00:34.142Z",
        "updatedAt": "2023-11-07T09:00:34.142Z"
    }
]
```

{% endtab %}
{% endtabs %}

## Delete rule

<mark style="color:red;">`DELETE`</mark> `{{BASE_URL}}/api/security-rules/{id}`

Delete a firewall policy rule.

#### Path Parameters

| Name                                 | Type   | Description |
| ------------------------------------ | ------ | ----------- |
| id<mark style="color:red;">\*</mark> | String | Rule ID     |

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer Token |

{% tabs %}
{% tab title="200: OK " %}

```json
{"message":"ok"}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.enclaive.cloud/enclaive-multi-cloud-platform/developers/api/client-api/manage/virtual-machine/security-rule.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
