# Write Access Policies

## What are Access Policies?

Access Policies are a way to specify the rules under which a user can get access to a resource.

Access Policies can be of different [types](/reference/access-policies/types-of-access-policies.md) and be used to allow or deny a request, skip specific workflow steps, or expire access after a certain period of time. For example:&#x20;

* Only Engineers can get access to a table containing PII
* Revoke access after a maximum of 24 hours.
* Require manager approval unless the request is from someone in Engineering

Policies are written in Rego and run by Open Policy Agent, and Abbey evaluates these policies on your behalf. Policies evaluate to either true or false, and if a policy or set of policies evaluate to false, then a user will not be granted access.&#x20;

Policies used to evaluate Access Requests are specified inside Abbey Grant Kit Policy blocks.

## What is Open Policy Agent?

Open Policy Agent (OPA) is an open source, general-purpose policy engine. Open Policy Agent is used to evaluate policies against structured data to make sure that the data passes the policy checks. OPA evaluates policies specified in Abbey Grant Kits and resolve as true or false when an Access Request is made. Abbey creates a structured data payload based on attributes and other information about a user, which is used as input to Policy Evaluation. On a false evaluation, the policy check fails, and the Access Request is denied.

Learn more about OPA [here](https://www.openpolicyagent.org/docs/latest/).

## What is Rego?

Rego is the Open Policy Agent language. Rego is a declarative language based on the well-known query language of Datalog. Rego is the policy language that Abbey and OPA use to evaluate policies. You can find documentation on the Rego language [here](https://www.openpolicyagent.org/docs/latest/).

## How do I write Policies?

There are two ways to write policies:

1. Policy Bundles
2. Inline Policies

Policy Bundles are sets of files that define a Rego package. Policy Bundles allow you to reuse policy code. You can write Policy code once, store it in a Bundle, and refer back to it as many times as you like.&#x20;

Inline Policies are used for simple policies, which don't require the complexity of multiple files. Inline Policies are specified within the definition of an Abbey Grant Kit and can be used for simple policies which require little Rego code in them.&#x20;

Policies can also be used to skip steps a workflow. Details about this and the differences between skipping workflow steps and using a policy for approval are found in [Types of Access Policies](/reference/access-policies/types-of-access-policies.md).

More information on writing Policy Bundles can be found in the [Policy Bundles](/reference/access-policies/policy-bundles.md). More information on writing Inline Policies can be found in the [Inline Policies](/reference/access-policies/inline-policies.md) section.

## Example Policies

The [Policy Examples](/reference/access-policies/policy-examples.md) section has examples of policies you can use with Abbey.


---

# 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.abbey.io/build-a-grant-kit/open-policy-agent-opa-policies.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.
