> For the complete documentation index, see [llms.txt](https://docs.p0.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.p0.dev/policy-studio/policy-studio/configure-your-first-access-policy.md).

# Configuring access policies

How to build access policies in Policy Studio: who can request access, which resources they can request, how requests are approved, and the order in which P0 evaluates a request against your policies.

Access policies give you fine-grained control over your organization's just-in-time access workflow: *who* can request access, *which* resources they can request, and *how* those requests are approved. You build and manage them in **Policy Studio**, the visual editor in [p0.app](https://p0.app). This page is the complete reference for every part of a policy, worked examples, and how P0 evaluates a request.

To build your first policy step by step, start with the [Configure your first access policy](/getting-started/configure-your-first-access-policy.md) tutorial, which gets a working policy in place in about ten minutes. Come back here for the full reference.

{% hint style="info" %}
This page details how to build policies using the P0 web UI. If you'd rather manage policies as YAML — in the YAML editor, the [Access policies API](/policy-studio/policy-studio/access-policies-api.md), or the P0 Terraform provider ([Manage P0 policies and settings as code](/p0-api/manage-p0-policies-and-settings-as-code.md)) — the [Access policy YAML reference](/policy-studio/policy-studio/access-policy-yaml-reference.md) gives the equivalent syntax for everything described here.
{% endhint %}

## Prerequisites

Before you begin, confirm the following:

* You have an **Owner** or **Security Reviewer** role in your P0 organization.
* At least one resource integration ([Resource integrations](/integrations/resource-integrations.md)) is installed (AWS, Google Cloud, Azure, Kubernetes, or another supported resource).
* A directory integration ([Directory integrations](/integrations/directory-integrations.md)) is configured (Google Workspace, Okta, or Microsoft Entra ID) if you plan to use group-based policies.

## Where to edit policies

Policy Studio is at **Policy Studio** in the [p0.app](https://p0.app) sidebar, or at `https://p0.app/o/<your-organization>/policies`. The **Control** tab lists your access policies; the **Access Bundles** tab manages [Access bundles](/policy-studio/policy-studio/access-bundles.md). Each row shows a policy's identity, resource, and actions at a glance, with an **Enabled** toggle — disabled policies are kept but not evaluated. Filter the list with **All**, **Enabled**, or **Disabled**.

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-4cf7491f84182163b9a628600298bb19d85dd1e6%2Fcontrol-table.png?alt=media" alt="The Policy Studio Control view listing access policies"><figcaption></figcaption></figure>

The **View options** (⋯) menu in the page header switches between **Table view** and the **YAML view**. The YAML view shows the same policies but as YAML; see the [Access policy YAML reference](/policy-studio/policy-studio/access-policy-yaml-reference.md) for P0 policy YAML syntax. You can also manage policies through the [Access policies API](/policy-studio/policy-studio/access-policies-api.md) and the P0 Terraform provider ([Manage P0 policies and settings as code](/p0-api/manage-p0-policies-and-settings-as-code.md)).

### Guided editor

**Add New Policy** opens the visual form. Name the policy at the top, for example "Engineering - AWS read-only", then fill in its three sections. Each one sets a part of the policy this page documents below:

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-39714a60268b8235f0027db66425c8e652fa6833%2Fguided-editor-overview.png?alt=media" alt="The Policy Studio guided editor with its Identity, Resource(s), and Actions sections"><figcaption></figcaption></figure>

| Section         | Sets                      | Reference                          |
| --------------- | ------------------------- | ---------------------------------- |
| **Identity**    | Who can request           | [#requestor](#requestor "mention") |
| **Resource(s)** | What they can request     | [#resource](#resource "mention")   |
| **Actions**     | How requests are approved | [#actions](#actions "mention")     |

Two buttons add entries within a section. **Add New Resource Filter** adds a filter under **Resource(s)**, where you choose a filter type, an effect, and a pattern. **Add New Access Rule** adds another action under **Actions**. When a policy has several actions, getting a match from any one of them is enough to grant access.

**Create Policy** saves a new policy, and **Save Policy** saves when you edit an existing one. Confirm the policy then appears in the list with its **Enabled** toggle on.

Policies take effect as soon as you save them, and apply to every later access request.

### Check that a policy works

Have someone who matches the policy make a request through Slack (`/p0 request`), the P0 CLI ([p0 request](/p0-cli/p0-commands-and-usage/p0-request.md)), or the [Web request modal](/access-management/access-management/just-in-time-access/requesting-access/web-request-modal.md). The **Activity** page at `https://p0.app/o/<your-organization>/access-management/activity` shows the request and which policy decided it.

If the requestor sees *"This resource doesn't exist, or your organization doesn't allow this principal to access this resource"*, no policy matched. Check the requestor and resource parts of your policy against the request.

## The parts of a policy

Every policy has three parts, matching the three sections of the guided editor: a **requestor** (who can request), a **resource** (what they can request), and one or more **actions** (how requests are approved). Your organization has a single set of access policies, which can hold as many individual policies as you need — you don't separate them by type, and a saved policy takes effect for every later P0 access request.

The rest of this page documents each part. For the YAML equivalent of anything on this page, see the [Access policy YAML reference](/policy-studio/policy-studio/access-policy-yaml-reference.md).

### Requestor

The **Identity** section of a policy — its *requestor* — matches who makes the request. In the editor, choose an **Identity**, then narrow it with **Match by**. There are four kinds. For the YAML form of any of them, see [Access policy YAML reference](/policy-studio/policy-studio/access-policy-yaml-reference.md#requestor).

#### "Any"

Set **Identity** to **Any identity** to match all requestors. Useful for global rules like fall-back restrictions of sensitive resources.

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-81542cd6b4a65560a31f96ee7b44f236d645031a%2Fidentity-any.png?alt=media" alt="Identity set to Any identity"><figcaption></figcaption></figure>

#### "Group"

Match anyone who is a member of a group in your identity provider. In the editor, set **Identity** to **User** and **Match by** to **Directory group**, then add one or more groups. P0 supports Google Workspace, Microsoft Entra ID, and Okta.

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-9c3e1fc4d2c06517ef8183f5af0f7928b08f9929%2Fidentity-directory-group.png?alt=media" alt="Identity set to User, matched by a directory group"><figcaption></figcaption></figure>

Choose **Include members in any of these groups** to match members of the listed groups, or **Exclude members in any of these groups** to match everyone who belongs to none of them. Each group carries three details:

* **id**: For Google Workspace, this is the group email address (for example, <engineering@yourco.com>). For Entra ID, this is the Entra ID group's UUID. For Okta, this is the group ID found in the URL of the group's page in the admin console. See [Okta docs](https://support.okta.com/help/s/article/how-to-find-group-ids-through-the-okta-user-interface?language=en_US).
* **label**: Any friendly human-readable name you like, although P0 suggests using the same name as displayed in your directory.
* **directory**: The identity provider the group comes from — Google Workspace, Okta, or Microsoft Entra ID.

#### "User"

Match a single user by their email address. In the editor, set **Identity** to **User** and **Match by** to **Specific user**, then enter the email.

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-3e45d77d595c264f2f4e3d4724cbf892fa990833%2Fidentity-specific-user.png?alt=media" alt="Identity set to User, matched by a specific user"><figcaption></figcaption></figure>

#### "Agentic"

Match requests made by AI agents through the P0 AI Gateway, part of [P0 Runtime Access for AI](/readme/agentic-control-plane.md), based on the combination of the agent that is acting and whoever it is acting for. In the editor, set **Identity** to **Agentic**, then set the **Subject** (who the agent acts for) and the **Actor agent**.

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-78983dc7921c428e32957abf67e470cfff3d0e24%2Fidentity-agentic.png?alt=media" alt="Identity set to Agentic, with Subject and Actor agent fields"><figcaption></figcaption></figure>

See [Agentic access policies](/policy-studio/policy-studio/agentic-access-policies.md) for the subject and actor options and examples.

### Resource

The **Resource(s)** section — a policy's *resource* — matches what can be requested. In the editor, open the resource selector and choose how broadly the policy applies. For the YAML form, see [Access policy YAML reference](/policy-studio/policy-studio/access-policy-yaml-reference.md#resource).

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-5dffb24b506790d0d8cbf60caee3db05c1d383a5%2Fresource-mode-select.png?alt=media" alt="The Resource(s) selector: Any resource, Specific resource, or Access bundle"><figcaption></figcaption></figure>

#### "Any"

Choose **Any resource** to match every resource the identity could access. Useful, for instance, when you want to route access for a particular user regardless of what resource or service they request.

#### "Integration"

Choose **Specific resource** to target one integration, then pick the integration and, optionally, an **Access type** to narrow the policy to one kind of request within it — for example AWS policies, or Google Cloud roles. Leave it as **Any access type** to match every kind. For instance, you might route all AWS requests to your DevOps team, or restrict Google Cloud to a select group.

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-24a9554b6d7a491f3fa4d882ca7fe411d8f6ed3c%2Fresource-section.png?alt=media" alt="A Specific resource for AWS, narrowed by access type and a filter"><figcaption></figcaption></figure>

**Filters** narrow a policy to the components within an integration that match a condition — for example, only AWS policies whose ARN matches a pattern. Click **Add New Resource Filter**, then choose a filter type, an **effect**, a key, and a pattern.

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-925888f6ed7405df0a1765d5a265f7e7fb8c156f%2Fresource-filter-editor.png?alt=media" alt="The resource filter editor with effect, filter type, and pattern"><figcaption></figcaption></figure>

Filters are independent when the access type is **Any access type**. For example, a `permission` filter for Google Cloud leaves roles unaffected, so all roles remain requestable.

Each filter has three parts:

* **effect** — how the filter is applied:
  * **Include only** (`keep`) — keeps objects that match the pattern as requestable.
  * **Exclude only** (`remove`) — keeps only objects that do *not* match the pattern.
  * **Exclude all** (`removeAll`) — disables the object type entirely.
  * To allow every object of a type, omit the filter.
* **key** — which property of the object the filter matches against; applies only to **Include only** and **Exclude only**. For example, with AWS `permission-set` the key can be `name` or `arn` — `name` matches the permission set's name, `arn` matches the entire ARN.
* **pattern** — a regular expression matched against the chosen property; applies only to **Include only** and **Exclude only**.

{% hint style="info" %}
Patterns are unanchored. Use line-start (`^`) and line-end (`$`) markers to anchor patterns.

P0 uses the [JavaScript regex dialect](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions).
{% endhint %}

*Filter behavior*

The behavior of filters depends on the requested access type.

For example, the "role" filter in the Gcloud integration has a slightly different meaning depending on which access type is used in the request:

* When making a GCP request with "role" as the access type (for example, `p0 request gcloud role`), the filter limits the roles the user can request access to
* When making a GCP request with "resource" as the access type (for example, `p0 request gcloud resource`), the filter limits the roles that the user can request on the resource they are requesting

By setting the rule's access type to either "role" or "resource", you can explicitly specify which of these requests is allowable.

{% hint style="warning" %}
To ensure predictable filtering behavior, P0 recommends setting an `accessType` constraint when using filters.
{% endhint %}

The following table summarizes valid filter filter-name / key combinations. For more detailed information on the filters, see [AWS filtering](/policy-studio/policy-studio/aws-filtering.md), [Microsoft Azure filtering](/policy-studio/policy-studio/microsoft-azure-filtering.md), [Google Cloud filtering](/policy-studio/policy-studio/google-cloud-filtering.md), and [SSH filtering](/policy-studio/policy-studio/ssh-filtering.md).

<table><thead><tr><th width="155">service</th><th width="147">access-type</th><th width="136">key</th><th>Notes</th></tr></thead><tbody><tr><td>aws</td><td>tag</td><td>&#x3C;tag key></td><td>Only filters policies and permission sets. AWS managed policies can't be tagged.</td></tr><tr><td></td><td>group</td><td>name</td><td>Filters IAM group names</td></tr><tr><td></td><td>permission-set</td><td>arn | name</td><td>Filters Identity Center permission sets</td></tr><tr><td></td><td>policy</td><td>arn</td><td>Filters policies with matching ARNs</td></tr><tr><td></td><td>resource</td><td>arn | name | service</td><td>Filters resource requests based on the resource ARN, the resource name, or the service the resource belongs to.</td></tr><tr><td>azure</td><td>subscription</td><td>id</td><td>Filters requests at a subscription level</td></tr><tr><td></td><td>resource</td><td>id | name</td><td>Filters requests based on what resource is requested</td></tr><tr><td></td><td>role</td><td>id | name</td><td>Filters requests based on the role requested</td></tr><tr><td>azure-ad|okta</td><td>group</td><td>id | label</td><td>Filters directory groups</td></tr><tr><td>gcloud</td><td>permission</td><td>id</td><td>Filters IAM permissions</td></tr><tr><td></td><td>role</td><td>id</td><td>Filters IAM roles based on full ID (for example, the ID for "Owner" is <code>roles/owner</code>)</td></tr><tr><td></td><td>resource</td><td>name | type | full-resource-name</td><td>Filters resource requests based on the resource name, resource type, or the full resource name.</td></tr><tr><td>snowflake</td><td>role</td><td>name</td><td>Filters roles</td></tr><tr><td>k8s</td><td>resource</td><td>kind | name | namespace</td><td>Filters resources</td></tr><tr><td></td><td>role</td><td>name</td><td>Filters roles and cluster roles</td></tr><tr><td></td><td>cluster</td><td>name</td><td>Filters clusters based on the cluster name specified when installed in P0</td></tr><tr><td>ssh</td><td>provider</td><td>id</td><td>Filters by cloud provider (<code>aws</code>, <code>gcloud</code>, <code>azure</code>, or <code>self-hosted</code>)</td></tr><tr><td></td><td>destination</td><td>arn | name | full-resource-name</td><td>Filters by instance identifier</td></tr><tr><td></td><td>group</td><td>name</td><td>Filters by SSH group name</td></tr><tr><td></td><td>parent</td><td>id</td><td>Filters by parent resource ID (AWS account ID, GCP project ID, or Azure subscription ID)</td></tr><tr><td></td><td>region</td><td>id</td><td>Filters by AWS region, GCP zone, or Azure region</td></tr><tr><td></td><td>sudo</td><td><em>(boolean)</em></td><td>Filters by whether sudo privileges are requested</td></tr></tbody></table>

Filters are not available for AWS or GCP resource-level grants, nor for Snowflake SQL grants.

For a worked example, see [#exclude-dangerous-permissions](#exclude-dangerous-permissions "mention"), which removes `FullAccess` AWS policies and keeps only those tagged `P0Grantable: true`. For a fuller version that covers each AWS access type — excluding `FullAccess` policies and permission sets, keeping only policies and permission sets tagged `P0Grantable: true`, and denying group requests — see [Access policy YAML reference](/policy-studio/policy-studio/access-policy-yaml-reference.md#resource) in the access policy YAML reference.

### Actions

The **Actions** section — a policy's *approvals* — says how matching requests are handled: who can approve (or deny) them, and whether access is granted automatically. Add an action with **Add New Access Rule** and pick its type from **Choose an action**. A policy can have several actions; when it does, approval from any one of them is enough. For how P0 decides which action handles a request when several match, see [#evaluation-of-access-policies](#evaluation-of-access-policies "mention").

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-de0f1fac9bbc1e1d17ea00f0cda1214d456a6e01%2Factions-list.png?alt=media" alt="A policy&#x27;s Actions section listing its approval actions"><figcaption></figcaption></figure>

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-73be7ef033ac985475278eb5f75387369d9fc0a4%2Faction-type-dropdown.png?alt=media" alt="The Choose an action menu listing the approval types"><figcaption></figcaption></figure>

Most actions share a set of options, shown as checkboxes in the action editor:

* **Require reason with request** — the requestor must give a reason.
* **Require duration with request** — the requestor must set a duration.
* **Require preapproval with request** — the request must be pre-approved.
* **Allow self-approvals** — the requestor may approve their own request (the `allowOneParty` option).
* **Approve break-glass access** — designates this approver for SSH "all" break-glass requests (SSH only). See [SSH filtering](/policy-studio/policy-studio/ssh-filtering.md#break-glass-access).
* **Match policy action by requested duration** — the action handles only requests up to a maximum duration you set. See [#limit-access-duration-for-specific-resources](#limit-access-duration-for-specific-resources "mention").

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-9f318bfc36c0164ac0ec7cf8ad7a935c990fad59%2Faction-editor-options.png?alt=media" alt="An action editor showing its options and the Maximum duration control"><figcaption></figcaption></figure>

The action types are below. For the YAML form of any of them, see [Access policy YAML reference](/policy-studio/policy-studio/access-policy-yaml-reference.md#approval).

#### "P0 Security Reviewers"

Choose **P0 Security Reviewers** (shown as **Approval by P0 Security Reviewers** in the policy list) to route approvals to the people designated as Security Reviewers on your Settings page. This is analogous to P0's default approval behavior. It supports all of the shared options — self-approval, require reason, and break-glass for SSH "all" requests. See [SSH filtering](/policy-studio/policy-studio/ssh-filtering.md#break-glass-access) for break-glass details.

#### "Group"

Choose **Group approval** (shown as **Approval by users in group** in the policy list) to let any member of a directory group approve. Set the group the same way as a group requestor ([#group](#group "mention")): choose **Include members in any of these groups** or **Exclude members in any of these groups**, then add the groups. P0 supports Google Workspace, Microsoft Entra ID, and Okta. Each group's **label** is printed in approval notifications. Group actions support the shared options (self-approval, require reason, break-glass).

#### "Auto-approve (on-call)"

Choose **Auto-approve (on-call)** (shown as **Allowed if on-call** in the policy list) to automatically approve a request when the requestor is on-call. For PagerDuty, P0 checks the configured escalation policies. For Incident.io, it checks the selected schedules ([Incident.io](/integrations/approval-integrations/incidentio.md#selecting-schedules)). For Grafana IRM, it checks the selected teams ([Grafana IRM](/integrations/approval-integrations/grafana-irm.md#selecting-teams)). This action appears only when a PagerDuty, Incident.io, or Grafana IRM integration is installed. Use **Require reason** to record a justification even on auto-approved requests.

#### "Escalation"

Choose **Escalation service** (shown as **Approval by on-call** in the policy list) to route approval to whoever is currently on-call for the chosen services or schedules. Combined with another action, it lets on-call users approve requests that have been escalated. For PagerDuty, on-call is determined by the configured services' escalation policies, and escalating creates an incident against those services. For Incident.io, it's determined by the selected schedules. For Grafana IRM, it's determined by the selected teams, and escalating pages those teams. Pick the PagerDuty services, Incident.io schedules, or Grafana IRM teams in the action editor. This action appears only when a PagerDuty, Incident.io, or Grafana IRM integration is installed.

#### "Manager approval"

Choose **Manager approval** (shown as **Approval by manager** in the policy list) to route approval to the person named in the requestor's identity-provider profile — typically their manager. In the action editor, pick the **Directory**, and if your profiles use a non-standard field, override the **Profile attribute that contains manager email** (default `manager`).

#### "Always allowed"

Choose **Always allowed** to grant matching requests automatically, with no approver — standing access for low-risk resources. Use **Require reason** to still record a justification.

#### "Deny"

Choose **Deny all** (shown as **Deny all access** in the policy list) to deny every matching request. Deny supersedes all other matching actions: if any matching policy denies, the request is denied.

### Limit access duration for specific resources

All granted access durations have organization-wide limits set by your P0 Administrator in [Organization access duration settings](/p0-management/organization-access-duration-settings.md).

To specify more fine-grain limits at the policy level for specific resources, give an approval action a maximum duration. The action then matches only requests with a duration at or below the approval's maximum duration. In the action editor, check **Match policy action by requested duration**, then set a **Maximum duration** (a number and a unit).

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-9f318bfc36c0164ac0ec7cf8ad7a935c990fad59%2Faction-editor-options.png?alt=media" alt="The Maximum duration control in a policy action editor"><figcaption></figcaption></figure>

With a maximum duration set:

* A request within the action's maximum duration is handled by the action as usual.
* A request with a longer duration than your approval's maximum duration is handled by another approval action that allows it, if one matches. If no matching action allows the requested duration, the request is **shortened** to the longest any matching action allows.
* An approver can never grant longer than the action's maximum duration.

The action maximum duration can't exceed your **Organization maximum access duration** (180 days by default). **Allowed if on-call** and **Always allowed** grant access without a human approver, so their maximum also can't exceed the **Organization maximum standing access duration** (24 hours by default). Leave it off and the action handles requests of any length, up to these organization limits, and does not route policy matching via the requested duration, but instead routes following the normal [#evaluation-of-access-policies](#evaluation-of-access-policies "mention").

For example, this **P0 Security Reviewers** action matches only requests of 1 week or less, meaning that the particular resource referenced in this policy cannot grant access for longer than 1 week:

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-e5bc546b846a899dc2c08ece6021f33bba067b36%2Faction-p0-reviewers-1-week.png?alt=media" alt="A P0 Security Reviewers action capped at 1 week"><figcaption></figcaption></figure>

### Route action based on requested duration

Policy maximum duration also supports routing actions based on how long of a duration was requested. This means that you can dynamically change the type of approval of a request based on how long was requested.

For example, you can pair a standard P0 Security Reviewers action with an **Always allowed** action that grants requests of up to 24 hours automatically:

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-be86b03b0ad47aae0cbec22fd1a7ad3c6715f66e%2Faction-always-allowed-24h.png?alt=media" alt="An Always allowed action capped at 24 hours"><figcaption></figcaption></figure>

A request of 24 hours or less matches the **Always allowed** action and is approved automatically. A longer request doesn't fit that action's maximum, so it falls through to the **P0 Security Reviewers** action, which routes to a Security Reviewer for manual approval, up to the organization maximum access duration setting.

For the `maxDuration` field and its YAML syntax, see [Access policy YAML reference](/policy-studio/policy-studio/access-policy-yaml-reference.md#maxduration).

## Common scenarios

These worked scenarios cover the most common access-policy setups. Adapt the group identifiers, account IDs, and service names to your own organization.

### Route requests by team

Route your engineering team's requests to the SRE team for approval, and your data team's requests to the Data Ops team.

Create two policies in Policy Studio. The first routes any engineering-group request to the SRE team; the second routes the data team's Snowflake requests to Data Ops. Set both actions to **Group approval** and leave **Allow self-approvals** off so requestors can't approve their own requests.

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-c2cf9f28b350bdc1571e55e76d2a78df09e22f7b%2Fscenario-route-by-team.png?alt=media" alt="A policy routing an engineering group&#x27;s requests to the SRE team"><figcaption></figcaption></figure>

For the full YAML, see [Access policy YAML reference](/policy-studio/policy-studio/access-policy-yaml-reference.md#route-requests-by-team).

**What this does:**

* Any engineer who requests access to any resource gets routed to the SRE team for approval.
* Any data team member who requests Snowflake access gets routed to Data Ops for approval.
* `allowOneParty: false` prevents requestors from approving their own requests.

{% hint style="warning" %}
If a request doesn't match any access policy, P0 rejects it with the message: "This resource doesn't exist, or your organization doesn't allow this principal to access this resource." Add a catch-all policy at the end of your workflow if you want unmatched requests to fall through to default approvers.
{% endhint %}

#### Add a catch-all policy

To ensure unmatched requests still reach your security reviewers, add this policy at the end of your workflow:

```yaml
- requestor:
    type: any
  resource:
    type: any
  approval:
    - type: p0
```

The `type: p0` approval routes requests to the Security Reviewers configured under **P0 Management** → **Access control**.

### Restrict access to production resources

Block requests to production AWS accounts while allowing development and staging access with different approval requirements.

Create three policies, one per AWS account, each selecting **Specific resource** → **Amazon Web Services** and filtering by the account's policy ARNs:

* **Development** — a **Group approval** action with **Allow self-approvals** on, so engineers can self-approve.

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-7f3a3d36bc6dcb8f8eaf9cb124777ae1b46bd975%2Fscenario-dev-aws-self-approve.png?alt=media" alt="A development AWS policy allowing self-approval"><figcaption></figcaption></figure>

* **Staging** — a **Group approval** action with **Allow self-approvals** off and **Require reason** on, so a peer must approve with a justification.

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-5fd4ae4a6a82111ac6b0367d949db362b21c250f%2Fscenario-staging-aws-peer.png?alt=media" alt="A staging AWS policy requiring peer approval and a reason"><figcaption></figcaption></figure>

* **Production** — a **Deny all** action, so no one can request access.

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-5ac28c71b1c72e0177ddf31cb711f6ccdd3f1f0b%2Fscenario-prod-aws-deny.png?alt=media" alt="A production AWS policy denying all requests"><figcaption></figcaption></figure>

For the full YAML, see [Access policy YAML reference](/policy-studio/policy-studio/access-policy-yaml-reference.md#restrict-access-to-production-resources).

**What this does:**

* **Development** (account `111111111111`): Engineers can self-approve their own requests.
* **Staging** (account `222222222222`): Engineers need a peer to approve, and must provide a reason.
* **Production** (account `333333333333`): P0 denies all requests. No one can request access through P0.

{% hint style="info" %}
Deny policies always take precedence. If any matching policy specifies `type: deny`, the request is denied immediately, regardless of other matching policies.
{% endhint %}

#### Exclude dangerous permissions

To further restrict which AWS permissions engineers can request, add filters that remove overly broad policies:

```yaml
resource:
  type: integration
  service: aws
  accessType: policy
  filters:
    policy: {effect: remove, key: arn, pattern: FullAccess}
    tag: {effect: keep, key: P0Grantable, pattern: "^true$"}
```

This removes any policy containing "FullAccess" in its ARN, and only keeps policies tagged with `P0Grantable: true`.

### Auto-approve on-call engineers

Automatically approve requests from engineers who are currently on-call in PagerDuty, Incident.io, or Grafana IRM, while directing all other requests to the SRE team.

1. Confirm that your [PagerDuty](/integrations/approval-integrations/pagerduty.md), [Incident.io](/integrations/approval-integrations/incidentio.md), or [Grafana IRM](/integrations/approval-integrations/grafana-irm.md) integration is installed.
2. Create a policy for your AWS resources with two actions: **Auto-approve (on-call)** with **Require reason** on, and a **Group approval** fallback to the SRE team. Approval from either is enough, so on-call engineers are auto-approved and everyone else is routed to SRE.

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-c3bc78abd1575e1f2d1884105813da5c7eca6f9e%2Fscenario-auto-approve-oncall.png?alt=media" alt="A policy auto-approving on-call engineers and routing others to the SRE team"><figcaption></figcaption></figure>

For the full YAML, with both the PagerDuty and Incident.io forms, see [Access policy YAML reference](/policy-studio/policy-studio/access-policy-yaml-reference.md#auto-approve-on-call-engineers).

3. Click **Submit**.

**What this does:**

* If the requestor is currently on-call (as determined by PagerDuty escalation policies, Incident.io schedules, or Grafana IRM teams), P0 automatically approves their request.
* If the requestor is not on-call, P0 routes the request to the SRE team for manual approval.
* `requireReason: true` ensures all requests include a justification in the audit log, even auto-approved ones.

#### Add escalation for urgent requests

You can also configure on-call users as escalation approvers. When a request is pending, the requestor can escalate it to the on-call engineer:

```yaml
approval:
  - type: p0
    options: {requireReason: true, allowOneParty: false}
  - type: escalation
    integration: pagerduty
    options: {requireReason: true, allowOneParty: false}
    services: [PSJXXXG]
```

Replace `PSJXXXG` with your PagerDuty service ID. When the requestor escalates, PagerDuty creates an incident against the specified service, and the on-call engineer receives both a PagerDuty alert and a P0 approval notification.

## Evaluation of access policies

When you have many policies, it isn't always obvious which one decides a given request. The steps below show exactly how P0 evaluates matching policies when a P0 access request comes in to determine what access is granted.

1. Match Policies to the Request

   Identify policies that match the request. A policy matches if both its requestor and resource criteria align with the request details — the **requestor** being the person or agent making the request, and the **resource** being the thing they're requesting access to.
2. Handle No Matching Policies

   If no policies match, access is denied. The access request is not created and further evaluation stops. The requestor will see the following message:

   *This resource doesn't exist, or your organization doesn't allow this principal to access this resource*
3. Evaluate Access Control of Matching Policies

   For matching policies, our evaluation engine reviews the Access Control field in the following order:

   * Deny all access\
     If *any* matching policy specifies "Deny all access", the request is denied immediately, and further evaluation stops.
   * Always allowed\
     If any policy specifies "Always allowed," the request is automatically approved and provisioned, and further evaluation stops.
   * Third-party auto-approval\
     If a policy specifies a third-party auto-approval, such as a PagerDuty, Incident.io, or Grafana IRM on-call action, the request is evaluated for automatic approval. If it is approved, access is granted. If it cannot be auto-approved, proceed to the next step.
   * Manual approval\
     For all other Access Control values, the request requires manual approval by a designated person or group. When multiple policies with different manual approvers match, approval from any one approver is sufficient to provision the request. All approvers are notified.

{% hint style="info" %}
The requested duration may also shape this evaluation if any policy action has been configured with a custom maximum duration. A policy whose action caps the maximum access duration only matches a request whose duration fits within that cap. If no matching action allows the full requested duration, P0 shortens the grant to the longest duration any matching action permits. See [#limit-access-duration-for-specific-resources](#limit-access-duration-for-specific-resources "mention").
{% endhint %}

### Key points to remember

* **Deny all access:** Always takes precedence and stops further evaluation immediately.
* **Always allowed:** Overrides other Access Control values and is prioritized in the evaluation process.
* **Multiple matching policies:** When multiple policies match the requestor and resource, approvers are combined using an **ANY** relationship, meaning approval from any one approver is sufficient.
* **Access duration:** An action with a maximum duration matches a request only when the requested duration fits within it. Among the actions that match, approval from any one is sufficient. If none allow the requested duration, it's shortened to the longest any matching action allows. See [#limit-access-duration-for-specific-resources](#limit-access-duration-for-specific-resources "mention").

### Examples

1. **Always allowed policy takes precedence over other allow policies**

Consider a scenario where two policies apply to the same resource, **`node1`** in the **devstack** group:

* An "Always allow" policy grants access to **`node1`**.
* Another "Allow" policy requires approval before granting access.

In this case, the **"Always allow" policy** takes precedence. As a result:

* The user is immediately granted access to **`node1`** without requiring additional approval.

2. **Deny policies are evaluated first, before ANY allow policies**

Using the same example as before, if there is an additional policy that **denies access** to any instance containing **`node`** in its name, the system evaluates the "Deny" policy first.

In this case:

* The "Deny" policy matches because **`node1`** contains the string **`node`** in its name.
* The user's request is immediately denied, and is not evaluated further.

This highlights the priority of "Deny" policies: the system enforces them before considering any other policies.

## Troubleshooting

| Symptom                                                | Cause                                                                      | Solution                                                                                                                                                                                  |
| ------------------------------------------------------ | -------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Request rejected with "This resource doesn't exist..." | No access policy matches the request.                                      | Add a catch-all policy or verify that your requestor and resource filters match the request.                                                                                              |
| Wrong approver notified                                | A broader policy matches before the specific one.                          | Reorder policies so more specific policies come first. Deny policies always take precedence regardless of order.                                                                          |
| Auto-approval not working                              | The requestor is not on-call, or the on-call integration is not installed. | Verify the requestor's on-call status in your incident management tool, and confirm the integration is active in **Integrations**.                                                        |
| Filter not matching                                    | Regex pattern mismatch.                                                    | Patterns are unanchored by default. Use `^` and `$` to anchor. P0 uses the [JavaScript regex dialect](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions). |

## Additional examples

Access policies support a wide range of setups. These examples show patterns beyond the common scenarios described earlier.

### Different rules by AWS account

Development AWS account (123456789) allows one-party approvals. Staging AWS account (234567891) allows peer approvals but no one-party approvals. Production AWS account (345678912) requires a manager approver represented by an Okta group. Assumes an AWS Identity Center setup where resource filters allow requesting customer-managed policies in specific AWS accounts, enforced by an ARN match that includes the AWS account ID. Permission sets are implicitly allowed because the `permission-set` access type filter is not defined.

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-66ebb21638185cdd3e1e65cfde4706d081b49c7e%2Fscenario-aws-by-account.png?alt=media" alt="Access policies routing requests differently per AWS account"><figcaption></figcaption></figure>

For the full YAML, see [Access policy YAML reference](/policy-studio/policy-studio/access-policy-yaml-reference.md#different-rules-by-aws-account).

### Approve by manager or service owner

Route approval to the person named in the requestor's identity-provider profile — their manager — with the **Manager approval** action. Pick the **Directory**, and if your profiles use a non-standard field, set the profile attribute that holds the manager's email.

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-6cdb60a6901d3efb6d3d30e2067f6a5fc2248878%2Fscenario-manager-approval.png?alt=media" alt="A policy routing approval to the requestor&#x27;s manager"><figcaption></figcaption></figure>

To let a service's owners approve instead, add a **Group approval** action pointing at the owner group. For the full YAML, see [Access policy YAML reference](/policy-studio/policy-studio/access-policy-yaml-reference.md#approve-by-manager-or-service-owner).

### Require a reason for a specific resource type

Make a reason mandatory for requests to a particular service by turning on **Require reason** on that policy's action.

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-8f554b3a7ccf51cea0bba12ff976dee2817e3e76%2Fscenario-require-reason.png?alt=media" alt="An AWS policy that requires a reason on every request"><figcaption></figcaption></figure>

For the full YAML, see [Access policy YAML reference](/policy-studio/policy-studio/access-policy-yaml-reference.md#require-a-reason-for-a-specific-resource-type).

### Exclude cluster-admin and restrict to the default namespace (Kubernetes)

Exclude the `cluster-admin` role and only allow requests in the `default` namespace by adding two resource filters: **Include only** resources whose namespace matches `^default$`, and **Exclude** the `ClusterRole/cluster-admin` role.

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-dba292669ee45633a280cc9bcaeb3429d482cca1%2Fscenario-k8s-namespace.png?alt=media" alt="A Kubernetes policy limited to the default namespace and excluding cluster-admin"><figcaption></figcaption></figure>

For the full YAML, see [Access policy YAML reference](/policy-studio/policy-studio/access-policy-yaml-reference.md#exclude-cluster-admin-and-restrict-to-the-default-namespace-kubernetes).

### Allow Google Cloud roles but not permissions

Let users request Google Cloud roles while denying direct permission requests, using two policies. The first allows **Role** requests with a **P0 Security Reviewers** action:

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-04f7d163847a15d1750c394aad928d5cda11eeb4%2Fscenario-gcloud-allow-roles.png?alt=media" alt="A Google Cloud policy allowing role requests"><figcaption></figcaption></figure>

The second denies **Permission** requests with a **Deny all** action:

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-8e46aa7d823ad2d447206abd94d6d140729d118f%2Fscenario-gcloud-deny-permissions.png?alt=media" alt="A Google Cloud policy denying permission requests"><figcaption></figcaption></figure>

For the full YAML, see [Access policy YAML reference](/policy-studio/policy-studio/access-policy-yaml-reference.md#allow-google-cloud-roles-but-not-permissions).

### Deny specific roles while allowing others

Deny the Owner role while allowing all other Google Cloud roles, using two policies: one that uses **Include only** on `roles/owner` with a **Deny all** action, and a catch-all role policy with a **P0 Security Reviewers** action. Order doesn't matter — deny always wins.

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-db83144da22e9fd3433d55b8c96fa93075ccb450%2Fscenario-gcloud-table.png?alt=media" alt="Google Cloud policies denying the Owner role while allowing others"><figcaption></figcaption></figure>

For the full YAML, see [Access policy YAML reference](/policy-studio/policy-studio/access-policy-yaml-reference.md#deny-specific-roles-while-allowing-others).

## Next steps

* Fine-tune which resources are requestable with [AWS filtering](/policy-studio/policy-studio/aws-filtering.md), [Google Cloud filtering](/policy-studio/policy-studio/google-cloud-filtering.md), [Microsoft Azure filtering](/policy-studio/policy-studio/microsoft-azure-filtering.md), or [SSH filtering](/policy-studio/policy-studio/ssh-filtering.md).
* Route or auto-approve requests made by AI agents with [Agentic access policies](/policy-studio/policy-studio/agentic-access-policies.md).
* Manage policies programmatically with the [Access policies API](/policy-studio/policy-studio/access-policies-api.md) or the P0 Terraform provider ([Manage P0 policies and settings as code](/p0-api/manage-p0-policies-and-settings-as-code.md)).
* Prefer YAML? See the [Access policy YAML reference](/policy-studio/policy-studio/access-policy-yaml-reference.md) for the syntax of everything on this page.
* New to access policies? Start with the [Configure your first access policy](/getting-started/configure-your-first-access-policy.md) tutorial.
