New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

pi-opa

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pi-opa

Enterprise-grade Open Policy Agent (OPA) integration for pi coding agent - comprehensive authorization, authentication, and policy enforcement

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

pi-opa

Enterprise-grade Open Policy Agent (OPA) integration for pi coding agent. Provides comprehensive authorization, authentication, and policy enforcement for multi-agent systems.

Overview

pi-opa brings enterprise-class authorization to pi using the industry-standard Open Policy Agent (OPA). It enables:

  • Policy-as-Code - Define authorization rules in Rego language
  • Multi-dimensional Access Control - WHO, WHAT, WHEN, WHERE, WHY
  • Audit Logging - Complete decision trail for compliance
  • A2A Integration - Secure multi-agent authorization
  • Dynamic Policy Updates - Hot-reload without restarting

Prerequisites

  • pi coding agent >= 1.0.0
  • Node.js >= 18.0.0
  • OPA binary installed (opa) - Install OPA

Installation

# Via npm (recommended)
pi install npm:pi-opa

# Via git
pi install git:github.com/DrOlu/pi-opa

Quick Start

1. Start OPA Server

/opa-start
# OPA server started on localhost:8181

2. Create a Policy

/opa-template my_policy
# Created: ~/.pi/agent/opa/policies/my_policy.rego

3. Edit the Policy

Edit the generated policy file to add your rules.

4. Test Authorization

/opa-check ci-bot deploy production
# ✅ ALLOWED
# Agent: ci-bot
# Action: deploy
# Resource: production
# Reason: Agent has high trust level and is within business hours

Features

Authorization Commands

CommandDescription
/opa-checkCheck authorization for an action
/opa-startStart OPA server
/opa-stopStop OPA server
/opa-statusShow OPA status

Policy Management

CommandDescription
/opa-loadLoad policies from directory
/opa-testTest policies
/opa-validateValidate policy syntax
/opa-templateCreate policy template

Audit & Logging

CommandDescription
/opa-auditShow authorization audit log
/opa-export-auditExport audit log (json/csv)

Configuration

CommandDescription
/opa-configConfigure settings
/opa-helpShow help

Policy Language (Rego)

Policies are written in OPA's Rego language:

package pi.authz

# Default deny
default allow := false

# Allow trusted agents to read non-sensitive resources
allow if {
    input.agent.trust_level == "high"
    input.action.category == "read"
    input.resource.classification != "secret"
}

# Deny destructive actions after hours
deny contains violation if {
    input.action.category == "delete"
    not is_business_hours
    violation := {
        "policy": "business_hours",
        "rule": "no_destructive_after_hours",
        "message": "Destructive actions not allowed outside 9-5"
    }
}

is_business_hours if {
    time.now_ns >= time.parse_rfc3339_ns("2026-01-01T09:00:00Z")
    time.now_ns <= time.parse_rfc3339_ns("2026-01-01T17:00:00Z")
}

Multi-Dimensional Access Control

OPA can evaluate multiple factors:

  • WHO - Agent identity, roles, trust level
  • WHAT - Action type, sensitivity
  • WHERE - Network zone, IP address, VPN status
  • WHEN - Time of day, business hours
  • WHY - Purpose, ticket ID, approval chain

A2A Integration

pi-opa integrates with pi-a2a-communication for agent-to-agent authorization:

# Enable A2A authorization
/opa-config integration.a2aEnabled true
/opa-config integration.requireOPAForA2A true

# Now all A2A requests go through OPA
/a2a-send some-agent "do something"
# → OPA evaluates authorization first

Tools

opa_evaluate

Evaluate authorization programmatically:

{
  "tool": "opa_evaluate",
  "params": {
    "agent": "ci-bot",
    "action": "deploy",
    "resource": "production",
    "context": {
      "time": "14:00",
      "emergency": false
    }
  }
}

opa_check_policy

Validate policy syntax:

{
  "tool": "opa_check_policy",
  "params": {
    "policy_file": "./my_policy.rego"
  }
}

Configuration

Default configuration location: ~/.pi/agent/opa/config.json

{
  "opa": {
    "binaryPath": "opa",
    "serverPort": 8181,
    "serverHost": "localhost",
    "autoStart": true,
    "logLevel": "info"
  },
  "policies": {
    "directory": "~/.pi/agent/opa/policies",
    "defaultPackage": "pi.authz",
    "autoReload": true,
    "testOnLoad": true
  },
  "authorization": {
    "defaultDecision": "deny",
    "cacheDecisions": true,
    "cacheTTL": 300000,
    "requireAuthentication": true
  },
  "audit": {
    "enabled": true,
    "logDirectory": "~/.pi/agent/opa/audit",
    "retentionDays": 90,
    "logSuccessful": true,
    "logFailed": true
  }
}

Enterprise Features

Audit Logging

All authorization decisions are logged with:

  • Timestamp
  • Agent identity
  • Action and resource
  • Decision (allow/deny)
  • Policy violations
  • Duration
  • Context

Export to JSON or CSV for compliance reporting.

Policy Testing

Write tests for your policies:

package pi.authz_test

import data.pi.authz

test_allow_trusted_read if {
    authz.allow with input as {
        "agent": {"trust_level": "high"},
        "action": {"category": "read"},
        "resource": {"classification": "internal"}
    }
}

Decision Caching

Frequently evaluated decisions are cached for performance (configurable TTL).

Hot Reload

Update policies without restarting - changes take effect immediately.

Examples

Example 1: Time-Based Access

# No destructive operations after 6 PM
deny contains violation if {
    input.action.category == "delete"
    time.now_ns > time.parse_rfc3339_ns("${TODAY}T18:00:00Z")
    violation := {
        "policy": "time_based",
        "message": "Destructive ops only allowed 9-6"
    }
}

Example 2: Need-to-Know

# Customer data only for assigned agents
allow if {
    input.resource.type == "customer_data"
    input.agent.id == input.resource.assigned_agent
}

Example 3: Emergency Override

# Emergency break-glass
allow if {
    input.context.emergency == true
    input.context.incident_id != ""
    input.agent.on_call == true
}

Integration with OPA Ecosystem

pi-opa works with:

  • OPA CLI - Local policy testing
  • OPA Server - Production deployment
  • OPA Bundles - Distributed policy updates
  • OPA Discovery - Dynamic configuration
  • Styra DAS - Managed OPA service

Documentation

License

MIT License - See LICENSE

Contributing

Contributions welcome! Please ensure:

  • Code follows TypeScript best practices
  • All new features include tests
  • Documentation is updated
  • Changes are backward compatible

Support

Secure your multi-agent workflows with pi-opa! 🔒

Keywords

pi

FAQs

Package last updated on 15 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts