Files
netbird-docs/docs/api/create-a-policy.api.mdx
2023-04-26 15:06:59 +02:00

62 lines
17 KiB
Plaintext

---
id: create-a-policy
title: "Create a Policy"
description: "Creates a Policy"
sidebar_label: "Create a Policy"
hide_title: true
hide_table_of_contents: true
api: {"description":"Creates a Policy","tags":["Policies"],"security":[{"BearerAuth":[]},{"TokenAuth":[]}],"requestBody":{"description":"New Policy request","content":{"application/json":{"schema":{"allOf":[{"type":"object","properties":{"name":{"description":"Policy name identifier","type":"string"},"description":{"description":"Policy friendly description","type":"string"},"enabled":{"description":"Policy status","type":"boolean"},"query":{"description":"Policy Rego query","type":"string"},"rules":{"description":"Policy rule object for policy UI editor","type":"array","items":{"type":"object","properties":{"id":{"description":"Rule ID","type":"string"},"name":{"description":"Rule name identifier","type":"string"},"description":{"description":"Rule friendly description","type":"string"},"enabled":{"description":"Rules status","type":"boolean"},"sources":{"description":"policy source groups","type":"array","items":{"type":"object","properties":{"id":{"description":"Group ID","type":"string"},"name":{"description":"Group Name identifier","type":"string"},"peers_count":{"description":"Count of peers associated to the group","type":"integer"}},"required":["id","name","peers_count"],"title":"GroupMinimum"}},"destinations":{"description":"policy destination groups","type":"array","items":{"type":"object","properties":{"id":{"description":"Group ID","type":"string"},"name":{"description":"Group Name identifier","type":"string"},"peers_count":{"description":"Count of peers associated to the group","type":"integer"}},"required":["id","name","peers_count"],"title":"GroupMinimum"}},"action":{"description":"policy accept or drops packets","type":"string","enum":["accept","drop"]}},"required":["name","sources","destinations","action","enabled"],"title":"PolicyRule"}}},"required":["name","description","enabled","query","rules"],"title":"PolicyMinimum"}]}}}},"responses":{"200":{"description":"A Policy Object","content":{"application/json":{"schema":{"allOf":[{"type":"object","properties":{"name":{"description":"Policy name identifier","type":"string"},"description":{"description":"Policy friendly description","type":"string"},"enabled":{"description":"Policy status","type":"boolean"},"query":{"description":"Policy Rego query","type":"string"},"rules":{"description":"Policy rule object for policy UI editor","type":"array","items":{"type":"object","properties":{"id":{"description":"Rule ID","type":"string"},"name":{"description":"Rule name identifier","type":"string"},"description":{"description":"Rule friendly description","type":"string"},"enabled":{"description":"Rules status","type":"boolean"},"sources":{"description":"policy source groups","type":"array","items":{"type":"object","properties":{"id":{"description":"Group ID","type":"string"},"name":{"description":"Group Name identifier","type":"string"},"peers_count":{"description":"Count of peers associated to the group","type":"integer"}},"required":["id","name","peers_count"],"title":"GroupMinimum"}},"destinations":{"description":"policy destination groups","type":"array","items":{"type":"object","properties":{"id":{"description":"Group ID","type":"string"},"name":{"description":"Group Name identifier","type":"string"},"peers_count":{"description":"Count of peers associated to the group","type":"integer"}},"required":["id","name","peers_count"],"title":"GroupMinimum"}},"action":{"description":"policy accept or drops packets","type":"string","enum":["accept","drop"]}},"required":["name","sources","destinations","action","enabled"],"title":"PolicyRule"}}},"required":["name","description","enabled","query","rules"],"title":"PolicyMinimum"},{"type":"object","properties":{"id":{"description":"Policy ID","type":"string"}},"required":["id"]}],"title":"Policy"}}}}},"method":"post","path":"/api/policies","servers":[{"url":"https://netbird.io","description":"Default server"}],"securitySchemes":{"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"},"TokenAuth":{"type":"apiKey","in":"header","name":"Authorization","description":"Prefix the value with \\\"Token\\\" to indicate the custom authorization type"}},"jsonRequestBodyExample":{"name":"string","description":"string","enabled":true,"query":"string","rules":[{"id":"string","name":"string","description":"string","enabled":true,"sources":[{"id":"string","name":"string","peers_count":0}],"destinations":[{"id":"string","name":"string","peers_count":0}],"action":"accept"}]},"info":{"title":"NetBird REST API","description":"API to manipulate groups, rules, policies and retrieve information about peers and users","version":"0.0.1"},"postman":{"name":"Create a Policy","description":{"content":"Creates a Policy","type":"text/plain"},"url":{"path":["api","policies"],"host":["{{baseUrl}}"],"query":[],"variable":[]},"header":[{"key":"Content-Type","value":"application/json"},{"key":"Accept","value":"application/json"}],"method":"POST","body":{"mode":"raw","raw":"\"\"","options":{"raw":{"language":"json"}}},"auth":{"type":"bearer","bearer":[{"type":"any","value":"<Bearer Token>","key":"token"}]}}}
sidebar_class_name: "post api-method"
info_path: api/netbird-rest-api
custom_edit_url: null
---
import ApiTabs from "@theme/ApiTabs";
import MimeTabs from "@theme/MimeTabs";
import ParamsItem from "@theme/ParamsItem";
import ResponseSamples from "@theme/ResponseSamples";
import SchemaItem from "@theme/SchemaItem";
import SchemaTabs from "@theme/SchemaTabs";
import DiscriminatorTabs from "@theme/DiscriminatorTabs";
import TabItem from "@theme/TabItem";
## Create a Policy
Creates a Policy
<MimeTabs><TabItem label={"application/json"} value={"application/json-schema"}><details style={{}} data-collapsed={false} open={true}><summary style={{"textAlign":"left"}}><strong>Request Body</strong></summary><div style={{"textAlign":"left","marginLeft":"1rem"}}><div style={{"marginTop":"1rem","marginBottom":"1rem"}}>
New Policy request
</div></div><ul style={{"marginLeft":"1rem"}}><SchemaItem collapsible={false} name={"name"} required={true} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Policy name identifier","type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"description"} required={true} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Policy friendly description","type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"enabled"} required={true} schemaName={"boolean"} qualifierMessage={undefined} schema={{"description":"Policy status","type":"boolean"}}></SchemaItem><SchemaItem collapsible={false} name={"query"} required={true} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Policy Rego query","type":"string"}}></SchemaItem><SchemaItem collapsible={true} className={"schemaItem"}><details style={{}}><summary style={{}}><strong>rules</strong><span style={{"opacity":"0.6"}}> object[]</span><strong style={{"fontSize":"var(--ifm-code-font-size)","color":"var(--openapi-required)"}}> required</strong></summary><div style={{"marginLeft":"1rem"}}><div style={{"marginTop":".5rem","marginBottom":".5rem"}}>
Policy rule object for policy UI editor
</div><li><div style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem","paddingBottom":".5rem"}}>Array [</div></li><SchemaItem collapsible={false} name={"id"} required={false} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Rule ID","type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"name"} required={true} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Rule name identifier","type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"description"} required={false} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Rule friendly description","type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"enabled"} required={true} schemaName={"boolean"} qualifierMessage={undefined} schema={{"description":"Rules status","type":"boolean"}}></SchemaItem><SchemaItem collapsible={true} className={"schemaItem"}><details style={{}}><summary style={{}}><strong>sources</strong><span style={{"opacity":"0.6"}}> object[]</span><strong style={{"fontSize":"var(--ifm-code-font-size)","color":"var(--openapi-required)"}}> required</strong></summary><div style={{"marginLeft":"1rem"}}><div style={{"marginTop":".5rem","marginBottom":".5rem"}}>
policy source groups
</div><li><div style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem","paddingBottom":".5rem"}}>Array [</div></li><SchemaItem collapsible={false} name={"id"} required={true} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Group ID","type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"name"} required={true} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Group Name identifier","type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"peers_count"} required={true} schemaName={"integer"} qualifierMessage={undefined} schema={{"description":"Count of peers associated to the group","type":"integer"}}></SchemaItem><li><div style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem"}}>]</div></li></div></details></SchemaItem><SchemaItem collapsible={true} className={"schemaItem"}><details style={{}}><summary style={{}}><strong>destinations</strong><span style={{"opacity":"0.6"}}> object[]</span><strong style={{"fontSize":"var(--ifm-code-font-size)","color":"var(--openapi-required)"}}> required</strong></summary><div style={{"marginLeft":"1rem"}}><div style={{"marginTop":".5rem","marginBottom":".5rem"}}>
policy destination groups
</div><li><div style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem","paddingBottom":".5rem"}}>Array [</div></li><SchemaItem collapsible={false} name={"id"} required={true} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Group ID","type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"name"} required={true} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Group Name identifier","type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"peers_count"} required={true} schemaName={"integer"} qualifierMessage={undefined} schema={{"description":"Count of peers associated to the group","type":"integer"}}></SchemaItem><li><div style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem"}}>]</div></li></div></details></SchemaItem><SchemaItem collapsible={false} name={"action"} required={true} schemaName={"string"} qualifierMessage={"**Possible values:** [`accept`, `drop`]"} schema={{"description":"policy accept or drops packets","type":"string","enum":["accept","drop"]}}></SchemaItem><li><div style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem"}}>]</div></li></div></details></SchemaItem></ul></details></TabItem></MimeTabs><div><ApiTabs><TabItem label={"200"} value={"200"}><div>
A Policy Object
</div><div><MimeTabs schemaType={"response"}><TabItem label={"application/json"} value={"application/json"}><SchemaTabs><TabItem label={"Schema"} value={"Schema"}><details style={{}} data-collapsed={false} open={true}><summary style={{"textAlign":"left"}}><strong>Schema</strong></summary><div style={{"textAlign":"left","marginLeft":"1rem"}}></div><ul style={{"marginLeft":"1rem"}}><SchemaItem collapsible={false} name={"name"} required={true} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Policy name identifier","type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"description"} required={true} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Policy friendly description","type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"enabled"} required={true} schemaName={"boolean"} qualifierMessage={undefined} schema={{"description":"Policy status","type":"boolean"}}></SchemaItem><SchemaItem collapsible={false} name={"query"} required={true} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Policy Rego query","type":"string"}}></SchemaItem><SchemaItem collapsible={true} className={"schemaItem"}><details style={{}}><summary style={{}}><strong>rules</strong><span style={{"opacity":"0.6"}}> object[]</span><strong style={{"fontSize":"var(--ifm-code-font-size)","color":"var(--openapi-required)"}}> required</strong></summary><div style={{"marginLeft":"1rem"}}><div style={{"marginTop":".5rem","marginBottom":".5rem"}}>
Policy rule object for policy UI editor
</div><li><div style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem","paddingBottom":".5rem"}}>Array [</div></li><SchemaItem collapsible={false} name={"id"} required={false} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Rule ID","type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"name"} required={true} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Rule name identifier","type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"description"} required={false} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Rule friendly description","type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"enabled"} required={true} schemaName={"boolean"} qualifierMessage={undefined} schema={{"description":"Rules status","type":"boolean"}}></SchemaItem><SchemaItem collapsible={true} className={"schemaItem"}><details style={{}}><summary style={{}}><strong>sources</strong><span style={{"opacity":"0.6"}}> object[]</span><strong style={{"fontSize":"var(--ifm-code-font-size)","color":"var(--openapi-required)"}}> required</strong></summary><div style={{"marginLeft":"1rem"}}><div style={{"marginTop":".5rem","marginBottom":".5rem"}}>
policy source groups
</div><li><div style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem","paddingBottom":".5rem"}}>Array [</div></li><SchemaItem collapsible={false} name={"id"} required={true} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Group ID","type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"name"} required={true} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Group Name identifier","type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"peers_count"} required={true} schemaName={"integer"} qualifierMessage={undefined} schema={{"description":"Count of peers associated to the group","type":"integer"}}></SchemaItem><li><div style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem"}}>]</div></li></div></details></SchemaItem><SchemaItem collapsible={true} className={"schemaItem"}><details style={{}}><summary style={{}}><strong>destinations</strong><span style={{"opacity":"0.6"}}> object[]</span><strong style={{"fontSize":"var(--ifm-code-font-size)","color":"var(--openapi-required)"}}> required</strong></summary><div style={{"marginLeft":"1rem"}}><div style={{"marginTop":".5rem","marginBottom":".5rem"}}>
policy destination groups
</div><li><div style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem","paddingBottom":".5rem"}}>Array [</div></li><SchemaItem collapsible={false} name={"id"} required={true} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Group ID","type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"name"} required={true} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Group Name identifier","type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"peers_count"} required={true} schemaName={"integer"} qualifierMessage={undefined} schema={{"description":"Count of peers associated to the group","type":"integer"}}></SchemaItem><li><div style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem"}}>]</div></li></div></details></SchemaItem><SchemaItem collapsible={false} name={"action"} required={true} schemaName={"string"} qualifierMessage={"**Possible values:** [`accept`, `drop`]"} schema={{"description":"policy accept or drops packets","type":"string","enum":["accept","drop"]}}></SchemaItem><li><div style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem"}}>]</div></li></div></details></SchemaItem><SchemaItem collapsible={false} name={"id"} required={true} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Policy ID","type":"string"}}></SchemaItem></ul></details></TabItem><TabItem label={"Example (from schema)"} value={"Example (from schema)"}><ResponseSamples responseExample={"{\n \"name\": \"string\",\n \"description\": \"string\",\n \"enabled\": true,\n \"query\": \"string\",\n \"rules\": [\n {\n \"id\": \"string\",\n \"name\": \"string\",\n \"description\": \"string\",\n \"enabled\": true,\n \"sources\": [\n {\n \"id\": \"string\",\n \"name\": \"string\",\n \"peers_count\": 0\n }\n ],\n \"destinations\": [\n {\n \"id\": \"string\",\n \"name\": \"string\",\n \"peers_count\": 0\n }\n ],\n \"action\": \"accept\"\n }\n ],\n \"id\": \"string\"\n}"} language={"json"}></ResponseSamples></TabItem></SchemaTabs></TabItem></MimeTabs></div></TabItem></ApiTabs></div>