Skip to main content

Module policy_annotations

Module policy_annotations 

Source
Expand description

Policy annotation parser for Cedar policies.

This module parses rustdoc-style annotations from Cedar policy comments to extract metadata for UI display and policy management.

§Annotation Format

/// @title Allow Write Operations
/// @description Permits adding and updating states in the policy database.
/// These operations are considered safe for automated execution.
/// @category write
/// @risk medium
/// @editable true
permit(
  principal,
  action == Action::"executeMutation",
  resource
) when {
  resource.mutation in ["addState", "updateState"]
};

§Supported Annotations

AnnotationRequiredDescription
@titleYesShort display name for the policy
@descriptionYesMulti-line description (continuation lines without @)
@categoryYesOne of: read, write, delete, fields, admin
@riskYesOne of: low, medium, high, critical
@editableNoWhether admins can modify (default: true)
@reasonNoWhy the policy exists or is non-editable
@authorNoWho created or last modified
@modifiedNoISO date of last modification

§Category Mapping

The unified categories work across all server types:

  • read: Queries (GraphQL), GET (OpenAPI), SELECT (SQL)
  • write: Create/update mutations, POST/PUT/PATCH, INSERT/UPDATE
  • delete: Delete mutations, DELETE, DELETE/TRUNCATE
  • admin: Introspection, schema access, DDL
  • fields: Field-level access control

Legacy category names are still supported for parsing: queriesread, mutationswrite, introspectionadmin.

Structs§

PolicyMetadata
Parsed policy metadata from Cedar doc comments.

Enums§

PolicyCategory
Unified policy category for grouping in the UI. Works consistently across GraphQL, OpenAPI, and SQL servers.
PolicyRiskLevel
Risk level for visual indication in the UI.
PolicyValidationError
Validation error for policy annotations.

Functions§

generate_policy_cedar
Generate Cedar policy text with annotations from metadata.
infer_category_and_risk_from_cedar
Infer category and risk from Cedar policy content when annotations are missing.
parse_policy_annotations
Parse Cedar policy annotations from doc comments.