Guides
Policy Enforcement

Policy Enforcement

AZTP uses OPA (Open Policy Agent) to provide fine-grained access control for AI agents.

Understanding OPA Policies

In AZTP, policies are written in Rego (OPA's policy language) and define:

  • What actions agents can perform
  • Under what conditions
  • With what data
  • For which targets

Policy Structure

A basic AZTP policy has these key elements:

# Package declaration - always use aztp.policy
package aztp.policy

# Default deny for safety
default allow = false

# Allow rules define when actions are permitted
allow {
    # Rule conditions go here
    input.action in ["read", "write"]
}

Policy Evaluation Flow

When an agent calls can(), AZTP:

  1. Verifies the agent's identity
  2. Prepares the policy input
  3. Evaluates the policy
  4. Returns the decision

Best Practices

  1. Default Deny

    • Always start with default allow = false
    • Explicitly define what's allowed
    • Never default to allow
  2. Policy Organization

    • Group related rules together
    • Use helper rules for common checks
    • Comment complex logic
  3. Input Validation

    • Always validate SPIFFE IDs
    • Check action strings
    • Validate payload data

Common Patterns

Role-Based Access

# Define roles and permissions
roles := {
    "reader": ["read"],
    "writer": ["read", "write"],
    "admin": ["read", "write", "delete"]
}

# Allow based on role
allow {
    # Get agent's role from SPIFFE ID path
    role := split(input.sender.spiffeId.path, "/")[1]
    
    # Check if action is allowed for role
    roles[role][_] == input.action
}

Environment-Based Policies

# Allow more actions in development
allow {
    # Check if in development environment
    endswith(input.sender.spiffeId.trustDomain, "dev.company.org")
    
    # Allow all actions in development
    input.action in ["read", "write", "delete"]
}

# Strict rules for production
allow {
    endswith(input.sender.spiffeId.trustDomain, "prod.company.org")
    
    # Limited actions in production
    input.action in ["read"]
}