highflame-policy 1.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ # Code generated by highflame-policy-codegen. DO NOT EDIT.
2
+ # Source: schema/highflame.cedarschema
3
+
4
+ """Highflame Policy - Cedar schema types and constants."""
5
+
6
+ from .entities import (
7
+ Entity,
8
+ EntityType,
9
+ EntityUID,
10
+ new_entity,
11
+ new_entity_uid,
12
+ )
13
+ from .actions import ActionType, action_uid
14
+ from .context import ContextKey
15
+
16
+ # Non-generated modules (require cedarpy)
17
+ from .engine import PolicyEngine, Decision
18
+
19
+ __all__ = [
20
+ # Entities
21
+ "Entity",
22
+ "EntityType",
23
+ "EntityUID",
24
+ "new_entity",
25
+ "new_entity_uid",
26
+ # Actions
27
+ "ActionType",
28
+ "action_uid",
29
+ # Context
30
+ "ContextKey",
31
+ # Engine
32
+ "PolicyEngine",
33
+ "Decision",
34
+ ]
@@ -0,0 +1,32 @@
1
+ # Code generated by highflame-policy-codegen. DO NOT EDIT.
2
+ # Source: schema/highflame.cedarschema
3
+
4
+ """Action types for Highflame Cedar policies."""
5
+
6
+ from .entities import EntityUID
7
+
8
+ class ActionType:
9
+ """Action types defined in the Highflame Cedar schema."""
10
+
11
+ ACCESS_SERVER_RESOURCE: str = "access_server_resource"
12
+ CALL_TOOL: str = "call_tool"
13
+ CONNECT_SERVER: str = "connect_server"
14
+ DEPLOY_MODEL: str = "deploy_model"
15
+ HTTP_REQUEST: str = "http_request"
16
+ LOAD_MODEL: str = "load_model"
17
+ PROCESS_PROMPT: str = "process_prompt"
18
+ PROCESS_RESPONSE: str = "process_response"
19
+ QUARANTINE_ARTIFACT: str = "quarantine_artifact"
20
+ READ_FILE: str = "read_file"
21
+ SCAN_ARTIFACT: str = "scan_artifact"
22
+ SCAN_PACKAGE: str = "scan_package"
23
+ SCAN_TARGET: str = "scan_target"
24
+ SKIP_GUARDRAILS: str = "skip_guardrails"
25
+ VALIDATE_INTEGRITY: str = "validate_integrity"
26
+ VALIDATE_PROVENANCE: str = "validate_provenance"
27
+ WRITE_FILE: str = "write_file"
28
+
29
+
30
+ def action_uid(action: str) -> EntityUID:
31
+ """Create an EntityUID for an action."""
32
+ return {"type": "Action", "id": action}
@@ -0,0 +1,105 @@
1
+ # Code generated by highflame-policy-codegen. DO NOT EDIT.
2
+ # Source: schema/context.yaml
3
+
4
+ """Context attribute keys for Highflame Cedar policies."""
5
+
6
+ class ContextKey:
7
+ """Context attribute keys for Cedar policy evaluation."""
8
+
9
+ # Guardrails/Core context attributes
10
+ # Name of tool being called
11
+ TOOL_NAME: str = "tool_name"
12
+ # Name of resource being accessed
13
+ RESOURCE_NAME: str = "resource_name"
14
+ # Name of prompt
15
+ PROMPT_NAME: str = "prompt_name"
16
+ # Raw prompt text
17
+ PROMPT_TEXT: str = "prompt_text"
18
+ # Response size in megabytes
19
+ RESPONSE_SIZE_MB: str = "response_size_mb"
20
+ # Set of detected YARA threat names
21
+ YARA_THREATS: str = "yara_threats"
22
+ # Number of threats detected
23
+ THREAT_COUNT: str = "threat_count"
24
+ # Highest severity (0-4)
25
+ MAX_THREAT_SEVERITY: str = "max_threat_severity"
26
+ # User type: external or internal
27
+ USER_TYPE: str = "user_type"
28
+ # Whether monitoring is active
29
+ MONITORING_ENABLED: str = "monitoring_enabled"
30
+ # File path
31
+ PATH: str = "path"
32
+ # HTTP hostname
33
+ HOSTNAME: str = "hostname"
34
+ # IP address
35
+ IP_ADDRESS: str = "ip_address"
36
+ # Whether the IP is private/loopback (set by application layer)
37
+ IS_PRIVATE_IP: str = "is_private_ip"
38
+ # HTTP scheme
39
+ SCHEME: str = "scheme"
40
+ # Port number
41
+ PORT: str = "port"
42
+
43
+ # Palisade context attributes
44
+ # Environment: production, development, research
45
+ ENVIRONMENT: str = "environment"
46
+ # Format: pickle, safetensors, gguf, onnx
47
+ ARTIFACT_FORMAT: str = "artifact_format"
48
+ # Whether artifact has signature
49
+ ARTIFACT_SIGNED: str = "artifact_signed"
50
+ # Severity: CRITICAL, HIGH, MEDIUM, LOW, INFO
51
+ SEVERITY: str = "severity"
52
+ # Type of security finding
53
+ FINDING_TYPE: str = "finding_type"
54
+ # Who signed the artifact
55
+ PROVENANCE_SIGNER: str = "provenance_signer"
56
+ # RCE path found in pickle
57
+ PICKLE_EXEC_PATH_DETECTED: str = "pickle_exec_path_detected"
58
+ # Malicious pattern in metadata
59
+ METADATA_MALICIOUS_PATTERN: str = "metadata_malicious_pattern"
60
+ # Number of added tokens
61
+ TOKENIZER_ADDED_TOKENS_COUNT: str = "tokenizer_added_tokens_count"
62
+ # Safetensors integrity failed
63
+ SAFETENSORS_INTEGRITY_VIOLATION: str = "safetensors_integrity_violation"
64
+ # Suspicious GGUF metadata
65
+ GGUF_SUSPICIOUS_METADATA: str = "gguf_suspicious_metadata"
66
+ # LoRA adapter digest mismatch
67
+ ADAPTER_BASE_DIGEST_MISMATCH: str = "adapter_base_digest_mismatch"
68
+ # CoSAI maturity level (0-5)
69
+ METADATA_COSAI_LEVEL_NUMERIC: str = "metadata_cosai_level_numeric"
70
+
71
+ # Overwatch context attributes
72
+ # IDE source: cursor, claudecode, vscode, geminicli
73
+ SOURCE: str = "source"
74
+ # Hook event type: beforeShellExecution, PreToolUse, etc.
75
+ EVENT: str = "event"
76
+ # The prompt/request content being evaluated
77
+ CONTENT: str = "content"
78
+ # User's email address (or 'anonymous')
79
+ USER_EMAIL: str = "user_email"
80
+ # Custom principal ID for policy evaluation
81
+ CEDAR_PRINCIPAL: str = "cedar_principal"
82
+ # MCP server name: filesystem, playwright, etc.
83
+ SERVER_NAME: str = "server_name"
84
+ # Whether the path is within the workspace
85
+ IS_WITHIN_WORKSPACE: str = "is_within_workspace"
86
+ # Response content from tool execution
87
+ RESPONSE_CONTENT: str = "response_content"
88
+ # Highest severity level: critical, high, medium, low
89
+ HIGHEST_SEVERITY: str = "highest_severity"
90
+ # Array of threat types detected
91
+ THREAT_TYPES: str = "threat_types"
92
+ # Array of threat categories found
93
+ THREAT_CATEGORIES: str = "threat_categories"
94
+ # Whether secrets were detected in the content
95
+ CONTAINS_SECRETS: str = "contains_secrets"
96
+ # Number of concurrent calls
97
+ CONCURRENT_CALLS: str = "concurrent_calls"
98
+ # Request rate per minute
99
+ REQUESTS_PER_MINUTE: str = "requests_per_minute"
100
+ # User trust level: high, medium, low
101
+ USER_TRUST_LEVEL: str = "user_trust_level"
102
+ # Whether alerting is enabled for this request
103
+ ALERT_ENABLED: str = "alert_enabled"
104
+ # Type of security scan being performed
105
+ SCAN_TYPE: str = "scan_type"
@@ -0,0 +1,148 @@
1
+ """
2
+ Highflame Policy Engine - Python Wrapper
3
+ Wraps cedarpy with Highflame-specific types
4
+ """
5
+
6
+ from dataclasses import dataclass
7
+ from typing import Any, Optional
8
+
9
+ import cedarpy
10
+
11
+ from .entities import EntityType
12
+ from .actions import ActionType
13
+
14
+
15
+ @dataclass
16
+ class EntityUID:
17
+ """Cedar entity unique identifier."""
18
+ type: str
19
+ id: str
20
+
21
+
22
+ @dataclass
23
+ class Decision:
24
+ """Result of a policy evaluation."""
25
+ effect: str # "Allow" or "Deny"
26
+ determining_policies: list[str]
27
+ reason: Optional[str] = None
28
+
29
+ def is_allowed(self) -> bool:
30
+ return self.effect == "Allow"
31
+
32
+ def is_denied(self) -> bool:
33
+ return self.effect == "Deny"
34
+
35
+
36
+ class PolicyEngine:
37
+ """
38
+ PolicyEngine wraps cedarpy with Highflame schema types.
39
+
40
+ Example:
41
+ engine = PolicyEngine()
42
+ engine.load_policies_from_file("policies/palisade/policy.cedar")
43
+
44
+ decision = engine.evaluate(
45
+ principal_type=EntityType.SCANNER,
46
+ principal_id="palisade",
47
+ action=ActionType.SCAN_ARTIFACT,
48
+ resource_type=EntityType.ARTIFACT,
49
+ resource_id="/path/to/model.safetensors",
50
+ context={
51
+ "artifact_format": "safetensors",
52
+ "severity": "HIGH",
53
+ "environment": "production",
54
+ }
55
+ )
56
+
57
+ if decision.is_denied():
58
+ print(f"Blocked by: {decision.determining_policies}")
59
+ """
60
+
61
+ def __init__(self):
62
+ self._policies: str = ""
63
+ self._schema: Optional[str] = None
64
+
65
+ def load_policies_from_file(self, path: str) -> None:
66
+ """Load Cedar policies from a file."""
67
+ with open(path, "r") as f:
68
+ self._policies = f.read()
69
+
70
+ def load_policies(self, policies: str) -> None:
71
+ """Load Cedar policies from a string."""
72
+ self._policies = policies
73
+
74
+ def load_schema_from_file(self, path: str) -> None:
75
+ """Load Cedar schema from a file."""
76
+ with open(path, "r") as f:
77
+ self._schema = f.read()
78
+
79
+ def load_schema(self, schema: str) -> None:
80
+ """Load Cedar schema from a string."""
81
+ self._schema = schema
82
+
83
+ def evaluate(
84
+ self,
85
+ principal_type: str,
86
+ principal_id: str,
87
+ action: str,
88
+ resource_type: str,
89
+ resource_id: str,
90
+ context: Optional[dict[str, Any]] = None,
91
+ ) -> Decision:
92
+ """
93
+ Evaluate a policy request and return a decision.
94
+
95
+ Args:
96
+ principal_type: Entity type of the principal (e.g., EntityType.USER)
97
+ principal_id: ID of the principal
98
+ action: Action being performed (e.g., ActionType.SCAN_ARTIFACT)
99
+ resource_type: Entity type of the resource (e.g., EntityType.ARTIFACT)
100
+ resource_id: ID of the resource
101
+ context: Optional context attributes for the request
102
+
103
+ Returns:
104
+ Decision with effect, determining policies, and optional reason
105
+ """
106
+ # Format entity UIDs for Cedar
107
+ principal = f'{principal_type}::"{principal_id}"'
108
+ action_uid = f'Action::"{action}"'
109
+ resource = f'{resource_type}::"{resource_id}"'
110
+
111
+ # Call cedarpy (v4.8.0+ uses request dict instead of separate args)
112
+ request = {
113
+ "principal": principal,
114
+ "action": action_uid,
115
+ "resource": resource,
116
+ "context": context or {},
117
+ }
118
+ result = cedarpy.is_authorized(
119
+ request=request,
120
+ policies=self._policies,
121
+ entities=[],
122
+ )
123
+
124
+ # Map result to Decision (using result.allowed for cleaner API)
125
+ return Decision(
126
+ effect="Allow" if result.allowed else "Deny",
127
+ determining_policies=list(result.diagnostics.reasons) if result.diagnostics else [],
128
+ reason="; ".join(result.diagnostics.errors) if result.diagnostics and result.diagnostics.errors else None,
129
+ )
130
+
131
+ def validate_policies(self, policies: str) -> list[str]:
132
+ """
133
+ Validate policies against the loaded schema.
134
+
135
+ Returns:
136
+ List of validation error messages, or empty list if valid.
137
+ """
138
+ if not self._schema:
139
+ return ["No schema loaded for validation"]
140
+
141
+ result = cedarpy.validate(
142
+ policies=policies,
143
+ schema=self._schema,
144
+ )
145
+
146
+ if result.validation_errors:
147
+ return [str(e) for e in result.validation_errors]
148
+ return []
@@ -0,0 +1,61 @@
1
+ # Code generated by highflame-policy-codegen. DO NOT EDIT.
2
+ # Source: schema/highflame.cedarschema
3
+
4
+ """Entity types for Highflame Cedar policies."""
5
+
6
+ from typing import Any, TypedDict
7
+
8
+ class EntityType:
9
+ """Entity types defined in the Highflame Cedar schema."""
10
+
11
+ AGENT: str = "Agent"
12
+ ARTIFACT: str = "Artifact"
13
+ FILE_PATH: str = "FilePath"
14
+ HTTP_ENDPOINT: str = "HttpEndpoint"
15
+ PACKAGE: str = "Package"
16
+ REPOSITORY: str = "Repository"
17
+ RESOURCE: str = "Resource"
18
+ RESPONSE_DATA: str = "ResponseData"
19
+ SCANNER: str = "Scanner"
20
+ SERVER: str = "Server"
21
+ SERVICE: str = "Service"
22
+ TOOL: str = "Tool"
23
+ USER: str = "User"
24
+
25
+
26
+ class EntityUID(TypedDict):
27
+ """Cedar entity unique identifier."""
28
+
29
+ type: str
30
+ id: str
31
+
32
+
33
+ class Entity(TypedDict, total=False):
34
+ """Cedar entity with attributes."""
35
+
36
+ uid: EntityUID
37
+ attrs: dict[str, Any]
38
+ parents: list[EntityUID]
39
+
40
+
41
+ def new_entity_uid(entity_type: str, entity_id: str) -> EntityUID:
42
+ """
43
+ Create a new EntityUID.
44
+
45
+ Services should use this with their own identity from config/environment.
46
+ Example: new_entity_uid(EntityType.SCANNER, os.environ['SERVICE_ID'])
47
+ """
48
+ return {"type": entity_type, "id": entity_id}
49
+
50
+
51
+ def new_entity(
52
+ entity_type: str,
53
+ entity_id: str,
54
+ attrs: dict[str, Any] | None = None,
55
+ ) -> Entity:
56
+ """Create a new Entity."""
57
+ return {
58
+ "uid": {"type": entity_type, "id": entity_id},
59
+ "attrs": attrs or {},
60
+ "parents": [],
61
+ }
@@ -0,0 +1,22 @@
1
+ Metadata-Version: 2.4
2
+ Name: highflame-policy
3
+ Version: 1.1.1
4
+ Summary: Highflame Cedar policy types and engine wrapper
5
+ License: Apache-2.0
6
+ Project-URL: Homepage, https://github.com/highflame-ai/highflame-policy
7
+ Project-URL: Repository, https://github.com/highflame-ai/highflame-policy.git
8
+ Keywords: cedar,policy,authorization,highflame
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Requires-Python: >=3.9
18
+ Description-Content-Type: text/markdown
19
+ Requires-Dist: cedarpy>=4.0.0
20
+ Provides-Extra: dev
21
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
22
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
@@ -0,0 +1,9 @@
1
+ highflame_policy/__init__.py,sha256=Ovcl_S13N3FJpZegN9gEsUpmgLZSUg5x7aapFNNJC4U,676
2
+ highflame_policy/actions.py,sha256=767MmcBl6Dp6TuC8z9NCasoc2VMWPNdhHbOxMJc6vXU,1121
3
+ highflame_policy/context.py,sha256=5AiXoWyB_KlAxm49Kt7-TB_LlOD9uIIM3R-CDhgZInE,4106
4
+ highflame_policy/engine.py,sha256=qtJDFC7UnzKEcb0ltJ115Go5ChgNVaU6Ks33kAzGe4Q,4462
5
+ highflame_policy/entities.py,sha256=y1tuFjN16bVbsHHVktdCx8Qh5SdR8faaYVvqRnqgXKs,1501
6
+ highflame_policy-1.1.1.dist-info/METADATA,sha256=M44FuCWr5B5M6mDFqtj7zGGecSdk6XVV1esL3P6SumU,942
7
+ highflame_policy-1.1.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
8
+ highflame_policy-1.1.1.dist-info/top_level.txt,sha256=kewf3s1KO3EJHyf29rFyM1FggQOrTlDT0nnurTrNpRQ,17
9
+ highflame_policy-1.1.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.10.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ highflame_policy