> ## Documentation Index
> Fetch the complete documentation index at: https://docs.0xkey.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Policy overview

> Our policy engine is the foundation for flexible controls and permissions within your organization. This page provides an overview of how to author policies.

## Policy structure

Our policies are defined using **JSON**. The `effect` determines if an activity should be allowed or denied based on the evaluation of the `consensus` and `condition` fields.

`consensus` and `condition` are composed of ergonomic expressions written in our [policy language](https://docs.0xkey.io/policies/language.md) that must evaluate to a `bool`. `consensus` determines which user(s) may take an action (e.g. a given user ID). `condition` determines the conditions under which the policy applies (e.g. signing with a specific wallet).

`condition` is **required**. Creating a policy whose `condition` is missing, empty, or only whitespace is rejected with HTTP 400 (`INVALID_ARGUMENT`, message `policy condition is required`); so is an update that sets `policyCondition` to an empty or whitespace-only value (an update that omits `policyCondition` keeps the current one). To write a policy that applies to every activity, set `"condition": "true"` explicitly. `consensus` is optional.

#### See below for an example policy that allows a single user to send transactions to a single address

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "effect": "EFFECT_ALLOW",
  "consensus": "approvers.any(user, user.id == '<USER_ID>')",
  "condition": "eth.tx.to == '<ALLOWED_ADDRESS>'"
}
```

## Managing policies

| Action | Endpoint | Activity type | Parameters | SDK method |
| :- | :- | :- | :- | :- |
| Create one | `POST /public/v1/submit/create_policy` | `ACTIVITY_TYPE_CREATE_POLICY_V3` | `policyName`, `effect`, `notes`, `condition`, optional `consensus` | `createPolicy` |
| Create several | `POST /public/v1/submit/create_policies` | `ACTIVITY_TYPE_CREATE_POLICIES` | `policies[]` (same fields as above) | `createPolicies` |
| Update | `POST /public/v1/submit/update_policy` | `ACTIVITY_TYPE_UPDATE_POLICY_V2` | `policyId` plus any of `policyName`, `policyEffect`, `policyCondition`, `policyConsensus`, `policyNotes` | `updatePolicy` |
| Delete one | `POST /public/v1/submit/delete_policy` | `ACTIVITY_TYPE_DELETE_POLICY` | `policyId` | `deletePolicy` |
| Delete several | `POST /public/v1/submit/delete_policies` | `ACTIVITY_TYPE_DELETE_POLICIES` | `policyIds[]` | `deletePolicies` |
| List / get | `POST /public/v1/query/list_policies`, `/query/get_policy` | — | `organizationId`, `policyId` | `getPolicies`, `getPolicy` |

The SDK method names are the same in `@0xkey-io/sdk-server`, the Swift SDK (`ZeroXKeyClient`), and the Kotlin SDK (`ZeroXKeyClient`). Deleting a policy ID that does not exist in the organization returns HTTP 404 (`NOT_FOUND`); call `list_policies` and retry with the current IDs. See [Errors](https://docs.0xkey.io/developer-reference/api-overview/errors.md#policy-not-found).

> [!TIP]
>
> For keys that are restricted by transaction fields (`eth.tx.*`, `solana.tx.*`, `tron.tx.*`), sign with the transaction-signing endpoints (such as `sign_transaction`), and add a policy that denies raw payload signing for those keys unless your integration needs it. See [Activity parameters](https://docs.0xkey.io/policies/language.md#activity-parameters).

## Policy evaluation

All policies defined within an Organization are evaluated on each request. The image below describes how an activity outcome is determined when resolving multiple policies. The rule follows the below steps:

**Step 1**

If a quorum of root users takes the action, the final outcome is
`OUTCOME_ALLOW`

**Step 2**

Else if any applicable policy has `EFFECT_DENY`, the final outcome is `OUTCOME_DENY`. This is also referred to as "explicit deny."

**Step 3**

Else if at least one applicable policy has `EFFECT_ALLOW`, then the final
outcome is `OUTCOME_ALLOW`

**Step 4**

Else the final outcome is `OUTCOME_DENY`. This is also referred to as
"implicit deny." In cases of conflicts, `EFFECT_DENY` always wins.

Stated differently:

![policy overview](https://mintcdn.com/chain/SBPPOKcVznKsWQeY/images/concepts/policies/img/diagrams/policy_overview.png?fit=max\&auto=format\&n=SBPPOKcVznKsWQeY\&q=85\&s=601f2ac7bc44966a6bef0ad813a7cda3)

Almost all actions on 0xkey are implicitly denied by default. There are a few exceptions, however:

* The Root Quorum bypasses any policies.
* All users have implicit GET (read) permissions in their own Organization and any associated Sub-Organizations.
* All users have implicit permission to change their own credentials, unless a policy explicitly allows or denies those actions.
* All users have implicit permission to approve an activity if they were included in consensus (i.e., a user specified as part of the consensus required to approve a SIGN\_TRANSACTION activity does not need separate, explicit permission to sign transactions).

To learn more about our Policies, checkout our Policy Language [here](https://docs.0xkey.io/policies/language.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.