Alec Handal
11/05/2025, 6:07 AMAsk Inkeep
11/05/2025, 6:07 AMAsk Inkeep
11/05/2025, 6:07 AMenv apply openapi command specifically for this purpose. (1) (2)
Using OpenAPI to Define Policies
The command creates a full policy schema in Permit by reading an OpenAPI spec file and using -x-permit extensions. (1) You can run it with:
permit env apply openapi --spec-file ./api-spec.json
(1) (2)
Or with a remote file:
permit env apply openapi --key permit_key_... --spec-file <https://raw.githubusercontent.com/daveads/openapispec/main/blog-api.json>
OpenAPI Extensions for Policy Definition
You define policies using these -x-permit extensions in your OpenAPI spec:
*Path Level:*
• x-permit-resource - The resource name (required)
*Operation Level (HTTP Method) :*
• x-permit-action - Action name (defaults to HTTP method if not provided)
• x-permit-role - Top-level role allowed for the operation
• x-permit-resource-role - Resource-level role allowed for the operation
Here's an example OpenAPI spec with Permit extensions:
openapi: 3.0.3
info:
title: 'Blog API with Permit Extensions'
version: '1.0.0'
paths:
/posts:
x-permit-resource: blog_post
get:
summary: List all posts
x-permit-action: list
x-permit-role: viewer
post:
summary: Create a new post
x-permit-action: create
x-permit-role: editor
x-permit-resource-role: post_creator
/posts/{postId}:
x-permit-resource: blog_post
delete:
summary: Delete a post
x-permit-action: delete
x-permit-role: admin
The CLI will automatically create URL mappings in Permit that connect API endpoints to the appropriate resources and actions for runtime authorization checks. (1) Ask Inkeep
11/05/2025, 6:07 AMOr Weis
11/05/2025, 6:12 AMAsk Inkeep
11/05/2025, 6:12 AMAsk Inkeep
11/05/2025, 6:12 AMterraform {
required_providers {
permitio = {
source = "<http://registry.terraform.io/permitio/permit-io|registry.terraform.io/permitio/permit-io>"
version = "~> 0.0.14" ///# Use the latest version
}
}
}
///# Configure the <http://Permit.io|Permit.io> provider
provider "permitio" {
api_key = "YOUR_API_KEY" ///# Replace with your actual API key
///# api_url = "<https://api.permit.io>" # Optional: defaults to <https://api.permit.io>
}
///# Define a resource (e.g., documents in your application)
resource "permitio_resource" "document" {
key = "document"
name = "Document"
description = "A confidential document that users can read and write"
actions = {
"read" = {
"name" = "Read"
"description" = "Read a document"
}
"write" = {
"name" = "Write"
"description" = "Write to a document"
}
"delete" = {
"name" = "Delete"
"description" = "Delete a document"
}
}
attributes = {
"title" = {
"description" = "The title of the document"
"type" = "string"
}
"owner" = {
"description" = "The owner of the document"
"type" = "string"
}
}
}
///# Define roles with specific permissions
resource "permitio_role" "reader" {
key = "reader"
name = "Reader"
description = "Can read documents but cannot modify them"
permissions = ["document:read"]
depends_on = [permitio_resource.document]
}
(3)
The Terraform Provider enables developers to configure and version policy schemas with Terraform scripts, integrating policy management directly into their software development lifecycle (SDLC) . (2) You can version policies, manage branches, and integrate them seamlessly with your CI/CD pipeline.
SDKs for Policy Creation
According to the SDK Feature Parity documentation, Permit provides SDKs for NodeJS, Go, .NET, Java, Python, Ruby, and Terraform. (4) The SDKs support various policy management features including:
• Users
• Resources
• Tenants
• Projects
• Environments
• Roles
• Role Assignments
• Condition Sets
• Condition Set Rules
• Relationship Tuples
• Resource Relations
• Role Derivations
• Resource Instances
• Resource Roles
• Resource Actions
• Resource Action Groups
• Resource Attributes
The management and synchronization of data can be handled through API/SDK integration, which is the most straightforward method for syncing data by integrating SDKs or direct API calls from within the application code. (9) Ask Inkeep
11/05/2025, 6:12 AMAlec Handal
11/05/2025, 6:21 AMOr Weis
11/05/2025, 6:25 AM