Your First Policy
Create and test your first authorization policy
In this guide, you'll create a simple authorization policy and test it in the Policy Playground. By the end, you'll understand the basic workflow of defining and validating policies in Denied.
Prerequisites
Before you begin, make sure you have:
- A Denied Platform account (sign up here)
- Access to at least one project
What We're Building
We'll create a policy that implements a simple ownership rule: users can only access resources they own. This is one of the most common authorization patterns and a great starting point.
Step 1: Navigate to Policies
- Open the Denied dashboard
- Make sure you have the correct project selected in the top navigation
- Click Governance in the sidebar
- Select Policies
You'll see your policy library. If this is a new project, it will be empty.
Step 2: Create a New Policy
Click the Create Policy button to open the policy creation form.
Fill in the Policy Details
| Field | Value |
|---|---|
| Name | allow-own-resources |
| Reason | Users can access resources they own |
| Effect | Allow |
Write the Policy Content
In the policy editor, enter the following Rego code:
# Allow access when the subject owns the resource
input.resource.properties.owner == input.subject.properties.user_idThis policy checks if the resource's owner property matches the requesting subject's user_id property. Denied Platform handles the rest — wrapping your conditions in the proper OPA structure and evaluating them against incoming requests.
Save the Policy
Click Create to save your policy. It will appear in your policy library with an Allow badge indicating its effect.
Step 3: Test in the Playground
Now let's verify the policy works as expected using the Policy Playground.
- Go to Governance → Playground
- You'll see a form where you can construct authorization requests
The Playground requires a configured decision node. If you haven't set one up yet, see Decision Nodes for instructions.
Test Case 1: Owner Accessing Their Resource (Should Allow)
Fill in the test request:
Subject Properties:
- user_id:
user-123
Resource Properties:
- owner:
user-123
Action Name: read
Click Evaluate. You should see:
Result: ALLOWED
Matched Rules: allow-own-resourcesThe request was allowed because the subject's user_id (user-123) matches the resource's owner (user-123).
Test Case 2: Non-Owner Accessing Resource (Should Deny)
Now test a case that should be denied:
Subject Properties:
- user_id:
user-456
Resource Properties:
- owner:
user-123
Action Name: read
Click Evaluate. You should see:
Result: DENIEDThe request was denied because user-456 doesn't own a resource belonging to user-123.
Step 4: Understanding the Result
When you evaluate a request, the Playground shows:
| Field | Description |
|---|---|
| Result | The final decision: ALLOWED or DENIED |
| Matched Rules | Which policies contributed to an ALLOWED decision |
| Request Details | The full input that was evaluated |
How Policy Evaluation Works
- Your authorization request is sent to the decision node
- The decision node loads all enabled policies from your project
- Each policy's conditions are evaluated against the request input
- If any allow policy's conditions all evaluate to
true, the request is allowed - If no allow policies match, the request is denied (secure by default)
Enhancing with More Policies
Let's make authorization more realistic by adding additional policies:
Policy 2: Admin Access
# Admins can access any resource
input.subject.properties.role == "admin"Policy 3: Public Read Access
# Anyone can read public resources
input.action.name == "read"
input.resource.properties.visibility == "public"With these three policies, access is allowed if:
- The subject owns the resource, OR
- The subject is an admin, OR
- The action is
readAND the resource is public
Try More Test Cases
Test your policies with these scenarios:
| Subject Properties | Resource Properties | Action Name | Expected |
|---|---|---|---|
{user_id: "user-1"} | {owner: "user-1"} | delete | Allow |
{user_id: "user-2", role: "admin"} | {owner: "user-1"} | delete | Allow |
{user_id: "user-3"} | {visibility: "public"} | read | Allow |
{user_id: "user-4"} | {owner: "user-1", visibility: "private"} | read | Deny |
Toggling Policies
You can enable or disable policies without deleting them:
- Go to Governance → Policies
- Find your policy in the list
- Use the toggle switch to enable/disable
Disabled policies are not included in the OPA bundle and won't affect authorization decisions.
Next Steps
Congratulations! You've created and tested your first policy. Here's where to go next:
- Rego Basics — Learn more about the Rego policy language
- Common Patterns — Explore RBAC, ABAC, and other authorization patterns
- Policies Guide — Deep dive into policy management features
- Decision Nodes — Set up your policy decision point for production